Skip to content

Commit 84114fe

Browse files
authored
Rollup merge of #120707 - compiler-errors:suitable-region, r=nnethercote
Don't expect early-bound region to be local when reporting errors in RPITIT well-formedness The implicit lifetime in the example code gets replaced with `ReError`, which fails a `sub_regions` check in the lexical region solver. Error reporting ends up calling `is_suitable_region` on an early bound region in the *trait* definition. This causes an ICE because we `expect_local()`. This is kind of a bad explanation, but this code just makes diagnostics reporting a bit more gracefully fallible. If the reviewer wants a thorough investigation of exactly where we get this region outlives obligation, I can write one up. Doesn't really seem worth it, though, imo. Fixes #120638 Fixes #120648
2 parents 012ce8a + d9cd0d4 commit 84114fe

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ impl<'tcx> TyCtxt<'tcx> {
11931193
let (suitable_region_binding_scope, bound_region) = loop {
11941194
let def_id = match region.kind() {
11951195
ty::ReLateParam(fr) => fr.bound_region.get_id()?.as_local()?,
1196-
ty::ReEarlyParam(ebr) => ebr.def_id.expect_local(),
1196+
ty::ReEarlyParam(ebr) => ebr.def_id.as_local()?,
11971197
_ => return None, // not a free region
11981198
};
11991199
let scope = self.local_parent(def_id);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// edition:2021
2+
3+
#[allow(async_fn_in_trait)]
4+
5+
pub trait BleRadio<'a> {
6+
async fn transmit(&mut self);
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// aux-build:bad-region.rs
2+
// edition:2021
3+
4+
#![allow(async_fn_in_trait)]
5+
6+
extern crate bad_region as jewel;
7+
8+
use jewel::BleRadio;
9+
10+
pub struct Radio {}
11+
12+
impl BleRadio for Radio {
13+
//~^ ERROR implicit elided lifetime not allowed here
14+
async fn transmit(&mut self) {}
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0726]: implicit elided lifetime not allowed here
2+
--> $DIR/bad-region.rs:12:6
3+
|
4+
LL | impl BleRadio for Radio {
5+
| ^^^^^^^^ expected lifetime parameter
6+
|
7+
help: indicate the anonymous lifetime
8+
|
9+
LL | impl BleRadio<'_> for Radio {
10+
| ++++
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0726`.

0 commit comments

Comments
 (0)