Skip to content

Commit b3594f0

Browse files
committed
Get back the more precise suggestion spans of old regionck
1 parent a72c360 commit b3594f0

6 files changed

+14
-12
lines changed

compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
99
use rustc_middle::ty::subst::Subst;
1010
use rustc_middle::ty::{self, RegionVid, Ty};
1111
use rustc_span::symbol::{kw, sym};
12-
use rustc_span::Span;
12+
use rustc_span::{BytePos, Span};
1313

1414
use crate::util::borrowck_errors;
1515

@@ -641,12 +641,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
641641
} else {
642642
"'_".to_string()
643643
};
644-
let suggestion = if snippet.ends_with(';') {
644+
let span = if snippet.ends_with(';') {
645645
// `type X = impl Trait;`
646-
format!("{} + {};", &snippet[..snippet.len() - 1], suggestable_fr_name)
646+
span.with_hi(span.hi() - BytePos(1))
647647
} else {
648-
format!("{} + {}", snippet, suggestable_fr_name)
648+
span
649649
};
650+
let suggestion = format!(" + {}", suggestable_fr_name);
651+
let span = span.shrink_to_hi();
650652
diag.span_suggestion(
651653
span,
652654
&format!(

src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | fn elided(x: &i32) -> impl Copy { x }
99
help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
1010
|
1111
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
12-
| ^^^^^^^^^^^^^^
12+
| ^^^^
1313

1414
error: lifetime may not live long enough
1515
--> $DIR/must_outlive_least_region_or_bound.rs:5:32
@@ -23,7 +23,7 @@ LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
2323
help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound
2424
|
2525
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
26-
| ^^^^^^^^^^^^^^
26+
| ^^^^
2727

2828
error: lifetime may not live long enough
2929
--> $DIR/must_outlive_least_region_or_bound.rs:7:46

src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
99
help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
1010
|
1111
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
12-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
| ^^^^
1313

1414
error: lifetime may not live long enough
1515
--> $DIR/static-return-lifetime-infered.rs:9:37
@@ -23,7 +23,7 @@ LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
2323
help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound
2424
|
2525
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
| ^^^^
2727

2828
error: aborting due to 2 previous errors
2929

src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
99
help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
1010
|
1111
LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
12-
| ^^^^^^^^^^^^^^^
12+
| ^^^^
1313

1414
error: aborting due to previous error
1515

src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | fn f(self: Pin<&Self>) -> impl Clone { self }
99
help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
1010
|
1111
LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
12-
| ^^^^^^^^^^^^^^^
12+
| ^^^^
1313

1414
error: aborting due to previous error
1515

src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.nll.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> {
99
help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
1010
|
1111
LL | fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> + '_ {
12-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
| ^^^^
1313

1414
error: lifetime may not live long enough
1515
--> $DIR/trait-object-nested-in-impl-trait.rs:39:9
@@ -47,7 +47,7 @@ LL | fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> {
4747
help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound
4848
|
4949
LL | fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> + 'a {
50-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
| ^^^^
5151

5252
error: aborting due to 4 previous errors
5353

0 commit comments

Comments
 (0)