diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2022-05-04 22:47:09 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-05-04 22:59:15 +0200 |
| commit | cca981661ab474f9bfe4a86b868e76d406b2a4e1 (patch) | |
| tree | 36376507dde81f8504dff8437e2a5aacfd541840 | |
| parent | bb6b433958cf1471f7df02f824a7112c2ef81792 (diff) | |
| download | rust-cca981661ab474f9bfe4a86b868e76d406b2a4e1.tar.gz rust-cca981661ab474f9bfe4a86b868e76d406b2a4e1.zip | |
Only keep predicates on `Self` when checking `dyn TraitAlias`.
| -rw-r--r-- | compiler/rustc_typeck/src/astconv/mod.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/traits/issue-65673.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/traits/issue-65673.stderr | 13 | ||||
| -rw-r--r-- | src/test/ui/traits/issue-96664.rs | 16 |
4 files changed, 23 insertions, 13 deletions
diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 673a2c2fcaf..a21e9f4a0a5 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -1334,8 +1334,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // is used and no 'maybe' bounds are used. let expanded_traits = traits::expand_trait_aliases(tcx, bounds.trait_bounds.iter().map(|&(a, b, _)| (a, b))); - let (mut auto_traits, regular_traits): (Vec<_>, Vec<_>) = - expanded_traits.partition(|i| tcx.trait_is_auto(i.trait_ref().def_id())); + let (mut auto_traits, regular_traits): (Vec<_>, Vec<_>) = expanded_traits + .filter(|i| i.trait_ref().self_ty().skip_binder() == dummy_self) + .partition(|i| tcx.trait_is_auto(i.trait_ref().def_id())); if regular_traits.len() > 1 { let first_trait = ®ular_traits[0]; let additional_trait = ®ular_traits[1]; 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..79f071ba302 100644 --- a/src/test/ui/traits/issue-65673.stderr +++ b/src/test/ui/traits/issue-65673.stderr @@ -1,16 +1,9 @@ -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 | 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() {} |
