Rollup merge of #78268 - JohnTitor:issue-78262, r=estebank
Do not try to report on closures to avoid ICE Fixes #78262
This commit is contained in:
commit
463b6cc0e1
@ -39,6 +39,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||
) if **sub_r == RegionKind::ReStatic => {
|
||||
// This is for an implicit `'static` requirement coming from `impl dyn Trait {}`.
|
||||
if let ObligationCauseCode::UnifyReceiver(ctxt) = &cause.code {
|
||||
// This may have a closure and it would cause ICE
|
||||
// through `find_param_with_region` (#78262).
|
||||
let anon_reg_sup = tcx.is_suitable_region(sup_r)?;
|
||||
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.def_id);
|
||||
if fn_returns.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let param = self.find_param_with_region(sup_r, sub_r)?;
|
||||
let lifetime = if sup_r.has_name() {
|
||||
format!("lifetime `{}`", sup_r)
|
||||
|
18
src/test/ui/regions/issue-78262.default.stderr
Normal file
18
src/test/ui/regions/issue-78262.default.stderr
Normal file
@ -0,0 +1,18 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-78262.rs:12:28
|
||||
|
|
||||
LL | let f = |x: &dyn TT| x.func();
|
||||
| ^^^^ lifetime mismatch
|
||||
|
|
||||
= note: expected reference `&(dyn TT + 'static)`
|
||||
found reference `&dyn TT`
|
||||
note: the anonymous lifetime #1 defined on the body at 12:13...
|
||||
--> $DIR/issue-78262.rs:12:13
|
||||
|
|
||||
LL | let f = |x: &dyn TT| x.func();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: ...does not necessarily outlive the static lifetime
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
10
src/test/ui/regions/issue-78262.nll.stderr
Normal file
10
src/test/ui/regions/issue-78262.nll.stderr
Normal file
@ -0,0 +1,10 @@
|
||||
error[E0521]: borrowed data escapes outside of closure
|
||||
--> $DIR/issue-78262.rs:12:26
|
||||
|
|
||||
LL | let f = |x: &dyn TT| x.func();
|
||||
| - ^^^^^^^^ `x` escapes the closure body here
|
||||
| |
|
||||
| `x` is a reference that is only valid in the closure body
|
||||
|
||||
error: aborting due to previous error
|
||||
|
14
src/test/ui/regions/issue-78262.rs
Normal file
14
src/test/ui/regions/issue-78262.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// revisions: nll default
|
||||
// ignore-compare-mode-nll
|
||||
//[nll]compile-flags: -Z borrowck=mir
|
||||
|
||||
trait TT {}
|
||||
|
||||
impl dyn TT {
|
||||
fn func(&self) {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let f = |x: &dyn TT| x.func(); //[default]~ ERROR: mismatched types
|
||||
//[nll]~^ ERROR: borrowed data escapes outside of closure
|
||||
}
|
Loading…
Reference in New Issue
Block a user