From e1d1487fc44104d59f3faa550b91d5e248d2bce1 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 9 Dec 2018 22:58:51 +0300 Subject: [PATCH] resolve: Prohibit use of uniform paths in macros originating from 2015 edition ...while still keeping ambiguity errors future-proofing for uniform paths. This corner case is not going to be stabilized for 1.32 and needs some more general experiments about retrofitting 2018 import rules to 2015 edition --- src/librustc_resolve/macros.rs | 13 +++++++++---- .../edition-imports-virtual-2015-gated.stderr | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 7856661741da..b2b794c6925c 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -828,7 +828,7 @@ impl<'a> Resolver<'a> { // but its `Def` should coincide with a crate passed with `--extern` // (otherwise there would be ambiguity) and we can skip feature error in this case. 'ok: { - if !is_import || self.session.features_untracked().uniform_paths { + if !is_import || (!rust_2015 && self.session.features_untracked().uniform_paths) { break 'ok; } if ns == TypeNS && use_prelude && self.extern_prelude_get(ident, true).is_some() { @@ -844,10 +844,15 @@ impl<'a> Resolver<'a> { } } - let msg = "imports can only refer to extern crate names \ - passed with `--extern` on stable channel"; + let reason = if rust_2015 { + "in macros originating from 2015 edition" + } else { + "on stable channel" + }; + let msg = format!("imports can only refer to extern crate names \ + passed with `--extern` {}", reason); let mut err = feature_err(&self.session.parse_sess, "uniform_paths", - ident.span, GateIssue::Language, msg); + ident.span, GateIssue::Language, &msg); let what = self.binding_description(binding, ident, flags.contains(Flags::MISC_FROM_PRELUDE)); diff --git a/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr b/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr index 7c1837e3f56e..3cf967dbf70e 100644 --- a/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr +++ b/src/test/ui/editions/edition-imports-virtual-2015-gated.stderr @@ -1,4 +1,4 @@ -error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130) +error[E0658]: imports can only refer to extern crate names passed with `--extern` in macros originating from 2015 edition (see issue #53130) --> <::edition_imports_2015::gen_gated macros>:1:50 | LL | ( ) => { fn check_gated ( ) { enum E { A } use E :: * ; } }