Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get back the more precise suggestion spans of old regionck #87311

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, RegionVid, Ty};
use rustc_span::symbol::{kw, sym};
use rustc_span::Span;
use rustc_span::{BytePos, Span};

use crate::util::borrowck_errors;

Expand Down Expand Up @@ -641,12 +641,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
} else {
"'_".to_string()
};
let suggestion = if snippet.ends_with(';') {
let span = if snippet.ends_with(';') {
// `type X = impl Trait;`
format!("{} + {};", &snippet[..snippet.len() - 1], suggestable_fr_name)
span.with_hi(span.hi() - BytePos(1))
} else {
format!("{} + {}", snippet, suggestable_fr_name)
span
};
let suggestion = format!(" + {}", suggestable_fr_name);
let span = span.shrink_to_hi();
diag.span_suggestion(
span,
&format!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | fn elided(x: &i32) -> impl Copy { x }
help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
|
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
| ^^^^^^^^^^^^^^
| ^^^^

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

error: lifetime may not live long enough
--> $DIR/must_outlive_least_region_or_bound.rs:7:46
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^

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

error: aborting due to 2 previous errors

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

error: aborting due to previous error

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

error: aborting due to previous error

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

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

error: aborting due to 4 previous errors