Skip to content

Commit 232eb69

Browse files
authored
Rollup merge of #110193 - compiler-errors:body-owner-issue, r=WaffleLapkin
Check for body owner fallibly in error reporting Sometimes the "body id" we use for an obligation cause is not actually a body owner, like when we're doing WF checking on items. Fixes #110157
2 parents d146211 + 1178c49 commit 232eb69

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2396,8 +2396,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23962396
}
23972397

23982398
if let Some(ty::subst::GenericArgKind::Type(_)) = subst.map(|subst| subst.unpack())
2399+
&& let Some(body_id) = self.tcx.hir().maybe_body_owned_by(obligation.cause.body_id)
23992400
{
2400-
let body_id = self.tcx.hir().body_owned_by(obligation.cause.body_id);
24012401
let mut expr_finder = FindExprBySpan::new(span);
24022402
expr_finder.visit_expr(&self.tcx.hir().body(body_id).value);
24032403

tests/ui/wf/issue-110157.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
struct NeedsDropTypes<'tcx, F>(std::marker::PhantomData<&'tcx F>);
2+
3+
impl<'tcx, F, I> Iterator for NeedsDropTypes<'tcx, F>
4+
//~^ ERROR type annotations needed
5+
where
6+
F: Fn(&Missing) -> Result<I, ()>,
7+
//~^ ERROR cannot find type `Missing` in this scope
8+
I: Iterator<Item = Missing>,
9+
//~^ ERROR cannot find type `Missing` in this scope
10+
{}
11+
12+
fn main() {}

tests/ui/wf/issue-110157.stderr

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0412]: cannot find type `Missing` in this scope
2+
--> $DIR/issue-110157.rs:6:12
3+
|
4+
LL | F: Fn(&Missing) -> Result<I, ()>,
5+
| ^^^^^^^ not found in this scope
6+
7+
error[E0412]: cannot find type `Missing` in this scope
8+
--> $DIR/issue-110157.rs:8:24
9+
|
10+
LL | I: Iterator<Item = Missing>,
11+
| ^^^^^^^ not found in this scope
12+
13+
error[E0283]: type annotations needed
14+
--> $DIR/issue-110157.rs:3:31
15+
|
16+
LL | impl<'tcx, F, I> Iterator for NeedsDropTypes<'tcx, F>
17+
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `I`
18+
|
19+
= note: cannot satisfy `_: Iterator`
20+
note: required for `NeedsDropTypes<'tcx, F>` to implement `Iterator`
21+
--> $DIR/issue-110157.rs:3:18
22+
|
23+
LL | impl<'tcx, F, I> Iterator for NeedsDropTypes<'tcx, F>
24+
| ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^
25+
...
26+
LL | I: Iterator<Item = Missing>,
27+
| ------------------------ unsatisfied trait bound introduced here
28+
29+
error: aborting due to 3 previous errors
30+
31+
Some errors have detailed explanations: E0283, E0412.
32+
For more information about an error, try `rustc --explain E0283`.

0 commit comments

Comments
 (0)