Skip to content

Commit cca9816

Browse files
committed
Only keep predicates on Self when checking dyn TraitAlias.
1 parent bb6b433 commit cca9816

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,8 +1334,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13341334
// is used and no 'maybe' bounds are used.
13351335
let expanded_traits =
13361336
traits::expand_trait_aliases(tcx, bounds.trait_bounds.iter().map(|&(a, b, _)| (a, b)));
1337-
let (mut auto_traits, regular_traits): (Vec<_>, Vec<_>) =
1338-
expanded_traits.partition(|i| tcx.trait_is_auto(i.trait_ref().def_id()));
1337+
let (mut auto_traits, regular_traits): (Vec<_>, Vec<_>) = expanded_traits
1338+
.filter(|i| i.trait_ref().self_ty().skip_binder() == dummy_self)
1339+
.partition(|i| tcx.trait_is_auto(i.trait_ref().def_id()));
13391340
if regular_traits.len() > 1 {
13401341
let first_trait = &regular_traits[0];
13411342
let additional_trait = &regular_traits[1];

src/test/ui/traits/issue-65673.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ trait Alias<T> = where T: Trait;
77

88
impl<T> WithType for T {
99
type Ctx = dyn Alias<T>;
10-
//~^ ERROR the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
10+
//~^ ERROR at least one trait is required for an object type [E0224]
1111
}
1212
fn main() {}

src/test/ui/traits/issue-65673.stderr

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
1+
error[E0224]: at least one trait is required for an object type
22
--> $DIR/issue-65673.rs:9:16
33
|
44
LL | type Ctx = dyn Alias<T>;
5-
| ^^^^^^^^^^^^ doesn't have a size known at compile-time
6-
|
7-
= help: the trait `Sized` is not implemented for `(dyn Trait + 'static)`
8-
note: required by a bound in `WithType::Ctx`
9-
--> $DIR/issue-65673.rs:4:5
10-
|
11-
LL | type Ctx;
12-
| ^^^^^^^^^ required by this bound in `WithType::Ctx`
5+
| ^^^^^^^^^^^^
136

147
error: aborting due to previous error
158

16-
For more information about this error, try `rustc --explain E0277`.
9+
For more information about this error, try `rustc --explain E0224`.

src/test/ui/traits/issue-96664.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// check-pass
2+
3+
#![feature(trait_alias)]
4+
5+
pub trait State = Clone + Send + Sync + PartialOrd + PartialEq + std::fmt::Display;
6+
pub trait RandState<S: State> = FnMut() -> S + Send;
7+
8+
pub trait Evaluator {
9+
type State;
10+
}
11+
12+
pub struct Evolver<E: Evaluator> {
13+
rand_state: Box<dyn RandState<E::State>>,
14+
}
15+
16+
fn main() {}

0 commit comments

Comments
 (0)