best_blame_constraint
: avoid blaming constraints from MIR generated by desugaring
This commit is contained in:
parent
2864906fce
commit
31e4d8175a
7 changed files with 36 additions and 33 deletions
|
@ -22,6 +22,7 @@ use rustc_middle::ty::fold::fold_regions;
|
||||||
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex};
|
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex};
|
||||||
use rustc_mir_dataflow::points::DenseLocationMap;
|
use rustc_mir_dataflow::points::DenseLocationMap;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
use rustc_span::hygiene::DesugaringKind;
|
||||||
use tracing::{debug, instrument, trace};
|
use tracing::{debug, instrument, trace};
|
||||||
|
|
||||||
use crate::BorrowckInferCtxt;
|
use crate::BorrowckInferCtxt;
|
||||||
|
@ -2033,7 +2034,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
| ConstraintCategory::BoringNoLocation
|
| ConstraintCategory::BoringNoLocation
|
||||||
| ConstraintCategory::Internal
|
| ConstraintCategory::Internal
|
||||||
| ConstraintCategory::Predicate(_)
|
| ConstraintCategory::Predicate(_)
|
||||||
)
|
) && constraint.span.desugaring_kind().is_none_or(|kind| {
|
||||||
|
// Try to avoid blaming constraints from desugarings, since they may not clearly
|
||||||
|
// clearly match what users have written. As an exception, allow blaming returns
|
||||||
|
// generated by `?` desugaring, since the correspondence is fairly clear.
|
||||||
|
kind == DesugaringKind::QuestionMark
|
||||||
|
&& matches!(constraint.category, ConstraintCategory::Return(_))
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
let best_choice = if blame_source {
|
let best_choice = if blame_source {
|
||||||
|
|
|
@ -17,8 +17,8 @@ impl<'a> Future for ListFut<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fut(bufs: &mut [&mut [u8]]) {
|
async fn fut(bufs: &mut [&mut [u8]]) {
|
||||||
//~^ ERROR lifetime may not live long enough
|
|
||||||
ListFut(bufs).await
|
ListFut(bufs).await
|
||||||
|
//~^ ERROR lifetime may not live long enough
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ListFut2<'a>(&'a mut [&'a mut [u8]]);
|
pub struct ListFut2<'a>(&'a mut [&'a mut [u8]]);
|
||||||
|
@ -31,8 +31,8 @@ impl<'a> Future for ListFut2<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fut2(bufs: &mut [&mut [u8]]) -> i32 {
|
async fn fut2(bufs: &mut [&mut [u8]]) -> i32 {
|
||||||
//~^ ERROR lifetime may not live long enough
|
|
||||||
ListFut2(bufs).await
|
ListFut2(bufs).await
|
||||||
|
//~^ ERROR lifetime may not live long enough
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
error: lifetime may not live long enough
|
error: lifetime may not live long enough
|
||||||
--> $DIR/issue-76547.rs:19:14
|
--> $DIR/issue-76547.rs:20:13
|
||||||
|
|
|
|
||||||
LL | async fn fut(bufs: &mut [&mut [u8]]) {
|
LL | async fn fut(bufs: &mut [&mut [u8]]) {
|
||||||
| ^^^^ - - let's call the lifetime of this reference `'2`
|
| - - let's call the lifetime of this reference `'2`
|
||||||
| | |
|
| |
|
||||||
| | let's call the lifetime of this reference `'1`
|
| let's call the lifetime of this reference `'1`
|
||||||
| assignment requires that `'1` must outlive `'2`
|
LL | ListFut(bufs).await
|
||||||
|
| ^^^^ this usage requires that `'1` must outlive `'2`
|
||||||
|
|
|
|
||||||
help: consider introducing a named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
||||||
|
|
|
|
||||||
|
@ -13,13 +14,14 @@ LL | async fn fut<'a>(bufs: &'a mut [&'a mut [u8]]) {
|
||||||
| ++++ ++ ++
|
| ++++ ++ ++
|
||||||
|
|
||||||
error: lifetime may not live long enough
|
error: lifetime may not live long enough
|
||||||
--> $DIR/issue-76547.rs:33:15
|
--> $DIR/issue-76547.rs:34:14
|
||||||
|
|
|
|
||||||
LL | async fn fut2(bufs: &mut [&mut [u8]]) -> i32 {
|
LL | async fn fut2(bufs: &mut [&mut [u8]]) -> i32 {
|
||||||
| ^^^^ - - let's call the lifetime of this reference `'2`
|
| - - let's call the lifetime of this reference `'2`
|
||||||
| | |
|
| |
|
||||||
| | let's call the lifetime of this reference `'1`
|
| let's call the lifetime of this reference `'1`
|
||||||
| assignment requires that `'1` must outlive `'2`
|
LL | ListFut2(bufs).await
|
||||||
|
| ^^^^ this usage requires that `'1` must outlive `'2`
|
||||||
|
|
|
|
||||||
help: consider introducing a named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
||||||
|
|
|
|
||||||
|
|
|
@ -11,8 +11,8 @@ impl Xyz {
|
||||||
&'a self, foo: &dyn Foo
|
&'a self, foo: &dyn Foo
|
||||||
) -> &dyn Foo //~ WARNING elided lifetime has a name
|
) -> &dyn Foo //~ WARNING elided lifetime has a name
|
||||||
{
|
{
|
||||||
//~^ ERROR explicit lifetime required in the type of `foo` [E0621]
|
|
||||||
foo
|
foo
|
||||||
|
//~^ ERROR explicit lifetime required in the type of `foo` [E0621]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,16 +10,13 @@ LL | ) -> &dyn Foo
|
||||||
= note: `#[warn(elided_named_lifetimes)]` on by default
|
= note: `#[warn(elided_named_lifetimes)]` on by default
|
||||||
|
|
||||||
error[E0621]: explicit lifetime required in the type of `foo`
|
error[E0621]: explicit lifetime required in the type of `foo`
|
||||||
--> $DIR/issue-63388-1.rs:13:5
|
--> $DIR/issue-63388-1.rs:14:9
|
||||||
|
|
|
|
||||||
LL | &'a self, foo: &dyn Foo
|
LL | &'a self, foo: &dyn Foo
|
||||||
| -------- help: add explicit lifetime `'a` to the type of `foo`: `&'a (dyn Foo + 'a)`
|
| -------- help: add explicit lifetime `'a` to the type of `foo`: `&'a (dyn Foo + 'a)`
|
||||||
LL | ) -> &dyn Foo
|
...
|
||||||
LL | / {
|
LL | foo
|
||||||
LL | |
|
| ^^^ lifetime `'a` required
|
||||||
LL | | foo
|
|
||||||
LL | | }
|
|
||||||
| |_____^ lifetime `'a` required
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error; 1 warning emitted
|
error: aborting due to 1 previous error; 1 warning emitted
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@ impl Xyz {
|
||||||
foo: &dyn Foo, bar: &'a dyn Foo
|
foo: &dyn Foo, bar: &'a dyn Foo
|
||||||
) -> &dyn Foo //~ ERROR missing lifetime specifier
|
) -> &dyn Foo //~ ERROR missing lifetime specifier
|
||||||
{
|
{
|
||||||
//~^ ERROR explicit lifetime required in the type of `foo` [E0621]
|
|
||||||
foo
|
foo
|
||||||
|
//~^ ERROR explicit lifetime required in the type of `foo` [E0621]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,16 +13,13 @@ LL | ) -> &'a dyn Foo
|
||||||
| ++
|
| ++
|
||||||
|
|
||||||
error[E0621]: explicit lifetime required in the type of `foo`
|
error[E0621]: explicit lifetime required in the type of `foo`
|
||||||
--> $DIR/issue-63388-2.rs:13:5
|
--> $DIR/issue-63388-2.rs:14:9
|
||||||
|
|
|
|
||||||
LL | foo: &dyn Foo, bar: &'a dyn Foo
|
LL | foo: &dyn Foo, bar: &'a dyn Foo
|
||||||
| -------- help: add explicit lifetime `'a` to the type of `foo`: `&'a (dyn Foo + 'a)`
|
| -------- help: add explicit lifetime `'a` to the type of `foo`: `&'a (dyn Foo + 'a)`
|
||||||
LL | ) -> &dyn Foo
|
...
|
||||||
LL | / {
|
LL | foo
|
||||||
LL | |
|
| ^^^ lifetime `'a` required
|
||||||
LL | | foo
|
|
||||||
LL | | }
|
|
||||||
| |_____^ lifetime `'a` required
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue