diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 3755342aef5df..4a2245c799dd0 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -446,10 +446,11 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder { if in_trait && !tcx.defaultness(owner).has_value() { - span_bug!( + return ty::EarlyBinder::bind(Ty::new_error_with_message( + tcx, tcx.def_span(def_id), - "tried to get type of this RPITIT with no definition" - ); + "tried to get type of this RPITIT with no definition", + )); } opaque::find_opaque_ty_constraints_for_rpit(tcx, def_id, owner) } diff --git a/tests/ui/impl-trait/in-trait/missing-type-parameter.current.stderr b/tests/ui/impl-trait/in-trait/missing-type-parameter.current.stderr new file mode 100644 index 0000000000000..559392ec1df13 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/missing-type-parameter.current.stderr @@ -0,0 +1,19 @@ +error: cannot check whether the hidden type of opaque type satisfies auto traits + --> $DIR/missing-type-parameter.rs:9:17 + | +LL | fn bar() -> Wrapper; + | ^^^^^^^^^^^^^^^^^^^ + | +note: opaque type is declared here + --> $DIR/missing-type-parameter.rs:9:25 + | +LL | fn bar() -> Wrapper; + | ^^^^^^^^^^ +note: required by a bound in `Wrapper` + --> $DIR/missing-type-parameter.rs:6:19 + | +LL | struct Wrapper(G); + | ^^^^ required by this bound in `Wrapper` + +error: aborting due to previous error + diff --git a/tests/ui/impl-trait/in-trait/missing-type-parameter.next.stderr b/tests/ui/impl-trait/in-trait/missing-type-parameter.next.stderr new file mode 100644 index 0000000000000..559392ec1df13 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/missing-type-parameter.next.stderr @@ -0,0 +1,19 @@ +error: cannot check whether the hidden type of opaque type satisfies auto traits + --> $DIR/missing-type-parameter.rs:9:17 + | +LL | fn bar() -> Wrapper; + | ^^^^^^^^^^^^^^^^^^^ + | +note: opaque type is declared here + --> $DIR/missing-type-parameter.rs:9:25 + | +LL | fn bar() -> Wrapper; + | ^^^^^^^^^^ +note: required by a bound in `Wrapper` + --> $DIR/missing-type-parameter.rs:6:19 + | +LL | struct Wrapper(G); + | ^^^^ required by this bound in `Wrapper` + +error: aborting due to previous error + diff --git a/tests/ui/impl-trait/in-trait/missing-type-parameter.rs b/tests/ui/impl-trait/in-trait/missing-type-parameter.rs new file mode 100644 index 0000000000000..11b10fa0d8678 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/missing-type-parameter.rs @@ -0,0 +1,13 @@ +// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty +// revisions: current next + +#![feature(return_position_impl_trait_in_trait)] + +struct Wrapper(G); + +trait Foo { + fn bar() -> Wrapper; + //~^ ERROR: cannot check whether the hidden type of opaque type satisfies auto traits +} + +fn main() {}