#45829 when a renamed import conflict with a previous import
This commit is contained in:
parent
5a52983d69
commit
cac95ee11c
@ -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,
|
||||
);
|
||||
|
11
src/test/ui/issues/issue-45829/auxiliary/issue_45829_a.rs
Normal file
11
src/test/ui/issues/issue-45829/auxiliary/issue_45829_a.rs
Normal file
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
pub const FOO: usize = *&0;
|
11
src/test/ui/issues/issue-45829/auxiliary/issue_45829_b.rs
Normal file
11
src/test/ui/issues/issue-45829/auxiliary/issue_45829_b.rs
Normal file
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
pub const FOO: usize = *&0;
|
16
src/test/ui/issues/issue-45829/rename-extern-vs-use.rs
Normal file
16
src/test/ui/issues/issue-45829/rename-extern-vs-use.rs
Normal file
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {}
|
27
src/test/ui/issues/issue-45829/rename-extern-vs-use.stderr
Normal file
27
src/test/ui/issues/issue-45829/rename-extern-vs-use.stderr
Normal file
@ -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`.
|
17
src/test/ui/issues/issue-45829/rename-extern.rs
Normal file
17
src/test/ui/issues/issue-45829/rename-extern.rs
Normal file
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {}
|
16
src/test/ui/issues/issue-45829/rename-extern.stderr
Normal file
16
src/test/ui/issues/issue-45829/rename-extern.stderr
Normal file
@ -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`.
|
16
src/test/ui/issues/issue-45829/rename-use-vs-extern.rs
Normal file
16
src/test/ui/issues/issue-45829/rename-use-vs-extern.rs
Normal file
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {}
|
17
src/test/ui/issues/issue-45829/rename-use-vs-extern.stderr
Normal file
17
src/test/ui/issues/issue-45829/rename-use-vs-extern.stderr
Normal file
@ -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`.
|
13
src/test/ui/issues/issue-45829/rename-with-path.rs
Normal file
13
src/test/ui/issues/issue-45829/rename-with-path.rs
Normal file
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {}
|
17
src/test/ui/issues/issue-45829/rename-with-path.stderr
Normal file
17
src/test/ui/issues/issue-45829/rename-with-path.stderr
Normal file
@ -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`.
|
16
src/test/ui/issues/issue-45829/rename.rs
Normal file
16
src/test/ui/issues/issue-45829/rename.rs
Normal file
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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;
|
||||
}
|
17
src/test/ui/issues/issue-45829/rename.stderr
Normal file
17
src/test/ui/issues/issue-45829/rename.stderr
Normal file
@ -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`.
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user