diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-07-19 13:30:44 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-19 13:30:44 +0200 |
| commit | bfefd587c081305ab81074fee1ff7fd26b058ef6 (patch) | |
| tree | 3da347d4655a970ff0ece525cafe8bf9bba58e79 /src | |
| parent | 4603ac31b0655793a82f110f544dc1c6abc57bb7 (diff) | |
| parent | 38ea23558eca629d668208e368dfa711b8229192 (diff) | |
| download | rust-bfefd587c081305ab81074fee1ff7fd26b058ef6.tar.gz rust-bfefd587c081305ab81074fee1ff7fd26b058ef6.zip | |
Rollup merge of #98028 - aticu:master, r=estebank
Add E0790 as more specific variant of E0283 Fixes #81701 I think this should be good to go, there are only two things where I am somewhat unsure: - Is there a better way to get the fully-qualified path for the suggestion? I tried `self.tcx.def_path_str`, but that didn't seem to always give a correct path for the context. - Should all this be extracted into it's own method or is it fine where it is? r? `@estebank`
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/associated-consts/issue-63496.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/associated-consts/issue-63496.stderr | 28 | ||||
| -rw-r--r-- | src/test/ui/associated-item/issue-48027.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/associated-item/issue-48027.stderr | 14 | ||||
| -rw-r--r-- | src/test/ui/associated-types/associated-types-unconstrained.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/associated-types/associated-types-unconstrained.stderr | 11 | ||||
| -rw-r--r-- | src/test/ui/error-codes/E0283.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/error-codes/E0283.stderr | 15 | ||||
| -rw-r--r-- | src/test/ui/error-codes/E0790.rs | 53 | ||||
| -rw-r--r-- | src/test/ui/error-codes/E0790.stderr | 73 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-54954.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-54954.stderr | 16 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-58022.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-58022.stderr | 17 | ||||
| -rw-r--r-- | src/test/ui/traits/static-method-generic-inference.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/traits/static-method-generic-inference.stderr | 14 |
16 files changed, 194 insertions, 63 deletions
diff --git a/src/test/ui/associated-consts/issue-63496.rs b/src/test/ui/associated-consts/issue-63496.rs index f9f663af5e2..67ef4e74cf2 100644 --- a/src/test/ui/associated-consts/issue-63496.rs +++ b/src/test/ui/associated-consts/issue-63496.rs @@ -2,8 +2,8 @@ trait A { const C: usize; fn f() -> ([u8; A::C], [u8; A::C]); - //~^ ERROR: type annotations needed - //~| ERROR: type annotations needed + //~^ ERROR: E0790 + //~| ERROR: E0790 } fn main() {} diff --git a/src/test/ui/associated-consts/issue-63496.stderr b/src/test/ui/associated-consts/issue-63496.stderr index db39fd762c3..f2a4e01adea 100644 --- a/src/test/ui/associated-consts/issue-63496.stderr +++ b/src/test/ui/associated-consts/issue-63496.stderr @@ -1,27 +1,21 @@ -error[E0283]: type annotations needed +error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type --> $DIR/issue-63496.rs:4:21 | +LL | const C: usize; + | --------------- `A::C` defined here +LL | LL | fn f() -> ([u8; A::C], [u8; A::C]); - | ^^^^ - | | - | cannot infer type - | help: use the fully qualified path to an implementation: `<Type as A>::C` - | - = note: cannot satisfy `_: A` - = note: associated constants cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl` + | ^^^^ cannot refer to the associated constant of trait -error[E0283]: type annotations needed +error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type --> $DIR/issue-63496.rs:4:33 | +LL | const C: usize; + | --------------- `A::C` defined here +LL | LL | fn f() -> ([u8; A::C], [u8; A::C]); - | ^^^^ - | | - | cannot infer type - | help: use the fully qualified path to an implementation: `<Type as A>::C` - | - = note: cannot satisfy `_: A` - = note: associated constants cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl` + | ^^^^ cannot refer to the associated constant of trait error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0283`. +For more information about this error, try `rustc --explain E0790`. diff --git a/src/test/ui/associated-item/issue-48027.rs b/src/test/ui/associated-item/issue-48027.rs index c9b4ccd3e8a..d2b51184c99 100644 --- a/src/test/ui/associated-item/issue-48027.rs +++ b/src/test/ui/associated-item/issue-48027.rs @@ -1,6 +1,6 @@ trait Bar { const X: usize; - fn return_n(&self) -> [u8; Bar::X]; //~ ERROR: type annotations needed + fn return_n(&self) -> [u8; Bar::X]; //~ ERROR: E0790 } impl dyn Bar {} //~ ERROR: the trait `Bar` cannot be made into an object diff --git a/src/test/ui/associated-item/issue-48027.stderr b/src/test/ui/associated-item/issue-48027.stderr index 5487af1a835..45ea419336b 100644 --- a/src/test/ui/associated-item/issue-48027.stderr +++ b/src/test/ui/associated-item/issue-48027.stderr @@ -13,19 +13,15 @@ LL | const X: usize; | ^ ...because it contains this associated `const` = help: consider moving `X` to another trait -error[E0283]: type annotations needed +error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type --> $DIR/issue-48027.rs:3:32 | +LL | const X: usize; + | --------------- `Bar::X` defined here LL | fn return_n(&self) -> [u8; Bar::X]; - | ^^^^^^ - | | - | cannot infer type - | help: use the fully qualified path to an implementation: `<Type as Bar>::X` - | - = note: cannot satisfy `_: Bar` - = note: associated constants cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl` + | ^^^^^^ cannot refer to the associated constant of trait error: aborting due to 2 previous errors -Some errors have detailed explanations: E0038, E0283. +Some errors have detailed explanations: E0038, E0790. For more information about an error, try `rustc --explain E0038`. diff --git a/src/test/ui/associated-types/associated-types-unconstrained.rs b/src/test/ui/associated-types/associated-types-unconstrained.rs index b97d4af184f..2fb27bf3cd1 100644 --- a/src/test/ui/associated-types/associated-types-unconstrained.rs +++ b/src/test/ui/associated-types/associated-types-unconstrained.rs @@ -12,5 +12,5 @@ impl Foo for isize { pub fn main() { let x: isize = Foo::bar(); - //~^ ERROR type annotations needed + //~^ ERROR E0790 } diff --git a/src/test/ui/associated-types/associated-types-unconstrained.stderr b/src/test/ui/associated-types/associated-types-unconstrained.stderr index 60ec23cf655..e51a8f3bd1a 100644 --- a/src/test/ui/associated-types/associated-types-unconstrained.stderr +++ b/src/test/ui/associated-types/associated-types-unconstrained.stderr @@ -1,11 +1,12 @@ -error[E0283]: type annotations needed +error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type --> $DIR/associated-types-unconstrained.rs:14:20 | +LL | fn bar() -> isize; + | ------------------ `Foo::bar` defined here +... LL | let x: isize = Foo::bar(); - | ^^^^^^^^ cannot infer type - | - = note: cannot satisfy `_: Foo` + | ^^^^^^^^ cannot call associated function of trait error: aborting due to previous error -For more information about this error, try `rustc --explain E0283`. +For more information about this error, try `rustc --explain E0790`. diff --git a/src/test/ui/error-codes/E0283.rs b/src/test/ui/error-codes/E0283.rs index 4d7c2f2396d..0643af4b7e8 100644 --- a/src/test/ui/error-codes/E0283.rs +++ b/src/test/ui/error-codes/E0283.rs @@ -27,7 +27,7 @@ impl Generator for AnotherImpl { } fn main() { - let cont: u32 = Generator::create(); //~ ERROR E0283 + let cont: u32 = Generator::create(); //~ ERROR E0790 } fn buzz() { diff --git a/src/test/ui/error-codes/E0283.stderr b/src/test/ui/error-codes/E0283.stderr index a107160d11a..90a28874ead 100644 --- a/src/test/ui/error-codes/E0283.stderr +++ b/src/test/ui/error-codes/E0283.stderr @@ -1,10 +1,16 @@ -error[E0283]: type annotations needed +error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type --> $DIR/E0283.rs:30:21 | +LL | fn create() -> u32; + | ------------------- `Generator::create` defined here +... LL | let cont: u32 = Generator::create(); - | ^^^^^^^^^^^^^^^^^ cannot infer type + | ^^^^^^^^^^^^^^^^^ cannot call associated function of trait + | +help: use a fully-qualified path to a specific available implementation (2 found) | - = note: cannot satisfy `_: Generator` +LL | let cont: u32 = <::Impl as Generator>::create(); + | ++++++++++ + error[E0283]: type annotations needed --> $DIR/E0283.rs:35:24 @@ -27,4 +33,5 @@ LL | let bar = <Impl as Into<T>>::into(foo_impl) * 1u32; error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0283`. +Some errors have detailed explanations: E0283, E0790. +For more information about an error, try `rustc --explain E0283`. diff --git a/src/test/ui/error-codes/E0790.rs b/src/test/ui/error-codes/E0790.rs new file mode 100644 index 00000000000..d99006d2df7 --- /dev/null +++ b/src/test/ui/error-codes/E0790.rs @@ -0,0 +1,53 @@ +mod inner { + pub trait MyTrait { + const MY_ASSOC_CONST: (); + + fn my_fn(); + } + + pub struct MyStruct; + + impl MyTrait for MyStruct { + const MY_ASSOC_CONST: () = (); + + fn my_fn() {} + } + + fn call() { + MyTrait::my_fn(); //~ ERROR E0790 + } + + fn use_const() { + let _ = MyTrait::MY_ASSOC_CONST; //~ ERROR E0790 + } +} + +fn call_inner() { + inner::MyTrait::my_fn(); //~ ERROR E0790 +} + +fn use_const_inner() { + let _ = inner::MyTrait::MY_ASSOC_CONST; //~ ERROR E0790 +} + +trait MyTrait2 { + fn my_fn(); +} + +struct Impl1; + +impl MyTrait2 for Impl1 { + fn my_fn() {} +} + +struct Impl2; + +impl MyTrait2 for Impl2 { + fn my_fn() {} +} + +fn call_multiple_impls() { + MyTrait2::my_fn(); //~ ERROR E0790 +} + +fn main() {} diff --git a/src/test/ui/error-codes/E0790.stderr b/src/test/ui/error-codes/E0790.stderr new file mode 100644 index 00000000000..6e173a9682a --- /dev/null +++ b/src/test/ui/error-codes/E0790.stderr @@ -0,0 +1,73 @@ +error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type + --> $DIR/E0790.rs:17:9 + | +LL | fn my_fn(); + | ----------- `MyTrait::my_fn` defined here +... +LL | MyTrait::my_fn(); + | ^^^^^^^^^^^^^^ cannot call associated function of trait + | +help: use the fully-qualified path to the only available implementation + | +LL | <::inner::MyStruct as MyTrait>::my_fn(); + | +++++++++++++++++++++ + + +error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type + --> $DIR/E0790.rs:21:17 + | +LL | const MY_ASSOC_CONST: (); + | ------------------------- `MyTrait::MY_ASSOC_CONST` defined here +... +LL | let _ = MyTrait::MY_ASSOC_CONST; + | ^^^^^^^^^^^^^^^^^^^^^^^ cannot refer to the associated constant of trait + | +help: use the fully-qualified path to the only available implementation + | +LL | let _ = <::inner::MyStruct as MyTrait>::MY_ASSOC_CONST; + | +++++++++++++++++++++ + + +error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type + --> $DIR/E0790.rs:26:5 + | +LL | fn my_fn(); + | ----------- `MyTrait::my_fn` defined here +... +LL | inner::MyTrait::my_fn(); + | ^^^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait + | +help: use the fully-qualified path to the only available implementation + | +LL | inner::<::inner::MyStruct as MyTrait>::my_fn(); + | +++++++++++++++++++++ + + +error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type + --> $DIR/E0790.rs:30:13 + | +LL | const MY_ASSOC_CONST: (); + | ------------------------- `MyTrait::MY_ASSOC_CONST` defined here +... +LL | let _ = inner::MyTrait::MY_ASSOC_CONST; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot refer to the associated constant of trait + | +help: use the fully-qualified path to the only available implementation + | +LL | let _ = inner::<::inner::MyStruct as MyTrait>::MY_ASSOC_CONST; + | +++++++++++++++++++++ + + +error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type + --> $DIR/E0790.rs:50:5 + | +LL | fn my_fn(); + | ----------- `MyTrait2::my_fn` defined here +... +LL | MyTrait2::my_fn(); + | ^^^^^^^^^^^^^^^ cannot call associated function of trait + | +help: use a fully-qualified path to a specific available implementation (2 found) + | +LL | <::Impl1 as MyTrait2>::my_fn(); + | +++++++++++ + + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0790`. diff --git a/src/test/ui/issues/issue-54954.rs b/src/test/ui/issues/issue-54954.rs index ddd39141541..d4e1df22770 100644 --- a/src/test/ui/issues/issue-54954.rs +++ b/src/test/ui/issues/issue-54954.rs @@ -1,5 +1,5 @@ const ARR_LEN: usize = Tt::const_val::<[i8; 123]>(); -//~^ ERROR type annotations needed +//~^ ERROR E0790 trait Tt { const fn const_val<T: Sized>() -> usize { diff --git a/src/test/ui/issues/issue-54954.stderr b/src/test/ui/issues/issue-54954.stderr index 6e8d3cac9a7..668985c2b59 100644 --- a/src/test/ui/issues/issue-54954.stderr +++ b/src/test/ui/issues/issue-54954.stderr @@ -4,13 +4,17 @@ error[E0379]: functions in traits cannot be declared const LL | const fn const_val<T: Sized>() -> usize { | ^^^^^ functions in traits cannot be const -error[E0283]: type annotations needed +error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type --> $DIR/issue-54954.rs:1:24 | -LL | const ARR_LEN: usize = Tt::const_val::<[i8; 123]>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type - | - = note: cannot satisfy `_: Tt` +LL | const ARR_LEN: usize = Tt::const_val::<[i8; 123]>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait +... +LL | / const fn const_val<T: Sized>() -> usize { +LL | | +LL | | core::mem::size_of::<T>() +LL | | } + | |_____- `Tt::const_val` defined here error[E0080]: evaluation of constant value failed --> $DIR/issue-54954.rs:11:15 @@ -26,5 +30,5 @@ LL | fn f(z: [f32; ARR_LEN]) -> [f32; ARR_LEN] { error: aborting due to 4 previous errors -Some errors have detailed explanations: E0080, E0283, E0379. +Some errors have detailed explanations: E0080, E0379, E0790. For more information about an error, try `rustc --explain E0080`. diff --git a/src/test/ui/issues/issue-58022.rs b/src/test/ui/issues/issue-58022.rs index e4b9b3b53a6..2a8a1eaa6d3 100644 --- a/src/test/ui/issues/issue-58022.rs +++ b/src/test/ui/issues/issue-58022.rs @@ -2,7 +2,7 @@ pub trait Foo: Sized { const SIZE: usize; fn new(slice: &[u8; Foo::SIZE]) -> Self; - //~^ ERROR: type annotations needed + //~^ ERROR: E0790 } pub struct Bar<T: ?Sized>(T); diff --git a/src/test/ui/issues/issue-58022.stderr b/src/test/ui/issues/issue-58022.stderr index 0128b70e216..6d24209ad3c 100644 --- a/src/test/ui/issues/issue-58022.stderr +++ b/src/test/ui/issues/issue-58022.stderr @@ -4,19 +4,16 @@ error[E0423]: expected function, tuple struct or tuple variant, found trait `Foo LL | Foo(Box::new(*slice)) | ^^^ not a function, tuple struct or tuple variant -error[E0283]: type annotations needed +error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type --> $DIR/issue-58022.rs:4:25 | +LL | const SIZE: usize; + | ------------------ `Foo::SIZE` defined here +LL | LL | fn new(slice: &[u8; Foo::SIZE]) -> Self; - | ^^^^^^^^^ - | | - | cannot infer type - | help: use the fully qualified path to an implementation: `<Type as Foo>::SIZE` - | - = note: cannot satisfy `_: Foo` - = note: associated constants cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl` + | ^^^^^^^^^ cannot refer to the associated constant of trait error: aborting due to 2 previous errors -Some errors have detailed explanations: E0283, E0423. -For more information about an error, try `rustc --explain E0283`. +Some errors have detailed explanations: E0423, E0790. +For more information about an error, try `rustc --explain E0423`. diff --git a/src/test/ui/traits/static-method-generic-inference.rs b/src/test/ui/traits/static-method-generic-inference.rs index 759416d1901..f4e94c4f786 100644 --- a/src/test/ui/traits/static-method-generic-inference.rs +++ b/src/test/ui/traits/static-method-generic-inference.rs @@ -22,7 +22,7 @@ mod base { pub fn foo() { let _f: base::Foo = base::HasNew::new(); - //~^ ERROR type annotations needed + //~^ ERROR E0790 } fn main() { } diff --git a/src/test/ui/traits/static-method-generic-inference.stderr b/src/test/ui/traits/static-method-generic-inference.stderr index 1a0bcf00a67..f1b8f23ecc7 100644 --- a/src/test/ui/traits/static-method-generic-inference.stderr +++ b/src/test/ui/traits/static-method-generic-inference.stderr @@ -1,11 +1,17 @@ -error[E0283]: type annotations needed +error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type --> $DIR/static-method-generic-inference.rs:24:25 | +LL | fn new() -> T; + | -------------- `HasNew::new` defined here +... LL | let _f: base::Foo = base::HasNew::new(); - | ^^^^^^^^^^^^^^^^^ cannot infer type + | ^^^^^^^^^^^^^^^^^ cannot call associated function of trait | - = note: cannot satisfy `_: HasNew<Foo>` +help: use the fully-qualified path to the only available implementation + | +LL | let _f: base::Foo = base::<::base::Foo as HasNew>::new(); + | +++++++++++++++ + error: aborting due to previous error -For more information about this error, try `rustc --explain E0283`. +For more information about this error, try `rustc --explain E0790`. |
