From 84f1bc8b662da4ceb0e448bf0d24ce627e6a462b Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 30 Jun 2018 01:53:17 +0300 Subject: [PATCH] Address comments --- src/libproc_macro/lib.rs | 5 ++++- src/librustc_resolve/lib.rs | 3 +-- src/libsyntax_pos/hygiene.rs | 1 - src/libsyntax_pos/symbol.rs | 10 +++++----- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index 820b0906a7554..fb5cbf473a387 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -1434,9 +1434,12 @@ pub mod __internal { CURRENT_SESS.with(|p| { let _reset = Reset { prev: p.get() }; - // No way to determine def location for a proc macro rigth now, so use call location. + // No way to determine def location for a proc macro right now, so use call location. let location = cx.current_expansion.mark.expn_info().unwrap().call_site; // Opaque mark was already created by expansion, now create its transparent twin. + // We can't use the call-site span literally here, even if it appears to provide + // correct name resolution, because it has all the `ExpnInfo` wrong, so the edition + // checks, lint macro checks, macro backtraces will all break. let opaque_mark = cx.current_expansion.mark; let transparent_mark = Mark::fresh_cloned(opaque_mark); transparent_mark.set_transparency(Transparency::Transparent); diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 9475b96d30bd9..8a32ec6978c4d 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2005,10 +2005,9 @@ impl<'a> Resolver<'a> { } } // Then find the last legacy mark from the end if it exists. - while let Some(&mark) = iter.peek() { + for mark in iter { if mark.transparency() == Transparency::SemiTransparent { result = Some(mark); - iter.next(); } else { break; } diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index e7f1f31084a64..33d02d0b10a7b 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -57,7 +57,6 @@ struct MarkData { pub enum Transparency { /// Identifier produced by a transparent expansion is always resolved at call-site. /// Call-site spans in procedural macros, hygiene opt-out in `macro` should use this. - /// (Not used yet.) Transparent, /// Identifier produced by a semi-transparent expansion may be resolved /// either at call-site or at definition-site. diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index fe0b479d16103..9a0c92f679366 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -68,11 +68,11 @@ impl Ident { Ident::new(self.name, self.span.modern()) } - // "Normalize" ident for use in comparisons using "local variable hygiene". - // Identifiers with same string value become same if they came from the same non-transparent - // macro (e.g. `macro` or `macro_rules!` items) and stay different if they came from different - // non-transparent macros. - // Technically, this operation strips all transparent marks from ident's syntactic context. + /// "Normalize" ident for use in comparisons using "local variable hygiene". + /// Identifiers with same string value become same if they came from the same non-transparent + /// macro (e.g. `macro` or `macro_rules!` items) and stay different if they came from different + /// non-transparent macros. + /// Technically, this operation strips all transparent marks from ident's syntactic context. pub fn modern_and_legacy(self) -> Ident { Ident::new(self.name, self.span.modern_and_legacy()) }