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.
This commit is contained in:
commit
362010d6be
10 changed files with 69 additions and 20 deletions
|
|
@ -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;
|
||||
| ^^^^^^
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {}
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
|
|
|||
16
src/test/ui/traits/issue-96664.rs
Normal file
16
src/test/ui/traits/issue-96664.rs
Normal file
|
|
@ -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() {}
|
||||
16
src/test/ui/traits/issue-96665.rs
Normal file
16
src/test/ui/traits/issue-96665.rs
Normal file
|
|
@ -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() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue