]> git.lizzy.rs Git - rust.git/commitdiff
Use full name to identify a macro in a `FileName`.
authorDiogo Sousa <diogogsousa@gmail.com>
Wed, 19 Sep 2018 00:09:36 +0000 (01:09 +0100)
committerDiogo Sousa <diogogsousa@gmail.com>
Wed, 19 Sep 2018 00:12:13 +0000 (01:12 +0100)
Before this two macros with same name would be indistinguishable inside a
`FileName`.  This caused a bug in incremental compilation (see #53097) since
two different macros would map out to the same `StableFilemapId`.

Fixes #53097.

src/librustc/hir/map/definitions.rs
src/librustc/ty/query/on_disk_cache.rs
src/librustc_metadata/creader.rs
src/librustc_metadata/cstore.rs
src/librustc_metadata/cstore_impl.rs
src/librustc_metadata/decoder.rs
src/libsyntax_pos/lib.rs
src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr
src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr
src/test/ui/imports/local-modularized-tricky-fail-1.stderr
src/test/ui/macro_backtrace/main.stderr

index c85cee736605533781bf9a876283e1b435737ecf..fa4bf1511b87434bc6c1d2094293f2b96fed6afe 100644 (file)
@@ -287,6 +287,31 @@ pub fn to_string_no_crate(&self) -> String {
         s
     }
 
+    /// Return filename friendly string of the DefPah with the
+    /// crate-prefix.
+    pub fn to_string_friendly<F>(&self, crate_imported_name: F) -> String
+        where F: FnOnce(CrateNum) -> Symbol
+    {
+        let crate_name_str = crate_imported_name(self.krate).as_str();
+        let mut s = String::with_capacity(crate_name_str.len() + self.data.len() * 16);
+
+        write!(s, "::{}", crate_name_str).unwrap();
+
+        for component in &self.data {
+            if component.disambiguator == 0 {
+                write!(s, "::{}", component.data.as_interned_str()).unwrap();
+            } else {
+                write!(s,
+                       "{}[{}]",
+                       component.data.as_interned_str(),
+                       component.disambiguator)
+                    .unwrap();
+            }
+        }
+
+        s
+    }
+
     /// Return filename friendly string of the DefPah without
     /// the crate-prefix. This method is useful if you don't have
     /// a TyCtxt available.
index 0e4d2f1f64730c940c91846871eef34fc9b642bb..296602e21bad74f13c0871478811dc8eb62adfdb 100644 (file)
@@ -606,6 +606,7 @@ fn specialized_decode(&mut self) -> Result<interpret::AllocId, Self::Error> {
         alloc_decoding_session.decode_alloc_id(self)
     }
 }
+
 impl<'a, 'tcx, 'x> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx, 'x> {
     fn specialized_decode(&mut self) -> Result<Span, Self::Error> {
         let tag: u8 = Decodable::decode(self)?;
index 6eef2397f9c6ed9b0cb28e0bd0ca9048aed2c27d..fa2debf2c0dc75e1cad65d7bf402f87c5d615af8 100644 (file)
@@ -256,6 +256,7 @@ fn register_crate(&mut self,
 
         let cmeta = cstore::CrateMetadata {
             name: crate_root.name,
+            imported_name: ident,
             extern_crate: Lock::new(None),
             def_path_table: Lrc::new(def_path_table),
             trait_impls,
index aad632f89180dd09e52b5fe963f5b82fcba71b03..ec48a4a4c6997187fd3e2a8cf1cbdbfa39e087a1 100644 (file)
@@ -53,8 +53,13 @@ pub struct ImportedSourceFile {
 }
 
 pub struct CrateMetadata {
+    /// Original name of the crate.
     pub name: Symbol,
 
+    /// Name of the crate as imported.  I.e. if imported with
+    /// `extern crate foo as bar;` this will be `bar`.
+    pub imported_name: Symbol,
+
     /// Information about the extern crate that caused this crate to
     /// be loaded. If this is `None`, then the crate was injected
     /// (e.g., by the allocator)
index d2285e8cbf1bea5ac1884b1bffdf2453c5023751..1236857826c1ce0325240843bf4215ae797659b0 100644 (file)
@@ -447,8 +447,7 @@ pub fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro {
         let data = self.get_crate_data(id.krate);
         if let Some(ref proc_macros) = data.proc_macros {
             return LoadedMacro::ProcMacro(proc_macros[id.index.to_proc_macro_index()].1.clone());
-        } else if data.name == "proc_macro" &&
-                  self.get_crate_data(id.krate).item_name(id.index) == "quote" {
+        } else if data.name == "proc_macro" && data.item_name(id.index) == "quote" {
             use syntax::ext::base::SyntaxExtension;
             use syntax_ext::proc_macro_impl::BangProcMacro;
 
@@ -460,8 +459,9 @@ pub fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro {
             return LoadedMacro::ProcMacro(Lrc::new(ext));
         }
 
-        let (name, def) = data.get_macro(id.index);
-        let source_name = FileName::Macros(name.to_string());
+        let def = data.get_macro(id.index);
+        let macro_full_name = data.def_path(id.index).to_string_friendly(|_| data.imported_name);
+        let source_name = FileName::Macros(macro_full_name);
 
         let source_file = sess.parse_sess.source_map().new_source_file(source_name, def.body);
         let local_span = Span::new(source_file.start_pos, source_file.end_pos, NO_EXPANSION);
index 9907df7ed02400094a1de14a4e2691184ced1f46..3f93bfcc3ae223333e4269489114f927552d5af7 100644 (file)
@@ -1069,10 +1069,10 @@ pub fn get_rendered_const(&self, id: DefIndex) -> String {
         }
     }
 
-    pub fn get_macro(&self, id: DefIndex) -> (InternedString, MacroDef) {
+    pub fn get_macro(&self, id: DefIndex) -> MacroDef {
         let entry = self.entry(id);
         match entry.kind {
-            EntryKind::MacroDef(macro_def) => (self.item_name(id), macro_def.decode(self)),
+            EntryKind::MacroDef(macro_def) => macro_def.decode(self),
             _ => bug!(),
         }
     }
index bd70344b018127992879e1f0684868c91cad8035..67fd847a2ae9197790a0d2a71917e0cec74d84fb 100644 (file)
@@ -87,7 +87,7 @@ pub fn new() -> Globals {
 #[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, RustcDecodable, RustcEncodable)]
 pub enum FileName {
     Real(PathBuf),
-    /// e.g. "std" macros
+    /// A macro.  This includes the full name of the macro, so that there are no clashes.
     Macros(String),
     /// call to `quote!`
     QuoteExpansion,
index 02e7d5b7cd01cc530acf271dc580df69078a0c46..5955410aa106b15582ac56b85c2e04d29e5a31f0 100644 (file)
@@ -23,7 +23,7 @@ LL |     r#async = consumes_async_raw!(async); //~ ERROR no rules expected the t
    |                                   ^^^^^
 
 error: expected one of `move`, `|`, or `||`, found `<eof>`
-  --> <passes_ident macros>:1:22
+  --> <::edition_kw_macro_2015::passes_ident macros>:1:22
    |
 LL | ( $ i : ident ) => ( $ i )
    |                      ^^^ expected one of `move`, `|`, or `||` here
index 435e395c2910e39919a5c93dbc27d244b53a55ff..6ea736828f9078e95716a36760032b4b3d3b50fe 100644 (file)
@@ -23,7 +23,7 @@ LL |     r#async = consumes_async_raw!(async); //~ ERROR no rules expected the t
    |                                   ^^^^^
 
 error: expected one of `move`, `|`, or `||`, found `<eof>`
-  --> <passes_ident macros>:1:22
+  --> <::edition_kw_macro_2018::passes_ident macros>:1:22
    |
 LL | ( $ i : ident ) => ( $ i )
    |                      ^^^ expected one of `move`, `|`, or `||` here
index cce1fd30f1d6db14ae3e90934113884afbc47c88..9c475451ce32f64e14cdd86af0a7e6512f7c0968 100644 (file)
@@ -60,7 +60,7 @@ LL |       define_panic!();
    = note: macro-expanded macros do not shadow
 
 error[E0659]: `panic` is ambiguous
-  --> <panic macros>:1:13
+  --> <::std::macros::panic macros>:1:13
    |
 LL | (  ) => ( { panic ! ( "explicit panic" ) } ) ; ( $ msg : expr ) => (
    |             ^^^^^ ambiguous name
index 10eabca63538d319c427297e79a4c2cdcec179dd..8cecef508a2b295f4fd2f156f2ec7f9ab8892b17 100644 (file)
@@ -22,7 +22,7 @@ LL | | }
 LL |       ping!();
    |       -------- in this macro invocation
    | 
-  ::: <ping macros>:1:1
+  ::: <::ping::ping macros>:1:1
    |
 LL |   (  ) => { pong ! (  ) ; }
    |   -------------------------
@@ -42,7 +42,7 @@ LL | | }
 LL |       deep!();
    |       -------- in this macro invocation (#1)
    | 
-  ::: <deep macros>:1:1
+  ::: <::ping::deep macros>:1:1
    |
 LL |   (  ) => { foo ! (  ) ; }
    |   ------------------------
@@ -50,7 +50,7 @@ LL |   (  ) => { foo ! (  ) ; }
    |   |         in this macro invocation (#2)
    |   in this expansion of `deep!` (#1)
    | 
-  ::: <foo macros>:1:1
+  ::: <::ping::foo macros>:1:1
    |
 LL |   (  ) => { bar ! (  ) ; }
    |   ------------------------
@@ -58,7 +58,7 @@ LL |   (  ) => { bar ! (  ) ; }
    |   |         in this macro invocation (#3)
    |   in this expansion of `foo!` (#2)
    | 
-  ::: <bar macros>:1:1
+  ::: <::ping::bar macros>:1:1
    |
 LL |   (  ) => { ping ! (  ) ; }
    |   -------------------------
@@ -66,7 +66,7 @@ LL |   (  ) => { ping ! (  ) ; }
    |   |         in this macro invocation (#4)
    |   in this expansion of `bar!` (#3)
    | 
-  ::: <ping macros>:1:1
+  ::: <::ping::ping macros>:1:1
    |
 LL |   (  ) => { pong ! (  ) ; }
    |   -------------------------