#45829 when a renamed import conflict with a previous import

This commit is contained in:
François Mockers 2018-10-16 08:22:32 +02:00
parent 5a52983d69
commit cac95ee11c
14 changed files with 207 additions and 5 deletions

View File

@ -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,
);

View 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;

View 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;

View 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() {}

View 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`.

View 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() {}

View 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`.

View 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() {}

View 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`.

View 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() {}

View 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`.

View 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;
}

View 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`.

View File

@ -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