Skip to content

Commit ca94899

Browse files
committed
Make type_of for RPITITs GAT on traits return a ty::Error if no default provided
1 parent fd68a6d commit ca94899

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,11 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
446446
..
447447
}) => {
448448
if in_trait && !tcx.defaultness(owner).has_value() {
449-
span_bug!(
449+
return ty::EarlyBinder::bind(Ty::new_error_with_message(
450+
tcx,
450451
tcx.def_span(def_id),
451-
"tried to get type of this RPITIT with no definition"
452-
);
452+
"tried to get type of this RPITIT with no definition",
453+
));
453454
}
454455
opaque::find_opaque_ty_constraints_for_rpit(tcx, def_id, owner)
455456
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error: cannot check whether the hidden type of opaque type satisfies auto traits
2+
--> $DIR/missing-type-parameter.rs:9:17
3+
|
4+
LL | fn bar() -> Wrapper<impl Sized>;
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: opaque type is declared here
8+
--> $DIR/missing-type-parameter.rs:9:25
9+
|
10+
LL | fn bar() -> Wrapper<impl Sized>;
11+
| ^^^^^^^^^^
12+
note: required by a bound in `Wrapper`
13+
--> $DIR/missing-type-parameter.rs:6:19
14+
|
15+
LL | struct Wrapper<G: Send>(G);
16+
| ^^^^ required by this bound in `Wrapper`
17+
18+
error: aborting due to previous error
19+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error: cannot check whether the hidden type of opaque type satisfies auto traits
2+
--> $DIR/missing-type-parameter.rs:9:17
3+
|
4+
LL | fn bar() -> Wrapper<impl Sized>;
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: opaque type is declared here
8+
--> $DIR/missing-type-parameter.rs:9:25
9+
|
10+
LL | fn bar() -> Wrapper<impl Sized>;
11+
| ^^^^^^^^^^
12+
note: required by a bound in `Wrapper`
13+
--> $DIR/missing-type-parameter.rs:6:19
14+
|
15+
LL | struct Wrapper<G: Send>(G);
16+
| ^^^^ required by this bound in `Wrapper`
17+
18+
error: aborting due to previous error
19+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
2+
// revisions: current next
3+
4+
#![feature(return_position_impl_trait_in_trait)]
5+
6+
struct Wrapper<G: Send>(G);
7+
8+
trait Foo {
9+
fn bar() -> Wrapper<impl Sized>;
10+
//~^ ERROR: cannot check whether the hidden type of opaque type satisfies auto traits
11+
}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)