Skip to content

Commit 50e34d6

Browse files
committed
Do not try to report on closures to avoid ICE
1 parent a9cd294 commit 50e34d6

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

Diff for: compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
3939
) if **sub_r == RegionKind::ReStatic => {
4040
// This is for an implicit `'static` requirement coming from `impl dyn Trait {}`.
4141
if let ObligationCauseCode::UnifyReceiver(ctxt) = &cause.code {
42+
// This may have a closure and it would cause ICE
43+
// through `find_param_with_region` (#78262).
44+
let anon_reg_sup = tcx.is_suitable_region(sup_r)?;
45+
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.def_id);
46+
if fn_returns.is_empty() {
47+
return None;
48+
}
49+
4250
let param = self.find_param_with_region(sup_r, sub_r)?;
4351
let lifetime = if sup_r.has_name() {
4452
format!("lifetime `{}`", sup_r)

Diff for: src/test/ui/regions/issue-78262.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait TT {}
2+
3+
impl dyn TT {
4+
fn func(&self) {}
5+
}
6+
7+
fn main() {
8+
let f = |x: &dyn TT| x.func(); //~ ERROR: mismatched types
9+
}

Diff for: src/test/ui/regions/issue-78262.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-78262.rs:8:28
3+
|
4+
LL | let f = |x: &dyn TT| x.func();
5+
| ^^^^ lifetime mismatch
6+
|
7+
= note: expected reference `&(dyn TT + 'static)`
8+
found reference `&dyn TT`
9+
note: the anonymous lifetime #1 defined on the body at 8:13...
10+
--> $DIR/issue-78262.rs:8:13
11+
|
12+
LL | let f = |x: &dyn TT| x.func();
13+
| ^^^^^^^^^^^^^^^^^^^^^
14+
= note: ...does not necessarily outlive the static lifetime
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)