Skip to content

Commit c1d3164

Browse files
committed
Add comments for Ident::from_name and identifiers in path segments
1 parent eb789de commit c1d3164

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/librustc_front/hir.rs

+14
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ pub struct Ident {
6363
}
6464

6565
impl Ident {
66+
/// Creates a HIR identifier with both `name` and `unhygienic_name` initialized with
67+
/// the argument. Hygiene properties of the created identifier depend entirely on this
68+
/// argument. If the argument is a plain interned string `intern("iter")`, then the result
69+
/// is unhygienic and can interfere with other entities named "iter". If the argument is
70+
/// a "fresh" name created with `gensym("iter")`, then the result is hygienic and can't
71+
/// interfere with other entities having the same string as a name.
6672
pub fn from_name(name: Name) -> Ident {
6773
Ident { name: name, unhygienic_name: name }
6874
}
@@ -157,6 +163,14 @@ impl fmt::Display for Path {
157163
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
158164
pub struct PathSegment {
159165
/// The identifier portion of this path segment.
166+
///
167+
/// Hygiene properties of this identifier are worth noting.
168+
/// Most path segments are not hygienic and they are not renamed during
169+
/// lowering from AST to HIR (see comments to `fn lower_path`). However segments from
170+
/// unqualified paths with one segment originating from `ExprPath` (local-variable-like paths)
171+
/// can be hygienic, so they are renamed. You should not normally care about this peculiarity
172+
/// and just use `identifier.name` unless you modify identifier resolution code
173+
/// (`fn resolve_identifier` and other functions called by it in `rustc_resolve`).
160174
pub identifier: Ident,
161175

162176
/// Type/lifetime parameters attached to this path. They come in

0 commit comments

Comments
 (0)