diff options
Diffstat (limited to 'src/test/ui/use')
45 files changed, 821 insertions, 0 deletions
diff --git a/src/test/ui/use/auxiliary/extern-use-primitive-type-lib.rs b/src/test/ui/use/auxiliary/extern-use-primitive-type-lib.rs new file mode 100644 index 000000000..3c7756ef7 --- /dev/null +++ b/src/test/ui/use/auxiliary/extern-use-primitive-type-lib.rs @@ -0,0 +1,3 @@ +// compile-flags: --edition=2018 + +pub use u32; diff --git a/src/test/ui/use/auxiliary/use-from-trait-xc.rs b/src/test/ui/use/auxiliary/use-from-trait-xc.rs new file mode 100644 index 000000000..4abe11941 --- /dev/null +++ b/src/test/ui/use/auxiliary/use-from-trait-xc.rs @@ -0,0 +1,29 @@ +pub use self::sub::{Bar, Baz}; + +pub trait Trait { + fn foo(&self); + type Assoc; + const CONST: u32; +} + +struct Foo; + +impl Foo { + pub fn new() {} + + pub const C: u32 = 0; +} + +mod sub { + pub struct Bar; + + impl Bar { + pub fn new() {} + } + + pub enum Baz {} + + impl Baz { + pub fn new() {} + } +} diff --git a/src/test/ui/use/issue-18986.rs b/src/test/ui/use/issue-18986.rs new file mode 100644 index 000000000..f0b292f29 --- /dev/null +++ b/src/test/ui/use/issue-18986.rs @@ -0,0 +1,10 @@ +// aux-build:use-from-trait-xc.rs + +extern crate use_from_trait_xc; +pub use use_from_trait_xc::Trait; + +fn main() { + match () { + Trait { x: 42 } => () //~ ERROR expected struct, variant or union type, found trait `Trait` + } +} diff --git a/src/test/ui/use/issue-18986.stderr b/src/test/ui/use/issue-18986.stderr new file mode 100644 index 000000000..6c23178c7 --- /dev/null +++ b/src/test/ui/use/issue-18986.stderr @@ -0,0 +1,9 @@ +error[E0574]: expected struct, variant or union type, found trait `Trait` + --> $DIR/issue-18986.rs:8:9 + | +LL | Trait { x: 42 } => () + | ^^^^^ not a struct, variant or union type + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0574`. diff --git a/src/test/ui/use/issue-60976-extern-use-primitive-type.rs b/src/test/ui/use/issue-60976-extern-use-primitive-type.rs new file mode 100644 index 000000000..4cd458302 --- /dev/null +++ b/src/test/ui/use/issue-60976-extern-use-primitive-type.rs @@ -0,0 +1,7 @@ +// Regression test for #60976: ICE (with <=1.36.0) when another file had `use <primitive_type>;`. +// check-pass +// aux-build:extern-use-primitive-type-lib.rs + +extern crate extern_use_primitive_type_lib; + +fn main() {} diff --git a/src/test/ui/use/use-after-move-based-on-type.rs b/src/test/ui/use/use-after-move-based-on-type.rs new file mode 100644 index 000000000..ba7aa0345 --- /dev/null +++ b/src/test/ui/use/use-after-move-based-on-type.rs @@ -0,0 +1,5 @@ +fn main() { + let x = "Hello!".to_string(); + let _y = x; + println!("{}", x); //~ ERROR borrow of moved value +} diff --git a/src/test/ui/use/use-after-move-based-on-type.stderr b/src/test/ui/use/use-after-move-based-on-type.stderr new file mode 100644 index 000000000..445f14d65 --- /dev/null +++ b/src/test/ui/use/use-after-move-based-on-type.stderr @@ -0,0 +1,15 @@ +error[E0382]: borrow of moved value: `x` + --> $DIR/use-after-move-based-on-type.rs:4:20 + | +LL | let x = "Hello!".to_string(); + | - move occurs because `x` has type `String`, which does not implement the `Copy` trait +LL | let _y = x; + | - value moved here +LL | println!("{}", x); + | ^ value borrowed here after move + | + = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/use/use-after-move-implicity-coerced-object.rs b/src/test/ui/use/use-after-move-implicity-coerced-object.rs new file mode 100644 index 000000000..47fbb5bf1 --- /dev/null +++ b/src/test/ui/use/use-after-move-implicity-coerced-object.rs @@ -0,0 +1,30 @@ +use std::fmt; + +struct Number { + n: i64 +} + +impl fmt::Display for Number { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.n) + } +} + +struct List { + list: Vec<Box<dyn ToString + 'static>> } + +impl List { + fn push(&mut self, n: Box<dyn ToString + 'static>) { + self.list.push(n); + } +} + +fn main() { + + let n: Box<_> = Number { n: 42 }.into(); + let mut l: Box<_> = List { list: Vec::new() }.into(); + l.push(n); + + let x = n.to_string(); + //~^ ERROR: borrow of moved value: `n` +} diff --git a/src/test/ui/use/use-after-move-implicity-coerced-object.stderr b/src/test/ui/use/use-after-move-implicity-coerced-object.stderr new file mode 100644 index 000000000..26804216d --- /dev/null +++ b/src/test/ui/use/use-after-move-implicity-coerced-object.stderr @@ -0,0 +1,15 @@ +error[E0382]: borrow of moved value: `n` + --> $DIR/use-after-move-implicity-coerced-object.rs:28:13 + | +LL | let n: Box<_> = Number { n: 42 }.into(); + | - move occurs because `n` has type `Box<Number>`, which does not implement the `Copy` trait +LL | let mut l: Box<_> = List { list: Vec::new() }.into(); +LL | l.push(n); + | - value moved here +LL | +LL | let x = n.to_string(); + | ^^^^^^^^^^^^^ value borrowed here after move + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/use/use-after-move-self-based-on-type.rs b/src/test/ui/use/use-after-move-self-based-on-type.rs new file mode 100644 index 000000000..932583495 --- /dev/null +++ b/src/test/ui/use/use-after-move-self-based-on-type.rs @@ -0,0 +1,21 @@ +struct S { + x: isize, +} + +impl Drop for S { + fn drop(&mut self) {} +} + +impl S { + pub fn foo(self) -> isize { + self.bar(); + return self.x; //~ ERROR use of moved value: `self` + } + + pub fn bar(self) {} +} + +fn main() { + let x = S { x: 1 }; + println!("{}", x.foo()); +} diff --git a/src/test/ui/use/use-after-move-self-based-on-type.stderr b/src/test/ui/use/use-after-move-self-based-on-type.stderr new file mode 100644 index 000000000..7fdc4ab25 --- /dev/null +++ b/src/test/ui/use/use-after-move-self-based-on-type.stderr @@ -0,0 +1,19 @@ +error[E0382]: use of moved value: `self` + --> $DIR/use-after-move-self-based-on-type.rs:12:16 + | +LL | pub fn foo(self) -> isize { + | ---- move occurs because `self` has type `S`, which does not implement the `Copy` trait +LL | self.bar(); + | ----- `self` moved due to this method call +LL | return self.x; + | ^^^^^^ value used here after move + | +note: this function takes ownership of the receiver `self`, which moves `self` + --> $DIR/use-after-move-self-based-on-type.rs:15:16 + | +LL | pub fn bar(self) {} + | ^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/use/use-after-move-self.rs b/src/test/ui/use/use-after-move-self.rs new file mode 100644 index 000000000..f7a3c0ecc --- /dev/null +++ b/src/test/ui/use/use-after-move-self.rs @@ -0,0 +1,19 @@ +struct S { + x: Box<isize>, +} + + + +impl S { + pub fn foo(self) -> isize { + self.bar(); + return *self.x; //~ ERROR use of moved value: `self` + } + + pub fn bar(self) {} +} + +fn main() { + let x = S { x: 1.into() }; + println!("{}", x.foo()); +} diff --git a/src/test/ui/use/use-after-move-self.stderr b/src/test/ui/use/use-after-move-self.stderr new file mode 100644 index 000000000..073deee63 --- /dev/null +++ b/src/test/ui/use/use-after-move-self.stderr @@ -0,0 +1,19 @@ +error[E0382]: use of moved value: `self` + --> $DIR/use-after-move-self.rs:10:16 + | +LL | pub fn foo(self) -> isize { + | ---- move occurs because `self` has type `S`, which does not implement the `Copy` trait +LL | self.bar(); + | ----- `self` moved due to this method call +LL | return *self.x; + | ^^^^^^^ value used here after move + | +note: this function takes ownership of the receiver `self`, which moves `self` + --> $DIR/use-after-move-self.rs:13:16 + | +LL | pub fn bar(self) {} + | ^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/use/use-associated-const.rs b/src/test/ui/use/use-associated-const.rs new file mode 100644 index 000000000..714fbdabb --- /dev/null +++ b/src/test/ui/use/use-associated-const.rs @@ -0,0 +1,13 @@ +#![allow(unused_imports)] + +pub mod foo { + pub struct Foo; + + impl Foo { + pub const BAR: i32 = 0; + } +} + +use foo::Foo::BAR; //~ ERROR unresolved import `foo::Foo` + +fn main() {} diff --git a/src/test/ui/use/use-associated-const.stderr b/src/test/ui/use/use-associated-const.stderr new file mode 100644 index 000000000..4bc0d7e61 --- /dev/null +++ b/src/test/ui/use/use-associated-const.stderr @@ -0,0 +1,9 @@ +error[E0432]: unresolved import `foo::Foo` + --> $DIR/use-associated-const.rs:11:10 + | +LL | use foo::Foo::BAR; + | ^^^ `Foo` is a struct, not a module + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/use/use-from-trait-xc.rs b/src/test/ui/use/use-from-trait-xc.rs new file mode 100644 index 000000000..695ed66a1 --- /dev/null +++ b/src/test/ui/use/use-from-trait-xc.rs @@ -0,0 +1,26 @@ +// aux-build:use-from-trait-xc.rs + +extern crate use_from_trait_xc; + +use use_from_trait_xc::Trait::foo; +//~^ ERROR `foo` is not directly importable + +use use_from_trait_xc::Trait::Assoc; +//~^ ERROR `Assoc` is not directly importable + +use use_from_trait_xc::Trait::CONST; +//~^ ERROR `CONST` is not directly importable + +use use_from_trait_xc::Foo::new; //~ ERROR struct `Foo` is private +//~^ ERROR unresolved import `use_from_trait_xc::Foo` + +use use_from_trait_xc::Foo::C; //~ ERROR struct `Foo` is private +//~^ ERROR unresolved import `use_from_trait_xc::Foo` + +use use_from_trait_xc::Bar::new as bnew; +//~^ ERROR unresolved import `use_from_trait_xc::Bar` + +use use_from_trait_xc::Baz::new as baznew; +//~^ ERROR unresolved import `use_from_trait_xc::Baz::new` + +fn main() {} diff --git a/src/test/ui/use/use-from-trait-xc.stderr b/src/test/ui/use/use-from-trait-xc.stderr new file mode 100644 index 000000000..4c4c2f622 --- /dev/null +++ b/src/test/ui/use/use-from-trait-xc.stderr @@ -0,0 +1,70 @@ +error[E0253]: `foo` is not directly importable + --> $DIR/use-from-trait-xc.rs:5:5 + | +LL | use use_from_trait_xc::Trait::foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot be imported directly + +error[E0253]: `Assoc` is not directly importable + --> $DIR/use-from-trait-xc.rs:8:5 + | +LL | use use_from_trait_xc::Trait::Assoc; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot be imported directly + +error[E0253]: `CONST` is not directly importable + --> $DIR/use-from-trait-xc.rs:11:5 + | +LL | use use_from_trait_xc::Trait::CONST; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot be imported directly + +error[E0432]: unresolved import `use_from_trait_xc::Foo` + --> $DIR/use-from-trait-xc.rs:14:24 + | +LL | use use_from_trait_xc::Foo::new; + | ^^^ `Foo` is a struct, not a module + +error[E0432]: unresolved import `use_from_trait_xc::Foo` + --> $DIR/use-from-trait-xc.rs:17:24 + | +LL | use use_from_trait_xc::Foo::C; + | ^^^ `Foo` is a struct, not a module + +error[E0432]: unresolved import `use_from_trait_xc::Bar` + --> $DIR/use-from-trait-xc.rs:20:24 + | +LL | use use_from_trait_xc::Bar::new as bnew; + | ^^^ `Bar` is a struct, not a module + +error[E0432]: unresolved import `use_from_trait_xc::Baz::new` + --> $DIR/use-from-trait-xc.rs:23:5 + | +LL | use use_from_trait_xc::Baz::new as baznew; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `new` in `sub::Baz` + +error[E0603]: struct `Foo` is private + --> $DIR/use-from-trait-xc.rs:14:24 + | +LL | use use_from_trait_xc::Foo::new; + | ^^^ private struct + | +note: the struct `Foo` is defined here + --> $DIR/auxiliary/use-from-trait-xc.rs:9:1 + | +LL | struct Foo; + | ^^^^^^^^^^ + +error[E0603]: struct `Foo` is private + --> $DIR/use-from-trait-xc.rs:17:24 + | +LL | use use_from_trait_xc::Foo::C; + | ^^^ private struct + | +note: the struct `Foo` is defined here + --> $DIR/auxiliary/use-from-trait-xc.rs:9:1 + | +LL | struct Foo; + | ^^^^^^^^^^ + +error: aborting due to 9 previous errors + +Some errors have detailed explanations: E0253, E0432, E0603. +For more information about an error, try `rustc --explain E0253`. diff --git a/src/test/ui/use/use-from-trait.rs b/src/test/ui/use/use-from-trait.rs new file mode 100644 index 000000000..eab4bb6e3 --- /dev/null +++ b/src/test/ui/use/use-from-trait.rs @@ -0,0 +1,22 @@ +use Trait::foo; //~ ERROR `foo` is not directly importable +use Trait::Assoc; //~ ERROR `Assoc` is not directly importable +use Trait::C; //~ ERROR `C` is not directly importable + +use Foo::new; //~ ERROR unresolved import `Foo` [E0432] + +use Foo::C2; //~ ERROR unresolved import `Foo` [E0432] + +pub trait Trait { + fn foo(); + type Assoc; + const C: u32; +} + +struct Foo; + +impl Foo { + fn new() {} + const C2: u32 = 0; +} + +fn main() {} diff --git a/src/test/ui/use/use-from-trait.stderr b/src/test/ui/use/use-from-trait.stderr new file mode 100644 index 000000000..a5b0e356b --- /dev/null +++ b/src/test/ui/use/use-from-trait.stderr @@ -0,0 +1,34 @@ +error[E0253]: `foo` is not directly importable + --> $DIR/use-from-trait.rs:1:5 + | +LL | use Trait::foo; + | ^^^^^^^^^^ cannot be imported directly + +error[E0253]: `Assoc` is not directly importable + --> $DIR/use-from-trait.rs:2:5 + | +LL | use Trait::Assoc; + | ^^^^^^^^^^^^ cannot be imported directly + +error[E0253]: `C` is not directly importable + --> $DIR/use-from-trait.rs:3:5 + | +LL | use Trait::C; + | ^^^^^^^^ cannot be imported directly + +error[E0432]: unresolved import `Foo` + --> $DIR/use-from-trait.rs:5:5 + | +LL | use Foo::new; + | ^^^ `Foo` is a struct, not a module + +error[E0432]: unresolved import `Foo` + --> $DIR/use-from-trait.rs:7:5 + | +LL | use Foo::C2; + | ^^^ `Foo` is a struct, not a module + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0253, E0432. +For more information about an error, try `rustc --explain E0253`. diff --git a/src/test/ui/use/use-keyword.rs b/src/test/ui/use/use-keyword.rs new file mode 100644 index 000000000..c30c2e06c --- /dev/null +++ b/src/test/ui/use/use-keyword.rs @@ -0,0 +1,17 @@ +// Check that imports with nakes super and self don't fail during parsing +// FIXME: this shouldn't fail during name resolution either + +mod a { + mod b { + use self as A; + //~^ ERROR `self` imports are only allowed within a { } list + use super as B; + //~^ ERROR unresolved import `super` [E0432] + //~| no `super` in the root + use super::{self as C}; + //~^ ERROR unresolved import `super` [E0432] + //~| no `super` in the root + } +} + +fn main() {} diff --git a/src/test/ui/use/use-keyword.stderr b/src/test/ui/use/use-keyword.stderr new file mode 100644 index 000000000..501d14be5 --- /dev/null +++ b/src/test/ui/use/use-keyword.stderr @@ -0,0 +1,22 @@ +error[E0429]: `self` imports are only allowed within a { } list + --> $DIR/use-keyword.rs:6:13 + | +LL | use self as A; + | ^^^^ + +error[E0432]: unresolved import `super` + --> $DIR/use-keyword.rs:8:13 + | +LL | use super as B; + | ^^^^^^^^^^ no `super` in the root + +error[E0432]: unresolved import `super` + --> $DIR/use-keyword.rs:11:21 + | +LL | use super::{self as C}; + | ^^^^^^^^^ no `super` in the root + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0429, E0432. +For more information about an error, try `rustc --explain E0429`. diff --git a/src/test/ui/use/use-meta-mismatch.rs b/src/test/ui/use/use-meta-mismatch.rs new file mode 100644 index 000000000..975209efb --- /dev/null +++ b/src/test/ui/use/use-meta-mismatch.rs @@ -0,0 +1,5 @@ +// error-pattern:can't find crate for `fake_crate` + +extern crate fake_crate as extra; + +fn main() { } diff --git a/src/test/ui/use/use-meta-mismatch.stderr b/src/test/ui/use/use-meta-mismatch.stderr new file mode 100644 index 000000000..62b71fe8e --- /dev/null +++ b/src/test/ui/use/use-meta-mismatch.stderr @@ -0,0 +1,9 @@ +error[E0463]: can't find crate for `fake_crate` + --> $DIR/use-meta-mismatch.rs:3:1 + | +LL | extern crate fake_crate as extra; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0463`. diff --git a/src/test/ui/use/use-mod.rs b/src/test/ui/use/use-mod.rs new file mode 100644 index 000000000..87064c6a4 --- /dev/null +++ b/src/test/ui/use/use-mod.rs @@ -0,0 +1,19 @@ +use foo::bar::{ + self, +//~^ ERROR `self` import can only appear once in an import list + Bar, + self +//~^ ERROR the name `bar` is defined multiple times +}; + +use {self}; +//~^ ERROR `self` import can only appear in an import list with a non-empty prefix + +mod foo { + pub mod bar { + pub struct Bar; + pub struct Baz; + } +} + +fn main() {} diff --git a/src/test/ui/use/use-mod.stderr b/src/test/ui/use/use-mod.stderr new file mode 100644 index 000000000..0cae5eb14 --- /dev/null +++ b/src/test/ui/use/use-mod.stderr @@ -0,0 +1,33 @@ +error[E0430]: `self` import can only appear once in an import list + --> $DIR/use-mod.rs:2:5 + | +LL | self, + | ^^^^ can only appear once in an import list +... +LL | self + | ---- another `self` import appears here + +error[E0431]: `self` import can only appear in an import list with a non-empty prefix + --> $DIR/use-mod.rs:9:6 + | +LL | use {self}; + | ^^^^ can only appear in an import list with a non-empty prefix + +error[E0252]: the name `bar` is defined multiple times + --> $DIR/use-mod.rs:5:5 + | +LL | self, + | ---- previous import of the module `bar` here +... +LL | self + | ^^^^ + | | + | `bar` reimported here + | help: remove unnecessary import + | + = note: `bar` must be defined only once in the type namespace of this module + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0252, E0430, E0431. +For more information about an error, try `rustc --explain E0252`. diff --git a/src/test/ui/use/use-mod/use-mod-2.rs b/src/test/ui/use/use-mod/use-mod-2.rs new file mode 100644 index 000000000..9373a62ba --- /dev/null +++ b/src/test/ui/use/use-mod/use-mod-2.rs @@ -0,0 +1,11 @@ +mod foo { + use self::{self}; + //~^ ERROR unresolved import `self` [E0432] + //~| no `self` in the root + + use super::{self}; + //~^ ERROR unresolved import `super` [E0432] + //~| no `super` in the root +} + +fn main() {} diff --git a/src/test/ui/use/use-mod/use-mod-2.stderr b/src/test/ui/use/use-mod/use-mod-2.stderr new file mode 100644 index 000000000..843767849 --- /dev/null +++ b/src/test/ui/use/use-mod/use-mod-2.stderr @@ -0,0 +1,15 @@ +error[E0432]: unresolved import `self` + --> $DIR/use-mod-2.rs:2:16 + | +LL | use self::{self}; + | ^^^^ no `self` in the root + +error[E0432]: unresolved import `super` + --> $DIR/use-mod-2.rs:6:17 + | +LL | use super::{self}; + | ^^^^ no `super` in the root + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/use/use-mod/use-mod-3.rs b/src/test/ui/use/use-mod/use-mod-3.rs new file mode 100644 index 000000000..0afa486b9 --- /dev/null +++ b/src/test/ui/use/use-mod/use-mod-3.rs @@ -0,0 +1,12 @@ +use foo::bar::{ //~ ERROR module `bar` is private + self +}; +use foo::bar::{ //~ ERROR module `bar` is private + Bar +}; + +mod foo { + mod bar { pub type Bar = isize; } +} + +fn main() {} diff --git a/src/test/ui/use/use-mod/use-mod-3.stderr b/src/test/ui/use/use-mod/use-mod-3.stderr new file mode 100644 index 000000000..1b12b3c6f --- /dev/null +++ b/src/test/ui/use/use-mod/use-mod-3.stderr @@ -0,0 +1,27 @@ +error[E0603]: module `bar` is private + --> $DIR/use-mod-3.rs:1:10 + | +LL | use foo::bar::{ + | ^^^ private module + | +note: the module `bar` is defined here + --> $DIR/use-mod-3.rs:9:5 + | +LL | mod bar { pub type Bar = isize; } + | ^^^^^^^ + +error[E0603]: module `bar` is private + --> $DIR/use-mod-3.rs:4:10 + | +LL | use foo::bar::{ + | ^^^ private module + | +note: the module `bar` is defined here + --> $DIR/use-mod-3.rs:9:5 + | +LL | mod bar { pub type Bar = isize; } + | ^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0603`. diff --git a/src/test/ui/use/use-mod/use-mod-4.rs b/src/test/ui/use/use-mod/use-mod-4.rs new file mode 100644 index 000000000..46ae8ddad --- /dev/null +++ b/src/test/ui/use/use-mod/use-mod-4.rs @@ -0,0 +1,7 @@ +use foo::self; //~ ERROR unresolved import `foo` +//~^ ERROR `self` imports are only allowed within a { } list + +use std::mem::self; +//~^ ERROR `self` imports are only allowed within a { } list + +fn main() {} diff --git a/src/test/ui/use/use-mod/use-mod-4.stderr b/src/test/ui/use/use-mod/use-mod-4.stderr new file mode 100644 index 000000000..0b4fbadb4 --- /dev/null +++ b/src/test/ui/use/use-mod/use-mod-4.stderr @@ -0,0 +1,42 @@ +error[E0429]: `self` imports are only allowed within a { } list + --> $DIR/use-mod-4.rs:1:8 + | +LL | use foo::self; + | ^^^^^^ + | +help: consider importing the module directly + | +LL - use foo::self; +LL + use foo; + | +help: alternatively, use the multi-path `use` syntax to import `self` + | +LL | use foo::{self}; + | + + + +error[E0429]: `self` imports are only allowed within a { } list + --> $DIR/use-mod-4.rs:4:13 + | +LL | use std::mem::self; + | ^^^^^^ + | +help: consider importing the module directly + | +LL - use std::mem::self; +LL + use std::mem; + | +help: alternatively, use the multi-path `use` syntax to import `self` + | +LL | use std::mem::{self}; + | + + + +error[E0432]: unresolved import `foo` + --> $DIR/use-mod-4.rs:1:5 + | +LL | use foo::self; + | ^^^^^^^^^ no `foo` in the root + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0429, E0432. +For more information about an error, try `rustc --explain E0429`. diff --git a/src/test/ui/use/use-mod/use-mod-5.rs b/src/test/ui/use/use-mod/use-mod-5.rs new file mode 100644 index 000000000..df5b423ec --- /dev/null +++ b/src/test/ui/use/use-mod/use-mod-5.rs @@ -0,0 +1,13 @@ +mod foo { + pub mod bar { + pub fn drop() {} + } +} + +use foo::bar::self; +//~^ ERROR `self` imports are only allowed within a { } list + +fn main() { + // Because of error recovery this shouldn't error + bar::drop(); +} diff --git a/src/test/ui/use/use-mod/use-mod-5.stderr b/src/test/ui/use/use-mod/use-mod-5.stderr new file mode 100644 index 000000000..62859e261 --- /dev/null +++ b/src/test/ui/use/use-mod/use-mod-5.stderr @@ -0,0 +1,19 @@ +error[E0429]: `self` imports are only allowed within a { } list + --> $DIR/use-mod-5.rs:7:13 + | +LL | use foo::bar::self; + | ^^^^^^ + | +help: consider importing the module directly + | +LL - use foo::bar::self; +LL + use foo::bar; + | +help: alternatively, use the multi-path `use` syntax to import `self` + | +LL | use foo::bar::{self}; + | + + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0429`. diff --git a/src/test/ui/use/use-mod/use-mod-6.rs b/src/test/ui/use/use-mod/use-mod-6.rs new file mode 100644 index 000000000..1f8777dac --- /dev/null +++ b/src/test/ui/use/use-mod/use-mod-6.rs @@ -0,0 +1,13 @@ +mod foo { + pub mod bar { + pub fn drop() {} + } +} + +use foo::bar::self as abc; +//~^ ERROR `self` imports are only allowed within a { } list + +fn main() { + // Because of error recovery this shouldn't error + abc::drop(); +} diff --git a/src/test/ui/use/use-mod/use-mod-6.stderr b/src/test/ui/use/use-mod/use-mod-6.stderr new file mode 100644 index 000000000..2d2c90067 --- /dev/null +++ b/src/test/ui/use/use-mod/use-mod-6.stderr @@ -0,0 +1,19 @@ +error[E0429]: `self` imports are only allowed within a { } list + --> $DIR/use-mod-6.rs:7:13 + | +LL | use foo::bar::self as abc; + | ^^^^^^ + | +help: consider importing the module directly + | +LL - use foo::bar::self as abc; +LL + use foo::bar as abc; + | +help: alternatively, use the multi-path `use` syntax to import `self` + | +LL | use foo::bar::{self as abc}; + | + + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0429`. diff --git a/src/test/ui/use/use-nested-groups-error.rs b/src/test/ui/use/use-nested-groups-error.rs new file mode 100644 index 000000000..d8b189d19 --- /dev/null +++ b/src/test/ui/use/use-nested-groups-error.rs @@ -0,0 +1,15 @@ +mod a { + pub mod b1 { + pub enum C2 {} + } + + pub enum B2 {} +} + +use a::{b1::{C1, C2}, B2}; +//~^ ERROR unresolved import `a::b1::C1` + +fn main() { + let _: C2; + let _: B2; +} diff --git a/src/test/ui/use/use-nested-groups-error.stderr b/src/test/ui/use/use-nested-groups-error.stderr new file mode 100644 index 000000000..7234c8ec6 --- /dev/null +++ b/src/test/ui/use/use-nested-groups-error.stderr @@ -0,0 +1,12 @@ +error[E0432]: unresolved import `a::b1::C1` + --> $DIR/use-nested-groups-error.rs:9:14 + | +LL | use a::{b1::{C1, C2}, B2}; + | ^^ + | | + | no `C1` in `a::b1` + | help: a similar name exists in the module: `C2` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/use/use-nested-groups-unused-imports.rs b/src/test/ui/use/use-nested-groups-unused-imports.rs new file mode 100644 index 000000000..ca6b8ba94 --- /dev/null +++ b/src/test/ui/use/use-nested-groups-unused-imports.rs @@ -0,0 +1,24 @@ +#![allow(dead_code)] +#![deny(unused_imports)] + +mod foo { + pub mod bar { + pub mod baz { + pub struct Bar(); + } + pub mod foobar {} + } + + pub struct Foo(); +} + +use foo::{Foo, bar::{baz::{}, foobar::*}, *}; + //~^ ERROR unused imports: `*`, `Foo`, `baz::{}`, `foobar::*` +use foo::bar::baz::{*, *}; + //~^ ERROR unused import: `*` +use foo::{}; + //~^ ERROR unused import: `foo::{}` + +fn main() { + let _: Bar; +} diff --git a/src/test/ui/use/use-nested-groups-unused-imports.stderr b/src/test/ui/use/use-nested-groups-unused-imports.stderr new file mode 100644 index 000000000..6610f8ecd --- /dev/null +++ b/src/test/ui/use/use-nested-groups-unused-imports.stderr @@ -0,0 +1,26 @@ +error: unused imports: `*`, `Foo`, `baz::{}`, `foobar::*` + --> $DIR/use-nested-groups-unused-imports.rs:15:11 + | +LL | use foo::{Foo, bar::{baz::{}, foobar::*}, *}; + | ^^^ ^^^^^^^ ^^^^^^^^^ ^ + | +note: the lint level is defined here + --> $DIR/use-nested-groups-unused-imports.rs:2:9 + | +LL | #![deny(unused_imports)] + | ^^^^^^^^^^^^^^ + +error: unused import: `*` + --> $DIR/use-nested-groups-unused-imports.rs:17:24 + | +LL | use foo::bar::baz::{*, *}; + | ^ + +error: unused import: `foo::{}` + --> $DIR/use-nested-groups-unused-imports.rs:19:5 + | +LL | use foo::{}; + | ^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/use/use-paths-as-items.rs b/src/test/ui/use/use-paths-as-items.rs new file mode 100644 index 000000000..7b5eb56b1 --- /dev/null +++ b/src/test/ui/use/use-paths-as-items.rs @@ -0,0 +1,9 @@ +// Each path node in a `use` declaration must be treated as an item. If not, the following code +// will trigger an ICE. +// +// Related issue: #25763 + +use std::{mem, ptr}; +use std::mem; //~ ERROR the name `mem` is defined multiple times + +fn main() {} diff --git a/src/test/ui/use/use-paths-as-items.stderr b/src/test/ui/use/use-paths-as-items.stderr new file mode 100644 index 000000000..b09001a9b --- /dev/null +++ b/src/test/ui/use/use-paths-as-items.stderr @@ -0,0 +1,13 @@ +error[E0252]: the name `mem` is defined multiple times + --> $DIR/use-paths-as-items.rs:7:5 + | +LL | use std::{mem, ptr}; + | --- previous import of the module `mem` here +LL | use std::mem; + | ^^^^^^^^ `mem` reimported here + | + = note: `mem` 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 E0252`. diff --git a/src/test/ui/use/use-self-type.rs b/src/test/ui/use/use-self-type.rs new file mode 100644 index 000000000..3b4ce4297 --- /dev/null +++ b/src/test/ui/use/use-self-type.rs @@ -0,0 +1,11 @@ +struct S; + +impl S { + fn f() {} + fn g() { + use Self::f; //~ ERROR unresolved import + pub(in Self::f) struct Z; //~ ERROR failed to resolve: `Self` + } +} + +fn main() {} diff --git a/src/test/ui/use/use-self-type.stderr b/src/test/ui/use/use-self-type.stderr new file mode 100644 index 000000000..e61539411 --- /dev/null +++ b/src/test/ui/use/use-self-type.stderr @@ -0,0 +1,16 @@ +error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions + --> $DIR/use-self-type.rs:7:16 + | +LL | pub(in Self::f) struct Z; + | ^^^^ `Self` is only available in impls, traits, and type definitions + +error[E0432]: unresolved import `Self` + --> $DIR/use-self-type.rs:6:13 + | +LL | use Self::f; + | ^^^^ `Self` is only available in impls, traits, and type definitions + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0432, E0433. +For more information about an error, try `rustc --explain E0432`. diff --git a/src/test/ui/use/use-super-global-path.rs b/src/test/ui/use/use-super-global-path.rs new file mode 100644 index 000000000..64bfd14b7 --- /dev/null +++ b/src/test/ui/use/use-super-global-path.rs @@ -0,0 +1,16 @@ +#![allow(unused)] + +struct S; +struct Z; + +mod foo { + use ::super::{S, Z}; //~ ERROR global paths cannot start with `super` + //~| ERROR global paths cannot start with `super` + + pub fn g() { + use ::super::main; //~ ERROR global paths cannot start with `super` + main(); + } +} + +fn main() { foo::g(); } diff --git a/src/test/ui/use/use-super-global-path.stderr b/src/test/ui/use/use-super-global-path.stderr new file mode 100644 index 000000000..7014a12e9 --- /dev/null +++ b/src/test/ui/use/use-super-global-path.stderr @@ -0,0 +1,21 @@ +error[E0433]: failed to resolve: global paths cannot start with `super` + --> $DIR/use-super-global-path.rs:7:11 + | +LL | use ::super::{S, Z}; + | ^^^^^ global paths cannot start with `super` + +error[E0433]: failed to resolve: global paths cannot start with `super` + --> $DIR/use-super-global-path.rs:7:11 + | +LL | use ::super::{S, Z}; + | ^^^^^ global paths cannot start with `super` + +error[E0433]: failed to resolve: global paths cannot start with `super` + --> $DIR/use-super-global-path.rs:11:15 + | +LL | use ::super::main; + | ^^^^^ global paths cannot start with `super` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0433`. |