diff options
| author | bors <bors@rust-lang.org> | 2023-07-05 08:48:04 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-07-05 08:48:04 +0000 |
| commit | 99f7d368c0ed753db797ee82e89b5a2b7e49509a (patch) | |
| tree | d7519592b88236169d473cfc2f2542622000c1b7 /compiler/rustc_middle/src | |
| parent | 6dab6dc5fcd9655adfa7bfb3e59e5cae487184d2 (diff) | |
| parent | f80aec7429e43b7ef5f508e3c41819b2552f6f26 (diff) | |
| download | rust-99f7d368c0ed753db797ee82e89b5a2b7e49509a.tar.gz rust-99f7d368c0ed753db797ee82e89b5a2b7e49509a.zip | |
Auto merge of #112319 - oli-obk:assoc_ty_sized_bound_for_object_safety2, r=compiler-errors
Don't require associated types with Self: Sized bounds in `dyn Trait` objects
Trait objects require *all* associated types to be specified, even if the associated type has an explicit `where Self: Sized` bound. The following snippet does not compile on master, but does with this PR.
```rust
fn _assert_is_object_safe(_: &dyn Foo) {}
pub trait Foo {
type Bar where Self: Sized;
}
```
In contrast, if a `Self: Sized` bound is added to a method, the methodjust isn't callable on trait objects, but the trait can be made object safe just fine.
```rust
fn _assert_is_object_safe(_: &dyn Foo) {}
pub trait Foo {
fn foo() where Self: Sized;
}
```
This PR closes this inconsistency (though it still exists for associated constants).
Additionally this PR adds a new lint that informs users they can remove associated type bounds from their trait objects if those associated type bounds have a `where Self: Sized` bound, and are thus useless.
r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/query/mod.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 6f942e0bc86..0e1c6d19e31 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -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! } |
