An absolute path identifies a Rust item through its complete namespace qualification. In generated code, full paths keep references independent of the user’s imports and local names. section 10.1.3
Use absolute paths in generated Rust code because they:
- Resolve items unavailable through the Rust prelude, such as std::collections::HashMap, without requiring user imports. section 10.1.3
- Avoid collisions when application code defines another item with the same name, including types or traits such as HashMap and Default. section 10.1.3 section 8.4
- Hide implementation choices so generated APIs can change their underlying types without forcing application-code changes. section 10.1.3
Qualifying generated types and traits
quote! { pub struct Config( pub std::collections::HashMap<&'static str, &'static str> ); } quote_spanned! {ty.span()=> struct ExampleStruct where SomeType: core::default::Default; } section 10.1.3 section 8.4
error[E0412]: cannot find type `HashMap` in this scope --> config-macro-usage/src/main.rs:5:5 | 5 | config!(); | ^^^^^^^^^ not found in this scope |
Inspect the compiler failure produced when generated code refers to HashMap without a qualifying path. section 10.1.3

