only avoid blaming assignments from argument patterns
This commit is contained in:
parent
1b2281a493
commit
fe8b12f8cf
14 changed files with 54 additions and 67 deletions
|
@ -2911,7 +2911,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
(
|
||||
name,
|
||||
BorrowExplanation::MustBeValidFor {
|
||||
category: ConstraintCategory::Assignment { .. },
|
||||
category: ConstraintCategory::Assignment,
|
||||
from_closure: false,
|
||||
region_name:
|
||||
RegionName {
|
||||
|
|
|
@ -41,7 +41,7 @@ impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
|
|||
fn description(&self) -> &'static str {
|
||||
// Must end with a space. Allows for empty names to be provided.
|
||||
match self {
|
||||
ConstraintCategory::Assignment { .. } => "assignment ",
|
||||
ConstraintCategory::Assignment => "assignment ",
|
||||
ConstraintCategory::Return(_) => "returning this value ",
|
||||
ConstraintCategory::Yield => "yielding this value ",
|
||||
ConstraintCategory::UseAsConst => "using this value as a constant ",
|
||||
|
@ -481,7 +481,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
(ConstraintCategory::Return(kind), true, false) if self.is_closure_fn_mut(fr) => {
|
||||
self.report_fnmut_error(&errci, kind)
|
||||
}
|
||||
(ConstraintCategory::Assignment { .. }, true, false)
|
||||
(ConstraintCategory::Assignment, true, false)
|
||||
| (ConstraintCategory::CallArgument(_), true, false) => {
|
||||
let mut db = self.report_escaping_data_error(&errci);
|
||||
|
||||
|
@ -673,7 +673,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
// Revert to the normal error in these cases.
|
||||
// Assignments aren't "escapes" in function items.
|
||||
if (fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none())
|
||||
|| (matches!(category, ConstraintCategory::Assignment { .. })
|
||||
|| (*category == ConstraintCategory::Assignment
|
||||
&& self.regioncx.universal_regions().defining_ty.is_fn_def())
|
||||
|| self.regioncx.universal_regions().defining_ty.is_const()
|
||||
{
|
||||
|
|
|
@ -2080,25 +2080,22 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
| ConstraintCategory::CallArgument(_)
|
||||
| ConstraintCategory::CopyBound
|
||||
| ConstraintCategory::SizedBound
|
||||
| ConstraintCategory::Assignment { has_interesting_ty: true }
|
||||
| ConstraintCategory::Assignment
|
||||
| ConstraintCategory::Usage
|
||||
| ConstraintCategory::ClosureUpvar(_) => 2,
|
||||
// Give assignments a lower priority when flagged as less likely to be interesting.
|
||||
// In particular, de-prioritize MIR assignments lowered from argument patterns.
|
||||
ConstraintCategory::Assignment { has_interesting_ty: false } => 3,
|
||||
// Generic arguments are unlikely to be what relates regions together
|
||||
ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg) => 4,
|
||||
ConstraintCategory::TypeAnnotation(AnnotationSource::GenericArg) => 3,
|
||||
// We handle predicates and opaque types specially; don't prioritize them here.
|
||||
ConstraintCategory::Predicate(_) | ConstraintCategory::OpaqueType => 5,
|
||||
ConstraintCategory::Predicate(_) | ConstraintCategory::OpaqueType => 4,
|
||||
// `Boring` constraints can correspond to user-written code and have useful spans,
|
||||
// but don't provide any other useful information for diagnostics.
|
||||
ConstraintCategory::Boring => 6,
|
||||
ConstraintCategory::Boring => 5,
|
||||
// `BoringNoLocation` constraints can point to user-written code, but are less
|
||||
// specific, and are not used for relations that would make sense to blame.
|
||||
ConstraintCategory::BoringNoLocation => 7,
|
||||
ConstraintCategory::BoringNoLocation => 6,
|
||||
// Do not blame internal constraints.
|
||||
ConstraintCategory::Internal => 8,
|
||||
ConstraintCategory::IllegalUniverse => 9,
|
||||
ConstraintCategory::Internal => 7,
|
||||
ConstraintCategory::IllegalUniverse => 8,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -892,18 +892,20 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
Some(l) if !body.local_decls[l].is_user_variable() => {
|
||||
ConstraintCategory::Boring
|
||||
}
|
||||
Some(l) => ConstraintCategory::Assignment {
|
||||
has_interesting_ty: body.local_decls[l].user_ty.is_some()
|
||||
|| matches!(
|
||||
body.local_decls[l].local_info(),
|
||||
LocalInfo::User(BindingForm::Var(VarBindingForm {
|
||||
opt_ty_info: Some(_),
|
||||
..
|
||||
}))
|
||||
),
|
||||
},
|
||||
// Assignments to projections should be considered interesting.
|
||||
_ => ConstraintCategory::Assignment { has_interesting_ty: true },
|
||||
Some(_)
|
||||
if let Some(body_id) = tcx
|
||||
.hir_node_by_def_id(body.source.def_id().expect_local())
|
||||
.body_id()
|
||||
&& let params = tcx.hir().body(body_id).params
|
||||
&& params
|
||||
.iter()
|
||||
.any(|param| param.span.contains(stmt.source_info.span)) =>
|
||||
{
|
||||
// Assignments generated from lowering argument patterns shouldn't be called
|
||||
// "assignments" in diagnostics and aren't interesting to blame for errors.
|
||||
ConstraintCategory::Boring
|
||||
}
|
||||
_ => ConstraintCategory::Assignment,
|
||||
};
|
||||
debug!(
|
||||
"assignment category: {:?} {:?}",
|
||||
|
@ -1238,7 +1240,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
ConstraintCategory::Boring
|
||||
}
|
||||
// The return type of a call is interesting for diagnostics.
|
||||
_ => ConstraintCategory::Assignment { has_interesting_ty: true },
|
||||
_ => ConstraintCategory::Assignment,
|
||||
};
|
||||
|
||||
let locations = term_location.to_locations();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue