Skip to content

Commit c78a67b

Browse files
authored
Rollup merge of #111488 - compiler-errors:error-term, r=lcnr
Use error term in projection if missing associated item in new solver We were previously delaying a bug but not bailing, leading to an ICE in the `tcx.type_of(assoc_def.item.def_id)` call below.
2 parents 8d162fb + 8921391 commit c78a67b

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

compiler/rustc_trait_selection/src/solve/project_goals.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,24 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
124124
};
125125

126126
if !assoc_def.item.defaultness(tcx).has_value() {
127-
tcx.sess.delay_span_bug(
127+
let guar = tcx.sess.delay_span_bug(
128128
tcx.def_span(assoc_def.item.def_id),
129129
"missing value for assoc item in impl",
130130
);
131+
let error_term = match assoc_def.item.kind {
132+
ty::AssocKind::Const => tcx
133+
.const_error(
134+
tcx.type_of(goal.predicate.def_id())
135+
.subst(tcx, goal.predicate.projection_ty.substs),
136+
guar,
137+
)
138+
.into(),
139+
ty::AssocKind::Type => tcx.ty_error(guar).into(),
140+
ty::AssocKind::Fn => unreachable!(),
141+
};
142+
ecx.eq(goal.param_env, goal.predicate.term, error_term)
143+
.expect("expected goal term to be fully unconstrained");
144+
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
131145
}
132146

133147
// Getting the right substitutions here is complex, e.g. given:

tests/ui/impl-trait/issue-103181-1.stderr renamed to tests/ui/impl-trait/issue-103181-1.current.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0046]: not all trait items implemented, missing: `Error`
2-
--> $DIR/issue-103181-1.rs:9:5
2+
--> $DIR/issue-103181-1.rs:11:5
33
|
44
LL | type Error;
55
| ---------- `Error` from trait
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0046]: not all trait items implemented, missing: `Error`
2+
--> $DIR/issue-103181-1.rs:11:5
3+
|
4+
LL | type Error;
5+
| ---------- `Error` from trait
6+
LL | }
7+
LL | impl HttpBody for () {
8+
| ^^^^^^^^^^^^^^^^^^^^ missing `Error` in implementation
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0046`.

tests/ui/impl-trait/issue-103181-1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// revisions: current next
2+
//[next] compile-flags: -Ztrait-solver=next
13
// edition:2021
24

35
mod hyper {

0 commit comments

Comments
 (0)