From cac95ee11c901f4d366c15acbbb9cf351f89632a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=CC=A7ois=20Mockers?= Date: Tue, 16 Oct 2018 08:22:32 +0200 Subject: [PATCH 1/6] #45829 when a renamed import conflict with a previous import --- src/librustc_resolve/lib.rs | 14 +++++++--- .../issue-45829/auxiliary/issue_45829_a.rs | 11 ++++++++ .../issue-45829/auxiliary/issue_45829_b.rs | 11 ++++++++ .../issue-45829/rename-extern-vs-use.rs | 16 +++++++++++ .../issue-45829/rename-extern-vs-use.stderr | 27 +++++++++++++++++++ .../ui/issues/issue-45829/rename-extern.rs | 17 ++++++++++++ .../issues/issue-45829/rename-extern.stderr | 16 +++++++++++ .../issue-45829/rename-use-vs-extern.rs | 16 +++++++++++ .../issue-45829/rename-use-vs-extern.stderr | 17 ++++++++++++ .../ui/issues/issue-45829/rename-with-path.rs | 13 +++++++++ .../issue-45829/rename-with-path.stderr | 17 ++++++++++++ src/test/ui/issues/issue-45829/rename.rs | 16 +++++++++++ src/test/ui/issues/issue-45829/rename.stderr | 17 ++++++++++++ ...lve-conflict-import-vs-extern-crate.stderr | 4 +-- 14 files changed, 207 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/issues/issue-45829/auxiliary/issue_45829_a.rs create mode 100644 src/test/ui/issues/issue-45829/auxiliary/issue_45829_b.rs create mode 100644 src/test/ui/issues/issue-45829/rename-extern-vs-use.rs create mode 100644 src/test/ui/issues/issue-45829/rename-extern-vs-use.stderr create mode 100644 src/test/ui/issues/issue-45829/rename-extern.rs create mode 100644 src/test/ui/issues/issue-45829/rename-extern.stderr create mode 100644 src/test/ui/issues/issue-45829/rename-use-vs-extern.rs create mode 100644 src/test/ui/issues/issue-45829/rename-use-vs-extern.stderr create mode 100644 src/test/ui/issues/issue-45829/rename-with-path.rs create mode 100644 src/test/ui/issues/issue-45829/rename-with-path.stderr create mode 100644 src/test/ui/issues/issue-45829/rename.rs create mode 100644 src/test/ui/issues/issue-45829/rename.stderr diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index a93cc7ad7518a..9d97997b1da16 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -4796,10 +4796,18 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { err.span_suggestion_with_applicability( binding.span, rename_msg, - if snippet.ends_with(';') { - format!("{} as {};", &snippet[..snippet.len() - 1], suggested_name) + if snippet.contains(" as ") { + format!( + "{} as {}", + &snippet[..snippet.find(" as ").unwrap()], + suggested_name, + ) } else { - format!("{} as {}", snippet, suggested_name) + if snippet.ends_with(';') { + format!("{} as {};", &snippet[..snippet.len() - 1], suggested_name) + } else { + format!("{} as {}", snippet, suggested_name) + } }, Applicability::MachineApplicable, ); diff --git a/src/test/ui/issues/issue-45829/auxiliary/issue_45829_a.rs b/src/test/ui/issues/issue-45829/auxiliary/issue_45829_a.rs new file mode 100644 index 0000000000000..56eb1541e1f68 --- /dev/null +++ b/src/test/ui/issues/issue-45829/auxiliary/issue_45829_a.rs @@ -0,0 +1,11 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub const FOO: usize = *&0; diff --git a/src/test/ui/issues/issue-45829/auxiliary/issue_45829_b.rs b/src/test/ui/issues/issue-45829/auxiliary/issue_45829_b.rs new file mode 100644 index 0000000000000..56eb1541e1f68 --- /dev/null +++ b/src/test/ui/issues/issue-45829/auxiliary/issue_45829_b.rs @@ -0,0 +1,11 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub const FOO: usize = *&0; diff --git a/src/test/ui/issues/issue-45829/rename-extern-vs-use.rs b/src/test/ui/issues/issue-45829/rename-extern-vs-use.rs new file mode 100644 index 0000000000000..3d3e03aa35004 --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename-extern-vs-use.rs @@ -0,0 +1,16 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue_45829_b.rs + +use std; +extern crate issue_45829_b as std; + +fn main() {} diff --git a/src/test/ui/issues/issue-45829/rename-extern-vs-use.stderr b/src/test/ui/issues/issue-45829/rename-extern-vs-use.stderr new file mode 100644 index 0000000000000..f723abd3301d8 --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename-extern-vs-use.stderr @@ -0,0 +1,27 @@ +error[E0259]: the name `std` is defined multiple times + --> $DIR/rename-extern-vs-use.rs:14:1 + | +LL | extern crate issue_45829_b as std; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `std` reimported here + | You can use `as` to change the binding name of the import + | + = note: `std` must be defined only once in the type namespace of this module + +error[E0254]: the name `std` is defined multiple times + --> $DIR/rename-extern-vs-use.rs:13:5 + | +LL | use std; + | ^^^ `std` reimported here + | + = note: `std` must be defined only once in the type namespace of this module +help: You can use `as` to change the binding name of the import + | +LL | use std as other_std; + | ^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +Some errors occurred: E0254, E0259. +For more information about an error, try `rustc --explain E0254`. diff --git a/src/test/ui/issues/issue-45829/rename-extern.rs b/src/test/ui/issues/issue-45829/rename-extern.rs new file mode 100644 index 0000000000000..7c3d972400574 --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename-extern.rs @@ -0,0 +1,17 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue_45829_a.rs +// aux-build:issue_45829_b.rs + +extern crate issue_45829_a; +extern crate issue_45829_b as issue_45829_a; + +fn main() {} diff --git a/src/test/ui/issues/issue-45829/rename-extern.stderr b/src/test/ui/issues/issue-45829/rename-extern.stderr new file mode 100644 index 0000000000000..e82e99588c150 --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename-extern.stderr @@ -0,0 +1,16 @@ +error[E0259]: the name `issue_45829_a` is defined multiple times + --> $DIR/rename-extern.rs:15:1 + | +LL | extern crate issue_45829_a; + | --------------------------- previous import of the extern crate `issue_45829_a` here +LL | extern crate issue_45829_b as issue_45829_a; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `issue_45829_a` reimported here + | You can use `as` to change the binding name of the import + | + = note: `issue_45829_a` must be defined only once in the type namespace of this module + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0259`. diff --git a/src/test/ui/issues/issue-45829/rename-use-vs-extern.rs b/src/test/ui/issues/issue-45829/rename-use-vs-extern.rs new file mode 100644 index 0000000000000..1cc261ed922eb --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename-use-vs-extern.rs @@ -0,0 +1,16 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue_45829_b.rs + +extern crate issue_45829_b; +use std as issue_45829_b; + +fn main() {} diff --git a/src/test/ui/issues/issue-45829/rename-use-vs-extern.stderr b/src/test/ui/issues/issue-45829/rename-use-vs-extern.stderr new file mode 100644 index 0000000000000..eff5d8a2cb67e --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename-use-vs-extern.stderr @@ -0,0 +1,17 @@ +error[E0254]: the name `issue_45829_b` is defined multiple times + --> $DIR/rename-use-vs-extern.rs:14:5 + | +LL | extern crate issue_45829_b; + | --------------------------- previous import of the extern crate `issue_45829_b` here +LL | use std as issue_45829_b; + | ^^^^^^^^^^^^^^^^^^^^ `issue_45829_b` reimported here + | + = note: `issue_45829_b` must be defined only once in the type namespace of this module +help: You can use `as` to change the binding name of the import + | +LL | use std as other_issue_45829_b; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0254`. diff --git a/src/test/ui/issues/issue-45829/rename-with-path.rs b/src/test/ui/issues/issue-45829/rename-with-path.rs new file mode 100644 index 0000000000000..dbe8733735e50 --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename-with-path.rs @@ -0,0 +1,13 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::{collections::HashMap as A, sync::Arc as A}; + +fn main() {} diff --git a/src/test/ui/issues/issue-45829/rename-with-path.stderr b/src/test/ui/issues/issue-45829/rename-with-path.stderr new file mode 100644 index 0000000000000..bfeb879e6e55b --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename-with-path.stderr @@ -0,0 +1,17 @@ +error[E0252]: the name `A` is defined multiple times + --> $DIR/rename-with-path.rs:11:38 + | +LL | use std::{collections::HashMap as A, sync::Arc as A}; + | ------------------------- ^^^^^^^^^^^^^^ `A` reimported here + | | + | previous import of the type `A` here + | + = note: `A` must be defined only once in the type namespace of this module +help: You can use `as` to change the binding name of the import + | +LL | use std::{collections::HashMap as A, sync::Arc as OtherA}; + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0252`. diff --git a/src/test/ui/issues/issue-45829/rename.rs b/src/test/ui/issues/issue-45829/rename.rs new file mode 100644 index 0000000000000..7c6d87b1d205e --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename.rs @@ -0,0 +1,16 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use core; +use std as core; + +fn main() { + 1 + 1; +} diff --git a/src/test/ui/issues/issue-45829/rename.stderr b/src/test/ui/issues/issue-45829/rename.stderr new file mode 100644 index 0000000000000..1ebd73a55a9fa --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename.stderr @@ -0,0 +1,17 @@ +error[E0252]: the name `core` is defined multiple times + --> $DIR/rename.rs:12:5 + | +LL | use core; + | ---- previous import of the module `core` here +LL | use std as core; + | ^^^^^^^^^^^ `core` reimported here + | + = note: `core` must be defined only once in the type namespace of this module +help: You can use `as` to change the binding name of the import + | +LL | use std as other_core; + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0252`. diff --git a/src/test/ui/resolve/resolve-conflict-import-vs-extern-crate.stderr b/src/test/ui/resolve/resolve-conflict-import-vs-extern-crate.stderr index 9978e75af30b7..be3600da51ddf 100644 --- a/src/test/ui/resolve/resolve-conflict-import-vs-extern-crate.stderr +++ b/src/test/ui/resolve/resolve-conflict-import-vs-extern-crate.stderr @@ -7,8 +7,8 @@ LL | use std::slice as std; //~ ERROR the name `std` is defined multiple times = note: `std` must be defined only once in the type namespace of this module help: You can use `as` to change the binding name of the import | -LL | use std::slice as std as other_std; //~ ERROR the name `std` is defined multiple times - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | use std::slice as other_std; //~ ERROR the name `std` is defined multiple times + | ^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error From ad4cea408df885f4c5b026aaafa0beed4e365c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=CC=A7ois=20Mockers?= Date: Wed, 17 Oct 2018 01:09:43 +0200 Subject: [PATCH 2/6] apply review --- src/librustc_resolve/lib.rs | 38 ++++++++----------- src/test/ui/issues/issue-45829/issue-45829.rs | 18 +++++++++ .../ui/issues/issue-45829/issue-45829.stderr | 17 +++++++++ .../issue-45829/rename-extern-vs-use.rs | 8 +++- .../issue-45829/rename-extern-vs-use.stderr | 32 ++++++---------- .../issues/issue-45829/rename-extern.stderr | 9 +++-- .../issue-45829/rename-use-vs-extern.stderr | 2 +- .../issue-45829/rename-with-path.stderr | 2 +- src/test/ui/issues/issue-45829/rename.stderr | 2 +- 9 files changed, 75 insertions(+), 53 deletions(-) create mode 100644 src/test/ui/issues/issue-45829/issue-45829.rs create mode 100644 src/test/ui/issues/issue-45829/issue-45829.stderr diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 9d97997b1da16..7320b6e7d9b7d 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1248,15 +1248,6 @@ impl<'a> NameBinding<'a> { } } - fn is_renamed_extern_crate(&self) -> bool { - if let NameBindingKind::Import { directive, ..} = self.kind { - if let ImportDirectiveSubclass::ExternCrate(Some(_)) = directive.subclass { - return true; - } - } - false - } - fn is_glob_import(&self) -> bool { match self.kind { NameBindingKind::Import { directive, .. } => directive.is_glob(), @@ -4783,10 +4774,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { }; let cm = self.session.source_map(); - let rename_msg = "You can use `as` to change the binding name of the import"; + let rename_msg = "you can use `as` to change the binding name of the import"; - if let (Ok(snippet), false) = (cm.span_to_snippet(binding.span), - binding.is_renamed_extern_crate()) { + if let Ok(snippet) = cm.span_to_snippet(binding.span) { let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() { format!("Other{}", name) } else { @@ -4796,20 +4786,22 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { err.span_suggestion_with_applicability( binding.span, rename_msg, - if snippet.contains(" as ") { - format!( - "{} as {}", + match (snippet.split_whitespace().find(|w| *w == "as"), snippet.ends_with(";")) { + (Some(_), false) => format!("{} as {}", &snippet[..snippet.find(" as ").unwrap()], suggested_name, - ) - } else { - if snippet.ends_with(';') { - format!("{} as {};", &snippet[..snippet.len() - 1], suggested_name) - } else { - format!("{} as {}", snippet, suggested_name) - } + ), + (Some(_), true) => format!("{} as {};", + &snippet[..snippet.find(" as ").unwrap()], + suggested_name, + ), + (None, false) => format!("{} as {}", snippet, suggested_name), + (None, true) => format!("{} as {};", + &snippet[..snippet.len() - 1], + suggested_name + ), }, - Applicability::MachineApplicable, + Applicability::MaybeIncorrect, ); } else { err.span_label(binding.span, rename_msg); diff --git a/src/test/ui/issues/issue-45829/issue-45829.rs b/src/test/ui/issues/issue-45829/issue-45829.rs new file mode 100644 index 0000000000000..eca46484699b3 --- /dev/null +++ b/src/test/ui/issues/issue-45829/issue-45829.rs @@ -0,0 +1,18 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +mod foo { + pub struct A; + pub struct B; +} + +use foo::{A, B as A}; + +fn main() {} diff --git a/src/test/ui/issues/issue-45829/issue-45829.stderr b/src/test/ui/issues/issue-45829/issue-45829.stderr new file mode 100644 index 0000000000000..872379d9fc303 --- /dev/null +++ b/src/test/ui/issues/issue-45829/issue-45829.stderr @@ -0,0 +1,17 @@ +error[E0252]: the name `A` is defined multiple times + --> $DIR/issue-45829.rs:16:14 + | +LL | use foo::{A, B as A}; + | - ^^^^^^ `A` reimported here + | | + | previous import of the type `A` here + | + = note: `A` must be defined only once in the type namespace of this module +help: you can use `as` to change the binding name of the import + | +LL | use foo::{A, B as OtherA}; + | ^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0252`. diff --git a/src/test/ui/issues/issue-45829/rename-extern-vs-use.rs b/src/test/ui/issues/issue-45829/rename-extern-vs-use.rs index 3d3e03aa35004..5230cadf60430 100644 --- a/src/test/ui/issues/issue-45829/rename-extern-vs-use.rs +++ b/src/test/ui/issues/issue-45829/rename-extern-vs-use.rs @@ -10,7 +10,11 @@ // aux-build:issue_45829_b.rs -use std; -extern crate issue_45829_b as std; +mod foo { + pub mod bar {} +} + +use foo::bar; +extern crate issue_45829_b as bar; fn main() {} diff --git a/src/test/ui/issues/issue-45829/rename-extern-vs-use.stderr b/src/test/ui/issues/issue-45829/rename-extern-vs-use.stderr index f723abd3301d8..6a513e90d95b9 100644 --- a/src/test/ui/issues/issue-45829/rename-extern-vs-use.stderr +++ b/src/test/ui/issues/issue-45829/rename-extern-vs-use.stderr @@ -1,27 +1,17 @@ -error[E0259]: the name `std` is defined multiple times - --> $DIR/rename-extern-vs-use.rs:14:1 +error[E0254]: the name `bar` is defined multiple times + --> $DIR/rename-extern-vs-use.rs:18:1 | -LL | extern crate issue_45829_b as std; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | `std` reimported here - | You can use `as` to change the binding name of the import +LL | use foo::bar; + | -------- previous import of the module `bar` here +LL | extern crate issue_45829_b as bar; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `bar` reimported here | - = note: `std` must be defined only once in the type namespace of this module - -error[E0254]: the name `std` is defined multiple times - --> $DIR/rename-extern-vs-use.rs:13:5 - | -LL | use std; - | ^^^ `std` reimported here + = note: `bar` must be defined only once in the type namespace of this module +help: you can use `as` to change the binding name of the import | - = note: `std` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +LL | extern crate issue_45829_b as other_bar; | -LL | use std as other_std; - | ^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors occurred: E0254, E0259. -For more information about an error, try `rustc --explain E0254`. +For more information about this error, try `rustc --explain E0254`. diff --git a/src/test/ui/issues/issue-45829/rename-extern.stderr b/src/test/ui/issues/issue-45829/rename-extern.stderr index e82e99588c150..ab77e592b4a99 100644 --- a/src/test/ui/issues/issue-45829/rename-extern.stderr +++ b/src/test/ui/issues/issue-45829/rename-extern.stderr @@ -4,12 +4,13 @@ error[E0259]: the name `issue_45829_a` is defined multiple times LL | extern crate issue_45829_a; | --------------------------- previous import of the extern crate `issue_45829_a` here LL | extern crate issue_45829_b as issue_45829_a; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | `issue_45829_a` reimported here - | You can use `as` to change the binding name of the import + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `issue_45829_a` reimported here | = note: `issue_45829_a` must be defined only once in the type namespace of this module +help: you can use `as` to change the binding name of the import + | +LL | extern crate issue_45829_b as other_issue_45829_a; + | error: aborting due to previous error diff --git a/src/test/ui/issues/issue-45829/rename-use-vs-extern.stderr b/src/test/ui/issues/issue-45829/rename-use-vs-extern.stderr index eff5d8a2cb67e..1395fbeea3b31 100644 --- a/src/test/ui/issues/issue-45829/rename-use-vs-extern.stderr +++ b/src/test/ui/issues/issue-45829/rename-use-vs-extern.stderr @@ -7,7 +7,7 @@ LL | use std as issue_45829_b; | ^^^^^^^^^^^^^^^^^^^^ `issue_45829_b` reimported here | = note: `issue_45829_b` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std as other_issue_45829_b; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/issues/issue-45829/rename-with-path.stderr b/src/test/ui/issues/issue-45829/rename-with-path.stderr index bfeb879e6e55b..2bc45f0a62d74 100644 --- a/src/test/ui/issues/issue-45829/rename-with-path.stderr +++ b/src/test/ui/issues/issue-45829/rename-with-path.stderr @@ -7,7 +7,7 @@ LL | use std::{collections::HashMap as A, sync::Arc as A}; | previous import of the type `A` here | = note: `A` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::{collections::HashMap as A, sync::Arc as OtherA}; | ^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/issues/issue-45829/rename.stderr b/src/test/ui/issues/issue-45829/rename.stderr index 1ebd73a55a9fa..ce13b45749042 100644 --- a/src/test/ui/issues/issue-45829/rename.stderr +++ b/src/test/ui/issues/issue-45829/rename.stderr @@ -7,7 +7,7 @@ LL | use std as core; | ^^^^^^^^^^^ `core` reimported here | = note: `core` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std as other_core; | ^^^^^^^^^^^^^^^^^ From 2ba567fc2799990f183f7b46e649bb8ce2de6787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=CC=A7ois=20Mockers?= Date: Wed, 17 Oct 2018 01:21:40 +0200 Subject: [PATCH 3/6] fix other tests failing due to change in case or new suggestion for extern crate --- .../ui/blind/blind-item-block-item-shadow.stderr | 2 +- src/test/ui/blind/blind-item-item-shadow.stderr | 2 +- src/test/ui/double-import.stderr | 2 +- src/test/ui/double-type-import.stderr | 2 +- .../duplicate/duplicate-check-macro-exports.stderr | 2 +- src/test/ui/error-codes/E0252.stderr | 2 +- src/test/ui/error-codes/E0254.stderr | 2 +- src/test/ui/error-codes/E0255.stderr | 2 +- src/test/ui/error-codes/E0259.stderr | 9 +++++---- src/test/ui/error-codes/E0260.stderr | 2 +- src/test/ui/error-codes/E0430.stderr | 2 +- src/test/ui/extern/extern-crate-rename.stderr | 9 +++++---- src/test/ui/imports/duplicate.stderr | 2 +- src/test/ui/issues/issue-19498.stderr | 6 +++--- src/test/ui/issues/issue-24081.stderr | 10 +++++----- src/test/ui/issues/issue-25396.stderr | 8 ++++---- src/test/ui/issues/issue-26886.stderr | 4 ++-- .../issues/issue-32354-suggest-import-rename.stderr | 2 +- ...-extern-crate-rename-suggestion-formatting.stderr | 2 +- src/test/ui/issues/issue-8640.stderr | 2 +- src/test/ui/no-std-inject.stderr | 2 +- ...olve-conflict-extern-crate-vs-extern-crate.stderr | 2 +- .../resolve-conflict-import-vs-extern-crate.stderr | 2 +- .../resolve/resolve-conflict-import-vs-import.stderr | 2 +- .../resolve-conflict-item-vs-extern-crate.stderr | 2 +- .../resolve/resolve-conflict-item-vs-import.stderr | 2 +- .../resolve/resolve-conflict-type-vs-import.stderr | 2 +- .../unresolved-extern-mod-suggestion.stderr | 2 +- src/test/ui/use/use-mod.stderr | 2 +- src/test/ui/use/use-paths-as-items.stderr | 2 +- src/test/ui/variants/variant-namespacing.stderr | 12 ++++++------ 31 files changed, 54 insertions(+), 52 deletions(-) diff --git a/src/test/ui/blind/blind-item-block-item-shadow.stderr b/src/test/ui/blind/blind-item-block-item-shadow.stderr index 5adc953e4058e..a24ba5d97b11c 100644 --- a/src/test/ui/blind/blind-item-block-item-shadow.stderr +++ b/src/test/ui/blind/blind-item-block-item-shadow.stderr @@ -7,7 +7,7 @@ LL | use foo::Bar; | ^^^^^^^^ `Bar` reimported here | = note: `Bar` must be defined only once in the type namespace of this block -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use foo::Bar as OtherBar; | ^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/blind/blind-item-item-shadow.stderr b/src/test/ui/blind/blind-item-item-shadow.stderr index 240ea6061b975..7874189534403 100644 --- a/src/test/ui/blind/blind-item-item-shadow.stderr +++ b/src/test/ui/blind/blind-item-item-shadow.stderr @@ -8,7 +8,7 @@ LL | use foo::foo; | ^^^^^^^^ `foo` reimported here | = note: `foo` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use foo::foo as other_foo; | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/double-import.stderr b/src/test/ui/double-import.stderr index df6463a7e2880..436d594921b07 100644 --- a/src/test/ui/double-import.stderr +++ b/src/test/ui/double-import.stderr @@ -7,7 +7,7 @@ LL | use sub2::foo; //~ ERROR the name `foo` is defined multiple times | ^^^^^^^^^ `foo` reimported here | = note: `foo` must be defined only once in the value namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use sub2::foo as other_foo; //~ ERROR the name `foo` is defined multiple times | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/double-type-import.stderr b/src/test/ui/double-type-import.stderr index d5d977da4aa4c..f1d6e63c713af 100644 --- a/src/test/ui/double-type-import.stderr +++ b/src/test/ui/double-type-import.stderr @@ -7,7 +7,7 @@ LL | use self::bar::X; | ^^^^^^^^^^^^ `X` reimported here | = note: `X` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use self::bar::X as OtherX; | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/duplicate/duplicate-check-macro-exports.stderr b/src/test/ui/duplicate/duplicate-check-macro-exports.stderr index e2119efbd3db5..eced6b303e853 100644 --- a/src/test/ui/duplicate/duplicate-check-macro-exports.stderr +++ b/src/test/ui/duplicate/duplicate-check-macro-exports.stderr @@ -8,7 +8,7 @@ LL | macro_rules! panic { () => {} } //~ ERROR the name `panic` is defined multi | ^^^^^^^^^^^^^^^^^^ `panic` redefined here | = note: `panic` must be defined only once in the macro namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | pub use std::panic as other_panic; | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/error-codes/E0252.stderr b/src/test/ui/error-codes/E0252.stderr index a4271bf3a4dff..0d112a4f02ea9 100644 --- a/src/test/ui/error-codes/E0252.stderr +++ b/src/test/ui/error-codes/E0252.stderr @@ -7,7 +7,7 @@ LL | use bar::baz; //~ ERROR E0252 | ^^^^^^^^ `baz` reimported here | = note: `baz` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use bar::baz as other_baz; //~ ERROR E0252 | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/error-codes/E0254.stderr b/src/test/ui/error-codes/E0254.stderr index a52215df0bbca..5e833f1ee3901 100644 --- a/src/test/ui/error-codes/E0254.stderr +++ b/src/test/ui/error-codes/E0254.stderr @@ -8,7 +8,7 @@ LL | use foo::alloc; | ^^^^^^^^^^ `alloc` reimported here | = note: `alloc` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use foo::alloc as other_alloc; | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/error-codes/E0255.stderr b/src/test/ui/error-codes/E0255.stderr index a077a43c152f0..d01a4c002e76f 100644 --- a/src/test/ui/error-codes/E0255.stderr +++ b/src/test/ui/error-codes/E0255.stderr @@ -8,7 +8,7 @@ LL | fn foo() {} //~ ERROR E0255 | ^^^^^^^^ `foo` redefined here | = note: `foo` must be defined only once in the value namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use bar::foo as other_foo; | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/error-codes/E0259.stderr b/src/test/ui/error-codes/E0259.stderr index 24a73544a35f0..8c3e3f851aed7 100644 --- a/src/test/ui/error-codes/E0259.stderr +++ b/src/test/ui/error-codes/E0259.stderr @@ -5,12 +5,13 @@ LL | extern crate alloc; | ------------------- previous import of the extern crate `alloc` here LL | LL | extern crate libc as alloc; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | `alloc` reimported here - | You can use `as` to change the binding name of the import + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `alloc` reimported here | = note: `alloc` must be defined only once in the type namespace of this module +help: you can use `as` to change the binding name of the import + | +LL | extern crate libc as other_alloc; + | error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0260.stderr b/src/test/ui/error-codes/E0260.stderr index 437794432b082..08792a3392104 100644 --- a/src/test/ui/error-codes/E0260.stderr +++ b/src/test/ui/error-codes/E0260.stderr @@ -8,7 +8,7 @@ LL | mod alloc { | ^^^^^^^^^ `alloc` redefined here | = note: `alloc` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | extern crate alloc as other_alloc; | diff --git a/src/test/ui/error-codes/E0430.stderr b/src/test/ui/error-codes/E0430.stderr index c50ed4ea5de8b..32198acec7726 100644 --- a/src/test/ui/error-codes/E0430.stderr +++ b/src/test/ui/error-codes/E0430.stderr @@ -15,7 +15,7 @@ LL | use std::fmt::{self, self}; //~ ERROR E0430 | previous import of the module `fmt` here | = note: `fmt` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::fmt::{self, self as other_fmt}; //~ ERROR E0430 | ^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/extern/extern-crate-rename.stderr b/src/test/ui/extern/extern-crate-rename.stderr index 2c2723fe4c5c8..f8a5de3654cdc 100644 --- a/src/test/ui/extern/extern-crate-rename.stderr +++ b/src/test/ui/extern/extern-crate-rename.stderr @@ -4,12 +4,13 @@ error[E0259]: the name `m1` is defined multiple times LL | extern crate m1; | ---------------- previous import of the extern crate `m1` here LL | extern crate m2 as m1; //~ ERROR is defined multiple times - | ^^^^^^^^^^^^^^^^^^^^^^ - | | - | `m1` reimported here - | You can use `as` to change the binding name of the import + | ^^^^^^^^^^^^^^^^^^^^^^ `m1` reimported here | = note: `m1` must be defined only once in the type namespace of this module +help: you can use `as` to change the binding name of the import + | +LL | extern crate m2 as other_m1; //~ ERROR is defined multiple times + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/imports/duplicate.stderr b/src/test/ui/imports/duplicate.stderr index 9cdd7aa88f18e..5d51981e8afa9 100644 --- a/src/test/ui/imports/duplicate.stderr +++ b/src/test/ui/imports/duplicate.stderr @@ -7,7 +7,7 @@ LL | use a::foo; //~ ERROR the name `foo` is defined multiple times | ^^^^^^ `foo` reimported here | = note: `foo` must be defined only once in the value namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use a::foo as other_foo; //~ ERROR the name `foo` is defined multiple times | ^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/issues/issue-19498.stderr b/src/test/ui/issues/issue-19498.stderr index 839ab778061c2..e4cefe9d7a4da 100644 --- a/src/test/ui/issues/issue-19498.stderr +++ b/src/test/ui/issues/issue-19498.stderr @@ -8,7 +8,7 @@ LL | mod A {} //~ ERROR the name `A` is defined multiple times | ^^^^^ `A` redefined here | = note: `A` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use self::A as OtherA; | ^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | pub mod B {} //~ ERROR the name `B` is defined multiple times | ^^^^^^^^^ `B` redefined here | = note: `B` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use self::B as OtherB; | ^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | mod D {} //~ ERROR the name `D` is defined multiple times | ^^^^^ `D` redefined here | = note: `D` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use C::D as OtherD; | ^^^^^^^^^^^^^^ diff --git a/src/test/ui/issues/issue-24081.stderr b/src/test/ui/issues/issue-24081.stderr index 17cd3ec0aa6d3..f9a97ac7c99c7 100644 --- a/src/test/ui/issues/issue-24081.stderr +++ b/src/test/ui/issues/issue-24081.stderr @@ -8,7 +8,7 @@ LL | type Add = bool; //~ ERROR the name `Add` is defined multiple times | ^^^^^^^^^^^^^^^^ `Add` redefined here | = note: `Add` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::ops::Add as OtherAdd; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | struct Sub { x: f32 } //~ ERROR the name `Sub` is defined multiple times | ^^^^^^^^^^ `Sub` redefined here | = note: `Sub` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::ops::Sub as OtherSub; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -38,7 +38,7 @@ LL | enum Mul { A, B } //~ ERROR the name `Mul` is defined multiple times | ^^^^^^^^ `Mul` redefined here | = note: `Mul` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::ops::Mul as OtherMul; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL | mod Div { } //~ ERROR the name `Div` is defined multiple times | ^^^^^^^ `Div` redefined here | = note: `Div` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::ops::Div as OtherDiv; | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -68,7 +68,7 @@ LL | trait Rem { } //~ ERROR the name `Rem` is defined multiple times | ^^^^^^^^^ `Rem` redefined here | = note: `Rem` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::ops::Rem as OtherRem; | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/issues/issue-25396.stderr b/src/test/ui/issues/issue-25396.stderr index 1946f39167238..33e7c37882180 100644 --- a/src/test/ui/issues/issue-25396.stderr +++ b/src/test/ui/issues/issue-25396.stderr @@ -7,7 +7,7 @@ LL | use bar::baz; //~ ERROR the name `baz` is defined multiple times | ^^^^^^^^ `baz` reimported here | = note: `baz` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use bar::baz as other_baz; //~ ERROR the name `baz` is defined multiple times | ^^^^^^^^^^^^^^^^^^^^^ @@ -21,7 +21,7 @@ LL | use bar::Quux; //~ ERROR the name `Quux` is defined multiple times | ^^^^^^^^^ `Quux` reimported here | = note: `Quux` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use bar::Quux as OtherQuux; //~ ERROR the name `Quux` is defined multiple times | ^^^^^^^^^^^^^^^^^^^^^^ @@ -35,7 +35,7 @@ LL | use bar::blah; //~ ERROR the name `blah` is defined multiple times | ^^^^^^^^^ `blah` reimported here | = note: `blah` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use bar::blah as other_blah; //~ ERROR the name `blah` is defined multiple times | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | use bar::WOMP; //~ ERROR the name `WOMP` is defined multiple times | ^^^^^^^^^ `WOMP` reimported here | = note: `WOMP` must be defined only once in the value namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use bar::WOMP as OtherWOMP; //~ ERROR the name `WOMP` is defined multiple times | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/issues/issue-26886.stderr b/src/test/ui/issues/issue-26886.stderr index 759426239410f..f2a43b0db798f 100644 --- a/src/test/ui/issues/issue-26886.stderr +++ b/src/test/ui/issues/issue-26886.stderr @@ -7,7 +7,7 @@ LL | use std::sync::Arc; //~ ERROR the name `Arc` is defined multiple times | ^^^^^^^^^^^^^^ `Arc` reimported here | = note: `Arc` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::sync::Arc as OtherArc; //~ ERROR the name `Arc` is defined multiple times | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +22,7 @@ LL | use std::sync; //~ ERROR the name `sync` is defined multiple times | ^^^^^^^^^ `sync` reimported here | = note: `sync` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::sync as other_sync; //~ ERROR the name `sync` is defined multiple times | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/issues/issue-32354-suggest-import-rename.stderr b/src/test/ui/issues/issue-32354-suggest-import-rename.stderr index f45a5f7dd619b..f3acd65e6a269 100644 --- a/src/test/ui/issues/issue-32354-suggest-import-rename.stderr +++ b/src/test/ui/issues/issue-32354-suggest-import-rename.stderr @@ -7,7 +7,7 @@ LL | use extension2::ConstructorExtension; //~ ERROR is defined multiple times | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ConstructorExtension` reimported here | = note: `ConstructorExtension` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use extension2::ConstructorExtension as OtherConstructorExtension; //~ ERROR is defined multiple times | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/issues/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr b/src/test/ui/issues/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr index ecdfec2b3bfd6..99c15976666e2 100644 --- a/src/test/ui/issues/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr +++ b/src/test/ui/issues/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr @@ -5,7 +5,7 @@ LL | extern crate std; | ^^^^^^^^^^^^^^^^^ `std` reimported here | = note: `std` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | extern crate std as other_std; | diff --git a/src/test/ui/issues/issue-8640.stderr b/src/test/ui/issues/issue-8640.stderr index 68fdea6e22805..029f76d152a37 100644 --- a/src/test/ui/issues/issue-8640.stderr +++ b/src/test/ui/issues/issue-8640.stderr @@ -7,7 +7,7 @@ LL | mod bar {} | ^^^^^^^ `bar` redefined here | = note: `bar` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use baz::bar as other_bar; | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/no-std-inject.stderr b/src/test/ui/no-std-inject.stderr index c1ea823a9bda0..fbc54124a088d 100644 --- a/src/test/ui/no-std-inject.stderr +++ b/src/test/ui/no-std-inject.stderr @@ -5,7 +5,7 @@ LL | extern crate core; //~ ERROR: the name `core` is defined multiple times | ^^^^^^^^^^^^^^^^^^ `core` reimported here | = note: `core` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | extern crate core as other_core; //~ ERROR: the name `core` is defined multiple times | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr b/src/test/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr index 5f21b4413e71b..83577b245b78d 100644 --- a/src/test/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr +++ b/src/test/ui/resolve/resolve-conflict-extern-crate-vs-extern-crate.stderr @@ -5,7 +5,7 @@ LL | extern crate std; | ^^^^^^^^^^^^^^^^^ `std` reimported here | = note: `std` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | extern crate std as other_std; | diff --git a/src/test/ui/resolve/resolve-conflict-import-vs-extern-crate.stderr b/src/test/ui/resolve/resolve-conflict-import-vs-extern-crate.stderr index be3600da51ddf..adb66b994db69 100644 --- a/src/test/ui/resolve/resolve-conflict-import-vs-extern-crate.stderr +++ b/src/test/ui/resolve/resolve-conflict-import-vs-extern-crate.stderr @@ -5,7 +5,7 @@ LL | use std::slice as std; //~ ERROR the name `std` is defined multiple times | ^^^^^^^^^^^^^^^^^ `std` reimported here | = note: `std` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::slice as other_std; //~ ERROR the name `std` is defined multiple times | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/resolve/resolve-conflict-import-vs-import.stderr b/src/test/ui/resolve/resolve-conflict-import-vs-import.stderr index 80ccb9aa2b3c3..15f826305bf38 100644 --- a/src/test/ui/resolve/resolve-conflict-import-vs-import.stderr +++ b/src/test/ui/resolve/resolve-conflict-import-vs-import.stderr @@ -7,7 +7,7 @@ LL | use std::mem::transmute; | ^^^^^^^^^^^^^^^^^^^ `transmute` reimported here | = note: `transmute` must be defined only once in the value namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::mem::transmute as other_transmute; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/resolve/resolve-conflict-item-vs-extern-crate.stderr b/src/test/ui/resolve/resolve-conflict-item-vs-extern-crate.stderr index d9ad248c01337..8e0baf3be6fbd 100644 --- a/src/test/ui/resolve/resolve-conflict-item-vs-extern-crate.stderr +++ b/src/test/ui/resolve/resolve-conflict-item-vs-extern-crate.stderr @@ -5,7 +5,7 @@ LL | mod std {} //~ ERROR the name `std` is defined multiple times | ^^^^^^^ `std` redefined here | = note: `std` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | as other_std// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ^^^^^^^^^^^^ diff --git a/src/test/ui/resolve/resolve-conflict-item-vs-import.stderr b/src/test/ui/resolve/resolve-conflict-item-vs-import.stderr index 5ef4bdf4aadd3..5305ddbd2ef6d 100644 --- a/src/test/ui/resolve/resolve-conflict-item-vs-import.stderr +++ b/src/test/ui/resolve/resolve-conflict-item-vs-import.stderr @@ -8,7 +8,7 @@ LL | fn transmute() {} | ^^^^^^^^^^^^^^ `transmute` redefined here | = note: `transmute` must be defined only once in the value namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::mem::transmute as other_transmute; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/resolve/resolve-conflict-type-vs-import.stderr b/src/test/ui/resolve/resolve-conflict-type-vs-import.stderr index 1e8df8f8ea78c..e5cafa3ac986f 100644 --- a/src/test/ui/resolve/resolve-conflict-type-vs-import.stderr +++ b/src/test/ui/resolve/resolve-conflict-type-vs-import.stderr @@ -8,7 +8,7 @@ LL | struct Iter; | ^^^^^^^^^^^^ `Iter` redefined here | = note: `Iter` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::slice::Iter as OtherIter; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/unresolved/unresolved-extern-mod-suggestion.stderr b/src/test/ui/unresolved/unresolved-extern-mod-suggestion.stderr index 4e3ea573d2795..86ea348ac47b7 100644 --- a/src/test/ui/unresolved/unresolved-extern-mod-suggestion.stderr +++ b/src/test/ui/unresolved/unresolved-extern-mod-suggestion.stderr @@ -7,7 +7,7 @@ LL | use core; | ^^^^ `core` reimported here | = note: `core` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use core as other_core; | ^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/use/use-mod.stderr b/src/test/ui/use/use-mod.stderr index dcdba6fce9ad9..adef47ac8fb79 100644 --- a/src/test/ui/use/use-mod.stderr +++ b/src/test/ui/use/use-mod.stderr @@ -23,7 +23,7 @@ LL | self | ^^^^ `bar` reimported here | = note: `bar` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | self as other_bar | diff --git a/src/test/ui/use/use-paths-as-items.stderr b/src/test/ui/use/use-paths-as-items.stderr index 200cefc23aff0..56db03fd16331 100644 --- a/src/test/ui/use/use-paths-as-items.stderr +++ b/src/test/ui/use/use-paths-as-items.stderr @@ -7,7 +7,7 @@ LL | use std::mem; //~ ERROR the name `mem` is defined multiple times | ^^^^^^^^ `mem` reimported here | = note: `mem` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | use std::mem as other_mem; //~ ERROR the name `mem` is defined multiple times | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/variants/variant-namespacing.stderr b/src/test/ui/variants/variant-namespacing.stderr index 322ea617f3439..ce2fb7cb92c56 100644 --- a/src/test/ui/variants/variant-namespacing.stderr +++ b/src/test/ui/variants/variant-namespacing.stderr @@ -8,7 +8,7 @@ LL | pub use variant_namespacing::XE::{XStruct, XTuple, XUnit}; | ^^^^^^^ `XStruct` reimported here | = note: `XStruct` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | pub use variant_namespacing::XE::{XStruct as OtherXStruct, XTuple, XUnit}; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | pub use variant_namespacing::XE::{XStruct, XTuple, XUnit}; | ^^^^^^ `XTuple` reimported here | = note: `XTuple` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | pub use variant_namespacing::XE::{XStruct, XTuple as OtherXTuple, XUnit}; | ^^^^^^^^^^^^^^^^^^^^^ @@ -38,7 +38,7 @@ LL | pub use variant_namespacing::XE::{XStruct, XTuple, XUnit}; | ^^^^^ `XUnit` reimported here | = note: `XUnit` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | pub use variant_namespacing::XE::{XStruct, XTuple, XUnit as OtherXUnit}; | ^^^^^^^^^^^^^^^^^^^ @@ -53,7 +53,7 @@ LL | pub use E::{Struct, Tuple, Unit}; | ^^^^^^ `Struct` reimported here | = note: `Struct` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | pub use E::{Struct as OtherStruct, Tuple, Unit}; | ^^^^^^^^^^^^^^^^^^^^^ @@ -68,7 +68,7 @@ LL | pub use E::{Struct, Tuple, Unit}; | ^^^^^ `Tuple` reimported here | = note: `Tuple` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | pub use E::{Struct, Tuple as OtherTuple, Unit}; | ^^^^^^^^^^^^^^^^^^^ @@ -83,7 +83,7 @@ LL | pub use E::{Struct, Tuple, Unit}; | ^^^^ `Unit` reimported here | = note: `Unit` must be defined only once in the type namespace of this module -help: You can use `as` to change the binding name of the import +help: you can use `as` to change the binding name of the import | LL | pub use E::{Struct, Tuple, Unit as OtherUnit}; | ^^^^^^^^^^^^^^^^^ From 4520b305ec477b90629d078b20acffe6b32da58c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=CC=A7ois=20Mockers?= Date: Wed, 17 Oct 2018 01:29:07 +0200 Subject: [PATCH 4/6] and style fix --- src/librustc_resolve/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 7320b6e7d9b7d..c1d1f3c5e0d2b 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -4786,7 +4786,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { err.span_suggestion_with_applicability( binding.span, rename_msg, - match (snippet.split_whitespace().find(|w| *w == "as"), snippet.ends_with(";")) { + match ( + snippet.split_whitespace().find(|w| *w == "as"), + snippet.ends_with(";") + ) { (Some(_), false) => format!("{} as {}", &snippet[..snippet.find(" as ").unwrap()], suggested_name, @@ -4796,7 +4799,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { suggested_name, ), (None, false) => format!("{} as {}", snippet, suggested_name), - (None, true) => format!("{} as {};", + (None, true) => format!("{} as {};", &snippet[..snippet.len() - 1], suggested_name ), From 9eacd68a4945aaba244885c330f64004da58a408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=CC=A7ois=20Mockers?= Date: Sun, 21 Oct 2018 00:23:29 +0200 Subject: [PATCH 5/6] manage cases with tabs or other whitespaces --- src/librustc_resolve/build_reduced_graph.rs | 5 +- src/librustc_resolve/check_unused.rs | 2 +- src/librustc_resolve/lib.rs | 55 ++++++++++++------- src/librustc_resolve/resolve_imports.rs | 7 ++- src/test/ui/issues/issue-45829/import-self.rs | 22 ++++++++ .../ui/issues/issue-45829/import-self.stderr | 31 +++++++++++ .../ui/issues/issue-45829/import-twice.rs | 18 ++++++ .../ui/issues/issue-45829/import-twice.stderr | 17 ++++++ .../issue-45829/rename-extern-with-tab.rs | 17 ++++++ .../issue-45829/rename-extern-with-tab.stderr | 17 ++++++ .../issue-45829/rename-use-with-tabs.rs | 21 +++++++ .../issue-45829/rename-use-with-tabs.stderr | 17 ++++++ ...solve-conflict-item-vs-extern-crate.stderr | 4 -- 13 files changed, 204 insertions(+), 29 deletions(-) create mode 100644 src/test/ui/issues/issue-45829/import-self.rs create mode 100644 src/test/ui/issues/issue-45829/import-self.stderr create mode 100644 src/test/ui/issues/issue-45829/import-twice.rs create mode 100644 src/test/ui/issues/issue-45829/import-twice.stderr create mode 100644 src/test/ui/issues/issue-45829/rename-extern-with-tab.rs create mode 100644 src/test/ui/issues/issue-45829/rename-extern-with-tab.stderr create mode 100644 src/test/ui/issues/issue-45829/rename-use-with-tabs.rs create mode 100644 src/test/ui/issues/issue-45829/rename-use-with-tabs.stderr diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 25a7ff9cd3f56..4158d20a5f86c 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -449,7 +449,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> { id: item.id, parent, imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))), - subclass: ImportDirectiveSubclass::ExternCrate(orig_name), + subclass: ImportDirectiveSubclass::ExternCrate { + source: orig_name, + target: ident, + }, root_span: item.span, span: item.span, module_path: Vec::new(), diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs index de9481579e2f4..5fa0460a28d0f 100644 --- a/src/librustc_resolve/check_unused.rs +++ b/src/librustc_resolve/check_unused.rs @@ -144,7 +144,7 @@ pub fn check_crate(resolver: &mut Resolver, krate: &ast::Crate) { } } } - ImportDirectiveSubclass::ExternCrate(_) => { + ImportDirectiveSubclass::ExternCrate { .. } => { resolver.maybe_unused_extern_crates.push((directive.id, directive.span)); } ImportDirectiveSubclass::MacroUse => { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index c1d1f3c5e0d2b..ba367cca2451d 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1234,7 +1234,7 @@ impl<'a> NameBinding<'a> { match self.kind { NameBindingKind::Import { directive: &ImportDirective { - subclass: ImportDirectiveSubclass::ExternCrate(_), .. + subclass: ImportDirectiveSubclass::ExternCrate { .. }, .. }, .. } => true, _ => false, @@ -3794,7 +3794,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { if let NameBindingKind::Import { directive: d, .. } = binding.kind { // Careful: we still want to rewrite paths from // renamed extern crates. - if let ImportDirectiveSubclass::ExternCrate(None) = d.subclass { + if let ImportDirectiveSubclass::ExternCrate { source: None, .. } = d.subclass { return } } @@ -4776,7 +4776,15 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { 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) = cm.span_to_snippet(binding.span) { + if let ( + Ok(snippet), + NameBindingKind::Import { directive, ..}, + _x @ 1 ... std::u32::MAX, + ) = ( + cm.span_to_snippet(binding.span), + binding.kind.clone(), + binding.span.hi().0, + ) { let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() { format!("Other{}", name) } else { @@ -4785,24 +4793,29 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { err.span_suggestion_with_applicability( binding.span, - rename_msg, - match ( - snippet.split_whitespace().find(|w| *w == "as"), - snippet.ends_with(";") - ) { - (Some(_), false) => format!("{} as {}", - &snippet[..snippet.find(" as ").unwrap()], - suggested_name, - ), - (Some(_), true) => format!("{} as {};", - &snippet[..snippet.find(" as ").unwrap()], - suggested_name, - ), - (None, false) => format!("{} as {}", snippet, suggested_name), - (None, true) => format!("{} as {};", - &snippet[..snippet.len() - 1], - suggested_name - ), + &rename_msg, + match (&directive.subclass, snippet.ends_with(";"), snippet.as_ref()) { + (ImportDirectiveSubclass::SingleImport { .. }, false, "self") => + format!("self as {}", suggested_name), + (ImportDirectiveSubclass::SingleImport { source, .. }, false, _) => + format!( + "{} as {}", + &snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)], + suggested_name, + ), + (ImportDirectiveSubclass::SingleImport { source, .. }, true, _) => + format!( + "{} as {};", + &snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)], + suggested_name, + ), + (ImportDirectiveSubclass::ExternCrate { source, target, .. }, _, _) => + format!( + "extern crate {} as {};", + source.unwrap_or(target.name), + suggested_name, + ), + (_, _, _) => unreachable!(), }, Applicability::MaybeIncorrect, ); diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 6e9877b1ab66d..bb51bf9505158 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -52,7 +52,10 @@ pub enum ImportDirectiveSubclass<'a> { max_vis: Cell, // The visibility of the greatest re-export. // n.b. `max_vis` is only used in `finalize_import` to check for re-export errors. }, - ExternCrate(Option), + ExternCrate { + source: Option, + target: Ident, + }, MacroUse, } @@ -1342,7 +1345,7 @@ fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass) -> St match *subclass { SingleImport { source, .. } => source.to_string(), GlobImport { .. } => "*".to_string(), - ExternCrate(_) => "".to_string(), + ExternCrate { .. } => "".to_string(), MacroUse => "#[macro_use]".to_string(), } } diff --git a/src/test/ui/issues/issue-45829/import-self.rs b/src/test/ui/issues/issue-45829/import-self.rs new file mode 100644 index 0000000000000..8b13ffd0076d5 --- /dev/null +++ b/src/test/ui/issues/issue-45829/import-self.rs @@ -0,0 +1,22 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +mod foo { + pub struct A; + pub struct B; +} + +use foo::{self}; + +use foo as self; + +use foo::self; + +fn main() {} diff --git a/src/test/ui/issues/issue-45829/import-self.stderr b/src/test/ui/issues/issue-45829/import-self.stderr new file mode 100644 index 0000000000000..985dc4e7131cf --- /dev/null +++ b/src/test/ui/issues/issue-45829/import-self.stderr @@ -0,0 +1,31 @@ +error: expected identifier, found keyword `self` + --> $DIR/import-self.rs:18:12 + | +LL | use foo as self; + | ^^^^ expected identifier, found keyword + +error[E0429]: `self` imports are only allowed within a { } list + --> $DIR/import-self.rs:20:5 + | +LL | use foo::self; + | ^^^^^^^^^ + +error[E0255]: the name `foo` is defined multiple times + --> $DIR/import-self.rs:16:11 + | +LL | mod foo { + | ------- previous definition of the module `foo` here +... +LL | use foo::{self}; + | ^^^^ `foo` reimported here + | + = note: `foo` must be defined only once in the type namespace of this module +help: you can use `as` to change the binding name of the import + | +LL | use foo::{self as other_foo}; + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + +Some errors occurred: E0255, E0429. +For more information about an error, try `rustc --explain E0255`. diff --git a/src/test/ui/issues/issue-45829/import-twice.rs b/src/test/ui/issues/issue-45829/import-twice.rs new file mode 100644 index 0000000000000..785932e5ef42a --- /dev/null +++ b/src/test/ui/issues/issue-45829/import-twice.rs @@ -0,0 +1,18 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +mod foo { + pub struct A; + pub struct B; +} + +use foo::{A, A}; + +fn main() {} diff --git a/src/test/ui/issues/issue-45829/import-twice.stderr b/src/test/ui/issues/issue-45829/import-twice.stderr new file mode 100644 index 0000000000000..566d47965f82f --- /dev/null +++ b/src/test/ui/issues/issue-45829/import-twice.stderr @@ -0,0 +1,17 @@ +error[E0252]: the name `A` is defined multiple times + --> $DIR/import-twice.rs:16:14 + | +LL | use foo::{A, A}; + | - ^ `A` reimported here + | | + | previous import of the type `A` here + | + = note: `A` must be defined only once in the type namespace of this module +help: you can use `as` to change the binding name of the import + | +LL | use foo::{A, A as OtherA}; + | ^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0252`. diff --git a/src/test/ui/issues/issue-45829/rename-extern-with-tab.rs b/src/test/ui/issues/issue-45829/rename-extern-with-tab.rs new file mode 100644 index 0000000000000..7066ed65c78c3 --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename-extern-with-tab.rs @@ -0,0 +1,17 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue_45829_a.rs +// aux-build:issue_45829_b.rs + +extern crate issue_45829_a; +extern crate issue_45829_b as issue_45829_a; + +fn main() {} diff --git a/src/test/ui/issues/issue-45829/rename-extern-with-tab.stderr b/src/test/ui/issues/issue-45829/rename-extern-with-tab.stderr new file mode 100644 index 0000000000000..769be545706cb --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename-extern-with-tab.stderr @@ -0,0 +1,17 @@ +error[E0259]: the name `issue_45829_a` is defined multiple times + --> $DIR/rename-extern-with-tab.rs:15:1 + | +LL | extern crate issue_45829_a; + | --------------------------- previous import of the extern crate `issue_45829_a` here +LL | extern crate issue_45829_b as issue_45829_a; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `issue_45829_a` reimported here + | + = note: `issue_45829_a` must be defined only once in the type namespace of this module +help: you can use `as` to change the binding name of the import + | +LL | extern crate issue_45829_b as other_issue_45829_a; + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0259`. diff --git a/src/test/ui/issues/issue-45829/rename-use-with-tabs.rs b/src/test/ui/issues/issue-45829/rename-use-with-tabs.rs new file mode 100644 index 0000000000000..c1e4d9089068d --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename-use-with-tabs.rs @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +mod foo { + pub struct A; + + pub mod bar { + pub struct B; + } +} + +use foo::{A, bar::B as A}; + +fn main() {} diff --git a/src/test/ui/issues/issue-45829/rename-use-with-tabs.stderr b/src/test/ui/issues/issue-45829/rename-use-with-tabs.stderr new file mode 100644 index 0000000000000..b80a692028aa0 --- /dev/null +++ b/src/test/ui/issues/issue-45829/rename-use-with-tabs.stderr @@ -0,0 +1,17 @@ +error[E0252]: the name `A` is defined multiple times + --> $DIR/rename-use-with-tabs.rs:19:14 + | +LL | use foo::{A, bar::B as A}; + | - ^^^^^^^^^^^^^^^^^ `A` reimported here + | | + | previous import of the type `A` here + | + = note: `A` must be defined only once in the type namespace of this module +help: you can use `as` to change the binding name of the import + | +LL | use foo::{A, bar::B as OtherA}; + | ^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0252`. diff --git a/src/test/ui/resolve/resolve-conflict-item-vs-extern-crate.stderr b/src/test/ui/resolve/resolve-conflict-item-vs-extern-crate.stderr index 8e0baf3be6fbd..0b082c1105f15 100644 --- a/src/test/ui/resolve/resolve-conflict-item-vs-extern-crate.stderr +++ b/src/test/ui/resolve/resolve-conflict-item-vs-extern-crate.stderr @@ -5,10 +5,6 @@ LL | mod std {} //~ ERROR the name `std` is defined multiple times | ^^^^^^^ `std` redefined here | = note: `std` must be defined only once in the type namespace of this module -help: you can use `as` to change the binding name of the import - | -LL | as other_std// Copyright 2014 The Rust Project Developers. See the COPYRIGHT - | ^^^^^^^^^^^^ error: aborting due to previous error From 8fe6688fcf14508f95db6c96b92f4279ccb0c6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=CC=A7ois=20Mockers?= Date: Mon, 22 Oct 2018 09:08:09 +0200 Subject: [PATCH 6/6] better dummy span detection and remove redundant branch --- src/librustc_resolve/lib.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index ba367cca2451d..b18747da0bcdd 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -4779,11 +4779,11 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { if let ( Ok(snippet), NameBindingKind::Import { directive, ..}, - _x @ 1 ... std::u32::MAX, + _dummy @ false, ) = ( cm.span_to_snippet(binding.span), binding.kind.clone(), - binding.span.hi().0, + binding.span.is_dummy(), ) { let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() { format!("Other{}", name) @@ -4794,28 +4794,27 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { err.span_suggestion_with_applicability( binding.span, &rename_msg, - match (&directive.subclass, snippet.ends_with(";"), snippet.as_ref()) { - (ImportDirectiveSubclass::SingleImport { .. }, false, "self") => + match (&directive.subclass, snippet.as_ref()) { + (ImportDirectiveSubclass::SingleImport { .. }, "self") => format!("self as {}", suggested_name), - (ImportDirectiveSubclass::SingleImport { source, .. }, false, _) => + (ImportDirectiveSubclass::SingleImport { source, .. }, _) => format!( - "{} as {}", - &snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)], - suggested_name, - ), - (ImportDirectiveSubclass::SingleImport { source, .. }, true, _) => - format!( - "{} as {};", + "{} as {}{}", &snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)], suggested_name, + if snippet.ends_with(";") { + ";" + } else { + "" + } ), - (ImportDirectiveSubclass::ExternCrate { source, target, .. }, _, _) => + (ImportDirectiveSubclass::ExternCrate { source, target, .. }, _) => format!( "extern crate {} as {};", source.unwrap_or(target.name), suggested_name, ), - (_, _, _) => unreachable!(), + (_, _) => unreachable!(), }, Applicability::MaybeIncorrect, );