Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0252]: the name `p` is defined multiple times
--> $DIR/use-statement-duplicate-check-7663.rs:34:9
|
LL | use crate::foo::p;
| ------------- previous import of the value `p` here
LL | use crate::bar::p;
| ^^^^^^^^^^^^^ `p` reimported here
|
= note: `p` 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
|
LL | use crate::bar::p as other_p;
| ++++++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0252`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0659]: `p` is ambiguous
--> $DIR/use-statement-duplicate-check-7663.rs:27:9
|
LL | p()
| ^ ambiguous name
|
= note: ambiguous because of multiple glob imports of a name in the same module
note: `p` could refer to the function imported here
--> $DIR/use-statement-duplicate-check-7663.rs:23:9
|
LL | use crate::bar::*;
| ^^^^^^^^^^^^^
= help: consider adding an explicit import of `p` to disambiguate
note: `p` could also refer to the function imported here
--> $DIR/use-statement-duplicate-check-7663.rs:24:9
|
LL | use crate::foo::*;
| ^^^^^^^^^^^^^
= help: consider adding an explicit import of `p` to disambiguate

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0659`.
53 changes: 34 additions & 19 deletions tests/ui/modules/use-statement-duplicate-check-7663.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
// https://github.com/rust-lang/rust/issues/7663
//@ run-pass
//! Regression test for #7663.
//@ revisions: glob_glob explicit_explicit glob_explicit
//@[glob_glob] check-fail
//@[explicit_explicit] check-fail
//@[glob_explicit] check-pass

#![allow(unused_imports, dead_code)]

mod test1 {
mod foo {
pub fn p() -> &'static str {
"foo"
}
}

mod foo { pub fn p() -> isize { 1 } }
mod bar { pub fn p() -> isize { 2 } }
mod bar {
pub fn p() -> usize {
2
}
}

pub mod baz {
use crate::test1::bar::p;
#[cfg(glob_glob)]
mod case {
use crate::bar::*;
use crate::foo::*;

pub fn my_main() { assert_eq!(p(), 2); }
fn check() -> usize {
p() //[glob_glob]~ ERROR `p` is ambiguous
}
}

mod test2 {

mod foo { pub fn p() -> isize { 1 } }
mod bar { pub fn p() -> isize { 2 } }
#[cfg(explicit_explicit)]
mod case {
use crate::foo::p;
use crate::bar::p;
//[explicit_explicit]~^ ERROR the name `p` is defined multiple times
}

pub mod baz {
use crate::test2::bar::p;
#[cfg(glob_explicit)]
mod case {
use crate::foo::*;
use crate::bar::p;

pub fn my_main() { assert_eq!(p(), 2); }
fn check() -> usize {
p()
}
}

fn main() {
test1::baz::my_main();
test2::baz::my_main();
}
fn main() {}
Loading