diff options
Diffstat (limited to '')
39 files changed, 530 insertions, 77 deletions
diff --git a/tests/ui/traits/new-solver/alias-bound-unsound.rs b/tests/ui/traits/new-solver/alias-bound-unsound.rs index 00294c708..959f1afa0 100644 --- a/tests/ui/traits/new-solver/alias-bound-unsound.rs +++ b/tests/ui/traits/new-solver/alias-bound-unsound.rs @@ -21,7 +21,7 @@ impl Foo for () { fn main() { let x = String::from("hello, world"); drop(<() as Foo>::copy_me(&x)); - //~^ ERROR `<() as Foo>::Item: Copy` is not satisfied + //~^ ERROR the type `&<() as Foo>::Item` is not well-formed //~| ERROR `<() as Foo>::Item` is not well-formed println!("{x}"); } diff --git a/tests/ui/traits/new-solver/alias-bound-unsound.stderr b/tests/ui/traits/new-solver/alias-bound-unsound.stderr index 9a43d2a66..5800e2c43 100644 --- a/tests/ui/traits/new-solver/alias-bound-unsound.stderr +++ b/tests/ui/traits/new-solver/alias-bound-unsound.stderr @@ -1,17 +1,8 @@ -error[E0277]: the trait bound `<() as Foo>::Item: Copy` is not satisfied - --> $DIR/alias-bound-unsound.rs:23:10 +error: the type `&<() as Foo>::Item` is not well-formed + --> $DIR/alias-bound-unsound.rs:23:31 | LL | drop(<() as Foo>::copy_me(&x)); - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `<() as Foo>::Item` - | -note: required by a bound in `Foo::Item` - --> $DIR/alias-bound-unsound.rs:10:30 - | -LL | type Item: Copy - | ---- required by a bound in this associated type -LL | where -LL | <Self as Foo>::Item: Copy; - | ^^^^ required by this bound in `Foo::Item` + | ^^ error: the type `<() as Foo>::Item` is not well-formed --> $DIR/alias-bound-unsound.rs:23:10 @@ -21,4 +12,3 @@ LL | drop(<() as Foo>::copy_me(&x)); error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/new-solver/alias_eq_substs_eq_not_intercrate.rs b/tests/ui/traits/new-solver/alias_eq_substs_eq_not_intercrate.rs index b036411be..204f6e8b0 100644 --- a/tests/ui/traits/new-solver/alias_eq_substs_eq_not_intercrate.rs +++ b/tests/ui/traits/new-solver/alias_eq_substs_eq_not_intercrate.rs @@ -1,22 +1,17 @@ // compile-flags: -Ztrait-solver=next -// check-pass -// (should not pass, should be turned into a coherence-only test) - -// check that a `alias-eq(<?0 as TraitB>::Assoc, <T as TraitB>::Assoc)` goal fails. - -// FIXME(deferred_projection_equality): add a test that this is true during coherence +// check that a `alias-eq(<?a as TraitB>::Assoc, <?b as TraitB>::Assoc)` goal fails +// during coherence. We must not incorrectly constrain `?a` and `?b` to be +// equal. trait TraitB { type Assoc; } -fn needs_a<T: TraitB>() -> T::Assoc { - unimplemented!() -} +trait Overlaps<T> {} -fn bar<T: TraitB>() { - let _: <_ as TraitB>::Assoc = needs_a::<T>(); -} +impl<T: TraitB> Overlaps<Box<T>> for <T as TraitB>::Assoc {} +impl<U: TraitB> Overlaps<U> for <U as TraitB>::Assoc {} +//~^ ERROR conflicting implementations of trait fn main() {} diff --git a/tests/ui/traits/new-solver/alias_eq_substs_eq_not_intercrate.stderr b/tests/ui/traits/new-solver/alias_eq_substs_eq_not_intercrate.stderr new file mode 100644 index 000000000..8eda64e44 --- /dev/null +++ b/tests/ui/traits/new-solver/alias_eq_substs_eq_not_intercrate.stderr @@ -0,0 +1,11 @@ +error[E0119]: conflicting implementations of trait `Overlaps<Box<_>>` for type `<_ as TraitB>::Assoc` + --> $DIR/alias_eq_substs_eq_not_intercrate.rs:14:1 + | +LL | impl<T: TraitB> Overlaps<Box<T>> for <T as TraitB>::Assoc {} + | --------------------------------------------------------- first implementation here +LL | impl<U: TraitB> Overlaps<U> for <U as TraitB>::Assoc {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `<_ as TraitB>::Assoc` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/traits/new-solver/array-default.rs b/tests/ui/traits/new-solver/array-default.rs new file mode 100644 index 000000000..5077137b0 --- /dev/null +++ b/tests/ui/traits/new-solver/array-default.rs @@ -0,0 +1,8 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +fn has_default<const N: usize>() where [(); N]: Default {} + +fn main() { + has_default::<1>(); +} diff --git a/tests/ui/traits/new-solver/async.fail.stderr b/tests/ui/traits/new-solver/async.fail.stderr index b395c23ae..72fa2eb31 100644 --- a/tests/ui/traits/new-solver/async.fail.stderr +++ b/tests/ui/traits/new-solver/async.fail.stderr @@ -1,8 +1,8 @@ -error[E0271]: expected `[async block@$DIR/async.rs:12:17: 12:25]` to be a future that resolves to `i32`, but it resolves to `()` +error[E0271]: type mismatch resolving `<[async block@$DIR/async.rs:12:17: 12:25] as Future>::Output == i32` --> $DIR/async.rs:12:17 | LL | needs_async(async {}); - | ----------- ^^^^^^^^ expected `i32`, found `()` + | ----------- ^^^^^^^^ types differ | | | required by a bound introduced by this call | diff --git a/tests/ui/traits/new-solver/async.rs b/tests/ui/traits/new-solver/async.rs index 195cc35ca..155b71eb7 100644 --- a/tests/ui/traits/new-solver/async.rs +++ b/tests/ui/traits/new-solver/async.rs @@ -10,7 +10,7 @@ fn needs_async(_: impl Future<Output = i32>) {} #[cfg(fail)] fn main() { needs_async(async {}); - //[fail]~^ ERROR to be a future that resolves to `i32`, but it resolves to `()` + //[fail]~^ ERROR type mismatch } #[cfg(pass)] diff --git a/tests/ui/traits/new-solver/closure-substs-ambiguity.rs b/tests/ui/traits/new-solver/closure-substs-ambiguity.rs new file mode 100644 index 000000000..48432f402 --- /dev/null +++ b/tests/ui/traits/new-solver/closure-substs-ambiguity.rs @@ -0,0 +1,7 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +fn main() { + let mut x: Vec<_> = vec![]; + x.extend(Some(1i32).into_iter().map(|x| x)); +} diff --git a/tests/ui/traits/new-solver/dedup-regions.rs b/tests/ui/traits/new-solver/dedup-regions.rs new file mode 100644 index 000000000..f376f39a5 --- /dev/null +++ b/tests/ui/traits/new-solver/dedup-regions.rs @@ -0,0 +1,31 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +struct A(*mut ()); + +unsafe impl Send for A where A: 'static {} + +macro_rules! mk { + ($name:ident $ty:ty) => { + struct $name($ty, $ty, $ty, $ty, $ty, $ty, $ty, $ty, $ty, $ty); + }; +} + +mk!(B A); +mk!(C B); +mk!(D C); +mk!(E D); +mk!(F E); +mk!(G F); +mk!(H G); +mk!(I H); +mk!(J I); +mk!(K J); +mk!(L K); +mk!(M L); + +fn needs_send<T: Send>() {} + +fn main() { + needs_send::<M>(); +} diff --git a/tests/ui/traits/new-solver/dont-remap-tait-substs.rs b/tests/ui/traits/new-solver/dont-remap-tait-substs.rs new file mode 100644 index 000000000..309bee8aa --- /dev/null +++ b/tests/ui/traits/new-solver/dont-remap-tait-substs.rs @@ -0,0 +1,19 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +// Makes sure we don't prepopulate the MIR typeck of `define` +// with `Foo<T, U> = T`, but instead, `Foo<B, A> = B`, so that +// the param-env predicates actually apply. + +#![feature(type_alias_impl_trait)] + +type Foo<T: Send, U> = impl NeedsSend<T>; + +trait NeedsSend<T> {} +impl<T: Send> NeedsSend<T> for T {} + +fn define<A, B: Send>(a: A, b: B, _: Foo<B, A>) { + let y: Option<Foo<B, A>> = Some(b); +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.not_send.stderr b/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.not_send.stderr new file mode 100644 index 000000000..ec1c3231a --- /dev/null +++ b/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.not_send.stderr @@ -0,0 +1,16 @@ +error[E0283]: type annotations needed: cannot satisfy `Foo: Send` + --> $DIR/dont-type_of-tait-in-defining-scope.rs:16:5 + | +LL | needs_send::<Foo>(); + | ^^^^^^^^^^^^^^^^^ + | + = note: cannot satisfy `Foo: Send` +note: required by a bound in `needs_send` + --> $DIR/dont-type_of-tait-in-defining-scope.rs:13:18 + | +LL | fn needs_send<T: Send>() {} + | ^^^^ required by this bound in `needs_send` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.rs b/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.rs new file mode 100644 index 000000000..08f14d749 --- /dev/null +++ b/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.rs @@ -0,0 +1,24 @@ +// revisions: is_send not_send +// compile-flags: -Ztrait-solver=next +//[is_send] check-pass + +#![feature(type_alias_impl_trait)] + +#[cfg(is_send)] +type Foo = impl Send; + +#[cfg(not_send)] +type Foo = impl Sized; + +fn needs_send<T: Send>() {} + +fn test(_: Foo) { + needs_send::<Foo>(); + //[not_send]~^ ERROR type annotations needed: cannot satisfy `Foo: Send` +} + +fn defines(_: Foo) { + let _: Foo = (); +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/dyn-any-dont-prefer-impl.rs b/tests/ui/traits/new-solver/dyn-any-dont-prefer-impl.rs new file mode 100644 index 000000000..7d15b8c63 --- /dev/null +++ b/tests/ui/traits/new-solver/dyn-any-dont-prefer-impl.rs @@ -0,0 +1,13 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +use std::any::Any; + +fn needs_usize(_: &usize) {} + +fn main() { + let x: &dyn Any = &1usize; + if let Some(x) = x.downcast_ref::<usize>() { + needs_usize(x); + } +} diff --git a/tests/ui/traits/new-solver/equating-projection-cyclically.rs b/tests/ui/traits/new-solver/equating-projection-cyclically.rs index 019c6e81c..2668da1b7 100644 --- a/tests/ui/traits/new-solver/equating-projection-cyclically.rs +++ b/tests/ui/traits/new-solver/equating-projection-cyclically.rs @@ -1,11 +1,10 @@ // compile-flags: -Ztrait-solver=next -// known-bug: unknown trait Test { type Assoc; } -fn transform<T: Test>(x: T) -> T::Assoc { +fn transform<T: Test>(x: Inv<T>) -> Inv<T::Assoc> { todo!() } @@ -17,8 +16,13 @@ impl Test for String { type Assoc = String; } +struct Inv<T>(Option<*mut T>); + fn main() { - let mut x = Default::default(); + let mut x: Inv<_> = Inv(None); + // This ends up equating `Inv<?x>` with `Inv<<?x as Test>::Assoc>` + // which fails the occurs check when generalizing `?x`. x = transform(x); - x = 1i32; + //~^ ERROR mismatched types + x = Inv::<i32>(None); } diff --git a/tests/ui/traits/new-solver/equating-projection-cyclically.stderr b/tests/ui/traits/new-solver/equating-projection-cyclically.stderr index 57cbc65a1..6031d4f08 100644 --- a/tests/ui/traits/new-solver/equating-projection-cyclically.stderr +++ b/tests/ui/traits/new-solver/equating-projection-cyclically.stderr @@ -1,13 +1,8 @@ error[E0308]: mismatched types - --> $DIR/equating-projection-cyclically.rs:22:19 + --> $DIR/equating-projection-cyclically.rs:25:9 | LL | x = transform(x); - | ^ expected inferred type, found associated type - | - = note: expected type `_` - found associated type `<_ as Test>::Assoc` - = help: consider constraining the associated type `<_ as Test>::Assoc` to `_` - = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + | ^^^^^^^^^^^^ cyclic type of infinite size error: aborting due to previous error diff --git a/tests/ui/traits/new-solver/lazy-nested-obligations-2.rs b/tests/ui/traits/new-solver/lazy-nested-obligations-2.rs index 32addd829..fd91d81cd 100644 --- a/tests/ui/traits/new-solver/lazy-nested-obligations-2.rs +++ b/tests/ui/traits/new-solver/lazy-nested-obligations-2.rs @@ -1,6 +1,5 @@ -// check-pass // compile-flags: -Ztrait-solver=next -// Issue 95863 +// known-bug: #95863 pub trait With { type F; diff --git a/tests/ui/traits/new-solver/lazy-nested-obligations-2.stderr b/tests/ui/traits/new-solver/lazy-nested-obligations-2.stderr new file mode 100644 index 000000000..d0a4cd661 --- /dev/null +++ b/tests/ui/traits/new-solver/lazy-nested-obligations-2.stderr @@ -0,0 +1,39 @@ +error[E0308]: mismatched types + --> $DIR/lazy-nested-obligations-2.rs:15:23 + | +LL | let _: V<i32> = V(f); + | - ^ types differ + | | + | arguments to this struct are incorrect + | + = note: expected associated type `<i32 as With>::F` + found fn item `for<'a> fn(&'a str) {f}` + = help: consider constraining the associated type `<i32 as With>::F` to `for<'a> fn(&'a str) {f}` or calling a method that returns `<i32 as With>::F` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html +note: tuple struct defined here + --> $DIR/lazy-nested-obligations-2.rs:16:16 + | +LL | pub struct V<T: With>(<T as With>::F); + | ^ + +error[E0308]: mismatched types + --> $DIR/lazy-nested-obligations-2.rs:21:30 + | +LL | let _: E3<i32> = E3::Var(f); + | ------- ^ types differ + | | + | arguments to this enum variant are incorrect + | + = note: expected associated type `<i32 as With>::F` + found fn item `for<'a> fn(&'a str) {f}` + = help: consider constraining the associated type `<i32 as With>::F` to `for<'a> fn(&'a str) {f}` or calling a method that returns `<i32 as With>::F` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html +note: tuple variant defined here + --> $DIR/lazy-nested-obligations-2.rs:19:9 + | +LL | Var(<T as With>::F), + | ^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/traits/new-solver/leak-check-coinductive-cycle.rs b/tests/ui/traits/new-solver/leak-check-coinductive-cycle.rs new file mode 100644 index 000000000..1f7d4a49c --- /dev/null +++ b/tests/ui/traits/new-solver/leak-check-coinductive-cycle.rs @@ -0,0 +1,33 @@ +// check-pass +// compile-flags: -Ztrait-solver=next +#![feature(rustc_attrs)] + +#[rustc_coinductive] +trait Trait<T> {} +impl<'a, 'b, T> Trait<T> for (&'a (), &'b ()) +where + 'b: 'a, + &'a (): Trait<T>, +{} + +impl Trait<i32> for &'static () {} +impl<'a> Trait<u32> for &'a () +where + for<'b> (&'a (), &'b ()): Trait<u32>, +{} + + +fn impls_trait<T: Trait<U>, U>() {} + +fn main() { + // This infers to `impls_trait::<(&'static (), &'static ()), i32>();` + // + // In the first attempt we have 2 candidates for `&'a (): Trait<_>` + // and we get ambiguity. The result is therefore ambiguity with a `'b: 'a` + // constraint. The next attempt then uses that provisional result when + // trying to apply `impl<'a> Trait<u32> for &'a ()`. This means we get a + // `for<'b> 'b: 'a` bound which fails the leak check. Because of this we + // end up with a single impl for `&'a (): Trait<_>` which infers `_` to `i32` + // and succeeds. + impls_trait::<(&(), &()), _>(); +} diff --git a/tests/ui/traits/new-solver/member-constraints-in-root-universe.rs b/tests/ui/traits/new-solver/member-constraints-in-root-universe.rs new file mode 100644 index 000000000..97c443058 --- /dev/null +++ b/tests/ui/traits/new-solver/member-constraints-in-root-universe.rs @@ -0,0 +1,17 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +trait Trait { + type Ty; +} + +impl Trait for for<'a> fn(&'a u8, &'a u8) { + type Ty = (); +} + +// argument is necessary to create universes before registering the hidden type. +fn test<'a>(_: <fn(&u8, &u8) as Trait>::Ty) -> impl Sized { + "hidden type is `&'?0 str` with '?0 member of ['static,]" +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/normalized-const-built-in-op.rs b/tests/ui/traits/new-solver/normalized-const-built-in-op.rs new file mode 100644 index 000000000..2443e5178 --- /dev/null +++ b/tests/ui/traits/new-solver/normalized-const-built-in-op.rs @@ -0,0 +1,11 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +const fn foo() { + let mut x = [1, 2, 3]; + // We need to fix up `<<[i32; 3] as Index<usize>>::Output as AddAssign>` + // to be treated like a built-in operation. + x[1] += 5; +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/object-unsafety.rs b/tests/ui/traits/new-solver/object-unsafety.rs index 7bdd863a7..da843c914 100644 --- a/tests/ui/traits/new-solver/object-unsafety.rs +++ b/tests/ui/traits/new-solver/object-unsafety.rs @@ -10,7 +10,15 @@ fn copy<U: Setup + ?Sized>(from: &U::From) -> U::From { pub fn copy_any<T>(t: &T) -> T { copy::<dyn Setup<From=T>>(t) - //~^ ERROR the trait bound `dyn Setup<From = T>: Setup` is not satisfied + //~^ ERROR the type `&<dyn Setup<From = T> as Setup>::From` is not well-formed + //~| ERROR the trait bound `dyn Setup<From = T>: Setup` is not satisfied + //~| ERROR mismatched types + //~| ERROR mismatched types + //~| ERROR the type `<dyn Setup<From = T> as Setup>::From` is not well-formed + //~| ERROR the size for values of type `<dyn Setup<From = T> as Setup>::From` cannot be known at compilation time + + // FIXME(-Ztrait-solver=next): These error messages are horrible and some of them + // are even simple fallout from previous error. } fn main() { diff --git a/tests/ui/traits/new-solver/object-unsafety.stderr b/tests/ui/traits/new-solver/object-unsafety.stderr index 198ac623d..bb7c68b89 100644 --- a/tests/ui/traits/new-solver/object-unsafety.stderr +++ b/tests/ui/traits/new-solver/object-unsafety.stderr @@ -14,6 +14,65 @@ help: consider introducing a `where` clause, but there might be an alternative b LL | pub fn copy_any<T>(t: &T) -> T where dyn Setup<From = T>: Setup { | ++++++++++++++++++++++++++++++++ -error: aborting due to previous error +error: the type `&<dyn Setup<From = T> as Setup>::From` is not well-formed + --> $DIR/object-unsafety.rs:12:31 + | +LL | copy::<dyn Setup<From=T>>(t) + | ^ + +error[E0308]: mismatched types + --> $DIR/object-unsafety.rs:12:31 + | +LL | copy::<dyn Setup<From=T>>(t) + | ------------------------- ^ types differ + | | + | arguments to this function are incorrect + | + = note: expected reference `&<dyn Setup<From = T> as Setup>::From` + found reference `&T` +note: function defined here + --> $DIR/object-unsafety.rs:7:4 + | +LL | fn copy<U: Setup + ?Sized>(from: &U::From) -> U::From { + | ^^^^ -------------- + +error[E0308]: mismatched types + --> $DIR/object-unsafety.rs:12:5 + | +LL | pub fn copy_any<T>(t: &T) -> T { + | - - expected `T` because of return type + | | + | this type parameter +LL | copy::<dyn Setup<From=T>>(t) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ + | + = note: expected type parameter `T` + found associated type `<dyn Setup<From = T> as Setup>::From` + = note: you might be missing a type parameter or trait bound + +error: the type `<dyn Setup<From = T> as Setup>::From` is not well-formed + --> $DIR/object-unsafety.rs:12:5 + | +LL | copy::<dyn Setup<From=T>>(t) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: the size for values of type `<dyn Setup<From = T> as Setup>::From` cannot be known at compilation time + --> $DIR/object-unsafety.rs:12:5 + | +LL | copy::<dyn Setup<From=T>>(t) + | ^^^^^^^^^^^^^^^^^^^^^^^^^--- + | | + | doesn't have a size known at compile-time + | this returned value is of type `<dyn Setup<From = T> as Setup>::From` + | + = help: the trait `Sized` is not implemented for `<dyn Setup<From = T> as Setup>::From` + = note: the return type of a function must have a statically known size +help: consider further restricting the associated type + | +LL | pub fn copy_any<T>(t: &T) -> T where <dyn Setup<From = T> as Setup>::From: Sized { + | +++++++++++++++++++++++++++++++++++++++++++++++++ + +error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0277`. +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/new-solver/opportunistic-region-resolve.rs b/tests/ui/traits/new-solver/opportunistic-region-resolve.rs new file mode 100644 index 000000000..2610789cd --- /dev/null +++ b/tests/ui/traits/new-solver/opportunistic-region-resolve.rs @@ -0,0 +1,19 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +#![feature(rustc_attrs)] + +#[rustc_coinductive] +trait Trait {} + +#[rustc_coinductive] +trait Indirect {} +impl<T: Trait + ?Sized> Indirect for T {} + +impl<'a> Trait for &'a () where &'a (): Indirect {} + +fn impls_trait<T: Trait>() {} + +fn main() { + impls_trait::<&'static ()>(); +} diff --git a/tests/ui/traits/new-solver/recursive-self-normalization-2.rs b/tests/ui/traits/new-solver/recursive-self-normalization-2.rs index 8c029f517..d086db475 100644 --- a/tests/ui/traits/new-solver/recursive-self-normalization-2.rs +++ b/tests/ui/traits/new-solver/recursive-self-normalization-2.rs @@ -1,3 +1,4 @@ +//~ ERROR overflow // compile-flags: -Ztrait-solver=next trait Foo1 { diff --git a/tests/ui/traits/new-solver/recursive-self-normalization-2.stderr b/tests/ui/traits/new-solver/recursive-self-normalization-2.stderr index 139b0a456..eebaf21d7 100644 --- a/tests/ui/traits/new-solver/recursive-self-normalization-2.stderr +++ b/tests/ui/traits/new-solver/recursive-self-normalization-2.stderr @@ -1,16 +1,20 @@ error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1: Bar` - --> $DIR/recursive-self-normalization-2.rs:15:5 + --> $DIR/recursive-self-normalization-2.rs:16: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 + --> $DIR/recursive-self-normalization-2.rs:13:17 | LL | fn needs_bar<S: Bar>() {} | ^^^ required by this bound in `needs_bar` -error: aborting due to previous error +error[E0275]: overflow evaluating the requirement `<T as Foo2>::Assoc2` + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization_2`) + +error: aborting due to 2 previous errors 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 index 06d187b5f..d15df7dea 100644 --- a/tests/ui/traits/new-solver/recursive-self-normalization.rs +++ b/tests/ui/traits/new-solver/recursive-self-normalization.rs @@ -1,3 +1,4 @@ +//~ ERROR overflow evaluating the requirement `<T as Foo>::Assoc` [E0275] // compile-flags: -Ztrait-solver=next trait Foo { diff --git a/tests/ui/traits/new-solver/recursive-self-normalization.stderr b/tests/ui/traits/new-solver/recursive-self-normalization.stderr index 8e9b9b4b4..6a87fe2f1 100644 --- a/tests/ui/traits/new-solver/recursive-self-normalization.stderr +++ b/tests/ui/traits/new-solver/recursive-self-normalization.stderr @@ -1,16 +1,20 @@ error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc: Bar` - --> $DIR/recursive-self-normalization.rs:11:5 + --> $DIR/recursive-self-normalization.rs:12: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 + --> $DIR/recursive-self-normalization.rs:9:17 | LL | fn needs_bar<S: Bar>() {} | ^^^ required by this bound in `needs_bar` -error: aborting due to previous error +error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc` + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization`) + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/new-solver/slice-match-byte-lit.rs b/tests/ui/traits/new-solver/slice-match-byte-lit.rs new file mode 100644 index 000000000..4f8480625 --- /dev/null +++ b/tests/ui/traits/new-solver/slice-match-byte-lit.rs @@ -0,0 +1,11 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +fn test(s: &[u8]) { + match &s[0..3] { + b"uwu" => {} + _ => {} + } +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/specialization-transmute.rs b/tests/ui/traits/new-solver/specialization-transmute.rs index a54701df4..f6b19e7ad 100644 --- a/tests/ui/traits/new-solver/specialization-transmute.rs +++ b/tests/ui/traits/new-solver/specialization-transmute.rs @@ -10,12 +10,11 @@ trait Default { } impl<T> Default for T { - default type Id = T; - - fn intu(&self) -> &Self::Id { + default type Id = T; + // This will be fixed by #111994 + fn intu(&self) -> &Self::Id { //~ ERROR type annotations needed self - //~^ ERROR cannot satisfy `T <: <T as Default>::Id` - } + } } fn transmute<T: Default<Id = U>, U: Copy>(t: T) -> U { @@ -24,7 +23,6 @@ fn transmute<T: Default<Id = U>, U: Copy>(t: T) -> U { use std::num::NonZeroU8; fn main() { - let s = transmute::<u8, Option<NonZeroU8>>(0); - //~^ ERROR cannot satisfy `<u8 as Default>::Id == Option<NonZeroU8> + let s = transmute::<u8, Option<NonZeroU8>>(0); // this call should then error assert_eq!(s, None); } diff --git a/tests/ui/traits/new-solver/specialization-transmute.stderr b/tests/ui/traits/new-solver/specialization-transmute.stderr index e67c56afc..09b1405fe 100644 --- a/tests/ui/traits/new-solver/specialization-transmute.stderr +++ b/tests/ui/traits/new-solver/specialization-transmute.stderr @@ -8,24 +8,14 @@ LL | #![feature(specialization)] = 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 +error[E0284]: type annotations needed + --> $DIR/specialization-transmute.rs:15:23 | -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 intu(&self) -> &Self::Id { + | ^^^^^^^^^ cannot infer type | -LL | fn transmute<T: Default<Id = U>, U: Copy>(t: T) -> U { - | ^^^^^^ required by this bound in `transmute` + = note: cannot satisfy `<T as Default>::Id == _` -error: aborting due to 2 previous errors; 1 warning emitted +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/specialization-unconstrained.rs b/tests/ui/traits/new-solver/specialization-unconstrained.rs index 02150689e..7fd753109 100644 --- a/tests/ui/traits/new-solver/specialization-unconstrained.rs +++ b/tests/ui/traits/new-solver/specialization-unconstrained.rs @@ -11,7 +11,7 @@ trait Default { } impl<T> Default for T { - default type Id = T; + default type Id = T; //~ ERROR type annotations needed } fn test<T: Default<Id = U>, U>() {} diff --git a/tests/ui/traits/new-solver/specialization-unconstrained.stderr b/tests/ui/traits/new-solver/specialization-unconstrained.stderr index 910925cba..9915da1a2 100644 --- a/tests/ui/traits/new-solver/specialization-unconstrained.stderr +++ b/tests/ui/traits/new-solver/specialization-unconstrained.stderr @@ -8,6 +8,12 @@ LL | #![feature(specialization)] = help: consider using `min_specialization` instead, which is more stable and complete = note: `#[warn(incomplete_features)]` on by default +error[E0282]: type annotations needed + --> $DIR/specialization-unconstrained.rs:14:22 + | +LL | default type Id = T; + | ^ cannot infer type for associated type `<T as Default>::Id` + error[E0284]: type annotations needed: cannot satisfy `<u32 as Default>::Id == ()` --> $DIR/specialization-unconstrained.rs:20:5 | @@ -20,6 +26,7 @@ note: required by a bound in `test` LL | fn test<T: Default<Id = U>, U>() {} | ^^^^^^ required by this bound in `test` -error: aborting due to previous error; 1 warning emitted +error: aborting due to 2 previous errors; 1 warning emitted -For more information about this error, try `rustc --explain E0284`. +Some errors have detailed explanations: E0282, E0284. +For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/traits/new-solver/tait-eq-proj-2.rs b/tests/ui/traits/new-solver/tait-eq-proj-2.rs new file mode 100644 index 000000000..77ea8bc24 --- /dev/null +++ b/tests/ui/traits/new-solver/tait-eq-proj-2.rs @@ -0,0 +1,23 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +#![feature(type_alias_impl_trait)] + +// Similar to tests/ui/traits/new-solver/tait-eq-proj.rs +// but check the alias-sub relation in the other direction. + +type Tait = impl Iterator<Item = impl Sized>; + +fn mk<T>() -> T { + todo!() +} + +fn a(_: Tait) { + let x: Tait = mk(); + let mut array = mk(); + let mut z = IntoIterator::into_iter(array); + z = x; + array = [0i32; 32]; +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/tait-eq-proj.rs b/tests/ui/traits/new-solver/tait-eq-proj.rs new file mode 100644 index 000000000..01ef2ec95 --- /dev/null +++ b/tests/ui/traits/new-solver/tait-eq-proj.rs @@ -0,0 +1,35 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +#![feature(type_alias_impl_trait)] + +type Tait = impl Iterator<Item = impl Sized>; + +/* + +Consider the goal - AliasRelate(Tait, <[i32; 32] as IntoIterator>::IntoIter) +which is registered on the line above. + +A. SubstRelate - fails (of course). + +B. NormalizesToRhs - Tait normalizes-to <[i32; 32] as IntoIterator>::IntoIter + * infer definition - Tait := <[i32; 32] as IntoIterator>::IntoIter + +C. NormalizesToLhs - <[i32; 32] as IntoIterator>::IntoIter normalizes-to Tait + * Find impl candidate, after substitute - std::array::IntoIter<i32, 32> + * Equate std::array::IntoIter<i32, 32> and Tait + * infer definition - Tait := std::array::IntoIter<i32, 32> + +B and C are not equal, but they are equivalent modulo normalization. + +We get around this by evaluating both the NormalizesToRhs and NormalizesToLhs +goals together. Essentially: + A alias-relate B if A normalizes-to B and B normalizes-to A. + +*/ + +fn a(_: Tait) { + let _: Tait = IntoIterator::into_iter([0i32; 32]); +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/tait-eq-tait.rs b/tests/ui/traits/new-solver/tait-eq-tait.rs new file mode 100644 index 000000000..70d9dc0ea --- /dev/null +++ b/tests/ui/traits/new-solver/tait-eq-tait.rs @@ -0,0 +1,18 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +// Not exactly sure if this is the inference behavior we *want*, +// but it is a side-effect of the lazy normalization of TAITs. + +#![feature(type_alias_impl_trait)] + +fn mk<T>() -> T { + todo!() +} + +fn main() { + type Tait = impl Sized; + type Tait2 = impl Sized; + let x: Tait = 1u32; + let y: Tait2 = x; +} diff --git a/tests/ui/traits/new-solver/two-projection-param-candidates-are-ambiguous.stderr b/tests/ui/traits/new-solver/two-projection-param-candidates-are-ambiguous.stderr index fa5e780ee..83a0452b0 100644 --- a/tests/ui/traits/new-solver/two-projection-param-candidates-are-ambiguous.stderr +++ b/tests/ui/traits/new-solver/two-projection-param-candidates-are-ambiguous.stderr @@ -5,6 +5,7 @@ LL | needs_bar::<T>(); | ^^^^^^^^^^^^^^ | = note: cannot satisfy `T: Bar` + = help: the trait `Bar` is implemented for `T` note: required by a bound in `needs_bar` --> $DIR/two-projection-param-candidates-are-ambiguous.rs:23:17 | diff --git a/tests/ui/traits/new-solver/unevaluated-const-impl-trait-ref.fails.stderr b/tests/ui/traits/new-solver/unevaluated-const-impl-trait-ref.fails.stderr new file mode 100644 index 000000000..072ac32a5 --- /dev/null +++ b/tests/ui/traits/new-solver/unevaluated-const-impl-trait-ref.fails.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `(): Trait<1>` is not satisfied + --> $DIR/unevaluated-const-impl-trait-ref.rs:20:13 + | +LL | needs::<1>(); + | ^ the trait `Trait<1>` is not implemented for `()` + | + = help: the following other types implement trait `Trait<N>`: + <() as Trait<0>> + <() as Trait<2>> +note: required by a bound in `needs` + --> $DIR/unevaluated-const-impl-trait-ref.rs:10:38 + | +LL | fn needs<const N: usize>() where (): Trait<N> {} + | ^^^^^^^^ required by this bound in `needs` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/new-solver/unevaluated-const-impl-trait-ref.rs b/tests/ui/traits/new-solver/unevaluated-const-impl-trait-ref.rs new file mode 100644 index 000000000..26c595bc9 --- /dev/null +++ b/tests/ui/traits/new-solver/unevaluated-const-impl-trait-ref.rs @@ -0,0 +1,22 @@ +// compile-flags: -Ztrait-solver=next +// revisions: works fails +//[works] check-pass + +trait Trait<const N: usize> {} + +impl Trait<{ 1 - 1 }> for () {} +impl Trait<{ 1 + 1 }> for () {} + +fn needs<const N: usize>() where (): Trait<N> {} + +#[cfg(works)] +fn main() { + needs::<0>(); + needs::<2>(); +} + +#[cfg(fails)] +fn main() { + needs::<1>(); + //[fails]~^ ERROR the trait bound `(): Trait<1>` is not satisfied +} diff --git a/tests/ui/traits/new-solver/winnow-specializing-impls.rs b/tests/ui/traits/new-solver/winnow-specializing-impls.rs new file mode 100644 index 000000000..06f64de74 --- /dev/null +++ b/tests/ui/traits/new-solver/winnow-specializing-impls.rs @@ -0,0 +1,22 @@ +// build-pass +// compile-flags: -Ztrait-solver=next + +// Tests that the specializing impl `<() as Foo>` holds during codegen. + +#![feature(min_specialization)] + +trait Foo { + fn bar(); +} + +impl<T> Foo for T { + default fn bar() {} +} + +impl Foo for () { + fn bar() {} +} + +fn main() { + <() as Foo>::bar(); +} |