Skip to content

Commit 32c9bca

Browse files
committed
Filter out RPITITs in object_safety_violations_for_trait
1 parent 995ebcc commit 32c9bca

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

compiler/rustc_trait_selection/src/traits/object_safety.rs

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ fn object_safety_violations_for_trait(
157157
.in_definition_order()
158158
.filter(|item| item.kind == ty::AssocKind::Type)
159159
.filter(|item| !tcx.generics_of(item.def_id).params.is_empty())
160+
.filter(|item| tcx.opt_rpitit_info(item.def_id).is_none())
160161
.map(|item| {
161162
let ident = item.ident(tcx);
162163
ObjectSafetyViolation::GAT(ident.name, ident.span)

tests/ui/async-await/in-trait/object-safety.stderr renamed to tests/ui/async-await/in-trait/object-safety.current.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
2-
--> $DIR/object-safety.rs:3:12
2+
--> $DIR/object-safety.rs:5:12
33
|
44
LL | #![feature(async_fn_in_trait)]
55
| ^^^^^^^^^^^^^^^^^
@@ -8,13 +8,13 @@ LL | #![feature(async_fn_in_trait)]
88
= note: `#[warn(incomplete_features)]` on by default
99

1010
error[E0038]: the trait `Foo` cannot be made into an object
11-
--> $DIR/object-safety.rs:11:12
11+
--> $DIR/object-safety.rs:13:12
1212
|
1313
LL | let x: &dyn Foo = todo!();
1414
| ^^^^^^^^ `Foo` cannot be made into an object
1515
|
1616
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
17-
--> $DIR/object-safety.rs:7:14
17+
--> $DIR/object-safety.rs:9:14
1818
|
1919
LL | trait Foo {
2020
| --- this trait cannot be made into an object...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/object-safety.rs:5:12
3+
|
4+
LL | #![feature(async_fn_in_trait)]
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0038]: the trait `Foo` cannot be made into an object
11+
--> $DIR/object-safety.rs:13:12
12+
|
13+
LL | let x: &dyn Foo = todo!();
14+
| ^^^^^^^^ `Foo` cannot be made into an object
15+
|
16+
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
17+
--> $DIR/object-safety.rs:9:14
18+
|
19+
LL | trait Foo {
20+
| --- this trait cannot be made into an object...
21+
LL | async fn foo(&self);
22+
| ^^^ ...because method `foo` is `async`
23+
= help: consider moving `foo` to another trait
24+
25+
error: aborting due to previous error; 1 warning emitted
26+
27+
For more information about this error, try `rustc --explain E0038`.

tests/ui/async-await/in-trait/object-safety.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// edition:2021
2+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
3+
// revisions: current next
24

35
#![feature(async_fn_in_trait)]
46
//~^ WARN the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes

0 commit comments

Comments
 (0)