summaryrefslogtreecommitdiffstats
path: root/tests/ui/traits/new-solver
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
commit837b550238aa671a591ccf282dddeab29cadb206 (patch)
tree914b6b8862bace72bd3245ca184d374b08d8a672 /tests/ui/traits/new-solver
parentAdding debian version 1.70.0+dfsg2-1. (diff)
downloadrustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz
rustc-837b550238aa671a591ccf282dddeab29cadb206.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/traits/new-solver')
-rw-r--r--tests/ui/traits/new-solver/alias-bound-unsound.rs27
-rw-r--r--tests/ui/traits/new-solver/alias-bound-unsound.stderr24
-rw-r--r--tests/ui/traits/new-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.rs4
-rw-r--r--tests/ui/traits/new-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.stderr9
-rw-r--r--tests/ui/traits/new-solver/alias_eq_substs_eq_not_intercrate.rs4
-rw-r--r--tests/ui/traits/new-solver/alias_eq_substs_eq_not_intercrate.stderr9
-rw-r--r--tests/ui/traits/new-solver/auto-with-drop_tracking_mir.fail.stderr4
-rw-r--r--tests/ui/traits/new-solver/auto-with-drop_tracking_mir.rs1
-rw-r--r--tests/ui/traits/new-solver/borrowck-error.rs11
-rw-r--r--tests/ui/traits/new-solver/borrowck-error.stderr12
-rw-r--r--tests/ui/traits/new-solver/exponential-trait-goals.rs20
-rw-r--r--tests/ui/traits/new-solver/exponential-trait-goals.stderr23
-rw-r--r--tests/ui/traits/new-solver/int-var-alias-eq.rs2
-rw-r--r--tests/ui/traits/new-solver/negative-coherence-bounds.rs40
-rw-r--r--tests/ui/traits/new-solver/negative-coherence-bounds.stderr12
-rw-r--r--tests/ui/traits/new-solver/nested-alias-bound.rs20
-rw-r--r--tests/ui/traits/new-solver/normalize-rcvr-for-inherent.rs25
-rw-r--r--tests/ui/traits/new-solver/structural-resolve-field.rs13
-rw-r--r--tests/ui/traits/new-solver/temporary-ambiguity.rs2
-rw-r--r--tests/ui/traits/new-solver/two-projection-param-candidates-are-ambiguous.rs2
20 files changed, 239 insertions, 25 deletions
diff --git a/tests/ui/traits/new-solver/alias-bound-unsound.rs b/tests/ui/traits/new-solver/alias-bound-unsound.rs
new file mode 100644
index 000000000..00294c708
--- /dev/null
+++ b/tests/ui/traits/new-solver/alias-bound-unsound.rs
@@ -0,0 +1,27 @@
+// compile-flags: -Ztrait-solver=next
+
+// Makes sure that alias bounds are not unsound!
+
+#![feature(trivial_bounds)]
+
+trait Foo {
+ type Item: Copy
+ where
+ <Self as Foo>::Item: Copy;
+
+ fn copy_me(x: &Self::Item) -> Self::Item {
+ *x
+ }
+}
+
+impl Foo for () {
+ type Item = String where String: Copy;
+}
+
+fn main() {
+ let x = String::from("hello, world");
+ drop(<() as Foo>::copy_me(&x));
+ //~^ ERROR `<() as Foo>::Item: Copy` is not satisfied
+ //~| 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
new file mode 100644
index 000000000..9a43d2a66
--- /dev/null
+++ b/tests/ui/traits/new-solver/alias-bound-unsound.stderr
@@ -0,0 +1,24 @@
+error[E0277]: the trait bound `<() as Foo>::Item: Copy` is not satisfied
+ --> $DIR/alias-bound-unsound.rs:23:10
+ |
+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
+ |
+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_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 531203d9c..3c7fc7403 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,5 +1,8 @@
// compile-flags: -Ztrait-solver=next
+// check-pass
+// (should not pass, should be turned into a coherence-only test)
+
// 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
// relating substs as either could be a valid solution.
@@ -36,7 +39,6 @@ where
{
// `<() as Foo<u16, STOP>>::Assoc == <() as Foo<_, STOP>>::Assoc`
let _: <() as Foo<u16, T>>::Assoc = output::<_, T>();
- //~^ error: type annotations needed
// let _: <() as Foo<u16, T>>::Assoc = output::<u8, T>(); // OK
// let _: <() as Foo<u16, T>>::Assoc = output::<u16, T>(); // OK
diff --git a/tests/ui/traits/new-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.stderr b/tests/ui/traits/new-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.stderr
deleted file mode 100644
index a6712332c..000000000
--- a/tests/ui/traits/new-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.stderr
+++ /dev/null
@@ -1,9 +0,0 @@
-error[E0282]: type annotations needed
- --> $DIR/alias_eq_dont_use_normalizes_to_if_substs_eq.rs:38:41
- |
-LL | let _: <() as Foo<u16, T>>::Assoc = output::<_, T>();
- | ^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `output`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0282`.
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 d4cc380fa..b036411be 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,5 +1,8 @@
// 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
@@ -14,7 +17,6 @@ fn needs_a<T: TraitB>() -> T::Assoc {
fn bar<T: TraitB>() {
let _: <_ as TraitB>::Assoc = needs_a::<T>();
- //~^ error: type annotations needed
}
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
deleted file mode 100644
index d063d8fce..000000000
--- a/tests/ui/traits/new-solver/alias_eq_substs_eq_not_intercrate.stderr
+++ /dev/null
@@ -1,9 +0,0 @@
-error[E0282]: type annotations needed
- --> $DIR/alias_eq_substs_eq_not_intercrate.rs:16:12
- |
-LL | let _: <_ as TraitB>::Assoc = needs_a::<T>();
- | ^^^^^^^^^^^^^^^^^^^^ cannot infer type for associated type `<_ as TraitB>::Assoc`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0282`.
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
index 6a926534e..4aefdd6bb 100644
--- 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
@@ -1,5 +1,5 @@
error[E0277]: `impl Future<Output = ()>` cannot be sent between threads safely
- --> $DIR/auto-with-drop_tracking_mir.rs:24:13
+ --> $DIR/auto-with-drop_tracking_mir.rs:25:13
|
LL | is_send(foo());
| ------- ^^^^^ `impl Future<Output = ()>` cannot be sent between threads safely
@@ -8,7 +8,7 @@ LL | is_send(foo());
|
= 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
+ --> $DIR/auto-with-drop_tracking_mir.rs:24:24
|
LL | fn is_send(_: impl Send) {}
| ^^^^ required by this bound in `is_send`
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
index a5db7c463..e311a4af2 100644
--- a/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.rs
+++ b/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.rs
@@ -14,6 +14,7 @@ async fn foo() {
#[cfg(fail)]
let x = &NotSync;
bar().await;
+ #[allow(dropping_references)]
drop(x);
}
diff --git a/tests/ui/traits/new-solver/borrowck-error.rs b/tests/ui/traits/new-solver/borrowck-error.rs
new file mode 100644
index 000000000..4787a2c7e
--- /dev/null
+++ b/tests/ui/traits/new-solver/borrowck-error.rs
@@ -0,0 +1,11 @@
+// compile-flags: -Ztrait-solver=next
+
+use std::collections::HashMap;
+
+fn foo() -> &'static HashMap<i32, i32>
+{
+ &HashMap::new()
+ //~^ ERROR cannot return reference to temporary value
+}
+
+fn main() {}
diff --git a/tests/ui/traits/new-solver/borrowck-error.stderr b/tests/ui/traits/new-solver/borrowck-error.stderr
new file mode 100644
index 000000000..a7d820174
--- /dev/null
+++ b/tests/ui/traits/new-solver/borrowck-error.stderr
@@ -0,0 +1,12 @@
+error[E0515]: cannot return reference to temporary value
+ --> $DIR/borrowck-error.rs:7:5
+ |
+LL | &HashMap::new()
+ | ^--------------
+ | ||
+ | |temporary value created here
+ | returns a reference to data owned by the current function
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0515`.
diff --git a/tests/ui/traits/new-solver/exponential-trait-goals.rs b/tests/ui/traits/new-solver/exponential-trait-goals.rs
new file mode 100644
index 000000000..b37f09ee1
--- /dev/null
+++ b/tests/ui/traits/new-solver/exponential-trait-goals.rs
@@ -0,0 +1,20 @@
+// compile-flags: -Ztrait-solver=next
+
+trait Trait {}
+
+struct W<T>(T);
+
+impl<T, U> Trait for W<(W<T>, W<U>)>
+where
+ W<T>: Trait,
+ W<U>: Trait,
+{
+}
+
+fn impls<T: Trait>() {}
+
+fn main() {
+ impls::<W<_>>();
+ //~^ ERROR type annotations needed
+ //~| ERROR overflow evaluating the requirement `W<_>: Trait`
+}
diff --git a/tests/ui/traits/new-solver/exponential-trait-goals.stderr b/tests/ui/traits/new-solver/exponential-trait-goals.stderr
new file mode 100644
index 000000000..28a99cbbc
--- /dev/null
+++ b/tests/ui/traits/new-solver/exponential-trait-goals.stderr
@@ -0,0 +1,23 @@
+error[E0282]: type annotations needed
+ --> $DIR/exponential-trait-goals.rs:17:5
+ |
+LL | impls::<W<_>>();
+ | ^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `impls`
+
+error[E0275]: overflow evaluating the requirement `W<_>: Trait`
+ --> $DIR/exponential-trait-goals.rs:17:5
+ |
+LL | impls::<W<_>>();
+ | ^^^^^^^^^^^^^
+ |
+ = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`exponential_trait_goals`)
+note: required by a bound in `impls`
+ --> $DIR/exponential-trait-goals.rs:14:13
+ |
+LL | fn impls<T: Trait>() {}
+ | ^^^^^ required by this bound in `impls`
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0275, E0282.
+For more information about an error, try `rustc --explain E0275`.
diff --git a/tests/ui/traits/new-solver/int-var-alias-eq.rs b/tests/ui/traits/new-solver/int-var-alias-eq.rs
index 2da387db4..790197e2d 100644
--- a/tests/ui/traits/new-solver/int-var-alias-eq.rs
+++ b/tests/ui/traits/new-solver/int-var-alias-eq.rs
@@ -1,7 +1,7 @@
// check-pass
// compile-flags: -Ztrait-solver=next
-// HIR typeck ends up equating `<_#0i as Add>::Output == _#0i`.
+// 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.
diff --git a/tests/ui/traits/new-solver/negative-coherence-bounds.rs b/tests/ui/traits/new-solver/negative-coherence-bounds.rs
new file mode 100644
index 000000000..5436b02c3
--- /dev/null
+++ b/tests/ui/traits/new-solver/negative-coherence-bounds.rs
@@ -0,0 +1,40 @@
+// check-pass
+
+// This test verifies that negative trait predicate cannot be satisfied from a
+// positive param-env candidate.
+
+// Negative coherence is one of the only places where we actually construct and
+// evaluate negative predicates. Specifically, when verifying whether the first
+// and second impls below overlap, we do not want to consider them disjoint,
+// otherwise the second impl would be missing an associated type `type Item`
+// which is provided by the first impl that it is specializing.
+
+#![feature(specialization)]
+//~^ WARN the feature `specialization` is incomplete
+#![feature(with_negative_coherence)]
+
+trait BoxIter {
+ type Item;
+
+ fn last(self) -> Option<Self::Item>;
+}
+
+impl<I: Iterator + ?Sized> BoxIter for Box<I> {
+ type Item = I::Item;
+
+ default fn last(self) -> Option<I::Item> {
+ todo!()
+ }
+}
+
+// When checking that this impl does/doesn't overlap the one above, we evaluate
+// a negative version of all of the where-clause predicates of the impl below.
+// For `I: !Iterator`, we should make sure that the param-env clause `I: Iterator`
+// from above doesn't satisfy this predicate.
+impl<I: Iterator> BoxIter for Box<I> {
+ fn last(self) -> Option<I::Item> {
+ (*self).last()
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/traits/new-solver/negative-coherence-bounds.stderr b/tests/ui/traits/new-solver/negative-coherence-bounds.stderr
new file mode 100644
index 000000000..4127f51f5
--- /dev/null
+++ b/tests/ui/traits/new-solver/negative-coherence-bounds.stderr
@@ -0,0 +1,12 @@
+warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/negative-coherence-bounds.rs:12: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
+
+warning: 1 warning emitted
+
diff --git a/tests/ui/traits/new-solver/nested-alias-bound.rs b/tests/ui/traits/new-solver/nested-alias-bound.rs
new file mode 100644
index 000000000..c365902db
--- /dev/null
+++ b/tests/ui/traits/new-solver/nested-alias-bound.rs
@@ -0,0 +1,20 @@
+// compile-flags: -Ztrait-solver=next
+// check-pass
+
+trait A {
+ type A: B;
+}
+
+trait B {
+ type B: C;
+}
+
+trait C {}
+
+fn needs_c<T: C>() {}
+
+fn test<T: A>() {
+ needs_c::<<T::A as B>::B>();
+}
+
+fn main() {}
diff --git a/tests/ui/traits/new-solver/normalize-rcvr-for-inherent.rs b/tests/ui/traits/new-solver/normalize-rcvr-for-inherent.rs
new file mode 100644
index 000000000..d70534feb
--- /dev/null
+++ b/tests/ui/traits/new-solver/normalize-rcvr-for-inherent.rs
@@ -0,0 +1,25 @@
+// compile-flags: -Ztrait-solver=next
+// check-pass
+
+// Verify that we can assemble inherent impl candidates on a possibly
+// unnormalized self type.
+
+trait Foo {
+ type Assoc;
+}
+impl Foo for i32 {
+ type Assoc = Bar;
+}
+
+struct Bar;
+impl Bar {
+ fn method(&self) {}
+}
+
+fn build<T: Foo>(_: T) -> T::Assoc {
+ todo!()
+}
+
+fn main() {
+ build(1i32).method();
+}
diff --git a/tests/ui/traits/new-solver/structural-resolve-field.rs b/tests/ui/traits/new-solver/structural-resolve-field.rs
new file mode 100644
index 000000000..01899c9ad
--- /dev/null
+++ b/tests/ui/traits/new-solver/structural-resolve-field.rs
@@ -0,0 +1,13 @@
+// compile-flags: -Ztrait-solver=next
+// check-pass
+
+#[derive(Default)]
+struct Foo {
+ x: i32,
+}
+
+fn main() {
+ let mut xs = <[Foo; 1]>::default();
+ xs[0].x = 1;
+ (&mut xs[0]).x = 2;
+}
diff --git a/tests/ui/traits/new-solver/temporary-ambiguity.rs b/tests/ui/traits/new-solver/temporary-ambiguity.rs
index 18ee05457..c6c11a1a1 100644
--- a/tests/ui/traits/new-solver/temporary-ambiguity.rs
+++ b/tests/ui/traits/new-solver/temporary-ambiguity.rs
@@ -18,5 +18,5 @@ fn main() {
let w = Wrapper(x);
needs_foo(w);
x = 1;
- drop(x);
+ let _ = x;
}
diff --git a/tests/ui/traits/new-solver/two-projection-param-candidates-are-ambiguous.rs b/tests/ui/traits/new-solver/two-projection-param-candidates-are-ambiguous.rs
index cde2059ca..3c7fc0d81 100644
--- a/tests/ui/traits/new-solver/two-projection-param-candidates-are-ambiguous.rs
+++ b/tests/ui/traits/new-solver/two-projection-param-candidates-are-ambiguous.rs
@@ -1,7 +1,7 @@
// compile-flags: -Ztrait-solver=next
// When we're solving `<T as Foo>::Assoc = i32`, we actually first solve
-// `<T as Foo>::Assoc = _#1t`, then unify `_#1t` with `i32`. That goal
+// `<T as Foo>::Assoc = ?1t`, then unify `?1t` with `i32`. That goal
// with the inference variable is ambiguous when there are >1 param-env
// candidates.