diff options
Diffstat (limited to '')
71 files changed, 613 insertions, 149 deletions
diff --git a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr index 006253f84..eb58ee73c 100644 --- a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr +++ b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr @@ -12,7 +12,7 @@ LL | V(u8) help: provide the argument | LL | <E>::V(/* u8 */); - | ~~~~~~~~~~~~~~~~ + | ~~~~~~~~~~ error[E0308]: mismatched types --> $DIR/enum-variant-priority-higher-than-other-inherent.rs:22:17 diff --git a/src/test/ui/type-alias-impl-trait/closure_args.rs b/src/test/ui/type-alias-impl-trait/closure_args.rs new file mode 100644 index 000000000..c5e7af81d --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/closure_args.rs @@ -0,0 +1,16 @@ +// check-pass + +// regression test for https://github.com/rust-lang/rust/issues/100800 + +#![feature(type_alias_impl_trait)] + +trait Anything {} +impl<T> Anything for T {} +type Input = impl Anything; +fn run<F: FnOnce(Input) -> ()>(f: F, i: Input) { + f(i); +} + +fn main() { + run(|x: u32| {println!("{x}");}, 0); +} diff --git a/src/test/ui/type-alias-impl-trait/closure_args2.rs b/src/test/ui/type-alias-impl-trait/closure_args2.rs new file mode 100644 index 000000000..82386c280 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/closure_args2.rs @@ -0,0 +1,23 @@ +// run-pass + +#![feature(type_alias_impl_trait)] + +trait Foo { + // This was reachable in https://github.com/rust-lang/rust/issues/100800 + fn foo(&self) { unreachable!() } +} +impl<T> Foo for T {} + +struct B; +impl B { + fn foo(&self) {} +} + +type Input = impl Foo; +fn run1<F: FnOnce(Input)>(f: F, i: Input) {f(i)} +fn run2<F: FnOnce(B)>(f: F, i: B) {f(i)} + +fn main() { + run1(|x: B| {x.foo()}, B); + run2(|x: B| {x.foo()}, B); +} diff --git a/src/test/ui/type-alias-impl-trait/constrain_inputs.rs b/src/test/ui/type-alias-impl-trait/constrain_inputs.rs index c32174288..03fb64b7b 100644 --- a/src/test/ui/type-alias-impl-trait/constrain_inputs.rs +++ b/src/test/ui/type-alias-impl-trait/constrain_inputs.rs @@ -1,17 +1,33 @@ -// check-pass - #![feature(type_alias_impl_trait)] -mod foo { +mod lifetime_params { type Ty<'a> = impl Sized; fn defining(s: &str) -> Ty<'_> { s } fn execute(ty: Ty<'_>) -> &str { todo!() } + //~^ ERROR return type references an anonymous lifetime, which is not constrained by the fn input types + + type BadFnSig = fn(Ty<'_>) -> &str; + //~^ ERROR return type references an anonymous lifetime, which is not constrained by the fn input types + type BadTraitRef = dyn Fn(Ty<'_>) -> &str; + //~^ ERROR binding for associated type `Output` references an anonymous lifetime } -mod bar { +mod lifetime_params_2 { type Ty<'a> = impl FnOnce() -> &'a str; fn defining(s: &str) -> Ty<'_> { move || s } fn execute(ty: Ty<'_>) -> &str { ty() } + //~^ ERROR return type references an anonymous lifetime, which is not constrained by the fn input types +} + +// regression test for https://github.com/rust-lang/rust/issues/97104 +mod type_params { + type Ty<T> = impl Sized; + fn define<T>(s: T) -> Ty<T> { s } + + type BadFnSig = fn(Ty<&str>) -> &str; + //~^ ERROR return type references an anonymous lifetime, which is not constrained by the fn input types + type BadTraitRef = dyn Fn(Ty<&str>) -> &str; + //~^ ERROR binding for associated type `Output` references an anonymous lifetime } fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/constrain_inputs.stderr b/src/test/ui/type-alias-impl-trait/constrain_inputs.stderr new file mode 100644 index 000000000..93953fd06 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/constrain_inputs.stderr @@ -0,0 +1,58 @@ +error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types + --> $DIR/constrain_inputs.rs:6:31 + | +LL | fn execute(ty: Ty<'_>) -> &str { todo!() } + | ^^^^ + | + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter + +error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types + --> $DIR/constrain_inputs.rs:9:35 + | +LL | type BadFnSig = fn(Ty<'_>) -> &str; + | ^^^^ + | + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter + +error[E0582]: binding for associated type `Output` references an anonymous lifetime, which does not appear in the trait input types + --> $DIR/constrain_inputs.rs:11:42 + | +LL | type BadTraitRef = dyn Fn(Ty<'_>) -> &str; + | ^^^^ + | + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter + +error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types + --> $DIR/constrain_inputs.rs:18:31 + | +LL | fn execute(ty: Ty<'_>) -> &str { ty() } + | ^^^^ + | + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter + +error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types + --> $DIR/constrain_inputs.rs:27:37 + | +LL | type BadFnSig = fn(Ty<&str>) -> &str; + | ^^^^ + | + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter + +error[E0582]: binding for associated type `Output` references an anonymous lifetime, which does not appear in the trait input types + --> $DIR/constrain_inputs.rs:29:44 + | +LL | type BadTraitRef = dyn Fn(Ty<&str>) -> &str; + | ^^^^ + | + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0581, E0582. +For more information about an error, try `rustc --explain E0581`. diff --git a/src/test/ui/type-alias-impl-trait/constrain_inputs_unsound.rs b/src/test/ui/type-alias-impl-trait/constrain_inputs_unsound.rs new file mode 100644 index 000000000..3bae0f173 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/constrain_inputs_unsound.rs @@ -0,0 +1,31 @@ +#![feature(type_alias_impl_trait)] + +trait Static: 'static {} +impl Static for () {} + +type Gal<T> = impl Static; +fn _defining<T>() -> Gal<T> {} + +trait Callable<Arg> { type Output; } + +/// We can infer `<C as Callable<Arg>>::Output: 'static`, +/// because we know `C: 'static` and `Arg: 'static`, +fn box_str<C, Arg>(s: C::Output) -> Box<dyn AsRef<str> + 'static> +where + Arg: Static, + C: ?Sized + Callable<Arg> + 'static, + C::Output: AsRef<str>, +{ + Box::new(s) +} + +fn extend_lifetime(s: &str) -> Box<dyn AsRef<str> + 'static> { + type MalformedTy = dyn for<'a> Callable<Gal<&'a ()>, Output = &'a str>; + //~^ ERROR binding for associated type `Output` references lifetime `'a` + box_str::<MalformedTy, _>(s) +} + +fn main() { + let extended = extend_lifetime(&String::from("hello")); + println!("{}", extended.as_ref().as_ref()); +} diff --git a/src/test/ui/type-alias-impl-trait/constrain_inputs_unsound.stderr b/src/test/ui/type-alias-impl-trait/constrain_inputs_unsound.stderr new file mode 100644 index 000000000..d5fc46cb1 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/constrain_inputs_unsound.stderr @@ -0,0 +1,9 @@ +error[E0582]: binding for associated type `Output` references lifetime `'a`, which does not appear in the trait input types + --> $DIR/constrain_inputs_unsound.rs:23:58 + | +LL | type MalformedTy = dyn for<'a> Callable<Gal<&'a ()>, Output = &'a str>; + | ^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0582`. diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr index 2768f0c3a..586ea8234 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr @@ -4,7 +4,7 @@ error[E0277]: `T` doesn't implement `Debug` LL | (t, u) | ^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(T, U)` + = note: required for `(T, U)` to implement `Debug` help: consider restricting type parameter `T` | LL | type Two<T: std::fmt::Debug, U> = impl Debug; @@ -16,7 +16,7 @@ error[E0277]: `U` doesn't implement `Debug` LL | (t, u) | ^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(T, U)` + = note: required for `(T, U)` to implement `Debug` help: consider restricting type parameter `U` | LL | type Two<T, U: std::fmt::Debug> = impl Debug; @@ -28,7 +28,7 @@ error[E0277]: `U` doesn't implement `Debug` LL | (u, t) | ^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(U, T)` + = note: required for `(U, T)` to implement `Debug` help: consider restricting type parameter `U` | LL | type Two<T, U: std::fmt::Debug> = impl Debug; @@ -40,7 +40,7 @@ error[E0277]: `T` doesn't implement `Debug` LL | (u, t) | ^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(U, T)` + = note: required for `(U, T)` to implement `Debug` help: consider restricting type parameter `T` | LL | type Two<T: std::fmt::Debug, U> = impl Debug; diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr index c1712ca2e..cb162d382 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr @@ -4,7 +4,7 @@ error[E0277]: `T` doesn't implement `Debug` LL | (t, t) | ^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(T, T)` + = note: required for `(T, T)` to implement `Debug` help: consider restricting type parameter `T` | LL | type Two<T: std::fmt::Debug, U> = impl Debug; @@ -16,7 +16,7 @@ error[E0277]: `U` doesn't implement `Debug` LL | (u, t) | ^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(U, T)` + = note: required for `(U, T)` to implement `Debug` help: consider restricting type parameter `U` | LL | type Two<T, U: std::fmt::Debug> = impl Debug; @@ -28,7 +28,7 @@ error[E0277]: `T` doesn't implement `Debug` LL | (u, t) | ^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(U, T)` + = note: required for `(U, T)` to implement `Debug` help: consider restricting type parameter `T` | LL | type Two<T: std::fmt::Debug, U> = impl Debug; diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr index b83105c45..14cbfb380 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr @@ -4,7 +4,7 @@ error[E0277]: `T` doesn't implement `Debug` LL | (t, 4u32) | ^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(T, u32)` + = note: required for `(T, u32)` to implement `Debug` help: consider restricting type parameter `T` | LL | type Two<T: std::fmt::Debug, U> = impl Debug; @@ -16,7 +16,7 @@ error[E0277]: `U` doesn't implement `Debug` LL | (u, 4u32) | ^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(U, u32)` + = note: required for `(U, u32)` to implement `Debug` help: consider restricting type parameter `U` | LL | type Two<T, U: std::fmt::Debug> = impl Debug; diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr index 50cf98273..722693e42 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr @@ -15,7 +15,7 @@ error[E0277]: `A` doesn't implement `Debug` LL | (t, u, T::BAR) | ^^^^^^^^^^^^^^ `A` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(A, B, _)` + = note: required for `(A, B, _)` to implement `Debug` help: consider restricting type parameter `A` | LL | type Two<A: std::fmt::Debug, B> = impl Debug; @@ -27,7 +27,7 @@ error[E0277]: `B` doesn't implement `Debug` LL | (t, u, T::BAR) | ^^^^^^^^^^^^^^ `B` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(A, B, _)` + = note: required for `(A, B, _)` to implement `Debug` help: consider restricting type parameter `B` | LL | type Two<A, B: std::fmt::Debug> = impl Debug; @@ -39,7 +39,7 @@ error[E0277]: `A` doesn't implement `Debug` LL | (t, u, 42) | ^^^^^^^^^^ `A` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(A, B, i32)` + = note: required for `(A, B, i32)` to implement `Debug` help: consider restricting type parameter `A` | LL | type Two<A: std::fmt::Debug, B> = impl Debug; @@ -51,7 +51,7 @@ error[E0277]: `B` doesn't implement `Debug` LL | (t, u, 42) | ^^^^^^^^^^ `B` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(A, B, i32)` + = note: required for `(A, B, i32)` to implement `Debug` help: consider restricting type parameter `B` | LL | type Two<A, B: std::fmt::Debug> = impl Debug; diff --git a/src/test/ui/type-alias-impl-trait/issue-57961.rs b/src/test/ui/type-alias-impl-trait/issue-57961.rs index 472886c9c..24b3a0458 100644 --- a/src/test/ui/type-alias-impl-trait/issue-57961.rs +++ b/src/test/ui/type-alias-impl-trait/issue-57961.rs @@ -8,7 +8,7 @@ trait Foo { impl Foo for () { type Bar = std::vec::IntoIter<u32>; - //~^ ERROR type mismatch resolving `<std::vec::IntoIter<u32> as Iterator>::Item == X + //~^ ERROR expected `std::vec::IntoIter<u32>` to be an iterator that yields `X`, but it yields `u32` } fn incoherent() { diff --git a/src/test/ui/type-alias-impl-trait/issue-57961.stderr b/src/test/ui/type-alias-impl-trait/issue-57961.stderr index ed4caf6ce..fb40895c4 100644 --- a/src/test/ui/type-alias-impl-trait/issue-57961.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-57961.stderr @@ -1,4 +1,4 @@ -error[E0271]: type mismatch resolving `<std::vec::IntoIter<u32> as Iterator>::Item == X` +error[E0271]: expected `std::vec::IntoIter<u32>` to be an iterator that yields `X`, but it yields `u32` --> $DIR/issue-57961.rs:10:16 | LL | type X = impl Sized; diff --git a/src/test/ui/type-alias-impl-trait/issue-60371.stderr b/src/test/ui/type-alias-impl-trait/issue-60371.stderr index 082b0f0c3..d0c04371b 100644 --- a/src/test/ui/type-alias-impl-trait/issue-60371.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-60371.stderr @@ -11,7 +11,7 @@ error[E0277]: the trait bound `(): Bug` is not satisfied --> $DIR/issue-60371.rs:10:40 | LL | const FUN: fn() -> Self::Item = || (); - | ^ the trait `Bug` is not implemented for `()` + | ^^ the trait `Bug` is not implemented for `()` | = help: the trait `Bug` is implemented for `&()` diff --git a/src/test/ui/type-alias-impl-trait/issue-74280.stderr b/src/test/ui/type-alias-impl-trait/issue-74280.stderr index 5ed29e0ac..66886db6e 100644 --- a/src/test/ui/type-alias-impl-trait/issue-74280.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-74280.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/issue-74280.rs:9:5 | LL | fn test() -> Test { - | ---- expected `_` because of return type + | ---- expected `()` because of return type LL | let y = || -> Test { () }; LL | 7 | ^ expected `()`, found integer diff --git a/src/test/ui/type-alias-impl-trait/issue-90400-1.rs b/src/test/ui/type-alias-impl-trait/issue-90400-1.rs index 8550a3e86..15aead2f6 100644 --- a/src/test/ui/type-alias-impl-trait/issue-90400-1.rs +++ b/src/test/ui/type-alias-impl-trait/issue-90400-1.rs @@ -1,7 +1,6 @@ // Regression test for #90400, // taken from https://github.com/rust-lang/rust/issues/90400#issuecomment-954927836 -#![feature(generic_associated_types)] #![feature(type_alias_impl_trait)] trait Bar { diff --git a/src/test/ui/type-alias-impl-trait/issue-90400-1.stderr b/src/test/ui/type-alias-impl-trait/issue-90400-1.stderr index 428a10740..ead28769f 100644 --- a/src/test/ui/type-alias-impl-trait/issue-90400-1.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-90400-1.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `B: Bar` is not satisfied - --> $DIR/issue-90400-1.rs:23:9 + --> $DIR/issue-90400-1.rs:22:9 | LL | move || bar.bar() | ^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `B` | note: required by a bound in `<MyFoo as Foo>::foo` - --> $DIR/issue-90400-1.rs:22:15 + --> $DIR/issue-90400-1.rs:21:15 | LL | fn foo<B: Bar>(&self, bar: B) -> Self::FooFn<B> { | ^^^ required by this bound in `<MyFoo as Foo>::foo` diff --git a/src/test/ui/type-alias-impl-trait/issue-90400-2.rs b/src/test/ui/type-alias-impl-trait/issue-90400-2.rs index 2b369bb8a..4c6e893c1 100644 --- a/src/test/ui/type-alias-impl-trait/issue-90400-2.rs +++ b/src/test/ui/type-alias-impl-trait/issue-90400-2.rs @@ -1,7 +1,6 @@ // Regression test for #90400, // taken from https://github.com/rust-lang/rust/issues/90400#issuecomment-954927836 -#![feature(generic_associated_types)] #![feature(type_alias_impl_trait)] trait Bar { diff --git a/src/test/ui/type-alias-impl-trait/issue-90400-2.stderr b/src/test/ui/type-alias-impl-trait/issue-90400-2.stderr index 5da05a439..50b2dc049 100644 --- a/src/test/ui/type-alias-impl-trait/issue-90400-2.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-90400-2.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `B: Bar` is not satisfied - --> $DIR/issue-90400-2.rs:26:9 + --> $DIR/issue-90400-2.rs:25:9 | LL | MyBaz(bar) | ^^^^^^^^^^ the trait `Bar` is not implemented for `B` | -note: required because of the requirements on the impl of `Baz` for `MyBaz<B>` - --> $DIR/issue-90400-2.rs:31:14 +note: required for `MyBaz<B>` to implement `Baz` + --> $DIR/issue-90400-2.rs:30:14 | LL | impl<B: Bar> Baz for MyBaz<B> { | ^^^ ^^^^^^^^ diff --git a/src/test/ui/type-alias-impl-trait/issue-98604.rs b/src/test/ui/type-alias-impl-trait/issue-98604.rs index a4fd8a82a..32c2f9ed5 100644 --- a/src/test/ui/type-alias-impl-trait/issue-98604.rs +++ b/src/test/ui/type-alias-impl-trait/issue-98604.rs @@ -1,13 +1,11 @@ // edition:2018 -type AsyncFnPtr = Box< - dyn Fn() -> std::pin::Pin<Box<dyn std::future::Future<Output = ()>>>, ->; +type AsyncFnPtr = Box<dyn Fn() -> std::pin::Pin<Box<dyn std::future::Future<Output = ()>>>>; async fn test() {} #[allow(unused_must_use)] fn main() { Box::new(test) as AsyncFnPtr; - //~^ ERROR type mismatch + //~^ ERROR expected `fn() -> impl Future<Output = ()> {test}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>` } diff --git a/src/test/ui/type-alias-impl-trait/issue-98604.stderr b/src/test/ui/type-alias-impl-trait/issue-98604.stderr index f04d1b4d7..92d01eb0d 100644 --- a/src/test/ui/type-alias-impl-trait/issue-98604.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-98604.stderr @@ -1,11 +1,11 @@ -error[E0271]: type mismatch resolving `<fn() -> impl Future<Output = ()> {test} as FnOnce<()>>::Output == Pin<Box<(dyn Future<Output = ()> + 'static)>>` - --> $DIR/issue-98604.rs:11:5 +error[E0271]: expected `fn() -> impl Future<Output = ()> {test}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>` + --> $DIR/issue-98604.rs:9:5 | LL | Box::new(test) as AsyncFnPtr; | ^^^^^^^^^^^^^^ expected struct `Pin`, found opaque type | note: while checking the return type of the `async fn` - --> $DIR/issue-98604.rs:7:17 + --> $DIR/issue-98604.rs:5:17 | LL | async fn test() {} | ^ checked the `Output` of this `async fn`, found opaque type diff --git a/src/test/ui/type-alias-impl-trait/issue-98608.rs b/src/test/ui/type-alias-impl-trait/issue-98608.rs index d75762a8b..1f89af045 100644 --- a/src/test/ui/type-alias-impl-trait/issue-98608.rs +++ b/src/test/ui/type-alias-impl-trait/issue-98608.rs @@ -1,8 +1,10 @@ -fn hi() -> impl Sized { std::ptr::null::<u8>() } +fn hi() -> impl Sized { + std::ptr::null::<u8>() +} fn main() { let b: Box<dyn Fn() -> Box<u8>> = Box::new(hi); - //~^ ERROR type mismatch resolving `<fn() -> impl Sized {hi} as FnOnce<()>>::Output == Box<u8>` + //~^ ERROR expected `fn() -> impl Sized {hi}` to be a fn item that returns `Box<u8>`, but it returns `impl Sized` let boxed = b(); let null = *boxed; println!("{null:?}"); diff --git a/src/test/ui/type-alias-impl-trait/issue-98608.stderr b/src/test/ui/type-alias-impl-trait/issue-98608.stderr index 8f3ec7d9d..916a58451 100644 --- a/src/test/ui/type-alias-impl-trait/issue-98608.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-98608.stderr @@ -1,7 +1,7 @@ -error[E0271]: type mismatch resolving `<fn() -> impl Sized {hi} as FnOnce<()>>::Output == Box<u8>` - --> $DIR/issue-98608.rs:4:39 +error[E0271]: expected `fn() -> impl Sized {hi}` to be a fn item that returns `Box<u8>`, but it returns `impl Sized` + --> $DIR/issue-98608.rs:6:39 | -LL | fn hi() -> impl Sized { std::ptr::null::<u8>() } +LL | fn hi() -> impl Sized { | ---------- the found opaque type ... LL | let b: Box<dyn Fn() -> Box<u8>> = Box::new(hi); diff --git a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr index cdaae99e2..66a6b0bbf 100644 --- a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr +++ b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr @@ -4,7 +4,7 @@ error[E0277]: the trait bound `&'static B: From<&A>` is not satisfied LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) { | ^^^^^^^^^^^^^^^^^^ the trait `From<&A>` is not implemented for `&'static B` | - = note: required because of the requirements on the impl of `Into<&'static B>` for `&A` + = note: required for `&A` to implement `Into<&'static B>` help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement | LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) where &'static B: From<&A> { diff --git a/src/test/ui/type-alias-impl-trait/not_a_defining_use.stderr b/src/test/ui/type-alias-impl-trait/not_a_defining_use.stderr index a5ac38c38..b11198c58 100644 --- a/src/test/ui/type-alias-impl-trait/not_a_defining_use.stderr +++ b/src/test/ui/type-alias-impl-trait/not_a_defining_use.stderr @@ -4,7 +4,7 @@ error[E0277]: `T` doesn't implement `Debug` LL | (t, 5i8) | ^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(T, i8)` + = note: required for `(T, i8)` to implement `Debug` help: consider restricting type parameter `T` | LL | type Two<T: std::fmt::Debug, U> = impl Debug; @@ -27,7 +27,7 @@ error[E0277]: `T` doesn't implement `Debug` LL | (t, <U as Bar>::FOO) | ^^^^^^^^^^^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | - = note: required because of the requirements on the impl of `Debug` for `(T, _)` + = note: required for `(T, _)` to implement `Debug` help: consider restricting type parameter `T` | LL | type Two<T: std::fmt::Debug, U> = impl Debug; diff --git a/src/test/ui/type-alias-impl-trait/underconstrained_generic.stderr b/src/test/ui/type-alias-impl-trait/underconstrained_generic.stderr index e70916573..95fb6f6a5 100644 --- a/src/test/ui/type-alias-impl-trait/underconstrained_generic.stderr +++ b/src/test/ui/type-alias-impl-trait/underconstrained_generic.stderr @@ -4,7 +4,7 @@ error[E0277]: the trait bound `T: Trait` is not satisfied LL | () | ^^ the trait `Trait` is not implemented for `T` | -note: required because of the requirements on the impl of `ProofForConversion<T>` for `()` +note: required for `()` to implement `ProofForConversion<T>` --> $DIR/underconstrained_generic.rs:13:16 | LL | impl<X: Trait> ProofForConversion<X> for () { diff --git a/src/test/ui/type/issue-100584.rs b/src/test/ui/type/issue-100584.rs new file mode 100644 index 000000000..102846563 --- /dev/null +++ b/src/test/ui/type/issue-100584.rs @@ -0,0 +1,15 @@ +#![deny(unused)] +fn foo(xyza: &str) { +//~^ ERROR unused variable: `xyza` + let _ = "{xyza}"; +} + +fn foo3(xyza: &str) { +//~^ ERROR unused variable: `xyza` + let _ = "aaa{xyza}bbb"; +} + +fn main() { + foo("x"); + foo3("xx"); +} diff --git a/src/test/ui/type/issue-100584.stderr b/src/test/ui/type/issue-100584.stderr new file mode 100644 index 000000000..e1db14d1f --- /dev/null +++ b/src/test/ui/type/issue-100584.stderr @@ -0,0 +1,44 @@ +error: unused variable: `xyza` + --> $DIR/issue-100584.rs:2:8 + | +LL | fn foo(xyza: &str) { + | ^^^^ unused variable +LL | +LL | let _ = "{xyza}"; + | -------- you might have meant to use string interpolation in this string literal + | +note: the lint level is defined here + --> $DIR/issue-100584.rs:1:9 + | +LL | #![deny(unused)] + | ^^^^^^ + = note: `#[deny(unused_variables)]` implied by `#[deny(unused)]` +help: string interpolation only works in `format!` invocations + | +LL | let _ = format!("{xyza}"); + | ++++++++ + +help: if this is intentional, prefix it with an underscore + | +LL | fn foo(_xyza: &str) { + | ~~~~~ + +error: unused variable: `xyza` + --> $DIR/issue-100584.rs:7:9 + | +LL | fn foo3(xyza: &str) { + | ^^^^ unused variable +LL | +LL | let _ = "aaa{xyza}bbb"; + | -------------- you might have meant to use string interpolation in this string literal + | +help: string interpolation only works in `format!` invocations + | +LL | let _ = format!("aaa{xyza}bbb"); + | ++++++++ + +help: if this is intentional, prefix it with an underscore + | +LL | fn foo3(_xyza: &str) { + | ~~~~~ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/type/type-alias-bounds.rs b/src/test/ui/type/type-alias-bounds.rs index 65b79650d..e49731725 100644 --- a/src/test/ui/type/type-alias-bounds.rs +++ b/src/test/ui/type/type-alias-bounds.rs @@ -52,7 +52,7 @@ type T2<U> where U: Bound = U::Assoc; //~ WARN not enforced in type aliases // Do this instead: type T4<U> = <U as Bound>::Assoc; -// Make sure the help about associatd types is not shown incorrectly +// Make sure the help about associated types is not shown incorrectly type T5<U: Bound> = <U as Bound>::Assoc; //~ WARN not enforced in type aliases type T6<U: Bound> = ::std::vec::Vec<U>; //~ WARN not enforced in type aliases diff --git a/src/test/ui/type/type-arg-out-of-scope.stderr b/src/test/ui/type/type-arg-out-of-scope.stderr index 0b6283fbc..7f18b4510 100644 --- a/src/test/ui/type/type-arg-out-of-scope.stderr +++ b/src/test/ui/type/type-arg-out-of-scope.stderr @@ -4,9 +4,9 @@ error[E0401]: can't use generic parameters from outer function LL | fn foo<T>(x: T) { | - type parameter from outer function LL | fn bar(f: Box<dyn FnMut(T) -> T>) { } - | --- ^ use of generic parameter from outer function - | | - | help: try using a local generic parameter instead: `bar<T>` + | - ^ use of generic parameter from outer function + | | + | help: try using a local generic parameter instead: `<T>` error[E0401]: can't use generic parameters from outer function --> $DIR/type-arg-out-of-scope.rs:3:35 @@ -14,9 +14,9 @@ error[E0401]: can't use generic parameters from outer function LL | fn foo<T>(x: T) { | - type parameter from outer function LL | fn bar(f: Box<dyn FnMut(T) -> T>) { } - | --- ^ use of generic parameter from outer function - | | - | help: try using a local generic parameter instead: `bar<T>` + | - ^ use of generic parameter from outer function + | | + | help: try using a local generic parameter instead: `<T>` error: aborting due to 2 previous errors diff --git a/src/test/ui/type/type-ascription-instead-of-initializer.stderr b/src/test/ui/type/type-ascription-instead-of-initializer.stderr index fcac6c495..de578ca93 100644 --- a/src/test/ui/type/type-ascription-instead-of-initializer.stderr +++ b/src/test/ui/type/type-ascription-instead-of-initializer.stderr @@ -21,7 +21,7 @@ LL | pub fn with_capacity(capacity: usize) -> Self { help: remove the extra argument | LL | let x: Vec::with_capacity(10); - | ~~~~~~~~~~~~~~~~~~~~~~ + | ~~~~ error: aborting due to 2 previous errors diff --git a/src/test/ui/type/type-check-defaults.stderr b/src/test/ui/type/type-check-defaults.stderr index 56a9b5317..cf77c057d 100644 --- a/src/test/ui/type/type-check-defaults.stderr +++ b/src/test/ui/type/type-check-defaults.stderr @@ -1,8 +1,8 @@ error[E0277]: a value of type `i32` cannot be built from an iterator over elements of type `i32` - --> $DIR/type-check-defaults.rs:6:19 + --> $DIR/type-check-defaults.rs:6:23 | LL | struct WellFormed<Z = Foo<i32, i32>>(Z); - | ^^^^^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>` + | ^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>` | = help: the trait `FromIterator<i32>` is not implemented for `i32` note: required by a bound in `Foo` @@ -12,10 +12,10 @@ LL | struct Foo<T, U: FromIterator<T>>(T, U); | ^^^^^^^^^^^^^^^ required by this bound in `Foo` error[E0277]: a value of type `i32` cannot be built from an iterator over elements of type `i32` - --> $DIR/type-check-defaults.rs:8:27 + --> $DIR/type-check-defaults.rs:8:38 | LL | struct WellFormedNoBounds<Z:?Sized = Foo<i32, i32>>(Z); - | ^^^^^^^^^^^^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>` + | ^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>` | = help: the trait `FromIterator<i32>` is not implemented for `i32` note: required by a bound in `Foo` diff --git a/src/test/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.stderr b/src/test/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.stderr index 615fd2ccb..847bc517e 100644 --- a/src/test/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.stderr +++ b/src/test/ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.stderr @@ -1,13 +1,13 @@ error: function can not have more than 65535 arguments - --> $DIR/issue-88577-check-fn-with-more-than-65535-arguments.rs:6:24 + --> $DIR/issue-88577-check-fn-with-more-than-65535-arguments.rs:6:22 | -LL | fn _f($($t: ()),*) {} - | ________________________^ -LL | | } -LL | | } -LL | | -LL | | many_args!{[_]########## ######} - | |____________^ +LL | fn _f($($t: ()),*) {} + | ^ +... +LL | many_args!{[_]########## ######} + | -------------------------------- in this macro invocation + | + = note: this error originates in the macro `many_args` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/type/type-params-in-different-spaces-2.stderr b/src/test/ui/type/type-params-in-different-spaces-2.stderr index 53610985f..220b3929c 100644 --- a/src/test/ui/type/type-params-in-different-spaces-2.stderr +++ b/src/test/ui/type/type-params-in-different-spaces-2.stderr @@ -1,8 +1,10 @@ error[E0277]: the trait bound `Self: Tr<U>` is not satisfied - --> $DIR/type-params-in-different-spaces-2.rs:10:9 + --> $DIR/type-params-in-different-spaces-2.rs:10:16 | LL | Tr::op(u) - | ^^^^^^ the trait `Tr<U>` is not implemented for `Self` + | ------ ^ the trait `Tr<U>` is not implemented for `Self` + | | + | required by a bound introduced by this call | help: consider further restricting `Self` | @@ -10,10 +12,12 @@ LL | fn test<U>(u: U) -> Self where Self: Tr<U> { | +++++++++++++++++ error[E0277]: the trait bound `Self: Tr<U>` is not satisfied - --> $DIR/type-params-in-different-spaces-2.rs:16:9 + --> $DIR/type-params-in-different-spaces-2.rs:16:16 | LL | Tr::op(u) - | ^^^^^^ the trait `Tr<U>` is not implemented for `Self` + | ------ ^ the trait `Tr<U>` is not implemented for `Self` + | | + | required by a bound introduced by this call | help: consider further restricting `Self` | diff --git a/src/test/ui/type_length_limit.stderr b/src/test/ui/type_length_limit.stderr index 1508b84c1..84ac48b1e 100644 --- a/src/test/ui/type_length_limit.stderr +++ b/src/test/ui/type_length_limit.stderr @@ -4,8 +4,8 @@ error: reached the type-length limit while instantiating `std::mem::drop::<Optio LL | pub fn drop<T>(_x: T) {} | ^^^^^^^^^^^^^^^^^^^^^ | - = note: the full type name has been written to '$TEST_BUILD_DIR/type_length_limit/type_length_limit.long-type.txt' = help: consider adding a `#![type_length_limit="8"]` attribute to your crate + = note: the full type name has been written to '$TEST_BUILD_DIR/type_length_limit/type_length_limit.long-type.txt' error: reached the type-length limit while instantiating `<[closure@std::rt::lang_start<()...e<()>>::call_once - shim(vtable)` --> $SRC_DIR/core/src/ops/function.rs:LL:COL @@ -13,8 +13,8 @@ error: reached the type-length limit while instantiating `<[closure@std::rt::lan LL | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: the full type name has been written to '$TEST_BUILD_DIR/type_length_limit/type_length_limit.long-type.txt' = help: consider adding a `#![type_length_limit="8"]` attribute to your crate + = note: the full type name has been written to '$TEST_BUILD_DIR/type_length_limit/type_length_limit.long-type.txt' error: aborting due to 2 previous errors diff --git a/src/test/ui/typeck/assign-non-lval-derefmut.stderr b/src/test/ui/typeck/assign-non-lval-derefmut.stderr index a6fcdfe21..e394cf820 100644 --- a/src/test/ui/typeck/assign-non-lval-derefmut.stderr +++ b/src/test/ui/typeck/assign-non-lval-derefmut.stderr @@ -19,7 +19,7 @@ LL | x.lock().unwrap() += 1; | | | cannot use `+=` on type `MutexGuard<'_, usize>` | -help: `+=` can be used on `usize`, you can dereference `x.lock().unwrap()` +help: `+=` can be used on `usize` if you dereference the left-hand side | LL | *x.lock().unwrap() += 1; | + @@ -47,7 +47,7 @@ LL | y += 1; | | | cannot use `+=` on type `MutexGuard<'_, usize>` | -help: `+=` can be used on `usize`, you can dereference `y` +help: `+=` can be used on `usize` if you dereference the left-hand side | LL | *y += 1; | + diff --git a/src/test/ui/typeck/assign-non-lval-mut-ref.stderr b/src/test/ui/typeck/assign-non-lval-mut-ref.stderr index be2e9fe95..cbdc960ba 100644 --- a/src/test/ui/typeck/assign-non-lval-mut-ref.stderr +++ b/src/test/ui/typeck/assign-non-lval-mut-ref.stderr @@ -19,7 +19,7 @@ LL | x.last_mut().unwrap() += 1; | | | cannot use `+=` on type `&mut usize` | -help: `+=` can be used on `usize`, you can dereference `x.last_mut().unwrap()` +help: `+=` can be used on `usize` if you dereference the left-hand side | LL | *x.last_mut().unwrap() += 1; | + @@ -45,7 +45,7 @@ LL | y += 1; | | | cannot use `+=` on type `&mut usize` | -help: `+=` can be used on `usize`, you can dereference `y` +help: `+=` can be used on `usize` if you dereference the left-hand side | LL | *y += 1; | + diff --git a/src/test/ui/typeck/assign-non-lval-needs-deref.rs b/src/test/ui/typeck/assign-non-lval-needs-deref.rs new file mode 100644 index 000000000..c979d76b4 --- /dev/null +++ b/src/test/ui/typeck/assign-non-lval-needs-deref.rs @@ -0,0 +1,19 @@ +// issue #101376 + +use std::ops::AddAssign; +struct Foo; + +impl AddAssign<()> for Foo { + fn add_assign(&mut self, _: ()) {} +} + +impl AddAssign<()> for &mut Foo { + fn add_assign(&mut self, _: ()) {} +} + +fn main() { + (&mut Foo) += (); + //~^ ERROR invalid left-hand side of assignment + //~| NOTE cannot assign to this expression + //~| HELP consider dereferencing the left-hand side of this operation +} diff --git a/src/test/ui/typeck/assign-non-lval-needs-deref.stderr b/src/test/ui/typeck/assign-non-lval-needs-deref.stderr new file mode 100644 index 000000000..ee83b1453 --- /dev/null +++ b/src/test/ui/typeck/assign-non-lval-needs-deref.stderr @@ -0,0 +1,16 @@ +error[E0067]: invalid left-hand side of assignment + --> $DIR/assign-non-lval-needs-deref.rs:15:16 + | +LL | (&mut Foo) += (); + | ---------- ^^ + | | + | cannot assign to this expression + | +help: consider dereferencing the left-hand side of this operation + | +LL | *(&mut Foo) += (); + | + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0067`. diff --git a/src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.rs b/src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.rs new file mode 100644 index 000000000..97e0b213f --- /dev/null +++ b/src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.rs @@ -0,0 +1,8 @@ +trait Foo { + const A; //~ ERROR missing type for `const` item + static B; + //~^ ERROR associated `static` items are not allowed + //~| ERROR missing type for `static` item +} + +fn main() {} diff --git a/src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.stderr b/src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.stderr new file mode 100644 index 000000000..8982d6285 --- /dev/null +++ b/src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.stderr @@ -0,0 +1,20 @@ +error: associated `static` items are not allowed + --> $DIR/do-not-suggest-placeholder-to-const-static-without-type.rs:3:5 + | +LL | static B; + | ^^^^^^^^^ + +error: missing type for `const` item + --> $DIR/do-not-suggest-placeholder-to-const-static-without-type.rs:2:12 + | +LL | const A; + | ^ help: provide a type for the item: `: <type>` + +error: missing type for `static` item + --> $DIR/do-not-suggest-placeholder-to-const-static-without-type.rs:3:13 + | +LL | static B; + | ^ help: provide a type for the item: `: <type>` + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/typeck/issue-100164.fixed b/src/test/ui/typeck/issue-100164.fixed new file mode 100644 index 000000000..a5f68beb1 --- /dev/null +++ b/src/test/ui/typeck/issue-100164.fixed @@ -0,0 +1,9 @@ +// run-rustfix + +const _A: i32 = 123; +//~^ ERROR: missing type for `const` item + +fn main() { + const _B: i32 = 123; + //~^ ERROR: missing type for `const` item +} diff --git a/src/test/ui/typeck/issue-100164.rs b/src/test/ui/typeck/issue-100164.rs new file mode 100644 index 000000000..7efb9ac62 --- /dev/null +++ b/src/test/ui/typeck/issue-100164.rs @@ -0,0 +1,9 @@ +// run-rustfix + +const _A: = 123; +//~^ ERROR: missing type for `const` item + +fn main() { + const _B: = 123; + //~^ ERROR: missing type for `const` item +} diff --git a/src/test/ui/typeck/issue-100164.stderr b/src/test/ui/typeck/issue-100164.stderr new file mode 100644 index 000000000..06a132d65 --- /dev/null +++ b/src/test/ui/typeck/issue-100164.stderr @@ -0,0 +1,14 @@ +error: missing type for `const` item + --> $DIR/issue-100164.rs:3:10 + | +LL | const _A: = 123; + | ^ help: provide a type for the constant: `i32` + +error: missing type for `const` item + --> $DIR/issue-100164.rs:7:14 + | +LL | const _B: = 123; + | ^ help: provide a type for the constant: `i32` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/typeck/issue-100246.rs b/src/test/ui/typeck/issue-100246.rs new file mode 100644 index 000000000..8f0b34bab --- /dev/null +++ b/src/test/ui/typeck/issue-100246.rs @@ -0,0 +1,30 @@ +#![recursion_limit = "5"] // To reduce noise + +//expect incompatible type error when ambiguous traits are in scope +//and not an overflow error on the span in the main function. + +struct Ratio<T>(T); + +pub trait Pow { + fn pow(self) -> Self; +} + +impl<'a, T> Pow for &'a Ratio<T> +where + &'a T: Pow, +{ + fn pow(self) -> Self { + self + } +} + +fn downcast<'a, W: ?Sized>() -> std::io::Result<&'a W> { + todo!() +} + +struct Other; + +fn main() -> std::io::Result<()> { + let other: Other = downcast()?;//~ERROR 28:24: 28:35: `?` operator has incompatible types + Ok(()) +} diff --git a/src/test/ui/typeck/issue-100246.stderr b/src/test/ui/typeck/issue-100246.stderr new file mode 100644 index 000000000..8b77de94e --- /dev/null +++ b/src/test/ui/typeck/issue-100246.stderr @@ -0,0 +1,13 @@ +error[E0308]: `?` operator has incompatible types + --> $DIR/issue-100246.rs:28:24 + | +LL | let other: Other = downcast()?; + | ^^^^^^^^^^^ expected struct `Other`, found reference + | + = note: `?` operator cannot convert from `&_` to `Other` + = note: expected struct `Other` + found reference `&_` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/typeck/issue-100285.rs b/src/test/ui/typeck/issue-100285.rs new file mode 100644 index 000000000..e206469b8 --- /dev/null +++ b/src/test/ui/typeck/issue-100285.rs @@ -0,0 +1,22 @@ +fn foo(n: i32) -> i32 { + for i in 0..0 { + //~^ ERROR: mismatched types [E0308] + if n < 0 { + return i; + } else if n < 10 { + return 1; + } else if n < 20 { + return 2; + } else if n < 30 { + return 3; + } else if n < 40 { + return 4; + } else { + return 5; + } + + } + //~| help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility +} + +fn main() {} diff --git a/src/test/ui/typeck/issue-100285.stderr b/src/test/ui/typeck/issue-100285.stderr new file mode 100644 index 000000000..42c64b039 --- /dev/null +++ b/src/test/ui/typeck/issue-100285.stderr @@ -0,0 +1,34 @@ +error[E0308]: mismatched types + --> $DIR/issue-100285.rs:2:5 + | +LL | fn foo(n: i32) -> i32 { + | --- expected `i32` because of return type +LL | / for i in 0..0 { +LL | | +LL | | if n < 0 { +LL | | return i; +... | +LL | | +LL | | } + | |_____^ expected `i32`, found `()` + | +note: the function expects a value to always be returned, but loops might run zero times + --> $DIR/issue-100285.rs:2:5 + | +LL | for i in 0..0 { + | ^^^^^^^^^^^^^ this might have zero elements to iterate on +... +LL | return i; + | -------- if the loop doesn't execute, this value would never get returned +LL | } else if n < 10 { +LL | return 1; + | -------- if the loop doesn't execute, this value would never get returned +LL | } else if n < 20 { +LL | return 2; + | -------- if the loop doesn't execute, this value would never get returned + = note: if the loop doesn't execute, 3 other values would never get returned + = help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/typeck/issue-29124.stderr b/src/test/ui/typeck/issue-29124.stderr index c5d2ec084..a837a7d2d 100644 --- a/src/test/ui/typeck/issue-29124.stderr +++ b/src/test/ui/typeck/issue-29124.stderr @@ -2,17 +2,13 @@ error[E0599]: no method named `x` found for fn item `fn() -> Ret {Obj::func}` in --> $DIR/issue-29124.rs:15:15 | LL | Obj::func.x(); - | --------- ^ method not found in `fn() -> Ret {Obj::func}` - | | - | this is a function, perhaps you wish to call it + | ^ method not found in `fn() -> Ret {Obj::func}` error[E0599]: no method named `x` found for fn item `fn() -> Ret {func}` in the current scope --> $DIR/issue-29124.rs:17:10 | LL | func.x(); - | ---- ^ method not found in `fn() -> Ret {func}` - | | - | this is a function, perhaps you wish to call it + | ^ method not found in `fn() -> Ret {func}` error: aborting due to 2 previous errors diff --git a/src/test/ui/typeck/issue-79040.stderr b/src/test/ui/typeck/issue-79040.stderr index aec2e1ec9..c820d1e08 100644 --- a/src/test/ui/typeck/issue-79040.stderr +++ b/src/test/ui/typeck/issue-79040.stderr @@ -7,10 +7,10 @@ LL | const FOO = "hello" + 1; | &str error: missing type for `const` item - --> $DIR/issue-79040.rs:2:11 + --> $DIR/issue-79040.rs:2:14 | LL | const FOO = "hello" + 1; - | ^^^ help: provide a type for the item: `FOO: <type>` + | ^ help: provide a type for the item: `: <type>` error: aborting due to 2 previous errors diff --git a/src/test/ui/typeck/issue-87181/empty-tuple-method.rs b/src/test/ui/typeck/issue-87181/empty-tuple-method.rs index 1875d8280..be68ad32a 100644 --- a/src/test/ui/typeck/issue-87181/empty-tuple-method.rs +++ b/src/test/ui/typeck/issue-87181/empty-tuple-method.rs @@ -4,7 +4,7 @@ struct Bar<T> { struct Foo(); impl Foo { - fn foo() { } + fn foo(&self) { } } fn main() { diff --git a/src/test/ui/typeck/issue-87181/empty-tuple-method.stderr b/src/test/ui/typeck/issue-87181/empty-tuple-method.stderr index 6ed70b301..a18c54a29 100644 --- a/src/test/ui/typeck/issue-87181/empty-tuple-method.stderr +++ b/src/test/ui/typeck/issue-87181/empty-tuple-method.stderr @@ -2,11 +2,9 @@ error[E0599]: no method named `foo` found for fn item `fn() -> Foo {Foo}` in the --> $DIR/empty-tuple-method.rs:12:15 | LL | thing.bar.foo(); - | --------- ^^^ method not found in `fn() -> Foo {Foo}` - | | - | this is the constructor of a struct + | ^^^ method not found in `fn() -> Foo {Foo}` | -help: call the constructor +help: use parentheses to instantiate this tuple struct | LL | (thing.bar)().foo(); | + +++ diff --git a/src/test/ui/typeck/issue-87181/enum-variant.rs b/src/test/ui/typeck/issue-87181/enum-variant.rs index 3b926b90f..d87f99c3c 100644 --- a/src/test/ui/typeck/issue-87181/enum-variant.rs +++ b/src/test/ui/typeck/issue-87181/enum-variant.rs @@ -6,7 +6,7 @@ enum Foo{ Tup() } impl Foo { - fn foo() { } + fn foo(&self) { } } fn main() { diff --git a/src/test/ui/typeck/issue-87181/enum-variant.stderr b/src/test/ui/typeck/issue-87181/enum-variant.stderr index a3a818696..90641410d 100644 --- a/src/test/ui/typeck/issue-87181/enum-variant.stderr +++ b/src/test/ui/typeck/issue-87181/enum-variant.stderr @@ -2,11 +2,9 @@ error[E0599]: no method named `foo` found for fn item `fn() -> Foo {Foo::Tup}` i --> $DIR/enum-variant.rs:14:15 | LL | thing.bar.foo(); - | --------- ^^^ method not found in `fn() -> Foo {Foo::Tup}` - | | - | this is the constructor of an enum variant + | ^^^ method not found in `fn() -> Foo {Foo::Tup}` | -help: call the constructor +help: use parentheses to instantiate this tuple variant | LL | (thing.bar)().foo(); | + +++ diff --git a/src/test/ui/typeck/issue-87181/tuple-field.stderr b/src/test/ui/typeck/issue-87181/tuple-field.stderr index 4d22ada02..c1ca26ee9 100644 --- a/src/test/ui/typeck/issue-87181/tuple-field.stderr +++ b/src/test/ui/typeck/issue-87181/tuple-field.stderr @@ -2,14 +2,12 @@ error[E0609]: no field `0` on type `fn(char, u16) -> Foo {Foo}` --> $DIR/tuple-field.rs:12:15 | LL | thing.bar.0; - | --------- ^ - | | - | this is the constructor of a struct + | ^ | -help: call the constructor +help: use parentheses to instantiate this tuple struct | -LL | (thing.bar)(_, _).0; - | + +++++++ +LL | (thing.bar)(/* char */, /* u16 */).0; + | + ++++++++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/typeck/issue-87181/tuple-method.stderr b/src/test/ui/typeck/issue-87181/tuple-method.stderr index 1e392e179..e27c41858 100644 --- a/src/test/ui/typeck/issue-87181/tuple-method.stderr +++ b/src/test/ui/typeck/issue-87181/tuple-method.stderr @@ -2,14 +2,7 @@ error[E0599]: no method named `foo` found for fn item `fn(u8, i32) -> Foo {Foo}` --> $DIR/tuple-method.rs:12:15 | LL | thing.bar.foo(); - | --------- ^^^ method not found in `fn(u8, i32) -> Foo {Foo}` - | | - | this is the constructor of a struct - | -help: call the constructor - | -LL | (thing.bar)(_, _).foo(); - | + +++++++ + | ^^^ method not found in `fn(u8, i32) -> Foo {Foo}` error: aborting due to previous error diff --git a/src/test/ui/typeck/issue-90101.stderr b/src/test/ui/typeck/issue-90101.stderr index ab9a72edf..d2729d853 100644 --- a/src/test/ui/typeck/issue-90101.stderr +++ b/src/test/ui/typeck/issue-90101.stderr @@ -12,7 +12,7 @@ LL | func(Path::new("hello").to_path_buf().to_string_lossy(), "world") <PathBuf as From<Cow<'a, Path>>> <PathBuf as From<OsString>> <PathBuf as From<String>> - = note: required because of the requirements on the impl of `Into<PathBuf>` for `Cow<'_, str>` + = note: required for `Cow<'_, str>` to implement `Into<PathBuf>` note: required by a bound in `func` --> $DIR/issue-90101.rs:3:20 | diff --git a/src/test/ui/typeck/issue-91210-ptr-method.stderr b/src/test/ui/typeck/issue-91210-ptr-method.stderr index 503a32373..7a0cfb2cf 100644 --- a/src/test/ui/typeck/issue-91210-ptr-method.stderr +++ b/src/test/ui/typeck/issue-91210-ptr-method.stderr @@ -2,9 +2,12 @@ error[E0615]: attempted to take value of method `read` on type `*mut Foo` --> $DIR/issue-91210-ptr-method.rs:10:7 | LL | x.read = 4; - | - ^^^^ method, not a field - | | - | help: to access the field, dereference first: `(*x)` + | ^^^^ method, not a field + | +help: to access the field, dereference first + | +LL | (*x).read = 4; + | ++ + error: aborting due to previous error diff --git a/src/test/ui/typeck/issue-91633.rs b/src/test/ui/typeck/issue-91633.rs new file mode 100644 index 000000000..331a798dd --- /dev/null +++ b/src/test/ui/typeck/issue-91633.rs @@ -0,0 +1,8 @@ +// check-pass +fn f<T> (it: &[T]) +where + [T] : std::ops::Index<usize>, +{ + let _ = &it[0]; +} +fn main(){} diff --git a/src/test/ui/typeck/issue-96738.stderr b/src/test/ui/typeck/issue-96738.stderr index 32f538498..0d4d87ef4 100644 --- a/src/test/ui/typeck/issue-96738.stderr +++ b/src/test/ui/typeck/issue-96738.stderr @@ -2,27 +2,13 @@ error[E0599]: no method named `nonexistent_method` found for fn item `fn(_) -> O --> $DIR/issue-96738.rs:2:10 | LL | Some.nonexistent_method(); - | ---- ^^^^^^^^^^^^^^^^^^ method not found in `fn(_) -> Option<_> {Option::<_>::Some}` - | | - | this is the constructor of an enum variant - | -help: call the constructor - | -LL | (Some)(_).nonexistent_method(); - | + ++++ + | ^^^^^^^^^^^^^^^^^^ method not found in `fn(_) -> Option<_> {Option::<_>::Some}` error[E0609]: no field `nonexistent_field` on type `fn(_) -> Option<_> {Option::<_>::Some}` --> $DIR/issue-96738.rs:3:10 | LL | Some.nonexistent_field; - | ---- ^^^^^^^^^^^^^^^^^ - | | - | this is the constructor of an enum variant - | -help: call the constructor - | -LL | (Some)(_).nonexistent_field; - | + ++++ + | ^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/typeck/issue-98982.rs b/src/test/ui/typeck/issue-98982.rs new file mode 100644 index 000000000..2553824bb --- /dev/null +++ b/src/test/ui/typeck/issue-98982.rs @@ -0,0 +1,9 @@ +fn foo() -> i32 { + for i in 0..0 { + //~^ ERROR: mismatched types [E0308] + return i; + } + //~| help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility +} + +fn main() {} diff --git a/src/test/ui/typeck/issue-98982.stderr b/src/test/ui/typeck/issue-98982.stderr new file mode 100644 index 000000000..3c9806ac9 --- /dev/null +++ b/src/test/ui/typeck/issue-98982.stderr @@ -0,0 +1,24 @@ +error[E0308]: mismatched types + --> $DIR/issue-98982.rs:2:5 + | +LL | fn foo() -> i32 { + | --- expected `i32` because of return type +LL | / for i in 0..0 { +LL | | +LL | | return i; +LL | | } + | |_____^ expected `i32`, found `()` + | +note: the function expects a value to always be returned, but loops might run zero times + --> $DIR/issue-98982.rs:2:5 + | +LL | for i in 0..0 { + | ^^^^^^^^^^^^^ this might have zero elements to iterate on +LL | +LL | return i; + | -------- if the loop doesn't execute, this value would never get returned + = help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/typeck/point-at-type-param-in-path-expr.rs b/src/test/ui/typeck/point-at-type-param-in-path-expr.rs new file mode 100644 index 000000000..9a21536f9 --- /dev/null +++ b/src/test/ui/typeck/point-at-type-param-in-path-expr.rs @@ -0,0 +1,6 @@ +fn foo<T: std::fmt::Display>() {} + +fn main() { + let x = foo::<()>; + //~^ ERROR `()` doesn't implement `std::fmt::Display` +} diff --git a/src/test/ui/typeck/point-at-type-param-in-path-expr.stderr b/src/test/ui/typeck/point-at-type-param-in-path-expr.stderr new file mode 100644 index 000000000..1feaa0508 --- /dev/null +++ b/src/test/ui/typeck/point-at-type-param-in-path-expr.stderr @@ -0,0 +1,17 @@ +error[E0277]: `()` doesn't implement `std::fmt::Display` + --> $DIR/point-at-type-param-in-path-expr.rs:4:19 + | +LL | let x = foo::<()>; + | ^^ `()` cannot be formatted with the default formatter + | + = help: the trait `std::fmt::Display` is not implemented for `()` + = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead +note: required by a bound in `foo` + --> $DIR/point-at-type-param-in-path-expr.rs:1:11 + | +LL | fn foo<T: std::fmt::Display>() {} + | ^^^^^^^^^^^^^^^^^ required by this bound in `foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/typeck/remove-extra-argument.stderr b/src/test/ui/typeck/remove-extra-argument.stderr index 703032a83..b734bcd4e 100644 --- a/src/test/ui/typeck/remove-extra-argument.stderr +++ b/src/test/ui/typeck/remove-extra-argument.stderr @@ -12,7 +12,7 @@ LL | fn l(_a: Vec<u8>) {} help: remove the extra argument | LL | l(vec![]) - | + | ~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/typeck/struct-enum-wrong-args.stderr b/src/test/ui/typeck/struct-enum-wrong-args.stderr index f72082d53..ea94bcbc2 100644 --- a/src/test/ui/typeck/struct-enum-wrong-args.stderr +++ b/src/test/ui/typeck/struct-enum-wrong-args.stderr @@ -12,7 +12,7 @@ LL | Some(#[stable(feature = "rust1", since = "1.0.0")] T), help: remove the extra argument | LL | let _ = Some(3); - | ~~~~~~~ + | ~~~ error[E0061]: this enum variant takes 1 argument but 3 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:7:13 @@ -30,7 +30,7 @@ LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T), help: remove the extra arguments | LL | let _ = Ok(3); - | ~~~~~ + | ~~~ error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:8:13 @@ -46,7 +46,7 @@ LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T), help: provide the argument | LL | let _ = Ok(/* value */); - | ~~~~~~~~~~~~~~~ + | ~~~~~~~~~~~~~ error[E0061]: this struct takes 1 argument but 0 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:9:13 @@ -62,7 +62,7 @@ LL | struct Wrapper(i32); help: provide the argument | LL | let _ = Wrapper(/* i32 */); - | ~~~~~~~~~~~~~~~~~~ + | ~~~~~~~~~~~ error[E0061]: this struct takes 1 argument but 2 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:10:13 @@ -78,7 +78,7 @@ LL | struct Wrapper(i32); help: remove the extra argument | LL | let _ = Wrapper(5); - | ~~~~~~~~~~ + | ~~~ error[E0061]: this struct takes 2 arguments but 0 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:11:13 @@ -94,7 +94,7 @@ LL | struct DoubleWrapper(i32, i32); help: provide the arguments | LL | let _ = DoubleWrapper(/* i32 */, /* i32 */); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + | ~~~~~~~~~~~~~~~~~~~~~~ error[E0061]: this struct takes 2 arguments but 1 argument was supplied --> $DIR/struct-enum-wrong-args.rs:12:13 @@ -110,7 +110,7 @@ LL | struct DoubleWrapper(i32, i32); help: provide the argument | LL | let _ = DoubleWrapper(5, /* i32 */); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + | ~~~~~~~~~~~~~~ error[E0061]: this struct takes 2 arguments but 3 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:13:13 @@ -126,7 +126,7 @@ LL | struct DoubleWrapper(i32, i32); help: remove the extra argument | LL | let _ = DoubleWrapper(5, 2); - | ~~~~~~~~~~~~~~~~~~~ + | ~~~~~~ error: aborting due to 8 previous errors diff --git a/src/test/ui/typeck/suggest-adding-missing-zero-to-floating-point-number.stderr b/src/test/ui/typeck/suggest-adding-missing-zero-to-floating-point-number.stderr index e8e069708..503015f3b 100644 --- a/src/test/ui/typeck/suggest-adding-missing-zero-to-floating-point-number.stderr +++ b/src/test/ui/typeck/suggest-adding-missing-zero-to-floating-point-number.stderr @@ -4,7 +4,7 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields LL | 2.e1; | ^^ | -help: If the number is meant to be a floating point number, consider adding a `0` after the period +help: if intended to be a floating point literal, consider adding a `0` after the period | LL | 2.0e1; | + @@ -15,7 +15,7 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields LL | 2.E1; | ^^ | -help: If the number is meant to be a floating point number, consider adding a `0` after the period +help: if intended to be a floating point literal, consider adding a `0` after the period | LL | 2.0E1; | + @@ -26,7 +26,7 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields LL | 2.f32; | ^^^ | -help: If the number is meant to be a floating point number, consider adding a `0` after the period +help: if intended to be a floating point literal, consider adding a `0` after the period | LL | 2.0f32; | + @@ -37,7 +37,7 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields LL | 2.f64; | ^^^ | -help: If the number is meant to be a floating point number, consider adding a `0` after the period +help: if intended to be a floating point literal, consider adding a `0` after the period | LL | 2.0f64; | + @@ -48,7 +48,7 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields LL | 2.e+12; | ^ | -help: If the number is meant to be a floating point number, consider adding a `0` after the period +help: if intended to be a floating point literal, consider adding a `0` after the period | LL | 2.0e+12; | + @@ -59,7 +59,7 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields LL | 2.e-12; | ^ | -help: If the number is meant to be a floating point number, consider adding a `0` after the period +help: if intended to be a floating point literal, consider adding a `0` after the period | LL | 2.0e-12; | + @@ -70,7 +70,7 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields LL | 2.e1f32; | ^^^^^ | -help: If the number is meant to be a floating point number, consider adding a `0` after the period +help: if intended to be a floating point literal, consider adding a `0` after the period | LL | 2.0e1f32; | + diff --git a/src/test/ui/typeck/typeck-default-trait-impl-negation-sync.stderr b/src/test/ui/typeck/typeck-default-trait-impl-negation-sync.stderr index 6bb5e1f54..b9fca1a1b 100644 --- a/src/test/ui/typeck/typeck-default-trait-impl-negation-sync.stderr +++ b/src/test/ui/typeck/typeck-default-trait-impl-negation-sync.stderr @@ -12,10 +12,10 @@ LL | fn is_sync<T: Sync>() {} | ^^^^ required by this bound in `is_sync` error[E0277]: `UnsafeCell<u8>` cannot be shared between threads safely - --> $DIR/typeck-default-trait-impl-negation-sync.rs:36:5 + --> $DIR/typeck-default-trait-impl-negation-sync.rs:36:15 | LL | is_sync::<MyTypeWUnsafe>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell<u8>` cannot be shared between threads safely + | ^^^^^^^^^^^^^ `UnsafeCell<u8>` cannot be shared between threads safely | = help: within `MyTypeWUnsafe`, the trait `Sync` is not implemented for `UnsafeCell<u8>` note: required because it appears within the type `MyTypeWUnsafe` @@ -30,10 +30,10 @@ LL | fn is_sync<T: Sync>() {} | ^^^^ required by this bound in `is_sync` error[E0277]: `Managed` cannot be shared between threads safely - --> $DIR/typeck-default-trait-impl-negation-sync.rs:39:5 + --> $DIR/typeck-default-trait-impl-negation-sync.rs:39:15 | LL | is_sync::<MyTypeManaged>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ `Managed` cannot be shared between threads safely + | ^^^^^^^^^^^^^ `Managed` cannot be shared between threads safely | = help: within `MyTypeManaged`, the trait `Sync` is not implemented for `Managed` note: required because it appears within the type `MyTypeManaged` diff --git a/src/test/ui/typeck/typeck_type_placeholder_item.stderr b/src/test/ui/typeck/typeck_type_placeholder_item.stderr index 3ea317dfb..c57f71b80 100644 --- a/src/test/ui/typeck/typeck_type_placeholder_item.stderr +++ b/src/test/ui/typeck/typeck_type_placeholder_item.stderr @@ -189,10 +189,10 @@ LL ~ b: (T, T), | error: missing type for `static` item - --> $DIR/typeck_type_placeholder_item.rs:73:12 + --> $DIR/typeck_type_placeholder_item.rs:73:13 | LL | static A = 42; - | ^ help: provide a type for the static variable: `A: i32` + | ^ help: provide a type for the static variable: `: i32` error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables --> $DIR/typeck_type_placeholder_item.rs:75:15 diff --git a/src/test/ui/typeof/issue-100183.rs b/src/test/ui/typeof/issue-100183.rs new file mode 100644 index 000000000..13e9493ea --- /dev/null +++ b/src/test/ui/typeof/issue-100183.rs @@ -0,0 +1,6 @@ +struct Struct { + y: (typeof("hey"),), + //~^ ERROR `typeof` is a reserved keyword but unimplemented +} + +fn main() {} diff --git a/src/test/ui/typeof/issue-100183.stderr b/src/test/ui/typeof/issue-100183.stderr new file mode 100644 index 000000000..01d3079b2 --- /dev/null +++ b/src/test/ui/typeof/issue-100183.stderr @@ -0,0 +1,14 @@ +error[E0516]: `typeof` is a reserved keyword but unimplemented + --> $DIR/issue-100183.rs:2:9 + | +LL | y: (typeof("hey"),), + | ^^^^^^^^^^^^^ reserved keyword + | +help: consider replacing `typeof(...)` with an actual type + | +LL | y: (&'static str,), + | ~~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0516`. |