Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 09dbf37

Browse files
committed
Add filtering based on involved required lifetime
More accurate filtering still needed.
1 parent ab45ab8 commit 09dbf37

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,13 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
156156
spans.dedup_by_key(|span| (span.lo(), span.hi()));
157157

158158
// We try to make the output have fewer overlapping spans if possible.
159-
let (require_msg, require_span) = if sup_origin.span().overlaps(return_sp) {
160-
("...is captured and required to live as long as `'static` here", sup_origin.span())
159+
let require_msg = if spans.is_empty() {
160+
"...is captured and required to live as long as `'static` here"
161161
} else {
162-
("...and is required to live as long as `'static` here", return_sp)
162+
"...and is required to live as long as `'static` here"
163163
};
164+
let require_span =
165+
if sup_origin.span().overlaps(return_sp) { sup_origin.span() } else { return_sp };
164166

165167
for span in &spans {
166168
err.span_label(*span, "...is captured here...");

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn resolve<'tcx>(
4848

4949
values.values.iter_mut().for_each(|v| match *v {
5050
VarValue::Value(ref mut r) => *r = re_erased,
51-
VarValue::ErrorValue => {}
51+
VarValue::ErrorValue(_) => {}
5252
});
5353
(values, errors)
5454
}
@@ -69,7 +69,7 @@ pub struct LexicalRegionResolutions<'tcx> {
6969
#[derive(Copy, Clone, Debug)]
7070
enum VarValue<'tcx> {
7171
Value(Region<'tcx>),
72-
ErrorValue,
72+
ErrorValue(RegionVid),
7373
}
7474

7575
#[derive(Clone, Debug)]
@@ -233,7 +233,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
233233
(None, a_region, b_vid, b_data)
234234
}
235235
Constraint::VarSubVar(a_vid, b_vid) => match *var_values.value(a_vid) {
236-
VarValue::ErrorValue => continue,
236+
VarValue::ErrorValue(_) => continue,
237237
VarValue::Value(a_region) => {
238238
let b_data = var_values.value_mut(b_vid);
239239
(Some(a_vid), a_region, b_vid, b_data)
@@ -250,7 +250,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
250250
}
251251
if let Some(a_vid) = a_vid {
252252
match *b_data {
253-
VarValue::Value(ReStatic) | VarValue::ErrorValue => (),
253+
VarValue::Value(ReStatic) | VarValue::ErrorValue(_) => (),
254254
_ => {
255255
constraints[a_vid].push((a_vid, b_vid));
256256
constraints[b_vid].push((a_vid, b_vid));
@@ -262,14 +262,14 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
262262
while let Some(vid) = changes.pop() {
263263
constraints[vid].retain(|&(a_vid, b_vid)| {
264264
let a_region = match *var_values.value(a_vid) {
265-
VarValue::ErrorValue => return false,
265+
VarValue::ErrorValue(_) => return false,
266266
VarValue::Value(a_region) => a_region,
267267
};
268268
let b_data = var_values.value_mut(b_vid);
269269
if self.expand_node(a_region, b_vid, b_data) {
270270
changes.push(b_vid);
271271
}
272-
!matches!(b_data, VarValue::Value(ReStatic) | VarValue::ErrorValue)
272+
!matches!(b_data, VarValue::Value(ReStatic) | VarValue::ErrorValue(_))
273273
});
274274
}
275275
}
@@ -332,7 +332,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
332332
true
333333
}
334334

335-
VarValue::ErrorValue => false,
335+
VarValue::ErrorValue(_) => false,
336336
}
337337
}
338338

@@ -476,7 +476,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
476476
debug!("contraction: {:?} == {:?}, {:?}", a_vid, a_data, b_region);
477477

478478
let a_region = match *a_data {
479-
VarValue::ErrorValue => continue,
479+
VarValue::ErrorValue(_) => continue,
480480
VarValue::Value(a_region) => a_region,
481481
};
482482

@@ -489,7 +489,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
489489
cannot verify that {:?}={:?} <= {:?}",
490490
origin, a_vid, a_region, b_region
491491
);
492-
*a_data = VarValue::ErrorValue;
492+
*a_data = VarValue::ErrorValue(a_vid);
493493
}
494494
}
495495
}
@@ -545,7 +545,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
545545
for (node_vid, value) in var_data.values.iter_enumerated() {
546546
match *value {
547547
VarValue::Value(_) => { /* Inference successful */ }
548-
VarValue::ErrorValue => {
548+
VarValue::ErrorValue(reg) => {
549549
// Inference impossible: this value contains
550550
// inconsistent constraints.
551551
//
@@ -577,9 +577,10 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
577577
.constraints
578578
.iter()
579579
.filter_map(|(constraint, origin)| match (constraint, origin) {
580-
(Constraint::VarSubVar(_, _), SubregionOrigin::DataBorrowed(_, sp)) => {
581-
Some(*sp)
582-
}
580+
(
581+
Constraint::VarSubVar(_, sup),
582+
SubregionOrigin::DataBorrowed(_, sp),
583+
) if sup == &reg => Some(*sp),
583584
_ => None,
584585
})
585586
.collect();
@@ -898,7 +899,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
898899
pub fn resolve_var(&self, rid: RegionVid) -> ty::Region<'tcx> {
899900
let result = match self.values[rid] {
900901
VarValue::Value(r) => r,
901-
VarValue::ErrorValue => self.error_region,
902+
VarValue::ErrorValue(_) => self.error_region,
902903
};
903904
debug!("resolve_var({:?}) = {:?}", rid, result);
904905
result

src/test/ui/async-await/issues/issue-62097.stderr

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'
44
LL | pub async fn run_dummy_fn(&self) {
55
| ^^^^^ this data with an anonymous lifetime `'_`...
66
LL | foo(|| self.bar()).await;
7-
| ------------------------ ...is captured here...
7+
| --- ...is captured and required to live as long as `'static` here
88
|
9-
note: ...and is required to live as long as `'static` here
10-
--> $DIR/issue-62097.rs:13:9
11-
|
12-
LL | foo(|| self.bar()).await;
13-
| ^^^
149
note: `'static` lifetime requirement introduced by this bound
1510
--> $DIR/issue-62097.rs:4:19
1611
|

0 commit comments

Comments
 (0)