about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-05-10 00:40:57 +0000
committerbors <bors@rust-lang.org>2022-05-10 00:40:57 +0000
commit362010d6be0e551fa35c6e0488abb18686b2add4 (patch)
treeac3d6255176d0d119485e26d9b878cb685243511 /src
parentcb390735b03aa44229ff2858be8fedbd7b0ce7cb (diff)
parente947fad68cc7dce9285364984931dc1f286b9fa3 (diff)
downloadrust-362010d6be0e551fa35c6e0488abb18686b2add4.tar.gz
rust-362010d6be0e551fa35c6e0488abb18686b2add4.zip
Auto merge of #96715 - cjgillot:trait-alias-loop, r=compiler-errors
Fortify handing of where bounds on trait & trait alias definitions

Closes https://github.com/rust-lang/rust/issues/96664
Closes https://github.com/rust-lang/rust/issues/96665

Since https://github.com/rust-lang/rust/pull/93803, when listing all bounds and predicates we now need to account for the possible presence of predicates on any of the generic parameters.  Both bugs were hidden by the special handling of bounds at  the generic parameter declaration position.

Trait alias expansion used to confuse predicates on `Self` and where predicates.
Exiting too late when listing all the bounds caused a cycle error.
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/traits/alias/only-maybe-bound.stderr6
-rw-r--r--src/test/ui/traits/issue-65673.rs2
-rw-r--r--src/test/ui/traits/issue-65673.stderr16
-rw-r--r--src/test/ui/traits/issue-96664.rs16
-rw-r--r--src/test/ui/traits/issue-96665.rs16
5 files changed, 45 insertions, 11 deletions
diff --git a/src/test/ui/traits/alias/only-maybe-bound.stderr b/src/test/ui/traits/alias/only-maybe-bound.stderr
index 99589edb535..e9e846c2ff3 100644
--- a/src/test/ui/traits/alias/only-maybe-bound.stderr
+++ b/src/test/ui/traits/alias/only-maybe-bound.stderr
@@ -1,12 +1,18 @@
 error[E0224]: at least one trait is required for an object type
   --> $DIR/only-maybe-bound.rs:13:12
    |
+LL | trait _1 = _0;
+   | -------------- this alias does not contain a trait
+...
 LL | type _T0 = dyn _1;
    |            ^^^^^^
 
 error[E0224]: at least one trait is required for an object type
   --> $DIR/only-maybe-bound.rs:19:12
    |
+LL | trait _2 = _1 + _1;
+   | ------------------- this alias does not contain a trait
+LL | 
 LL | type _T1 = dyn _2;
    |            ^^^^^^
 
diff --git a/src/test/ui/traits/issue-65673.rs b/src/test/ui/traits/issue-65673.rs
index 4b47bd493a5..e5c2fccb2b5 100644
--- a/src/test/ui/traits/issue-65673.rs
+++ b/src/test/ui/traits/issue-65673.rs
@@ -7,6 +7,6 @@ trait Alias<T> = where T: Trait;
 
 impl<T> WithType for T {
     type Ctx = dyn Alias<T>;
-//~^ ERROR the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
+    //~^ ERROR at least one trait is required for an object type [E0224]
 }
 fn main() {}
diff --git a/src/test/ui/traits/issue-65673.stderr b/src/test/ui/traits/issue-65673.stderr
index 245c4ee525e..71f3a0e7c7c 100644
--- a/src/test/ui/traits/issue-65673.stderr
+++ b/src/test/ui/traits/issue-65673.stderr
@@ -1,16 +1,12 @@
-error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
+error[E0224]: at least one trait is required for an object type
   --> $DIR/issue-65673.rs:9:16
    |
+LL | trait Alias<T> = where T: Trait;
+   | -------------------------------- this alias does not contain a trait
+...
 LL |     type Ctx = dyn Alias<T>;
-   |                ^^^^^^^^^^^^ doesn't have a size known at compile-time
-   |
-   = help: the trait `Sized` is not implemented for `(dyn Trait + 'static)`
-note: required by a bound in `WithType::Ctx`
-  --> $DIR/issue-65673.rs:4:5
-   |
-LL |     type Ctx;
-   |     ^^^^^^^^^ required by this bound in `WithType::Ctx`
+   |                ^^^^^^^^^^^^
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0277`.
+For more information about this error, try `rustc --explain E0224`.
diff --git a/src/test/ui/traits/issue-96664.rs b/src/test/ui/traits/issue-96664.rs
new file mode 100644
index 00000000000..3c5314af73e
--- /dev/null
+++ b/src/test/ui/traits/issue-96664.rs
@@ -0,0 +1,16 @@
+// check-pass
+
+#![feature(trait_alias)]
+
+pub trait State = Clone + Send + Sync + PartialOrd + PartialEq + std::fmt::Display;
+pub trait RandState<S: State> = FnMut() -> S + Send;
+
+pub trait Evaluator {
+    type State;
+}
+
+pub struct Evolver<E: Evaluator> {
+    rand_state: Box<dyn RandState<E::State>>,
+}
+
+fn main() {}
diff --git a/src/test/ui/traits/issue-96665.rs b/src/test/ui/traits/issue-96665.rs
new file mode 100644
index 00000000000..a571d48d97a
--- /dev/null
+++ b/src/test/ui/traits/issue-96665.rs
@@ -0,0 +1,16 @@
+// check-pass
+
+pub trait Sequence<Item, Subsequence: Sequence<Item, Subsequence>> {}
+
+pub trait NodeWalk<Graph: GraphBase, NodeSubwalk: NodeWalk<Graph, NodeSubwalk>>:
+    Sequence<Graph::NodeIndex, NodeSubwalk>
+{
+}
+
+pub trait GraphBase {
+    type NodeIndex;
+}
+
+pub trait WalkableGraph: GraphBase {}
+
+fn main() {}