diff options
Diffstat (limited to '')
97 files changed, 1481 insertions, 71 deletions
diff --git a/tests/ui/traits/alias/dont-elaborate-non-self.rs b/tests/ui/traits/alias/dont-elaborate-non-self.rs new file mode 100644 index 000000000..4f9eaacb8 --- /dev/null +++ b/tests/ui/traits/alias/dont-elaborate-non-self.rs @@ -0,0 +1,10 @@ +#![feature(trait_alias)] + +use std::future::Future; + +trait F<Fut: Future<Output = usize>> = Fn() -> Fut; + +fn f<Fut>(a: dyn F<Fut>) {} +//~^ ERROR the size for values of type `(dyn Fn() -> Fut + 'static)` cannot be known at compilation time + +fn main() {} diff --git a/tests/ui/traits/alias/dont-elaborate-non-self.stderr b/tests/ui/traits/alias/dont-elaborate-non-self.stderr new file mode 100644 index 000000000..247a4f812 --- /dev/null +++ b/tests/ui/traits/alias/dont-elaborate-non-self.stderr @@ -0,0 +1,20 @@ +error[E0277]: the size for values of type `(dyn Fn() -> Fut + 'static)` cannot be known at compilation time + --> $DIR/dont-elaborate-non-self.rs:7:11 + | +LL | fn f<Fut>(a: dyn F<Fut>) {} + | ^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `(dyn Fn() -> Fut + 'static)` + = help: unsized fn params are gated as an unstable feature +help: you can use `impl Trait` as the argument type + | +LL | fn f<Fut>(a: impl F<Fut>) {} + | ~~~~ +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn f<Fut>(a: &dyn F<Fut>) {} + | + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/associated_type_bound/assoc_type_bound_with_struct.rs b/tests/ui/traits/associated_type_bound/assoc_type_bound_with_struct.rs index 471a6b836..8e43b7249 100644 --- a/tests/ui/traits/associated_type_bound/assoc_type_bound_with_struct.rs +++ b/tests/ui/traits/associated_type_bound/assoc_type_bound_with_struct.rs @@ -18,6 +18,6 @@ fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: String { //~ ERROR expec fn issue_95327() where <u8 as Unresolved>::Assoc: String {} //~^ ERROR expected trait, found struct -//~| ERROR use of undeclared type `Unresolved` +//~| ERROR cannot find trait `Unresolved` in this scope fn main() {} diff --git a/tests/ui/traits/associated_type_bound/assoc_type_bound_with_struct.stderr b/tests/ui/traits/associated_type_bound/assoc_type_bound_with_struct.stderr index 5be334986..0020f9e41 100644 --- a/tests/ui/traits/associated_type_bound/assoc_type_bound_with_struct.stderr +++ b/tests/ui/traits/associated_type_bound/assoc_type_bound_with_struct.stderr @@ -1,9 +1,3 @@ -error[E0433]: failed to resolve: use of undeclared type `Unresolved` - --> $DIR/assoc_type_bound_with_struct.rs:19:31 - | -LL | fn issue_95327() where <u8 as Unresolved>::Assoc: String {} - | ^^^^^^^^^^ use of undeclared type `Unresolved` - error[E0404]: expected trait, found struct `String` --> $DIR/assoc_type_bound_with_struct.rs:5:46 | @@ -76,6 +70,12 @@ help: a trait with a similar name exists LL | fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: ToString { | ~~~~~~~~ +error[E0405]: cannot find trait `Unresolved` in this scope + --> $DIR/assoc_type_bound_with_struct.rs:19:31 + | +LL | fn issue_95327() where <u8 as Unresolved>::Assoc: String {} + | ^^^^^^^^^^ not found in this scope + error[E0404]: expected trait, found struct `String` --> $DIR/assoc_type_bound_with_struct.rs:19:51 | @@ -87,5 +87,5 @@ LL | fn issue_95327() where <u8 as Unresolved>::Assoc: String {} error: aborting due to 6 previous errors -Some errors have detailed explanations: E0404, E0433. +Some errors have detailed explanations: E0404, E0405. For more information about an error, try `rustc --explain E0404`. diff --git a/tests/ui/traits/copy-is-not-modulo-regions.not_static.stderr b/tests/ui/traits/copy-is-not-modulo-regions.not_static.stderr index edd94d201..130425211 100644 --- a/tests/ui/traits/copy-is-not-modulo-regions.not_static.stderr +++ b/tests/ui/traits/copy-is-not-modulo-regions.not_static.stderr @@ -1,4 +1,4 @@ -error[E0204]: the trait `Copy` may not be implemented for this type +error[E0204]: the trait `Copy` cannot be implemented for this type --> $DIR/copy-is-not-modulo-regions.rs:13:21 | LL | struct Bar<'lt>(Foo<'lt>); diff --git a/tests/ui/traits/copy-is-not-modulo-regions.rs b/tests/ui/traits/copy-is-not-modulo-regions.rs index adb870237..b89908374 100644 --- a/tests/ui/traits/copy-is-not-modulo-regions.rs +++ b/tests/ui/traits/copy-is-not-modulo-regions.rs @@ -11,7 +11,7 @@ struct Bar<'lt>(Foo<'lt>); #[cfg(not_static)] impl<'any> Copy for Bar<'any> {} -//[not_static]~^ the trait `Copy` may not be implemented for this type +//[not_static]~^ the trait `Copy` cannot be implemented for this type #[cfg(yes_static)] impl<'any> Copy for Bar<'static> {} diff --git a/tests/ui/traits/dyn-trait.rs b/tests/ui/traits/dyn-trait.rs index e1c1a8de5..10e69105c 100644 --- a/tests/ui/traits/dyn-trait.rs +++ b/tests/ui/traits/dyn-trait.rs @@ -1,5 +1,4 @@ // run-pass -// ignore-pretty `dyn ::foo` parses differently in the current edition use std::fmt::Display; diff --git a/tests/ui/traits/inductive-overflow/lifetime.rs b/tests/ui/traits/inductive-overflow/lifetime.rs index bf536d21c..2f3c90dce 100644 --- a/tests/ui/traits/inductive-overflow/lifetime.rs +++ b/tests/ui/traits/inductive-overflow/lifetime.rs @@ -15,9 +15,9 @@ impl<'a> Y for C<'a> { struct C<'a>(&'a ()); struct X<T: Y>(T::P); -impl<T: NotAuto> NotAuto for Box<T> {} //~ NOTE: required +impl<T: NotAuto> NotAuto for Box<T> {} +impl<T: Y> NotAuto for X<T> where T::P: NotAuto {} //~ NOTE: required //~^ NOTE unsatisfied trait bound introduced here -impl<T: Y> NotAuto for X<T> where T::P: NotAuto {} impl<'a> NotAuto for C<'a> {} fn is_send<S: NotAuto>() {} @@ -28,6 +28,4 @@ fn main() { // Should only be a few notes. is_send::<X<C<'static>>>(); //~^ ERROR overflow evaluating - //~| 3 redundant requirements hidden - //~| required for } diff --git a/tests/ui/traits/inductive-overflow/lifetime.stderr b/tests/ui/traits/inductive-overflow/lifetime.stderr index 357e59991..7ab2864a8 100644 --- a/tests/ui/traits/inductive-overflow/lifetime.stderr +++ b/tests/ui/traits/inductive-overflow/lifetime.stderr @@ -1,18 +1,14 @@ -error[E0275]: overflow evaluating the requirement `X<C<'_>>: NotAuto` +error[E0275]: overflow evaluating the requirement `Box<X<C<'static>>>: NotAuto` --> $DIR/lifetime.rs:29:5 | LL | is_send::<X<C<'static>>>(); | ^^^^^^^^^^^^^^^^^^^^^^^^ | -note: required for `Box<X<C<'_>>>` to implement `NotAuto` - --> $DIR/lifetime.rs:18:18 +note: required for `X<C<'static>>` to implement `NotAuto` + --> $DIR/lifetime.rs:19:12 | -LL | impl<T: NotAuto> NotAuto for Box<T> {} - | ------- ^^^^^^^ ^^^^^^ - | | - | unsatisfied trait bound introduced here - = note: 3 redundant requirements hidden - = note: required for `X<C<'static>>` to implement `NotAuto` +LL | impl<T: Y> NotAuto for X<T> where T::P: NotAuto {} + | ^^^^^^^ ^^^^ ------- unsatisfied trait bound introduced here note: required by a bound in `is_send` --> $DIR/lifetime.rs:23:15 | diff --git a/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr index dc967d512..e723c7c51 100644 --- a/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr +++ b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr @@ -26,7 +26,8 @@ LL | fn copy<T: Magic>(x: T) -> (T, T) { (x, x) } | ^^^^^ required by this bound in `copy` help: consider annotating `NoClone` with `#[derive(Copy)]` | -LL | #[derive(Copy)] +LL + #[derive(Copy)] +LL | struct NoClone; | error: aborting due to 2 previous errors diff --git a/tests/ui/traits/issue-50480.rs b/tests/ui/traits/issue-50480.rs index 005939e0c..683a85a32 100644 --- a/tests/ui/traits/issue-50480.rs +++ b/tests/ui/traits/issue-50480.rs @@ -1,5 +1,5 @@ #[derive(Clone, Copy)] -//~^ ERROR the trait `Copy` may not be implemented for this type +//~^ ERROR the trait `Copy` cannot be implemented for this type struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); //~^ ERROR cannot find type `NotDefined` in this scope //~| ERROR cannot find type `NotDefined` in this scope @@ -7,7 +7,7 @@ struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); //~| ERROR cannot find type `N` in this scope #[derive(Clone, Copy)] -//~^ ERROR the trait `Copy` may not be implemented for this type +//~^ ERROR the trait `Copy` cannot be implemented for this type struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); //~^ ERROR cannot find type `NotDefined` in this scope //~| ERROR cannot find type `N` in this scope diff --git a/tests/ui/traits/issue-50480.stderr b/tests/ui/traits/issue-50480.stderr index 5063fdca0..4f72db60a 100644 --- a/tests/ui/traits/issue-50480.stderr +++ b/tests/ui/traits/issue-50480.stderr @@ -60,7 +60,7 @@ error[E0412]: cannot find type `NotDefined` in this scope LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); | ^^^^^^^^^^ not found in this scope -error[E0204]: the trait `Copy` may not be implemented for this type +error[E0204]: the trait `Copy` cannot be implemented for this type --> $DIR/issue-50480.rs:1:17 | LL | #[derive(Clone, Copy)] @@ -73,7 +73,7 @@ LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); | = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0204]: the trait `Copy` may not be implemented for this type +error[E0204]: the trait `Copy` cannot be implemented for this type --> $DIR/issue-50480.rs:9:17 | LL | #[derive(Clone, Copy)] diff --git a/tests/ui/traits/issue-71136.stderr b/tests/ui/traits/issue-71136.stderr index f54173392..ef5579618 100644 --- a/tests/ui/traits/issue-71136.stderr +++ b/tests/ui/traits/issue-71136.stderr @@ -11,7 +11,8 @@ LL | the_foos: Vec<Foo>, = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider annotating `Foo` with `#[derive(Clone)]` | -LL | #[derive(Clone)] +LL + #[derive(Clone)] +LL | struct Foo(u8); | error: aborting due to previous error diff --git a/tests/ui/traits/issue-78372.stderr b/tests/ui/traits/issue-78372.stderr index 8e7fd5f25..ec692ff91 100644 --- a/tests/ui/traits/issue-78372.stderr +++ b/tests/ui/traits/issue-78372.stderr @@ -6,7 +6,7 @@ LL | struct Smaht<T, MISC>(PhantomData); | help: consider importing this struct | -LL | use std::marker::PhantomData; +LL + use std::marker::PhantomData; | error[E0412]: cannot find type `U` in this scope diff --git a/tests/ui/traits/issue-87558.stderr b/tests/ui/traits/issue-87558.stderr index 494274d8c..b647f9794 100644 --- a/tests/ui/traits/issue-87558.stderr +++ b/tests/ui/traits/issue-87558.stderr @@ -17,6 +17,12 @@ error[E0229]: associated type bindings are not allowed here | LL | impl Fn(&isize) for Error { | ^^^^^^^^^^ associated type not allowed here + | +help: parenthesized trait syntax expands to `Fn<(&isize,), Output=()>` + --> $DIR/issue-87558.rs:3:6 + | +LL | impl Fn(&isize) for Error { + | ^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/tests/ui/traits/issue-91949-hangs-on-recursion.rs b/tests/ui/traits/issue-91949-hangs-on-recursion.rs index 6474b2b38..4eca643a9 100644 --- a/tests/ui/traits/issue-91949-hangs-on-recursion.rs +++ b/tests/ui/traits/issue-91949-hangs-on-recursion.rs @@ -1,6 +1,6 @@ // build-fail // compile-flags: -Zinline-mir=no -// error-pattern: overflow evaluating the requirement `(): Sized` +// error-pattern: overflow evaluating the requirement `<std::iter::Empty<()> as Iterator>::Item == ()` // error-pattern: function cannot return without recursing // normalize-stderr-test: "long-type-\d+" -> "long-type-hash" diff --git a/tests/ui/traits/issue-91949-hangs-on-recursion.stderr b/tests/ui/traits/issue-91949-hangs-on-recursion.stderr index 1f18c5daf..144990d50 100644 --- a/tests/ui/traits/issue-91949-hangs-on-recursion.stderr +++ b/tests/ui/traits/issue-91949-hangs-on-recursion.stderr @@ -12,11 +12,17 @@ LL | recurse(IteratorOfWrapped(elements).map(|t| t.0)) = help: a `loop` may express intention better if this is on purpose = note: `#[warn(unconditional_recursion)]` on by default -error[E0275]: overflow evaluating the requirement `(): Sized` +error[E0275]: overflow evaluating the requirement `<std::iter::Empty<()> as Iterator>::Item == ()` | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "512"]` attribute to your crate (`issue_91949_hangs_on_recursion`) - = note: required for `std::iter::Empty<()>` to implement `Iterator` - = note: 171 redundant requirements hidden +note: required for `IteratorOfWrapped<(), std::iter::Empty<()>>` to implement `Iterator` + --> $DIR/issue-91949-hangs-on-recursion.rs:16:32 + | +LL | impl<T, I: Iterator<Item = T>> Iterator for IteratorOfWrapped<T, I> { + | -------- ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ + | | + | unsatisfied trait bound introduced here + = note: 256 redundant requirements hidden = note: required for `IteratorOfWrapped<(), Map<IteratorOfWrapped<(), Map<IteratorOfWrapped<(), Map<..., ...>>, ...>>, ...>>` to implement `Iterator` = note: the full type name has been written to '$TEST_BUILD_DIR/traits/issue-91949-hangs-on-recursion/issue-91949-hangs-on-recursion.long-type-hash.txt' diff --git a/tests/ui/traits/item-privacy.stderr b/tests/ui/traits/item-privacy.stderr index 04995b3a1..f53813189 100644 --- a/tests/ui/traits/item-privacy.stderr +++ b/tests/ui/traits/item-privacy.stderr @@ -29,7 +29,7 @@ LL | S.b(); = help: items from traits can only be used if the trait is in scope help: the following trait is implemented but not in scope; perhaps add a `use` for it: | -LL | use method::B; +LL + use method::B; | error[E0624]: method `a` is private @@ -69,7 +69,7 @@ LL | S::b(&S); = help: items from traits can only be used if the trait is in scope help: the following trait is implemented but not in scope; perhaps add a `use` for it: | -LL | use method::B; +LL + use method::B; | error[E0624]: method `a` is private @@ -109,7 +109,7 @@ LL | S::B; = help: items from traits can only be used if the trait is in scope help: the following trait is implemented but not in scope; perhaps add a `use` for it: | -LL | use assoc_const::B; +LL + use assoc_const::B; | error[E0624]: associated constant `A` is private diff --git a/tests/ui/traits/method-private.stderr b/tests/ui/traits/method-private.stderr index 55656f21e..e11799308 100644 --- a/tests/ui/traits/method-private.stderr +++ b/tests/ui/traits/method-private.stderr @@ -10,7 +10,7 @@ LL | foo.method(); = help: items from traits can only be used if the trait is in scope help: the following trait is implemented but not in scope; perhaps add a `use` for it: | -LL | use inner::Bar; +LL + use inner::Bar; | error: aborting due to previous error diff --git a/tests/ui/traits/new-solver/alias-eq-in-canonical-response.rs b/tests/ui/traits/new-solver/alias-eq-in-canonical-response.rs new file mode 100644 index 000000000..4bfb6323a --- /dev/null +++ b/tests/ui/traits/new-solver/alias-eq-in-canonical-response.rs @@ -0,0 +1,40 @@ +// check-pass +// compile-flags: -Ztrait-solver=next + +trait Foo { + type Gat<'a> + where + Self: 'a; + fn bar(&self) -> Self::Gat<'_>; +} + +enum Option<T> { + Some(T), + None, +} + +impl<T> Option<T> { + fn as_ref(&self) -> Option<&T> { + match self { + Option::Some(t) => Option::Some(t), + Option::None => Option::None, + } + } + + fn map<U>(self, f: impl FnOnce(T) -> U) -> Option<U> { + match self { + Option::Some(t) => Option::Some(f(t)), + Option::None => Option::None, + } + } +} + +impl<T: Foo + 'static> Foo for Option<T> { + type Gat<'a> = Option<<T as Foo>::Gat<'a>> where Self: 'a; + + fn bar(&self) -> Self::Gat<'_> { + self.as_ref().map(Foo::bar) + } +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/alias-sub.rs b/tests/ui/traits/new-solver/alias-sub.rs new file mode 100644 index 000000000..30c1981a9 --- /dev/null +++ b/tests/ui/traits/new-solver/alias-sub.rs @@ -0,0 +1,34 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +trait Trait { + type Assoc: Sized; +} + +impl Trait for &'static str { + type Assoc = &'static str; +} + +// Wrapper is just here to get around stupid `Sized` obligations in mir typeck +struct Wrapper<T: ?Sized>(std::marker::PhantomData<T>); +fn mk<T: Trait>(x: T) -> Wrapper<<T as Trait>::Assoc> { todo!() } + + +trait IsStaticStr {} +impl IsStaticStr for (&'static str,) {} +fn define<T: IsStaticStr>(_: T) {} + +fn foo<'a, T: Trait>() { + let y = Default::default(); + + // `<?0 as Trait>::Assoc <: &'a str` + // In the old solver, this would *equate* the LHS and RHS. + let _: Wrapper<&'a str> = mk(y); + + // ... then later on, we constrain `?0 = &'static str` + // but that should not mean that `'a = 'static`, because + // we should use *sub* above. + define((y,)); +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.rs b/tests/ui/traits/new-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.rs index fd5d0e3b1..531203d9c 100644 --- a/tests/ui/traits/new-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.rs +++ b/tests/ui/traits/new-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.rs @@ -1,7 +1,7 @@ // compile-flags: -Ztrait-solver=next // check that when computing `alias-eq(<() as Foo<u16, T>>::Assoc, <() as Foo<?0, T>>::Assoc)` -// we do not infer `?0 = u8` via the `for<STOP> (): Foo<u8, STOP>` impl or `?0 = u16` by +// we do not infer `?0 = u8` via the `for<STOP> (): Foo<u8, STOP>` impl or `?0 = u16` by // relating substs as either could be a valid solution. trait Foo<T, STOP> { diff --git a/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.fail.stderr b/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.fail.stderr new file mode 100644 index 000000000..6a926534e --- /dev/null +++ b/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.fail.stderr @@ -0,0 +1,18 @@ +error[E0277]: `impl Future<Output = ()>` cannot be sent between threads safely + --> $DIR/auto-with-drop_tracking_mir.rs:24:13 + | +LL | is_send(foo()); + | ------- ^^^^^ `impl Future<Output = ()>` cannot be sent between threads safely + | | + | required by a bound introduced by this call + | + = help: the trait `Send` is not implemented for `impl Future<Output = ()>` +note: required by a bound in `is_send` + --> $DIR/auto-with-drop_tracking_mir.rs:23:24 + | +LL | fn is_send(_: impl Send) {} + | ^^^^ required by this bound in `is_send` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.rs b/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.rs new file mode 100644 index 000000000..a5db7c463 --- /dev/null +++ b/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.rs @@ -0,0 +1,26 @@ +// compile-flags: -Ztrait-solver=next -Zdrop-tracking-mir +// edition: 2021 +// revisions: pass fail +//[pass] check-pass + +#![feature(negative_impls)] + +struct NotSync; +impl !Sync for NotSync {} + +async fn foo() { + #[cfg(pass)] + let x = &(); + #[cfg(fail)] + let x = &NotSync; + bar().await; + drop(x); +} + +async fn bar() {} + +fn main() { + fn is_send(_: impl Send) {} + is_send(foo()); + //[fail]~^ ERROR `impl Future<Output = ()>` cannot be sent between threads safely +} diff --git a/tests/ui/traits/new-solver/canonical-int-var-eq-in-response.rs b/tests/ui/traits/new-solver/canonical-int-var-eq-in-response.rs new file mode 100644 index 000000000..4b013983a --- /dev/null +++ b/tests/ui/traits/new-solver/canonical-int-var-eq-in-response.rs @@ -0,0 +1,22 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +trait Mirror { + type Assoc; +} + +impl<T> Mirror for T { + type Assoc = T; +} + +trait Test {} +impl Test for i64 {} +impl Test for u64 {} + +fn mirror_me<T: Mirror>(t: T, s: <T as Mirror>::Assoc) where <T as Mirror>::Assoc: Test {} + +fn main() { + let mut x = 0; + mirror_me(x, 1); + x = 1i64; +} diff --git a/tests/ui/traits/new-solver/canonical-ty-var-eq-in-response.rs b/tests/ui/traits/new-solver/canonical-ty-var-eq-in-response.rs new file mode 100644 index 000000000..d1c6b1077 --- /dev/null +++ b/tests/ui/traits/new-solver/canonical-ty-var-eq-in-response.rs @@ -0,0 +1,39 @@ +// check-pass +// compile-flags: -Ztrait-solver=next + +trait Mirror { + type Item; +} + +struct Wrapper<T>(T); +impl<T> Mirror for Wrapper<T> { + type Item = T; +} + +fn mirror<T>() +where + Wrapper<T>: Mirror<Item = i32>, +{ +} + +fn main() { + mirror::<_ /* ?0 */>(); + + // Solving `<Wrapper<?0> as Mirror>::Item = i32` + + // First, we replace the term with a fresh infer var: + // `<Wrapper<?0> as Mirror>::Item = ?1` + + // We select the impl candidate on line #6, which leads us to learn that + // `?0 == ?1`. + + // That should be reflected in our canonical response, which should have + // `^0 = ^0, ^1 = ^0` + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + // !! We used to return a totally unconstrained response here :< !! + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + // Then, during the "equate term" part of the projection solving, we + // instantiate the response from the unconstrained projection predicate, + // and equate `?0 == i32`. +} diff --git a/tests/ui/typeck/lazy-norm/cast-checks-handling-projections.rs b/tests/ui/traits/new-solver/cast-checks-handling-projections.rs index 5ff567cd0..3b261062f 100644 --- a/tests/ui/typeck/lazy-norm/cast-checks-handling-projections.rs +++ b/tests/ui/traits/new-solver/cast-checks-handling-projections.rs @@ -1,5 +1,5 @@ // compile-flags: -Ztrait-solver=next -// known-bug: unknown +// check-pass fn main() { (0u8 + 0u8) as char; diff --git a/tests/ui/traits/new-solver/closure-inference-guidance.rs b/tests/ui/traits/new-solver/closure-inference-guidance.rs new file mode 100644 index 000000000..d2ad0cc03 --- /dev/null +++ b/tests/ui/traits/new-solver/closure-inference-guidance.rs @@ -0,0 +1,11 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +fn foo(i: isize) -> isize { i + 1 } + +fn apply<A, F>(f: F, v: A) -> A where F: FnOnce(A) -> A { f(v) } + +pub fn main() { + let f = |i| foo(i); + assert_eq!(apply(f, 2), 3); +} diff --git a/tests/ui/traits/new-solver/coherence/issue-102048.rs b/tests/ui/traits/new-solver/coherence/issue-102048.rs new file mode 100644 index 000000000..11636bfeb --- /dev/null +++ b/tests/ui/traits/new-solver/coherence/issue-102048.rs @@ -0,0 +1,44 @@ +// This must fail coherence. +// +// Getting this to pass was fairly difficult, so here's an explanation +// of what's happening: +// +// Normalizing projections currently tries to replace them with inference variables +// while emitting a nested `Projection` obligation. This cannot be done if the projection +// has bound variables which is the case here. +// +// So the projections stay until after normalization. When unifying two projections we +// currently treat them as if they are injective, so we **incorrectly** unify their +// substs. This means that coherence for the two impls ends up unifying `?T` and `?U` +// as it tries to unify `<?T as WithAssoc1<'a>>::Assoc` with `<?U as WithAssoc1<'a>>::Assoc`. +// +// `impl1` therefore has the projection `<?T as WithAssoc2<'a>>::Assoc` and we have the +// assumption `?T: for<'a> WithAssoc2<'a, Assoc = i32>` in the `param_env`, so we normalize +// that to `i32`. We then try to unify `i32` from `impl1` with `u32` from `impl2` which fails, +// causing coherence to consider these two impls distinct. + +// compile-flags: -Ztrait-solver=next +pub trait Trait<T> {} + +pub trait WithAssoc1<'a> { + type Assoc; +} +pub trait WithAssoc2<'a> { + type Assoc; +} + +// impl 1 +impl<T, U> Trait<for<'a> fn(<T as WithAssoc1<'a>>::Assoc, <U as WithAssoc2<'a>>::Assoc)> for (T, U) +where + T: for<'a> WithAssoc1<'a> + for<'a> WithAssoc2<'a, Assoc = i32>, + U: for<'a> WithAssoc2<'a>, +{ +} + +// impl 2 +impl<T, U> Trait<for<'a> fn(<U as WithAssoc1<'a>>::Assoc, u32)> for (T, U) where + U: for<'a> WithAssoc1<'a> //~^ ERROR conflicting implementations of trait +{ +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/coherence/issue-102048.stderr b/tests/ui/traits/new-solver/coherence/issue-102048.stderr new file mode 100644 index 000000000..17a43838f --- /dev/null +++ b/tests/ui/traits/new-solver/coherence/issue-102048.stderr @@ -0,0 +1,12 @@ +error[E0119]: conflicting implementations of trait `Trait<for<'a> fn(<_ as WithAssoc1<'a>>::Assoc, <_ as WithAssoc2<'a>>::Assoc)>` for type `(_, _)` + --> $DIR/issue-102048.rs:39:1 + | +LL | impl<T, U> Trait<for<'a> fn(<T as WithAssoc1<'a>>::Assoc, <U as WithAssoc2<'a>>::Assoc)> for (T, U) + | --------------------------------------------------------------------------------------------------- first implementation here +... +LL | impl<T, U> Trait<for<'a> fn(<U as WithAssoc1<'a>>::Assoc, u32)> for (T, U) where + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(_, _)` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/traits/new-solver/const-param-placeholder.fail.stderr b/tests/ui/traits/new-solver/const-param-placeholder.fail.stderr new file mode 100644 index 000000000..4db6e22e5 --- /dev/null +++ b/tests/ui/traits/new-solver/const-param-placeholder.fail.stderr @@ -0,0 +1,16 @@ +error[E0277]: the trait bound `[T; N]: Foo` is not satisfied + --> $DIR/const-param-placeholder.rs:17:17 + | +LL | needs_foo::<[T; N]>(); + | ^^^^^^ the trait `Foo` is not implemented for `[T; N]` + | + = help: the trait `Foo` is implemented for `[T; 1]` +note: required by a bound in `needs_foo` + --> $DIR/const-param-placeholder.rs:8:17 + | +LL | fn needs_foo<F: Foo>() {} + | ^^^ required by this bound in `needs_foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/new-solver/const-param-placeholder.rs b/tests/ui/traits/new-solver/const-param-placeholder.rs new file mode 100644 index 000000000..a83102a4c --- /dev/null +++ b/tests/ui/traits/new-solver/const-param-placeholder.rs @@ -0,0 +1,21 @@ +// compile-flags: -Ztrait-solver=next +// revisions: pass fail +//[pass] check-pass + +struct Wrapper<T, const N: usize>([T; N]); + +trait Foo {} +fn needs_foo<F: Foo>() {} + +#[cfg(fail)] +impl<T> Foo for [T; 1] {} + +#[cfg(pass)] +impl<T, const N: usize> Foo for [T; N] {} + +fn test<T, const N: usize>() { + needs_foo::<[T; N]>(); + //[fail]~^ ERROR the trait bound `[T; N]: Foo` is not satisfied +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/deduce-ty-from-object.rs b/tests/ui/traits/new-solver/deduce-ty-from-object.rs new file mode 100644 index 000000000..7398bce7b --- /dev/null +++ b/tests/ui/traits/new-solver/deduce-ty-from-object.rs @@ -0,0 +1,6 @@ +// check-pass +// compile-flags: -Ztrait-solver=next + +fn main() { + let x: Box<dyn Iterator<Item = ()>> = Box::new(std::iter::empty()); +} diff --git a/tests/ui/traits/new-solver/destruct.rs b/tests/ui/traits/new-solver/destruct.rs new file mode 100644 index 000000000..30d7777b7 --- /dev/null +++ b/tests/ui/traits/new-solver/destruct.rs @@ -0,0 +1,13 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +#![feature(const_trait_impl)] + +fn foo(_: impl std::marker::Destruct) {} + +struct MyAdt; + +fn main() { + foo(1); + foo(MyAdt); +} diff --git a/tests/ui/traits/new-solver/dont-elaborate-for-projections.rs b/tests/ui/traits/new-solver/dont-elaborate-for-projections.rs new file mode 100644 index 000000000..e60825006 --- /dev/null +++ b/tests/ui/traits/new-solver/dont-elaborate-for-projections.rs @@ -0,0 +1,12 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +trait Iter<'a, I: 'a>: Iterator<Item = &'a I> {} + +fn needs_iter<'a, T: Iter<'a, I> + ?Sized, I: 'a>(_: &T) {} + +fn test(x: &dyn Iter<'_, ()>) { + needs_iter(x); +} + +fn main() {} diff --git a/tests/ui/typeck/lazy-norm/equating-projection-cyclically.rs b/tests/ui/traits/new-solver/equating-projection-cyclically.rs index 019c6e81c..019c6e81c 100644 --- a/tests/ui/typeck/lazy-norm/equating-projection-cyclically.rs +++ b/tests/ui/traits/new-solver/equating-projection-cyclically.rs diff --git a/tests/ui/typeck/lazy-norm/equating-projection-cyclically.stderr b/tests/ui/traits/new-solver/equating-projection-cyclically.stderr index 57cbc65a1..57cbc65a1 100644 --- a/tests/ui/typeck/lazy-norm/equating-projection-cyclically.stderr +++ b/tests/ui/traits/new-solver/equating-projection-cyclically.stderr diff --git a/tests/ui/traits/new-solver/float-canonical.rs b/tests/ui/traits/new-solver/float-canonical.rs new file mode 100644 index 000000000..b8748cd43 --- /dev/null +++ b/tests/ui/traits/new-solver/float-canonical.rs @@ -0,0 +1,8 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +fn foo(x: f64) { + let y = x + 1.0; +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/fn-trait.rs b/tests/ui/traits/new-solver/fn-trait.rs index d566ead10..0599e51d7 100644 --- a/tests/ui/traits/new-solver/fn-trait.rs +++ b/tests/ui/traits/new-solver/fn-trait.rs @@ -1,5 +1,4 @@ // compile-flags: -Ztrait-solver=next -// check-pass fn require_fn(_: impl Fn() -> i32) {} @@ -7,7 +6,27 @@ fn f() -> i32 { 1i32 } +extern "C" fn g() -> i32 { + 2i32 +} + +unsafe fn h() -> i32 { + 2i32 +} + fn main() { require_fn(f); require_fn(f as fn() -> i32); + require_fn(f as unsafe fn() -> i32); + //~^ ERROR: expected a `Fn<()>` closure, found `unsafe fn() -> i32` + //~| ERROR: type mismatch resolving `<unsafe fn() -> i32 as FnOnce<()>>::Output == i32` + require_fn(g); + //~^ ERROR: expected a `Fn<()>` closure, found `extern "C" fn() -> i32 {g}` + //~| ERROR: type mismatch resolving `<extern "C" fn() -> i32 {g} as FnOnce<()>>::Output == i32` + require_fn(g as extern "C" fn() -> i32); + //~^ ERROR: expected a `Fn<()>` closure, found `extern "C" fn() -> i32` + //~| ERROR: type mismatch resolving `<extern "C" fn() -> i32 as FnOnce<()>>::Output == i32` + require_fn(h); + //~^ ERROR: expected a `Fn<()>` closure, found `unsafe fn() -> i32 {h}` + //~| ERROR: type mismatch resolving `<unsafe fn() -> i32 {h} as FnOnce<()>>::Output == i32` } diff --git a/tests/ui/traits/new-solver/fn-trait.stderr b/tests/ui/traits/new-solver/fn-trait.stderr new file mode 100644 index 000000000..d52bcaf25 --- /dev/null +++ b/tests/ui/traits/new-solver/fn-trait.stderr @@ -0,0 +1,124 @@ +error[E0277]: expected a `Fn<()>` closure, found `unsafe fn() -> i32` + --> $DIR/fn-trait.rs:20:16 + | +LL | require_fn(f as unsafe fn() -> i32); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` + | | + | required by a bound introduced by this call + | + = help: the trait `Fn<()>` is not implemented for `unsafe fn() -> i32` + = note: wrap the `unsafe fn() -> i32` in a closure with no arguments: `|| { /* code */ }` +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:23 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^^^^^^^^^ required by this bound in `require_fn` + +error[E0271]: type mismatch resolving `<unsafe fn() -> i32 as FnOnce<()>>::Output == i32` + --> $DIR/fn-trait.rs:20:16 + | +LL | require_fn(f as unsafe fn() -> i32); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^ types differ + | | + | required by a bound introduced by this call + | +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:31 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^ required by this bound in `require_fn` + +error[E0277]: expected a `Fn<()>` closure, found `extern "C" fn() -> i32 {g}` + --> $DIR/fn-trait.rs:23:16 + | +LL | require_fn(g); + | ---------- ^ expected an `Fn<()>` closure, found `extern "C" fn() -> i32 {g}` + | | + | required by a bound introduced by this call + | + = help: the trait `Fn<()>` is not implemented for fn item `extern "C" fn() -> i32 {g}` + = note: wrap the `extern "C" fn() -> i32 {g}` in a closure with no arguments: `|| { /* code */ }` +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:23 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^^^^^^^^^ required by this bound in `require_fn` + +error[E0271]: type mismatch resolving `<extern "C" fn() -> i32 {g} as FnOnce<()>>::Output == i32` + --> $DIR/fn-trait.rs:23:16 + | +LL | require_fn(g); + | ---------- ^ types differ + | | + | required by a bound introduced by this call + | +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:31 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^ required by this bound in `require_fn` + +error[E0277]: expected a `Fn<()>` closure, found `extern "C" fn() -> i32` + --> $DIR/fn-trait.rs:26:16 + | +LL | require_fn(g as extern "C" fn() -> i32); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `extern "C" fn() -> i32` + | | + | required by a bound introduced by this call + | + = help: the trait `Fn<()>` is not implemented for `extern "C" fn() -> i32` + = note: wrap the `extern "C" fn() -> i32` in a closure with no arguments: `|| { /* code */ }` +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:23 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^^^^^^^^^ required by this bound in `require_fn` + +error[E0271]: type mismatch resolving `<extern "C" fn() -> i32 as FnOnce<()>>::Output == i32` + --> $DIR/fn-trait.rs:26:16 + | +LL | require_fn(g as extern "C" fn() -> i32); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ + | | + | required by a bound introduced by this call + | +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:31 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^ required by this bound in `require_fn` + +error[E0277]: expected a `Fn<()>` closure, found `unsafe fn() -> i32 {h}` + --> $DIR/fn-trait.rs:29:16 + | +LL | require_fn(h); + | ---------- ^ call the function in a closure: `|| unsafe { /* code */ }` + | | + | required by a bound introduced by this call + | + = help: the trait `Fn<()>` is not implemented for fn item `unsafe fn() -> i32 {h}` + = note: wrap the `unsafe fn() -> i32 {h}` in a closure with no arguments: `|| { /* code */ }` +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:23 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^^^^^^^^^ required by this bound in `require_fn` + +error[E0271]: type mismatch resolving `<unsafe fn() -> i32 {h} as FnOnce<()>>::Output == i32` + --> $DIR/fn-trait.rs:29:16 + | +LL | require_fn(h); + | ---------- ^ types differ + | | + | required by a bound introduced by this call + | +note: required by a bound in `require_fn` + --> $DIR/fn-trait.rs:3:31 + | +LL | fn require_fn(_: impl Fn() -> i32) {} + | ^^^ required by this bound in `require_fn` + +error: aborting due to 8 previous errors + +Some errors have detailed explanations: E0271, E0277. +For more information about an error, try `rustc --explain E0271`. diff --git a/tests/ui/traits/new-solver/int-var-alias-eq.rs b/tests/ui/traits/new-solver/int-var-alias-eq.rs new file mode 100644 index 000000000..2da387db4 --- /dev/null +++ b/tests/ui/traits/new-solver/int-var-alias-eq.rs @@ -0,0 +1,18 @@ +// check-pass +// compile-flags: -Ztrait-solver=next + +// HIR typeck ends up equating `<_#0i as Add>::Output == _#0i`. +// Want to make sure that we emit an alias-eq goal for this, +// instead of treating it as a type error and bailing. + +fn test() { + // fallback + let x = 1 + 2; +} + +fn test2() -> u32 { + // expectation from return ty + 1 + 2 +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/int-var-is-send.rs b/tests/ui/traits/new-solver/int-var-is-send.rs new file mode 100644 index 000000000..083aa90e1 --- /dev/null +++ b/tests/ui/traits/new-solver/int-var-is-send.rs @@ -0,0 +1,8 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +fn needs_send(_: impl Send) {} + +fn main() { + needs_send(1); +} diff --git a/tests/ui/traits/new-solver/iter-filter-projection.rs b/tests/ui/traits/new-solver/iter-filter-projection.rs new file mode 100644 index 000000000..8fb62323a --- /dev/null +++ b/tests/ui/traits/new-solver/iter-filter-projection.rs @@ -0,0 +1,12 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +use std::{iter, slice}; + +struct Attr; + +fn test<'a, T: Iterator<Item = &'a Attr>>() {} + +fn main() { + test::<iter::Filter<slice::Iter<'_, Attr>, fn(&&Attr) -> bool>>(); +} diff --git a/tests/ui/traits/new-solver/lazy-nested-obligations-1.rs b/tests/ui/traits/new-solver/lazy-nested-obligations-1.rs new file mode 100644 index 000000000..af00cbb3b --- /dev/null +++ b/tests/ui/traits/new-solver/lazy-nested-obligations-1.rs @@ -0,0 +1,13 @@ +// check-pass +// compile-flags: -Ztrait-solver=next +// Issue 94358 + +fn foo<C>(_: C) +where + for <'a> &'a C: IntoIterator, + for <'a> <&'a C as IntoIterator>::IntoIter: ExactSizeIterator, +{} + +fn main() { + foo::<_>(vec![true, false]); +} diff --git a/tests/ui/traits/new-solver/lazy-nested-obligations-2.rs b/tests/ui/traits/new-solver/lazy-nested-obligations-2.rs new file mode 100644 index 000000000..32addd829 --- /dev/null +++ b/tests/ui/traits/new-solver/lazy-nested-obligations-2.rs @@ -0,0 +1,23 @@ +// check-pass +// compile-flags: -Ztrait-solver=next +// Issue 95863 + +pub trait With { + type F; +} + +impl With for i32 { + type F = fn(&str); +} + +fn f(_: &str) {} + +fn main() { + let _: V<i32> = V(f); + pub struct V<T: With>(<T as With>::F); + + pub enum E3<T: With> { + Var(<T as With>::F), + } + let _: E3<i32> = E3::Var(f); +} diff --git a/tests/ui/traits/new-solver/lazy-nested-obligations-3.rs b/tests/ui/traits/new-solver/lazy-nested-obligations-3.rs new file mode 100644 index 000000000..baf399572 --- /dev/null +++ b/tests/ui/traits/new-solver/lazy-nested-obligations-3.rs @@ -0,0 +1,38 @@ +// check-pass +// compile-flags: -Ztrait-solver=next +// Issue 96750 + +use std::marker::PhantomData; + +trait AsyncFn<Arg> { + type Output; +} +trait RequestFamily { + type Type<'a>; +} +trait Service {} + +struct MyFn; +impl AsyncFn<String> for MyFn { + type Output = (); +} + +impl RequestFamily for String { + type Type<'a> = String; +} + +struct ServiceFromAsyncFn<F, Req>(F, PhantomData<Req>); + +impl<F, Req, O> Service for ServiceFromAsyncFn<F, Req> +where + Req: RequestFamily, + F: AsyncFn<Req>, + F: for<'a> AsyncFn<Req::Type<'a>, Output = O>, +{ +} + +fn assert_service() -> impl Service { + ServiceFromAsyncFn(MyFn, PhantomData) +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/more-object-bound.rs b/tests/ui/traits/new-solver/more-object-bound.rs index 712759ef0..bb730b18e 100644 --- a/tests/ui/traits/new-solver/more-object-bound.rs +++ b/tests/ui/traits/new-solver/more-object-bound.rs @@ -10,7 +10,7 @@ trait Trait: SuperTrait<A = <Self as SuperTrait>::B> {} fn transmute<A, B>(x: A) -> B { foo::<A, B, dyn Trait<A = A, B = B>>(x) - //~^ ERROR type annotations needed: cannot satisfy `dyn Trait<A = A, B = B>: Trait` + //~^ ERROR the trait bound `dyn Trait<A = A, B = B>: Trait` is not satisfied } fn foo<A, B, T: ?Sized>(x: T::A) -> B diff --git a/tests/ui/traits/new-solver/more-object-bound.stderr b/tests/ui/traits/new-solver/more-object-bound.stderr index 208fdecb0..4554b8c74 100644 --- a/tests/ui/traits/new-solver/more-object-bound.stderr +++ b/tests/ui/traits/new-solver/more-object-bound.stderr @@ -1,10 +1,9 @@ -error[E0283]: type annotations needed: cannot satisfy `dyn Trait<A = A, B = B>: Trait` - --> $DIR/more-object-bound.rs:12:5 +error[E0277]: the trait bound `dyn Trait<A = A, B = B>: Trait` is not satisfied + --> $DIR/more-object-bound.rs:12:17 | LL | foo::<A, B, dyn Trait<A = A, B = B>>(x) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `dyn Trait<A = A, B = B>` | - = note: cannot satisfy `dyn Trait<A = A, B = B>: Trait` note: required by a bound in `foo` --> $DIR/more-object-bound.rs:18:8 | @@ -13,7 +12,11 @@ LL | fn foo<A, B, T: ?Sized>(x: T::A) -> B LL | where LL | T: Trait<B = B>, | ^^^^^^^^^^^^ required by this bound in `foo` +help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement + | +LL | fn transmute<A, B>(x: A) -> B where dyn Trait<A = A, B = B>: 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 E0277`. diff --git a/tests/ui/traits/new-solver/nested-obligations-with-bound-vars-gat.rs b/tests/ui/traits/new-solver/nested-obligations-with-bound-vars-gat.rs new file mode 100644 index 000000000..92bad9590 --- /dev/null +++ b/tests/ui/traits/new-solver/nested-obligations-with-bound-vars-gat.rs @@ -0,0 +1,43 @@ +// check-pass +// compile-flags: -Ztrait-solver=next +// Issue 96230 + +use std::fmt::Debug; + +trait Classic { + type Assoc; +} + +trait Gat { + type Assoc<'a>; +} + +struct Foo; + +impl Classic for Foo { + type Assoc = (); +} + +impl Gat for Foo { + type Assoc<'i> = (); +} + +fn classic_debug<T: Classic>(_: T) +where + T::Assoc: Debug, +{ +} + +fn gat_debug<T: Gat>(_: T) +where + for<'a> T::Assoc<'a>: Debug, +{ +} + +fn main() { + classic_debug::<Foo>(Foo); // fine + classic_debug(Foo); // fine + + gat_debug::<Foo>(Foo); // fine + gat_debug(Foo); // boom +} diff --git a/tests/ui/traits/new-solver/normalize-param-env-1.rs b/tests/ui/traits/new-solver/normalize-param-env-1.rs new file mode 100644 index 000000000..b02a5d623 --- /dev/null +++ b/tests/ui/traits/new-solver/normalize-param-env-1.rs @@ -0,0 +1,40 @@ +// check-pass +// compile-flags: -Ztrait-solver=next +// Issue 108933 + +trait Add<Rhs> { + type Sum; +} + +impl Add<()> for () { + type Sum = (); +} + +type Unit = <() as Add<()>>::Sum; + +trait Trait<C> { + type Output; +} + +fn f<T>() +where + T: Trait<()>, + <T as Trait<()>>::Output: Sized, +{ +} + +fn g<T>() +where + T: Trait<Unit>, + <T as Trait<()>>::Output: Sized, +{ +} + +fn h<T>() +where + T: Trait<()>, + <T as Trait<Unit>>::Output: Sized, +{ +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/normalize-param-env-2.rs b/tests/ui/traits/new-solver/normalize-param-env-2.rs new file mode 100644 index 000000000..7c2cebdd2 --- /dev/null +++ b/tests/ui/traits/new-solver/normalize-param-env-2.rs @@ -0,0 +1,26 @@ +// check-pass +// compile-flags: -Ztrait-solver=next +// Issue 92505 + +trait A<T> { + type I; + + fn f() + where + Self::I: A<T>, + { + } +} + +impl<T> A<T> for () { + type I = (); + + fn f() + where + Self::I: A<T>, + { + <() as A<T>>::f(); + } +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/normalize-param-env-3.rs b/tests/ui/traits/new-solver/normalize-param-env-3.rs new file mode 100644 index 000000000..ce2974b2a --- /dev/null +++ b/tests/ui/traits/new-solver/normalize-param-env-3.rs @@ -0,0 +1,32 @@ +// check-pass +// compile-flags: -Ztrait-solver=next +// Issue 100177 + +trait GenericTrait<T> {} + +trait Channel<I>: GenericTrait<Self::T> { + type T; +} + +trait Sender { + type Msg; + + fn send<C>() + where + C: Channel<Self::Msg>; +} + +impl<T> Sender for T { + type Msg = (); + + fn send<C>() + where + C: Channel<Self::Msg>, + { + } +} + +// This works +fn foo<I, C>(ch: C) where C: Channel<I> {} + +fn main() {} diff --git a/tests/ui/traits/new-solver/param-discr-kind.rs b/tests/ui/traits/new-solver/param-discr-kind.rs new file mode 100644 index 000000000..e319ddea1 --- /dev/null +++ b/tests/ui/traits/new-solver/param-discr-kind.rs @@ -0,0 +1,8 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +fn foo<T>(x: T) { + std::mem::discriminant(&x); +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/pointee.rs b/tests/ui/traits/new-solver/pointee.rs index fa6ee2e2d..93c0542ac 100644 --- a/tests/ui/traits/new-solver/pointee.rs +++ b/tests/ui/traits/new-solver/pointee.rs @@ -7,17 +7,15 @@ use std::ptr::{DynMetadata, Pointee}; trait Trait<U> {} struct MyDst<T: ?Sized>(T); -fn works<T>() { - let _: <T as Pointee>::Metadata = (); - let _: <[T] as Pointee>::Metadata = 1_usize; - let _: <str as Pointee>::Metadata = 1_usize; - let _: <dyn Trait<T> as Pointee>::Metadata = give::<DynMetadata<dyn Trait<T>>>(); - let _: <MyDst<T> as Pointee>::Metadata = (); - let _: <((((([u8],),),),),) as Pointee>::Metadata = 1_usize; -} +fn meta_is<T: Pointee<Metadata = U> + ?Sized, U>() {} -fn give<U>() -> U { - loop {} +fn works<T>() { + meta_is::<T, ()>(); + meta_is::<[T], usize>(); + meta_is::<str, usize>(); + meta_is::<dyn Trait<T>, DynMetadata<dyn Trait<T>>>(); + meta_is::<MyDst<T>, ()>(); + meta_is::<((((([u8],),),),),), usize>(); } fn main() {} diff --git a/tests/ui/traits/new-solver/pointer-like.rs b/tests/ui/traits/new-solver/pointer-like.rs index 3745a075e..986301769 100644 --- a/tests/ui/traits/new-solver/pointer-like.rs +++ b/tests/ui/traits/new-solver/pointer-like.rs @@ -9,6 +9,6 @@ fn require_(_: impl PointerLike) {} fn main() { require_(1usize); require_(1u16); - //~^ ERROR `u16` needs to have the same alignment and size as a pointer + //~^ ERROR `u16` needs to have the same ABI as a pointer require_(&1i16); } diff --git a/tests/ui/traits/new-solver/pointer-like.stderr b/tests/ui/traits/new-solver/pointer-like.stderr index f695e6418..215a81cc2 100644 --- a/tests/ui/traits/new-solver/pointer-like.stderr +++ b/tests/ui/traits/new-solver/pointer-like.stderr @@ -1,4 +1,4 @@ -error[E0277]: `u16` needs to have the same alignment and size as a pointer +error[E0277]: `u16` needs to have the same ABI as a pointer --> $DIR/pointer-like.rs:11:14 | LL | require_(1u16); diff --git a/tests/ui/traits/new-solver/prefer-candidate-no-constraints.rs b/tests/ui/traits/new-solver/prefer-candidate-no-constraints.rs new file mode 100644 index 000000000..6f8164f3a --- /dev/null +++ b/tests/ui/traits/new-solver/prefer-candidate-no-constraints.rs @@ -0,0 +1,22 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +trait Foo {} + +impl<T> Foo for T {} + +trait Bar {} + +struct Wrapper<'a, T>(&'a T); + +impl<'a, T> Bar for Wrapper<'a, T> where &'a T: Foo {} +// We need to satisfy `&'a T: Foo` when checking that this impl is WF +// that can either be satisfied via the param-env, or via an impl. +// +// When satisfied via the param-env, since each lifetime is canonicalized +// separately, we end up getting extra region constraints. +// +// However, when satisfied via the impl, there are no region constraints, +// and we can short-circuit a response with no external constraints. + +fn main() {} diff --git a/tests/ui/traits/new-solver/prefer-param-env-on-ambiguity.rs b/tests/ui/traits/new-solver/prefer-param-env-on-ambiguity.rs new file mode 100644 index 000000000..909b33ec3 --- /dev/null +++ b/tests/ui/traits/new-solver/prefer-param-env-on-ambiguity.rs @@ -0,0 +1,10 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +trait Foo<'a> {} +trait Bar<'a> {} + +impl<'a, T: Bar<'a>> Foo<'a> for T {} +impl<T> Bar<'static> for T {} + +fn main() {} diff --git a/tests/ui/traits/new-solver/projection-discr-kind.rs b/tests/ui/traits/new-solver/projection-discr-kind.rs new file mode 100644 index 000000000..20296b287 --- /dev/null +++ b/tests/ui/traits/new-solver/projection-discr-kind.rs @@ -0,0 +1,18 @@ +// compile-flags: -Ztrait-solver=next + +// Check that `<T::Assoc as DiscriminantKind>::Discriminant` doesn't normalize +// to itself and cause overflow/ambiguity. + +trait Foo { + type Assoc; +} + +trait Bar {} +fn needs_bar(_: impl Bar) {} + +fn foo<T: Foo>(x: T::Assoc) { + needs_bar(std::mem::discriminant(&x)); + //~^ ERROR the trait bound `Discriminant<<T as Foo>::Assoc>: Bar` is not satisfied +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/projection-discr-kind.stderr b/tests/ui/traits/new-solver/projection-discr-kind.stderr new file mode 100644 index 000000000..03e28f993 --- /dev/null +++ b/tests/ui/traits/new-solver/projection-discr-kind.stderr @@ -0,0 +1,17 @@ +error[E0277]: the trait bound `Discriminant<<T as Foo>::Assoc>: Bar` is not satisfied + --> $DIR/projection-discr-kind.rs:14:15 + | +LL | needs_bar(std::mem::discriminant(&x)); + | --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `Discriminant<<T as Foo>::Assoc>` + | | + | required by a bound introduced by this call + | +note: required by a bound in `needs_bar` + --> $DIR/projection-discr-kind.rs:11:22 + | +LL | fn needs_bar(_: impl Bar) {} + | ^^^ required by this bound in `needs_bar` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/new-solver/recursive-self-normalization-2.rs b/tests/ui/traits/new-solver/recursive-self-normalization-2.rs new file mode 100644 index 000000000..8c029f517 --- /dev/null +++ b/tests/ui/traits/new-solver/recursive-self-normalization-2.rs @@ -0,0 +1,19 @@ +// compile-flags: -Ztrait-solver=next + +trait Foo1 { + type Assoc1; +} + +trait Foo2 { + type Assoc2; +} + +trait Bar {} +fn needs_bar<S: Bar>() {} + +fn test<T: Foo1<Assoc1 = <T as Foo2>::Assoc2> + Foo2<Assoc2 = <T as Foo1>::Assoc1>>() { + needs_bar::<T::Assoc1>(); + //~^ ERROR overflow evaluating the requirement `<T as Foo1>::Assoc1: Bar` +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/recursive-self-normalization-2.stderr b/tests/ui/traits/new-solver/recursive-self-normalization-2.stderr new file mode 100644 index 000000000..139b0a456 --- /dev/null +++ b/tests/ui/traits/new-solver/recursive-self-normalization-2.stderr @@ -0,0 +1,16 @@ +error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1: Bar` + --> $DIR/recursive-self-normalization-2.rs:15:5 + | +LL | needs_bar::<T::Assoc1>(); + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization_2`) +note: required by a bound in `needs_bar` + --> $DIR/recursive-self-normalization-2.rs:12:17 + | +LL | fn needs_bar<S: Bar>() {} + | ^^^ required by this bound in `needs_bar` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/new-solver/recursive-self-normalization.rs b/tests/ui/traits/new-solver/recursive-self-normalization.rs new file mode 100644 index 000000000..06d187b5f --- /dev/null +++ b/tests/ui/traits/new-solver/recursive-self-normalization.rs @@ -0,0 +1,15 @@ +// compile-flags: -Ztrait-solver=next + +trait Foo { + type Assoc; +} + +trait Bar {} +fn needs_bar<S: Bar>() {} + +fn test<T: Foo<Assoc = <T as Foo>::Assoc>>() { + needs_bar::<T::Assoc>(); + //~^ ERROR overflow evaluating the requirement `<T as Foo>::Assoc: Bar` +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/recursive-self-normalization.stderr b/tests/ui/traits/new-solver/recursive-self-normalization.stderr new file mode 100644 index 000000000..8e9b9b4b4 --- /dev/null +++ b/tests/ui/traits/new-solver/recursive-self-normalization.stderr @@ -0,0 +1,16 @@ +error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc: Bar` + --> $DIR/recursive-self-normalization.rs:11:5 + | +LL | needs_bar::<T::Assoc>(); + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization`) +note: required by a bound in `needs_bar` + --> $DIR/recursive-self-normalization.rs:8:17 + | +LL | fn needs_bar<S: Bar>() {} + | ^^^ required by this bound in `needs_bar` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/new-solver/runaway-impl-candidate-selection.rs b/tests/ui/traits/new-solver/runaway-impl-candidate-selection.rs new file mode 100644 index 000000000..1dca86d36 --- /dev/null +++ b/tests/ui/traits/new-solver/runaway-impl-candidate-selection.rs @@ -0,0 +1,15 @@ +// compile-flags: -Ztrait-solver=next + +// In the new solver, we are trying to select `<?0 as Iterator>::Item: Debug`, +// which, naively can be unified with every impl of `Debug` if we're not careful. +// This test makes sure that we treat projections with inference var substs as +// placeholders during fast reject. + +fn iter<T: Iterator>() -> <T as Iterator>::Item { + todo!() +} + +fn main() { + println!("{:?}", iter::<_>()); + //~^ ERROR type annotations needed +} diff --git a/tests/ui/traits/new-solver/runaway-impl-candidate-selection.stderr b/tests/ui/traits/new-solver/runaway-impl-candidate-selection.stderr new file mode 100644 index 000000000..47004821a --- /dev/null +++ b/tests/ui/traits/new-solver/runaway-impl-candidate-selection.stderr @@ -0,0 +1,9 @@ +error[E0282]: type annotations needed + --> $DIR/runaway-impl-candidate-selection.rs:13:22 + | +LL | println!("{:?}", iter::<_>()); + | ^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `iter` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/traits/new-solver/specialization-transmute.rs b/tests/ui/traits/new-solver/specialization-transmute.rs new file mode 100644 index 000000000..a54701df4 --- /dev/null +++ b/tests/ui/traits/new-solver/specialization-transmute.rs @@ -0,0 +1,30 @@ +// compile-flags: -Ztrait-solver=next + +#![feature(specialization)] +//~^ WARN the feature `specialization` is incomplete + +trait Default { + type Id; + + fn intu(&self) -> &Self::Id; +} + +impl<T> Default for T { + default type Id = T; + + fn intu(&self) -> &Self::Id { + self + //~^ ERROR cannot satisfy `T <: <T as Default>::Id` + } +} + +fn transmute<T: Default<Id = U>, U: Copy>(t: T) -> U { + *t.intu() +} + +use std::num::NonZeroU8; +fn main() { + let s = transmute::<u8, Option<NonZeroU8>>(0); + //~^ ERROR cannot satisfy `<u8 as Default>::Id == Option<NonZeroU8> + assert_eq!(s, None); +} diff --git a/tests/ui/traits/new-solver/specialization-transmute.stderr b/tests/ui/traits/new-solver/specialization-transmute.stderr new file mode 100644 index 000000000..e67c56afc --- /dev/null +++ b/tests/ui/traits/new-solver/specialization-transmute.stderr @@ -0,0 +1,31 @@ +warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/specialization-transmute.rs:3:12 + | +LL | #![feature(specialization)] + | ^^^^^^^^^^^^^^ + | + = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information + = help: consider using `min_specialization` instead, which is more stable and complete + = note: `#[warn(incomplete_features)]` on by default + +error[E0284]: type annotations needed: cannot satisfy `T <: <T as Default>::Id` + --> $DIR/specialization-transmute.rs:16:9 + | +LL | self + | ^^^^ cannot satisfy `T <: <T as Default>::Id` + +error[E0284]: type annotations needed: cannot satisfy `<u8 as Default>::Id == Option<NonZeroU8>` + --> $DIR/specialization-transmute.rs:27:13 + | +LL | let s = transmute::<u8, Option<NonZeroU8>>(0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `<u8 as Default>::Id == Option<NonZeroU8>` + | +note: required by a bound in `transmute` + --> $DIR/specialization-transmute.rs:21:25 + | +LL | fn transmute<T: Default<Id = U>, U: Copy>(t: T) -> U { + | ^^^^^^ required by this bound in `transmute` + +error: aborting due to 2 previous errors; 1 warning emitted + +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/traits/new-solver/specialization-unconstrained.rs b/tests/ui/traits/new-solver/specialization-unconstrained.rs new file mode 100644 index 000000000..02150689e --- /dev/null +++ b/tests/ui/traits/new-solver/specialization-unconstrained.rs @@ -0,0 +1,22 @@ +// compile-flags: -Ztrait-solver=next + +#![feature(specialization)] +//~^ WARN the feature `specialization` is incomplete + +// Do not treat the RHS of a projection-goal as an unconstrained `Certainty::Yes` response +// if the impl is still further specializable. + +trait Default { + type Id; +} + +impl<T> Default for T { + default type Id = T; +} + +fn test<T: Default<Id = U>, U>() {} + +fn main() { + test::<u32, ()>(); + //~^ ERROR cannot satisfy `<u32 as Default>::Id == ()` +} diff --git a/tests/ui/traits/new-solver/specialization-unconstrained.stderr b/tests/ui/traits/new-solver/specialization-unconstrained.stderr new file mode 100644 index 000000000..910925cba --- /dev/null +++ b/tests/ui/traits/new-solver/specialization-unconstrained.stderr @@ -0,0 +1,25 @@ +warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/specialization-unconstrained.rs:3:12 + | +LL | #![feature(specialization)] + | ^^^^^^^^^^^^^^ + | + = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information + = help: consider using `min_specialization` instead, which is more stable and complete + = note: `#[warn(incomplete_features)]` on by default + +error[E0284]: type annotations needed: cannot satisfy `<u32 as Default>::Id == ()` + --> $DIR/specialization-unconstrained.rs:20:5 + | +LL | test::<u32, ()>(); + | ^^^^^^^^^^^^^^^ cannot satisfy `<u32 as Default>::Id == ()` + | +note: required by a bound in `test` + --> $DIR/specialization-unconstrained.rs:17:20 + | +LL | fn test<T: Default<Id = U>, U>() {} + | ^^^^^^ required by this bound in `test` + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/traits/new-solver/stall-num-var-auto-trait.fallback.stderr b/tests/ui/traits/new-solver/stall-num-var-auto-trait.fallback.stderr new file mode 100644 index 000000000..a3ab7836c --- /dev/null +++ b/tests/ui/traits/new-solver/stall-num-var-auto-trait.fallback.stderr @@ -0,0 +1,17 @@ +error[E0277]: the trait bound `i32: Foo` is not satisfied + --> $DIR/stall-num-var-auto-trait.rs:18:15 + | +LL | needs_foo(x); + | --------- ^ the trait `Foo` is not implemented for `i32` + | | + | required by a bound introduced by this call + | +note: required by a bound in `needs_foo` + --> $DIR/stall-num-var-auto-trait.rs:14:22 + | +LL | fn needs_foo(x: impl Foo) {} + | ^^^ required by this bound in `needs_foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/new-solver/stall-num-var-auto-trait.rs b/tests/ui/traits/new-solver/stall-num-var-auto-trait.rs new file mode 100644 index 000000000..0539c3a42 --- /dev/null +++ b/tests/ui/traits/new-solver/stall-num-var-auto-trait.rs @@ -0,0 +1,25 @@ +// compile-flags: -Ztrait-solver=next +// revisions: fallback constrain +//[constrain] check-pass + +// Tests that we stall the `{integer}: Foo` obligation until after we +// constrain the int type (or fallback occurs). + +#![feature(negative_impls, auto_traits)] + +auto trait Foo {} + +impl !Foo for i32 {} + +fn needs_foo(x: impl Foo) {} + +fn main() { + let mut x = 0; + needs_foo(x); + //[fallback]~^ ERROR the trait bound `i32: Foo` is not satisfied + + #[cfg(constrain)] + { + x = 1u64; + } +} diff --git a/tests/ui/traits/non_lifetime_binders/bad-copy-cond.rs b/tests/ui/traits/non_lifetime_binders/bad-copy-cond.rs new file mode 100644 index 000000000..506cad25f --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/bad-copy-cond.rs @@ -0,0 +1,9 @@ +#![feature(non_lifetime_binders)] +//~^ WARN the feature `non_lifetime_binders` is incomplete + +fn foo() where for<T> T: Copy {} + +fn main() { + foo(); + //~^ ERROR the trait bound `T: Copy` is not satisfied +} diff --git a/tests/ui/traits/non_lifetime_binders/bad-copy-cond.stderr b/tests/ui/traits/non_lifetime_binders/bad-copy-cond.stderr new file mode 100644 index 000000000..07e02d47f --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/bad-copy-cond.stderr @@ -0,0 +1,24 @@ +warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/bad-copy-cond.rs:1:12 + | +LL | #![feature(non_lifetime_binders)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information + = note: `#[warn(incomplete_features)]` on by default + +error[E0277]: the trait bound `T: Copy` is not satisfied + --> $DIR/bad-copy-cond.rs:7:5 + | +LL | foo(); + | ^^^ the trait `Copy` is not implemented for `T` + | +note: required by a bound in `foo` + --> $DIR/bad-copy-cond.rs:4:26 + | +LL | fn foo() where for<T> T: Copy {} + | ^^^^ required by this bound in `foo` + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/non_lifetime_binders/capture-late-ct-in-anon.rs b/tests/ui/traits/non_lifetime_binders/capture-late-ct-in-anon.rs new file mode 100644 index 000000000..91c6dfb8e --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/capture-late-ct-in-anon.rs @@ -0,0 +1,11 @@ +#![feature(non_lifetime_binders)] +//~^ WARN the feature `non_lifetime_binders` is incomplete + +fn b() +where + for<const C: usize> [(); C]: Copy, + //~^ ERROR cannot capture late-bound const parameter in a constant +{ +} + +fn main() {} diff --git a/tests/ui/traits/non_lifetime_binders/capture-late-ct-in-anon.stderr b/tests/ui/traits/non_lifetime_binders/capture-late-ct-in-anon.stderr new file mode 100644 index 000000000..69bb605bf --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/capture-late-ct-in-anon.stderr @@ -0,0 +1,19 @@ +warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/capture-late-ct-in-anon.rs:1:12 + | +LL | #![feature(non_lifetime_binders)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information + = note: `#[warn(incomplete_features)]` on by default + +error: cannot capture late-bound const parameter in a constant + --> $DIR/capture-late-ct-in-anon.rs:6:30 + | +LL | for<const C: usize> [(); C]: Copy, + | -------------- ^ + | | + | parameter defined here + +error: aborting due to previous error; 1 warning emitted + diff --git a/tests/ui/traits/non_lifetime_binders/method-probe.rs b/tests/ui/traits/non_lifetime_binders/method-probe.rs new file mode 100644 index 000000000..8df240c20 --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/method-probe.rs @@ -0,0 +1,16 @@ +// check-pass + +#![feature(non_lifetime_binders)] +//~^ WARN the feature `non_lifetime_binders` is incomplete + +trait Foo: for<T> Bar<T> {} + +trait Bar<T> { + fn method() -> T; +} + +fn x<T: Foo>() { + let _: i32 = T::method(); +} + +fn main() {} diff --git a/tests/ui/traits/non_lifetime_binders/method-probe.stderr b/tests/ui/traits/non_lifetime_binders/method-probe.stderr new file mode 100644 index 000000000..8f61792e6 --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/method-probe.stderr @@ -0,0 +1,11 @@ +warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/method-probe.rs:3:12 + | +LL | #![feature(non_lifetime_binders)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/traits/non_lifetime_binders/missing-assoc-item.rs b/tests/ui/traits/non_lifetime_binders/missing-assoc-item.rs new file mode 100644 index 000000000..50f0152e9 --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/missing-assoc-item.rs @@ -0,0 +1,11 @@ +#![feature(non_lifetime_binders)] +//~^ WARN the feature `non_lifetime_binders` is incomplete + +fn f() +where + for<B> B::Item: Send, + //~^ ERROR ambiguous associated type +{ +} + +fn main() {} diff --git a/tests/ui/traits/non_lifetime_binders/missing-assoc-item.stderr b/tests/ui/traits/non_lifetime_binders/missing-assoc-item.stderr new file mode 100644 index 000000000..d98538642 --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/missing-assoc-item.stderr @@ -0,0 +1,23 @@ +warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/missing-assoc-item.rs:1:12 + | +LL | #![feature(non_lifetime_binders)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information + = note: `#[warn(incomplete_features)]` on by default + +error[E0223]: ambiguous associated type + --> $DIR/missing-assoc-item.rs:6:12 + | +LL | for<B> B::Item: Send, + | ^^^^^^^ + | +help: if there were a trait named `Example` with associated type `Item` implemented for `B`, you could use the fully-qualified path + | +LL | for<B> <B as Example>::Item: Send, + | ~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0223`. diff --git a/tests/ui/traits/non_lifetime_binders/supertrait-object-safety.rs b/tests/ui/traits/non_lifetime_binders/supertrait-object-safety.rs new file mode 100644 index 000000000..a635edb44 --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/supertrait-object-safety.rs @@ -0,0 +1,24 @@ +#![feature(non_lifetime_binders)] +//~^ WARN the feature `non_lifetime_binders` is incomplete + +trait Foo: for<T> Bar<T> {} + +trait Bar<T: ?Sized> { + fn method(&self) {} +} + +fn needs_bar(x: &(impl Bar<i32> + ?Sized)) { + x.method(); +} + +impl Foo for () {} + +impl<T: ?Sized> Bar<T> for () {} + +fn main() { + let x: &dyn Foo = &(); + //~^ ERROR the trait `Foo` cannot be made into an object + //~| ERROR the trait `Foo` cannot be made into an object + needs_bar(x); + //~^ ERROR the trait `Foo` cannot be made into an object +} diff --git a/tests/ui/traits/non_lifetime_binders/supertrait-object-safety.stderr b/tests/ui/traits/non_lifetime_binders/supertrait-object-safety.stderr new file mode 100644 index 000000000..47fa29b66 --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/supertrait-object-safety.stderr @@ -0,0 +1,56 @@ +warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/supertrait-object-safety.rs:1:12 + | +LL | #![feature(non_lifetime_binders)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information + = note: `#[warn(incomplete_features)]` on by default + +error[E0038]: the trait `Foo` cannot be made into an object + --> $DIR/supertrait-object-safety.rs:19:23 + | +LL | let x: &dyn Foo = &(); + | ^^^ `Foo` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> + --> $DIR/supertrait-object-safety.rs:4:12 + | +LL | trait Foo: for<T> Bar<T> {} + | --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables + | | + | this trait cannot be made into an object... + = note: required for `&()` to implement `CoerceUnsized<&dyn Foo>` + = note: required by cast to type `&dyn Foo` + +error[E0038]: the trait `Foo` cannot be made into an object + --> $DIR/supertrait-object-safety.rs:19:12 + | +LL | let x: &dyn Foo = &(); + | ^^^^^^^^ `Foo` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> + --> $DIR/supertrait-object-safety.rs:4:12 + | +LL | trait Foo: for<T> Bar<T> {} + | --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables + | | + | this trait cannot be made into an object... + +error[E0038]: the trait `Foo` cannot be made into an object + --> $DIR/supertrait-object-safety.rs:22:5 + | +LL | needs_bar(x); + | ^^^^^^^^^ `Foo` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> + --> $DIR/supertrait-object-safety.rs:4:12 + | +LL | trait Foo: for<T> Bar<T> {} + | --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables + | | + | this trait cannot be made into an object... + +error: aborting due to 3 previous errors; 1 warning emitted + +For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/traits/reservation-impl/coherence-conflict.next.stderr b/tests/ui/traits/reservation-impl/coherence-conflict.next.stderr new file mode 100644 index 000000000..e5a3c3f5c --- /dev/null +++ b/tests/ui/traits/reservation-impl/coherence-conflict.next.stderr @@ -0,0 +1,11 @@ +error[E0119]: conflicting implementations of trait `OtherTrait` for type `()` + --> $DIR/coherence-conflict.rs:12:1 + | +LL | impl OtherTrait for () {} + | ---------------------- first implementation here +LL | impl<T: MyTrait> OtherTrait for T {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/traits/reservation-impl/coherence-conflict.stderr b/tests/ui/traits/reservation-impl/coherence-conflict.old.stderr index a811d7e32..393350ea3 100644 --- a/tests/ui/traits/reservation-impl/coherence-conflict.stderr +++ b/tests/ui/traits/reservation-impl/coherence-conflict.old.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `OtherTrait` for type `()` - --> $DIR/coherence-conflict.rs:11:1 + --> $DIR/coherence-conflict.rs:12:1 | LL | impl OtherTrait for () {} | ---------------------- first implementation here diff --git a/tests/ui/traits/reservation-impl/coherence-conflict.rs b/tests/ui/traits/reservation-impl/coherence-conflict.rs index fa4a30931..6bbd90f94 100644 --- a/tests/ui/traits/reservation-impl/coherence-conflict.rs +++ b/tests/ui/traits/reservation-impl/coherence-conflict.rs @@ -1,5 +1,6 @@ // check that reservation impls are accounted for in negative reasoning. - +// revisions: old next +//[next] compile-flags: -Ztrait-solver=next #![feature(rustc_attrs)] trait MyTrait {} diff --git a/tests/ui/traits/reservation-impl/no-use.stderr b/tests/ui/traits/reservation-impl/no-use.next.stderr index cefb2a879..542e3a28a 100644 --- a/tests/ui/traits/reservation-impl/no-use.stderr +++ b/tests/ui/traits/reservation-impl/no-use.next.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `(): MyTrait` is not satisfied - --> $DIR/no-use.rs:10:26 + --> $DIR/no-use.rs:11:26 | LL | <() as MyTrait>::foo(&()); | -------------------- ^^^ the trait `MyTrait` is not implemented for `()` diff --git a/tests/ui/traits/reservation-impl/no-use.old.stderr b/tests/ui/traits/reservation-impl/no-use.old.stderr new file mode 100644 index 000000000..542e3a28a --- /dev/null +++ b/tests/ui/traits/reservation-impl/no-use.old.stderr @@ -0,0 +1,13 @@ +error[E0277]: the trait bound `(): MyTrait` is not satisfied + --> $DIR/no-use.rs:11:26 + | +LL | <() as MyTrait>::foo(&()); + | -------------------- ^^^ the trait `MyTrait` is not implemented for `()` + | | + | required by a bound introduced by this call + | + = help: the trait `MyTrait` is implemented for `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/reservation-impl/no-use.rs b/tests/ui/traits/reservation-impl/no-use.rs index 65a55d9e2..864f1791f 100644 --- a/tests/ui/traits/reservation-impl/no-use.rs +++ b/tests/ui/traits/reservation-impl/no-use.rs @@ -1,5 +1,6 @@ // check that reservation impls can't be used as normal impls in positive reasoning. - +// revisions: old next +//[next] compile-flags: -Ztrait-solver=next #![feature(rustc_attrs)] trait MyTrait { fn foo(&self); } diff --git a/tests/ui/traits/reservation-impl/non-lattice-ok.rs b/tests/ui/traits/reservation-impl/non-lattice-ok.rs index a71051243..7787904d9 100644 --- a/tests/ui/traits/reservation-impl/non-lattice-ok.rs +++ b/tests/ui/traits/reservation-impl/non-lattice-ok.rs @@ -30,6 +30,12 @@ // // [ii]: https://smallcultfollowing.com/babysteps/blog/2016/09/24/intersection-impls/ + +// check that reservation impls can't be used as normal impls in positive reasoning. + +// revisions: old next +//[next] compile-flags: -Ztrait-solver=next + #![feature(rustc_attrs, never_type)] trait MyTrait {} diff --git a/tests/ui/traits/reservation-impl/ok.rs b/tests/ui/traits/reservation-impl/ok.rs index 611c8d884..8ff6645a2 100644 --- a/tests/ui/traits/reservation-impl/ok.rs +++ b/tests/ui/traits/reservation-impl/ok.rs @@ -3,6 +3,9 @@ // rpass test for reservation impls. Not 100% required because `From` uses them, // but still. +// revisions: old next +//[next] compile-flags: -Ztrait-solver=next + #![feature(rustc_attrs)] use std::mem; diff --git a/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.rs b/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.rs new file mode 100644 index 000000000..d37943b92 --- /dev/null +++ b/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.rs @@ -0,0 +1,34 @@ +//~ ERROR overflow +// A regression test for #111729 checking that we correctly +// track recursion depth for obligations returned by confirmation. +use std::panic::RefUnwindSafe; + +trait Database { + type Storage; +} +trait Query<DB> { + type Data; +} +struct ParseQuery; +struct RootDatabase { + _runtime: Runtime<RootDatabase>, +} + +impl<T: RefUnwindSafe> Database for T { + type Storage = SalsaStorage; +} +impl Database for RootDatabase { + type Storage = SalsaStorage; +} + +struct Runtime<DB: Database> { + _storage: Box<DB::Storage>, +} +struct SalsaStorage { + _parse: <ParseQuery as Query<RootDatabase>>::Data, +} + +impl<DB: Database> Query<DB> for ParseQuery { + type Data = RootDatabase; +} +fn main() {} diff --git a/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.stderr b/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.stderr new file mode 100644 index 000000000..8f9ce3ef1 --- /dev/null +++ b/tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.stderr @@ -0,0 +1,24 @@ +error[E0275]: overflow evaluating the requirement `Runtime<RootDatabase>: RefUnwindSafe` + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`cycle_via_builtin_auto_trait_impl`) +note: required because it appears within the type `RootDatabase` + --> $DIR/cycle-via-builtin-auto-trait-impl.rs:13:8 + | +LL | struct RootDatabase { + | ^^^^^^^^^^^^ +note: required for `RootDatabase` to implement `Database` + --> $DIR/cycle-via-builtin-auto-trait-impl.rs:17:24 + | +LL | impl<T: RefUnwindSafe> Database for T { + | ------------- ^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here +note: required because it appears within the type `Runtime<RootDatabase>` + --> $DIR/cycle-via-builtin-auto-trait-impl.rs:24:8 + | +LL | struct Runtime<DB: Database> { + | ^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.rs b/tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.rs new file mode 100644 index 000000000..4a5e445d1 --- /dev/null +++ b/tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.rs @@ -0,0 +1,33 @@ +#![feature(trait_upcasting)] +#![feature(trait_alias)] + +// Although we *elaborate* `T: Alias` to `i32: B`, we should +// not consider `B` to be a supertrait of the type. +trait Alias = A where i32: B; + +trait A {} + +trait B { + fn test(&self); +} + +trait C: Alias {} + +impl A for () {} + +impl C for () {} + +impl B for i32 { + fn test(&self) { + println!("hi {self}"); + } +} + +fn test(x: &dyn C) -> &dyn B { + x + //~^ ERROR mismatched types +} + +fn main() { + let x: &dyn C = &(); +} diff --git a/tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.stderr b/tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.stderr new file mode 100644 index 000000000..5574a0320 --- /dev/null +++ b/tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/alias-where-clause-isnt-supertrait.rs:27:5 + | +LL | fn test(x: &dyn C) -> &dyn B { + | ------ expected `&dyn B` because of return type +LL | x + | ^ expected trait `B`, found trait `C` + | + = note: expected reference `&dyn B` + found reference `&dyn C` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr b/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr index 15faab16a..ca98e1831 100644 --- a/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr +++ b/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr @@ -1,15 +1,10 @@ error[E0391]: cycle detected when computing the super predicates of `A` - --> $DIR/cyclic-trait-resolution.rs:1:1 - | -LL | trait A: B + A {} - | ^^^^^^^^^^^^^^ - | -note: ...which requires computing the super traits of `A`... --> $DIR/cyclic-trait-resolution.rs:1:14 | LL | trait A: B + A {} | ^ - = note: ...which again requires computing the super predicates of `A`, completing the cycle + | + = note: ...which immediately requires computing the super predicates of `A` again note: cycle used when collecting item types in top-level module --> $DIR/cyclic-trait-resolution.rs:1:1 | diff --git a/tests/ui/wrong-mul-method-signature.rs b/tests/ui/traits/wrong-mul-method-signature.rs index 1c2f86559..1c2f86559 100644 --- a/tests/ui/wrong-mul-method-signature.rs +++ b/tests/ui/traits/wrong-mul-method-signature.rs diff --git a/tests/ui/wrong-mul-method-signature.stderr b/tests/ui/traits/wrong-mul-method-signature.stderr index 25a92f5ec..25a92f5ec 100644 --- a/tests/ui/wrong-mul-method-signature.stderr +++ b/tests/ui/traits/wrong-mul-method-signature.stderr |