From 09d073a4c59dee09f69f3cb144c3067a153c30e6 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Mon, 7 Jan 2019 07:09:17 -0800 Subject: [PATCH 01/10] stabilize extern_crate_self --- src/librustc_resolve/build_reduced_graph.rs | 6 +----- src/libsyntax/feature_gate.rs | 5 ++--- .../feature-gate-extern_crate_self.rs | 3 --- .../feature-gate-extern_crate_self.stderr | 11 ----------- .../extern-crate-self-fail.rs | 2 -- .../extern-crate-self-fail.stderr | 4 ++-- .../extern-crate-self-macro-alias.rs | 16 ++++++++++++++++ .../extern-crate-self-macro-item.rs | 12 ++++++++++++ .../extern-crate-self-macro-self.rs | 16 ++++++++++++++++ .../extern-crate-self-pass.rs | 2 -- 10 files changed, 49 insertions(+), 28 deletions(-) delete mode 100644 src/test/ui/feature-gates/feature-gate-extern_crate_self.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-extern_crate_self.stderr rename src/test/ui/imports/{ => extern-crate-self}/extern-crate-self-fail.rs (85%) rename src/test/ui/imports/{ => extern-crate-self}/extern-crate-self-fail.stderr (91%) create mode 100644 src/test/ui/imports/extern-crate-self/extern-crate-self-macro-alias.rs create mode 100644 src/test/ui/imports/extern-crate-self/extern-crate-self-macro-item.rs create mode 100644 src/test/ui/imports/extern-crate-self/extern-crate-self-macro-self.rs rename src/test/ui/imports/{ => extern-crate-self}/extern-crate-self-pass.rs (79%) diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index a452bbf0c9d54..75bfdcc2f448a 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -30,7 +30,7 @@ use syntax::ext::base::{MacroKind, SyntaxExtension}; use syntax::ext::base::Determinacy::Undetermined; use syntax::ext::hygiene::Mark; use syntax::ext::tt::macro_rules; -use syntax::feature_gate::{is_builtin_attr, emit_feature_err, GateIssue}; +use syntax::feature_gate::is_builtin_attr; use syntax::parse::token::{self, Token}; use syntax::std_inject::injected_crate_name; use syntax::symbol::keywords; @@ -349,10 +349,6 @@ impl<'a> Resolver<'a> { .emit(); return; } else if orig_name == Some(keywords::SelfLower.name()) { - if !self.session.features_untracked().extern_crate_self { - emit_feature_err(&self.session.parse_sess, "extern_crate_self", item.span, - GateIssue::Language, "`extern crate self` is unstable"); - } self.graph_root } else { let crate_id = self.crate_loader.process_extern_crate(item, &self.definitions); diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index ed278e834cbc7..afbc010626276 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -453,9 +453,6 @@ declare_features! ( // Adds `reason` and `expect` lint attributes. (active, lint_reasons, "1.31.0", Some(54503), None), - // `extern crate self as foo;` puts local crate root into extern prelude under name `foo`. - (active, extern_crate_self, "1.31.0", Some(56409), None), - // Allows paths to enum variants on type aliases. (active, type_alias_enum_variants, "1.31.0", Some(49683), None), @@ -685,6 +682,8 @@ declare_features! ( (accepted, uniform_paths, "1.32.0", Some(53130), None), // Allows `cfg(target_vendor = "...")`. (accepted, cfg_target_vendor, "1.33.0", Some(29718), None), + // `extern crate self as foo;` puts local crate root into extern prelude under name `foo`. + (accepted, extern_crate_self, "1.34.0", Some(56409), None), ); // If you change this, please modify `src/doc/unstable-book` as well. You must diff --git a/src/test/ui/feature-gates/feature-gate-extern_crate_self.rs b/src/test/ui/feature-gates/feature-gate-extern_crate_self.rs deleted file mode 100644 index 2161932c2f6aa..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-extern_crate_self.rs +++ /dev/null @@ -1,3 +0,0 @@ -extern crate self as foo; //~ ERROR `extern crate self` is unstable - -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-extern_crate_self.stderr b/src/test/ui/feature-gates/feature-gate-extern_crate_self.stderr deleted file mode 100644 index 530015b2cb712..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-extern_crate_self.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0658]: `extern crate self` is unstable (see issue #56409) - --> $DIR/feature-gate-extern_crate_self.rs:1:1 - | -LL | extern crate self as foo; //~ ERROR `extern crate self` is unstable - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: add #![feature(extern_crate_self)] to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/imports/extern-crate-self-fail.rs b/src/test/ui/imports/extern-crate-self/extern-crate-self-fail.rs similarity index 85% rename from src/test/ui/imports/extern-crate-self-fail.rs rename to src/test/ui/imports/extern-crate-self/extern-crate-self-fail.rs index eab7b7032aa07..defa0e294bd74 100644 --- a/src/test/ui/imports/extern-crate-self-fail.rs +++ b/src/test/ui/imports/extern-crate-self/extern-crate-self-fail.rs @@ -1,5 +1,3 @@ -#![feature(extern_crate_self)] - extern crate self; //~ ERROR `extern crate self;` requires renaming #[macro_use] //~ ERROR `macro_use` is not supported on `extern crate self` diff --git a/src/test/ui/imports/extern-crate-self-fail.stderr b/src/test/ui/imports/extern-crate-self/extern-crate-self-fail.stderr similarity index 91% rename from src/test/ui/imports/extern-crate-self-fail.stderr rename to src/test/ui/imports/extern-crate-self/extern-crate-self-fail.stderr index 0ca0d89eaf08e..b47d10343f689 100644 --- a/src/test/ui/imports/extern-crate-self-fail.stderr +++ b/src/test/ui/imports/extern-crate-self/extern-crate-self-fail.stderr @@ -1,11 +1,11 @@ error: `extern crate self;` requires renaming - --> $DIR/extern-crate-self-fail.rs:3:1 + --> $DIR/extern-crate-self-fail.rs:1:1 | LL | extern crate self; //~ ERROR `extern crate self;` requires renaming | ^^^^^^^^^^^^^^^^^^ help: try: `extern crate self as name;` error: `macro_use` is not supported on `extern crate self` - --> $DIR/extern-crate-self-fail.rs:5:1 + --> $DIR/extern-crate-self-fail.rs:3:1 | LL | #[macro_use] //~ ERROR `macro_use` is not supported on `extern crate self` | ^^^^^^^^^^^^ diff --git a/src/test/ui/imports/extern-crate-self/extern-crate-self-macro-alias.rs b/src/test/ui/imports/extern-crate-self/extern-crate-self-macro-alias.rs new file mode 100644 index 0000000000000..79683522888cb --- /dev/null +++ b/src/test/ui/imports/extern-crate-self/extern-crate-self-macro-alias.rs @@ -0,0 +1,16 @@ +// run-pass + +// Test that a macro can correctly expand the alias +// in an `extern crate self as ALIAS` item. + +fn the_answer() -> usize { 42 } + +macro_rules! alias_self { + ($alias:ident) => { extern crate self as $alias; } +} + +alias_self!(the_alias); + +fn main() { + assert_eq!(the_alias::the_answer(), 42); +} diff --git a/src/test/ui/imports/extern-crate-self/extern-crate-self-macro-item.rs b/src/test/ui/imports/extern-crate-self/extern-crate-self-macro-item.rs new file mode 100644 index 0000000000000..9c9397999ff67 --- /dev/null +++ b/src/test/ui/imports/extern-crate-self/extern-crate-self-macro-item.rs @@ -0,0 +1,12 @@ +// compile-pass + +// Test that `extern crate self;` is accepted +// syntactically as an item for use in a macro. + +macro_rules! accept_item { ($x:item) => {} } + +accept_item! { + extern crate self; +} + +fn main() {} diff --git a/src/test/ui/imports/extern-crate-self/extern-crate-self-macro-self.rs b/src/test/ui/imports/extern-crate-self/extern-crate-self-macro-self.rs new file mode 100644 index 0000000000000..009a92e877645 --- /dev/null +++ b/src/test/ui/imports/extern-crate-self/extern-crate-self-macro-self.rs @@ -0,0 +1,16 @@ +// run-pass + +// Test that a macro can correctly expand `self` in +// an `extern crate self as ALIAS` item. + +fn the_answer() -> usize { 42 } + +macro_rules! extern_something { + ($alias:ident) => { extern crate $alias as the_alias; } +} + +extern_something!(self); + +fn main() { + assert_eq!(the_alias::the_answer(), 42); +} diff --git a/src/test/ui/imports/extern-crate-self-pass.rs b/src/test/ui/imports/extern-crate-self/extern-crate-self-pass.rs similarity index 79% rename from src/test/ui/imports/extern-crate-self-pass.rs rename to src/test/ui/imports/extern-crate-self/extern-crate-self-pass.rs index bf255bb6b8194..6f6343a614886 100644 --- a/src/test/ui/imports/extern-crate-self-pass.rs +++ b/src/test/ui/imports/extern-crate-self/extern-crate-self-pass.rs @@ -1,7 +1,5 @@ // compile-pass -#![feature(extern_crate_self)] - extern crate self as foo; struct S; From 7b557119883685e541d555135fb81c0dc10e2752 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 17 Jan 2019 18:57:46 +0100 Subject: [PATCH 02/10] Make MutexGuard's Debug implementation more useful. Fixes #57702. --- src/libstd/sync/mutex.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 856bb26042490..e4cc29792072f 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -450,9 +450,13 @@ impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> { #[stable(feature = "std_debug", since = "1.16.0")] impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'a, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("MutexGuard") - .field("lock", &self.__lock) - .finish() + struct MutexFmt<'a, T: ?Sized>(&'a MutexGuard<'a, T>); + impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexFmt<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("Mutex").field("data", &&*self.0).finish() + } + } + f.debug_struct("MutexGuard").field("lock", &MutexFmt(self)).finish() } } From 2e9deed9f130d2342bec2a55358305cb7137605e Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 17 Jan 2019 20:03:59 +0100 Subject: [PATCH 03/10] Simplify Debug implementation of MutexGuard. Just transparently print the guarded data, instead of wrapping it in `MutexGuard { lock: Mutex { data: ... } }`. --- src/libstd/sync/mutex.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index e4cc29792072f..59829db23cbc2 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -450,13 +450,7 @@ impl<'a, T: ?Sized> Drop for MutexGuard<'a, T> { #[stable(feature = "std_debug", since = "1.16.0")] impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'a, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - struct MutexFmt<'a, T: ?Sized>(&'a MutexGuard<'a, T>); - impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexFmt<'a, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("Mutex").field("data", &&*self.0).finish() - } - } - f.debug_struct("MutexGuard").field("lock", &MutexFmt(self)).finish() + fmt::Debug::fmt(&**self, f) } } From c14508fd252742e6f7ad99b1519ef1039b1eb80c Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Sun, 20 Jan 2019 00:04:28 +0100 Subject: [PATCH 04/10] Add missing #![feature(rustc_private)] annotation --- src/libfmt_macros/lib.rs | 1 + src/libtest/lib.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 32ae878909f30..5127c76b55c6d 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -11,6 +11,7 @@ test(attr(deny(warnings))))] #![feature(nll)] +#![feature(rustc_private)] pub use self::Piece::*; pub use self::Position::*; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 2cc80ddea2df4..fc03e685b6f54 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -25,7 +25,7 @@ #![feature(asm)] #![cfg_attr(stage0, feature(cfg_target_vendor))] #![feature(fnbox)] -#![cfg_attr(any(unix, target_os = "cloudabi"), feature(libc))] +#![cfg_attr(any(unix, target_os = "cloudabi"), feature(libc, rustc_private))] #![feature(nll)] #![feature(set_stdio)] #![feature(panic_unwind)] From ff41abcf8bbeefae4df033d6a1bac1543d67c388 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Sun, 20 Jan 2019 00:05:10 +0100 Subject: [PATCH 05/10] linkchecker: Update deprecated trim_left_matches usage --- src/tools/linkchecker/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs index 59662be349dcb..2cf0fcfd34cd6 100644 --- a/src/tools/linkchecker/main.rs +++ b/src/tools/linkchecker/main.rs @@ -78,7 +78,7 @@ impl FileEntry { fn parse_ids(&mut self, file: &Path, contents: &str, errors: &mut bool) { if self.ids.is_empty() { with_attrs_in_source(contents, " id", |fragment, i, _| { - let frag = fragment.trim_left_matches("#").to_owned(); + let frag = fragment.trim_start_matches("#").to_owned(); let encoded = small_url_encode(&frag); if !self.ids.insert(frag) { *errors = true; @@ -343,7 +343,7 @@ fn with_attrs_in_source(contents: &str, attr: &str, Some(i) => i, None => continue, }; - if rest[..pos_equals].trim_left_matches(" ") != "" { + if rest[..pos_equals].trim_start_matches(" ") != "" { continue; } @@ -355,7 +355,7 @@ fn with_attrs_in_source(contents: &str, attr: &str, }; let quote_delim = rest.as_bytes()[pos_quote] as char; - if rest[..pos_quote].trim_left_matches(" ") != "" { + if rest[..pos_quote].trim_start_matches(" ") != "" { continue; } let rest = &rest[pos_quote + 1..]; From e7998bf6a6e5cb3c12604d97c72435c1b4cea492 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 21 Jan 2019 22:30:52 +0100 Subject: [PATCH 06/10] un-deprecate mem::zeroed --- src/libcore/mem.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 8fcbb73d9ce46..9e100d0a58d17 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -489,7 +489,6 @@ pub const fn needs_drop() -> bool { /// assert_eq!(0, x); /// ``` #[inline] -#[rustc_deprecated(since = "2.0.0", reason = "use `mem::MaybeUninit::zeroed` instead")] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn zeroed() -> T { #[cfg(not(stage0))] From 9aa1ca2f462d16c5f6d49830b72af91888bc8ab4 Mon Sep 17 00:00:00 2001 From: James Duley Date: Thu, 17 Jan 2019 23:17:21 +0000 Subject: [PATCH 07/10] Ignore aarch64 in simd-intrinsic-generic-reduction This fails on AArch64 see https://github.com/rust-lang/rust/issues/54510 --- src/test/run-pass/simd/simd-intrinsic-generic-reduction.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/run-pass/simd/simd-intrinsic-generic-reduction.rs b/src/test/run-pass/simd/simd-intrinsic-generic-reduction.rs index b39f54a5efbb4..e3faa7c625ccc 100644 --- a/src/test/run-pass/simd/simd-intrinsic-generic-reduction.rs +++ b/src/test/run-pass/simd/simd-intrinsic-generic-reduction.rs @@ -2,6 +2,7 @@ #![allow(non_camel_case_types)] // ignore-emscripten +// ignore-aarch64 FIXME: https://github.com/rust-lang/rust/issues/54510 // Test that the simd_reduce_{op} intrinsics produce the correct results. From ac4b685650d1ba0a38806ce8f7cbf12e7a00f573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Tue, 18 Dec 2018 02:22:08 +0100 Subject: [PATCH 08/10] #56411 do not suggest a fix for a import conflict in a macro --- src/librustc_resolve/lib.rs | 4 +++- src/test/ui/issues/issue-56411.rs | 17 +++++++++++++++ src/test/ui/issues/issue-56411.stderr | 31 +++++++++++++++++++++++++++ src/test/ui/issues/issue_56411.rs | 5 +++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/issues/issue-56411.rs create mode 100644 src/test/ui/issues/issue-56411.stderr create mode 100644 src/test/ui/issues/issue_56411.rs diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 4c9347afa611d..8dd09076a00ac 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -5147,11 +5147,13 @@ impl<'a> Resolver<'a> { if let ( Ok(snippet), NameBindingKind::Import { directive, ..}, - _dummy @ false, + false, + false, ) = ( cm.span_to_snippet(binding.span), binding.kind.clone(), binding.span.is_dummy(), + binding.span.ctxt().outer().expn_info().is_some(), ) { let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() { format!("Other{}", name) diff --git a/src/test/ui/issues/issue-56411.rs b/src/test/ui/issues/issue-56411.rs new file mode 100644 index 0000000000000..599f277123cc8 --- /dev/null +++ b/src/test/ui/issues/issue-56411.rs @@ -0,0 +1,17 @@ +macro_rules! import { + ( $($name:ident),* ) => { + $( + mod $name; + pub use self::$name; + //~^ ERROR the name `issue_56411` is defined multiple times + //~| ERROR `issue_56411` is private, and cannot be re-exported + + )* + } +} + +import!(issue_56411); + +fn main() { + println!("Hello, world!"); +} diff --git a/src/test/ui/issues/issue-56411.stderr b/src/test/ui/issues/issue-56411.stderr new file mode 100644 index 0000000000000..842d86f4a3a9c --- /dev/null +++ b/src/test/ui/issues/issue-56411.stderr @@ -0,0 +1,31 @@ +error[E0255]: the name `issue_56411` is defined multiple times + --> $DIR/issue-56411.rs:5:21 + | +LL | mod $name; + | ---------- previous definition of the module `issue_56411` here +LL | pub use self::$name; + | ^^^^^^^^^^^ + | | + | `issue_56411` reimported here + | you can use `as` to change the binding name of the import +... +LL | import!(issue_56411); + | --------------------- in this macro invocation + | + = note: `issue_56411` must be defined only once in the type namespace of this module + +error[E0365]: `issue_56411` is private, and cannot be re-exported + --> $DIR/issue-56411.rs:5:21 + | +LL | pub use self::$name; + | ^^^^^^^^^^^ re-export of private `issue_56411` +... +LL | import!(issue_56411); + | --------------------- in this macro invocation + | + = note: consider declaring type or module `issue_56411` with `pub` + +error: aborting due to 2 previous errors + +Some errors occurred: E0255, E0365. +For more information about an error, try `rustc --explain E0255`. diff --git a/src/test/ui/issues/issue_56411.rs b/src/test/ui/issues/issue_56411.rs new file mode 100644 index 0000000000000..bd689e913aba6 --- /dev/null +++ b/src/test/ui/issues/issue_56411.rs @@ -0,0 +1,5 @@ +// compile-pass + +struct T {} + +fn main() {} From 1b659d69bc0ba7fe534cc26bda8544a558a7d2b2 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 26 Jan 2019 00:36:50 +0300 Subject: [PATCH 09/10] Address review comments and cleanup code --- src/librustc_resolve/lib.rs | 93 +++++++++---------- src/test/ui/issues/issue-56411.rs | 6 +- src/test/ui/issues/issue-56411.stderr | 22 ++--- .../{issue_56411.rs => issue_56411_aux.rs} | 0 4 files changed, 59 insertions(+), 62 deletions(-) rename src/test/ui/issues/{issue_56411.rs => issue_56411_aux.rs} (100%) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 8dd09076a00ac..873ace9017260 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -5134,62 +5134,59 @@ impl<'a> Resolver<'a> { ); // See https://github.com/rust-lang/rust/issues/32354 - if old_binding.is_import() || new_binding.is_import() { - let binding = if new_binding.is_import() && !new_binding.span.is_dummy() { - new_binding + let directive = match (&new_binding.kind, &old_binding.kind) { + (NameBindingKind::Import { directive, .. }, _) if !new_binding.span.is_dummy() => + Some((directive, new_binding.span)), + (_, NameBindingKind::Import { directive, .. }) if !old_binding.span.is_dummy() => + Some((directive, old_binding.span)), + _ => None, + }; + if let Some((directive, binding_span)) = directive { + let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() { + format!("Other{}", name) } else { - old_binding + format!("other_{}", name) }; - let cm = self.session.source_map(); - let rename_msg = "you can use `as` to change the binding name of the import"; - - if let ( - Ok(snippet), - NameBindingKind::Import { directive, ..}, - false, - false, - ) = ( - cm.span_to_snippet(binding.span), - binding.kind.clone(), - binding.span.is_dummy(), - binding.span.ctxt().outer().expn_info().is_some(), - ) { - let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() { - format!("Other{}", name) - } else { - format!("other_{}", name) - }; + let mut suggestion = None; + match directive.subclass { + ImportDirectiveSubclass::SingleImport { type_ns_only: true, .. } => + suggestion = Some(format!("self as {}", suggested_name)), + ImportDirectiveSubclass::SingleImport { source, .. } => { + if let Some(pos) = source.span.hi().0.checked_sub(binding_span.lo().0) + .map(|pos| pos as usize) { + if let Ok(snippet) = self.session.source_map() + .span_to_snippet(binding_span) { + if pos <= snippet.len() { + suggestion = Some(format!( + "{} as {}{}", + &snippet[..pos], + suggested_name, + if snippet.ends_with(";") { ";" } else { "" } + )) + } + } + } + } + ImportDirectiveSubclass::ExternCrate { source, target, .. } => + suggestion = Some(format!( + "extern crate {} as {};", + source.unwrap_or(target.name), + suggested_name, + )), + _ => unreachable!(), + } + let rename_msg = "you can use `as` to change the binding name of the import"; + if let Some(suggestion) = suggestion { err.span_suggestion_with_applicability( - binding.span, - &rename_msg, - match directive.subclass { - ImportDirectiveSubclass::SingleImport { type_ns_only: true, .. } => - format!("self as {}", suggested_name), - ImportDirectiveSubclass::SingleImport { source, .. } => - format!( - "{} as {}{}", - &snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)], - suggested_name, - if snippet.ends_with(";") { - ";" - } else { - "" - } - ), - ImportDirectiveSubclass::ExternCrate { source, target, .. } => - format!( - "extern crate {} as {};", - source.unwrap_or(target.name), - suggested_name, - ), - _ => unreachable!(), - }, + binding_span, + rename_msg, + suggestion, Applicability::MaybeIncorrect, ); } else { - err.span_label(binding.span, rename_msg); + err.span_label(binding_span, rename_msg); } } diff --git a/src/test/ui/issues/issue-56411.rs b/src/test/ui/issues/issue-56411.rs index 599f277123cc8..3561c21cc7ee3 100644 --- a/src/test/ui/issues/issue-56411.rs +++ b/src/test/ui/issues/issue-56411.rs @@ -3,14 +3,14 @@ macro_rules! import { $( mod $name; pub use self::$name; - //~^ ERROR the name `issue_56411` is defined multiple times - //~| ERROR `issue_56411` is private, and cannot be re-exported + //~^ ERROR the name `issue_56411_aux` is defined multiple times + //~| ERROR `issue_56411_aux` is private, and cannot be re-exported )* } } -import!(issue_56411); +import!(issue_56411_aux); fn main() { println!("Hello, world!"); diff --git a/src/test/ui/issues/issue-56411.stderr b/src/test/ui/issues/issue-56411.stderr index 842d86f4a3a9c..dd05852c09159 100644 --- a/src/test/ui/issues/issue-56411.stderr +++ b/src/test/ui/issues/issue-56411.stderr @@ -1,29 +1,29 @@ -error[E0255]: the name `issue_56411` is defined multiple times +error[E0255]: the name `issue_56411_aux` is defined multiple times --> $DIR/issue-56411.rs:5:21 | LL | mod $name; - | ---------- previous definition of the module `issue_56411` here + | ---------- previous definition of the module `issue_56411_aux` here LL | pub use self::$name; | ^^^^^^^^^^^ | | - | `issue_56411` reimported here + | `issue_56411_aux` reimported here | you can use `as` to change the binding name of the import ... -LL | import!(issue_56411); - | --------------------- in this macro invocation +LL | import!(issue_56411_aux); + | ------------------------- in this macro invocation | - = note: `issue_56411` must be defined only once in the type namespace of this module + = note: `issue_56411_aux` must be defined only once in the type namespace of this module -error[E0365]: `issue_56411` is private, and cannot be re-exported +error[E0365]: `issue_56411_aux` is private, and cannot be re-exported --> $DIR/issue-56411.rs:5:21 | LL | pub use self::$name; - | ^^^^^^^^^^^ re-export of private `issue_56411` + | ^^^^^^^^^^^ re-export of private `issue_56411_aux` ... -LL | import!(issue_56411); - | --------------------- in this macro invocation +LL | import!(issue_56411_aux); + | ------------------------- in this macro invocation | - = note: consider declaring type or module `issue_56411` with `pub` + = note: consider declaring type or module `issue_56411_aux` with `pub` error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue_56411.rs b/src/test/ui/issues/issue_56411_aux.rs similarity index 100% rename from src/test/ui/issues/issue_56411.rs rename to src/test/ui/issues/issue_56411_aux.rs From b215fbdbb42e44e67f5bcaec6af45343ce33576a Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Sat, 26 Jan 2019 15:50:05 +0900 Subject: [PATCH 10/10] Change crate-visibility-modifier issue number in The Unstable Book --- .../src/language-features/crate-visibility-modifier.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/unstable-book/src/language-features/crate-visibility-modifier.md b/src/doc/unstable-book/src/language-features/crate-visibility-modifier.md index 11b3ee8edf0b1..b59859dd348e7 100644 --- a/src/doc/unstable-book/src/language-features/crate-visibility-modifier.md +++ b/src/doc/unstable-book/src/language-features/crate-visibility-modifier.md @@ -1,8 +1,8 @@ # `crate_visibility_modifier` -The tracking issue for this feature is: [#45388] +The tracking issue for this feature is: [#53120] -[#45388]: https://github.com/rust-lang/rust/issues/45388 +[#53120]: https://github.com/rust-lang/rust/issues/53120 -----