mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
Don't require associated types with Self: Sized
bounds in dyn Trait
objects
This commit is contained in:
parent
9227ff28af
commit
ca581f9161
@ -1131,6 +1131,16 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
}
|
||||
}
|
||||
|
||||
for def_ids in associated_types.values_mut() {
|
||||
for def_id in def_ids.clone() {
|
||||
// If the associated type has a `where Self: Sized` bound, we do not need to constrain the associated
|
||||
// type in the `dyn Trait`.
|
||||
if tcx.generics_require_sized_self(def_id) {
|
||||
def_ids.remove(&def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.complain_about_missing_associated_types(
|
||||
associated_types,
|
||||
potential_assoc_types,
|
||||
|
@ -2197,6 +2197,10 @@ rustc_queries! {
|
||||
desc { "getting cfg-ed out item names" }
|
||||
separate_provide_extern
|
||||
}
|
||||
|
||||
query generics_require_sized_self(def_id: DefId) -> bool {
|
||||
desc { "check whether the item has a `where Self: Sized` bound" }
|
||||
}
|
||||
}
|
||||
|
||||
rustc_query_append! { define_callbacks! }
|
||||
|
@ -922,5 +922,10 @@ pub fn contains_illegal_impl_trait_in_trait<'tcx>(
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
*providers = Providers { object_safety_violations, check_is_object_safe, ..*providers };
|
||||
*providers = Providers {
|
||||
object_safety_violations,
|
||||
check_is_object_safe,
|
||||
generics_require_sized_self,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
// check-pass
|
||||
|
||||
trait Foo {
|
||||
type Bar
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
fn foo(_: &dyn Foo) {} //~ ERROR: the value of the associated type `Bar` (from trait `Foo`) must be specified
|
||||
fn foo(_: &dyn Foo) {}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,12 +0,0 @@
|
||||
error[E0191]: the value of the associated type `Bar` (from trait `Foo`) must be specified
|
||||
--> $DIR/assoc_type_bounds_sized.rs:7:16
|
||||
|
|
||||
LL | type Bar
|
||||
| -------- `Bar` defined here
|
||||
...
|
||||
LL | fn foo(_: &dyn Foo) {}
|
||||
| ^^^ help: specify the associated type: `Foo<Bar = Type>`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0191`.
|
Loading…
Reference in New Issue
Block a user