Skip to content

Commit

Permalink
Auto merge of rust-lang#101902 - jackh726:revert-static-hrtb-error, r…
Browse files Browse the repository at this point in the history
…=nikomatsakis

Partially revert rust-lang#101433

reverts rust-lang#101433 to fix rust-lang#101844

We should get this into the beta cut, since the ICE is getting hit quite a bit.
  • Loading branch information
bors committed Sep 16, 2022
2 parents 54f20bb + d97fdf1 commit 4d4e51e
Show file tree
Hide file tree
Showing 34 changed files with 179 additions and 495 deletions.
5 changes: 4 additions & 1 deletion compiler/rustc_borrowck/src/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ pub(crate) struct OutlivesConstraintSet<'tcx> {

impl<'tcx> OutlivesConstraintSet<'tcx> {
pub(crate) fn push(&mut self, constraint: OutlivesConstraint<'tcx>) {
debug!("OutlivesConstraintSet::push({:?})", constraint);
debug!(
"OutlivesConstraintSet::push({:?}: {:?} @ {:?}",
constraint.sup, constraint.sub, constraint.locations
);
if constraint.sup == constraint.sub {
// 'a: 'a is pretty uninteresting
return;
Expand Down
30 changes: 9 additions & 21 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_middle::ty::{self, RegionVid, TyCtxt};
use rustc_span::symbol::{kw, Symbol};
use rustc_span::{sym, DesugaringKind, Span};

use crate::region_infer::{BlameConstraint, ExtraConstraintInfo};
use crate::region_infer::BlameConstraint;
use crate::{
borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt,
WriteKind,
Expand All @@ -38,7 +38,6 @@ pub(crate) enum BorrowExplanation<'tcx> {
span: Span,
region_name: RegionName,
opt_place_desc: Option<String>,
extra_info: Vec<ExtraConstraintInfo>,
},
Unexplained,
}
Expand Down Expand Up @@ -244,7 +243,6 @@ impl<'tcx> BorrowExplanation<'tcx> {
ref region_name,
ref opt_place_desc,
from_closure: _,
ref extra_info,
} => {
region_name.highlight_region_name(err);

Expand All @@ -270,14 +268,6 @@ impl<'tcx> BorrowExplanation<'tcx> {
);
};

for extra in extra_info {
match extra {
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
err.span_note(*span, format!("due to current limitations in the borrow checker, this implies a `'static` lifetime"));
}
}
}

self.add_lifetime_bound_suggestion_to_diagnostic(err, &category, span, region_name);
}
_ => {}
Expand Down Expand Up @@ -319,17 +309,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&self,
borrow_region: RegionVid,
outlived_region: RegionVid,
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>, Vec<ExtraConstraintInfo>) {
let (blame_constraint, extra_info) = self.regioncx.best_blame_constraint(
borrow_region,
NllRegionVariableOrigin::FreeRegion,
|r| self.regioncx.provides_universal_region(r, borrow_region, outlived_region),
);
let BlameConstraint { category, from_closure, cause, .. } = blame_constraint;
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>) {
let BlameConstraint { category, from_closure, cause, variance_info: _ } = self
.regioncx
.best_blame_constraint(borrow_region, NllRegionVariableOrigin::FreeRegion, |r| {
self.regioncx.provides_universal_region(r, borrow_region, outlived_region)
});

let outlived_fr_name = self.give_region_a_name(outlived_region);

(category, from_closure, cause.span, outlived_fr_name, extra_info)
(category, from_closure, cause.span, outlived_fr_name)
}

/// Returns structured explanation for *why* the borrow contains the
Expand Down Expand Up @@ -401,7 +390,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

None => {
if let Some(region) = self.to_error_region_vid(borrow_region_vid) {
let (category, from_closure, span, region_name, extra_info) =
let (category, from_closure, span, region_name) =
self.free_region_constraint_info(borrow_region_vid, region);
if let Some(region_name) = region_name {
let opt_place_desc = self.describe_place(borrow.borrowed_place.as_ref());
Expand All @@ -411,7 +400,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
span,
region_name,
opt_place_desc,
extra_info,
}
} else {
debug!("Could not generate a region name");
Expand Down
14 changes: 2 additions & 12 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::session_diagnostics::{
};

use super::{OutlivesSuggestionBuilder, RegionName};
use crate::region_infer::{BlameConstraint, ExtraConstraintInfo};
use crate::region_infer::BlameConstraint;
use crate::{
nll::ConstraintDescription,
region_infer::{values::RegionElement, TypeTest},
Expand Down Expand Up @@ -354,11 +354,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
) {
debug!("report_region_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);

let (blame_constraint, extra_info) =
let BlameConstraint { category, cause, variance_info, from_closure: _ } =
self.regioncx.best_blame_constraint(fr, fr_origin, |r| {
self.regioncx.provides_universal_region(r, fr, outlived_fr)
});
let BlameConstraint { category, cause, variance_info, .. } = blame_constraint;

debug!("report_region_error: category={:?} {:?} {:?}", category, cause, variance_info);

Expand Down Expand Up @@ -467,14 +466,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
}

for extra in extra_info {
match extra {
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
diag.span_note(span, format!("due to current limitations in the borrow checker, this implies a `'static` lifetime"));
}
}
}

self.buffer_error(diag);
}

Expand Down Expand Up @@ -566,7 +557,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
/// LL | ref_obj(x)
/// | ^^^^^^^^^^ `x` escapes the function body here
/// ```
#[instrument(level = "debug", skip(self))]
fn report_escaping_data_error(
&self,
errci: &ErrorConstraintInfo<'tcx>,
Expand Down
49 changes: 11 additions & 38 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,6 @@ enum Trace<'tcx> {
NotVisited,
}

#[derive(Clone, PartialEq, Eq, Debug)]
pub enum ExtraConstraintInfo {
PlaceholderFromPredicate(Span),
}

impl<'tcx> RegionInferenceContext<'tcx> {
/// Creates a new region inference context with a total of
/// `num_region_variables` valid inference variables; the first N
Expand Down Expand Up @@ -1823,9 +1818,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
fr1_origin: NllRegionVariableOrigin,
fr2: RegionVid,
) -> (ConstraintCategory<'tcx>, ObligationCause<'tcx>) {
let BlameConstraint { category, cause, .. } = self
.best_blame_constraint(fr1, fr1_origin, |r| self.provides_universal_region(r, fr1, fr2))
.0;
let BlameConstraint { category, cause, .. } =
self.best_blame_constraint(fr1, fr1_origin, |r| {
self.provides_universal_region(r, fr1, fr2)
});
(category, cause)
}

Expand Down Expand Up @@ -2014,7 +2010,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
from_region: RegionVid,
from_region_origin: NllRegionVariableOrigin,
target_test: impl Fn(RegionVid) -> bool,
) -> (BlameConstraint<'tcx>, Vec<ExtraConstraintInfo>) {
) -> BlameConstraint<'tcx> {
// Find all paths
let (path, target_region) =
self.find_constraint_paths_between_regions(from_region, target_test).unwrap();
Expand All @@ -2030,18 +2026,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
.collect::<Vec<_>>()
);

let mut extra_info = vec![];
for constraint in path.iter() {
let outlived = constraint.sub;
let Some(origin) = self.var_infos.get(outlived) else { continue; };
let RegionVariableOrigin::Nll(NllRegionVariableOrigin::Placeholder(p)) = origin.origin else { continue; };
debug!(?constraint, ?p);
let ConstraintCategory::Predicate(span) = constraint.category else { continue; };
extra_info.push(ExtraConstraintInfo::PlaceholderFromPredicate(span));
// We only want to point to one
break;
}

// We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint.
// Instead, we use it to produce an improved `ObligationCauseCode`.
// FIXME - determine what we should do if we encounter multiple `ConstraintCategory::Predicate`
Expand Down Expand Up @@ -2089,7 +2073,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
from_closure,
cause: ObligationCause::new(span, CRATE_HIR_ID, cause_code),
variance_info: constraint.variance_info,
outlives_constraint: *constraint,
}
})
.collect();
Expand Down Expand Up @@ -2191,7 +2174,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let best_choice =
if blame_source { range.rev().find(find_region) } else { range.find(find_region) };

debug!(?best_choice, ?blame_source, ?extra_info);
debug!(?best_choice, ?blame_source);

if let Some(i) = best_choice {
if let Some(next) = categorized_path.get(i + 1) {
Expand All @@ -2200,7 +2183,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
{
// The return expression is being influenced by the return type being
// impl Trait, point at the return type and not the return expr.
return (next.clone(), extra_info);
return next.clone();
}
}

Expand All @@ -2220,7 +2203,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
}
}

return (categorized_path[i].clone(), extra_info);
return categorized_path[i].clone();
}

// If that search fails, that is.. unusual. Maybe everything
Expand All @@ -2230,7 +2213,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
categorized_path.sort_by(|p0, p1| p0.category.cmp(&p1.category));
debug!("sorted_path={:#?}", categorized_path);

(categorized_path.remove(0), extra_info)
categorized_path.remove(0)
}

pub(crate) fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
Expand Down Expand Up @@ -2312,13 +2295,7 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
outlives_requirement={:?}",
region, outlived_region, outlives_requirement,
);
(
ty::Binder::dummy(ty::OutlivesPredicate(
region.into(),
outlived_region,
)),
ConstraintCategory::BoringNoLocation,
)
ty::Binder::dummy(ty::OutlivesPredicate(region.into(), outlived_region))
}

ClosureOutlivesSubject::Ty(ty) => {
Expand All @@ -2328,10 +2305,7 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
outlives_requirement={:?}",
ty, outlived_region, outlives_requirement,
);
(
ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), outlived_region)),
ConstraintCategory::BoringNoLocation,
)
ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), outlived_region))
}
}
})
Expand All @@ -2345,5 +2319,4 @@ pub struct BlameConstraint<'tcx> {
pub from_closure: bool,
pub cause: ObligationCause<'tcx>,
pub variance_info: ty::VarianceDiagInfo<'tcx>,
pub outlives_constraint: OutlivesConstraint<'tcx>,
}
26 changes: 5 additions & 21 deletions compiler/rustc_borrowck/src/type_check/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
/// constraints should occur within this method so that those
/// constraints can be properly localized!**
#[instrument(skip(self, op), level = "trace")]
pub(super) fn fully_perform_op<R: fmt::Debug, Op>(
pub(super) fn fully_perform_op<R, Op>(
&mut self,
locations: Locations,
category: ConstraintCategory<'tcx>,
Expand All @@ -39,8 +39,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {

let TypeOpOutput { output, constraints, error_info } = op.fully_perform(self.infcx)?;

debug!(?output, ?constraints);

if let Some(data) = constraints {
self.push_region_constraints(locations, category, data);
}
Expand Down Expand Up @@ -104,7 +102,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
);
}

#[instrument(level = "debug", skip(self))]
pub(super) fn normalize_and_prove_instantiated_predicates(
&mut self,
// Keep this parameter for now, in case we start using
Expand All @@ -119,9 +116,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
.zip(instantiated_predicates.spans.into_iter())
{
debug!(?predicate);
let category = ConstraintCategory::Predicate(span);
let predicate = self.normalize_with_category(predicate, locations, category);
self.prove_predicate(predicate, locations, category);
let predicate = self.normalize(predicate, locations);
self.prove_predicate(predicate, locations, ConstraintCategory::Predicate(span));
}
}

Expand Down Expand Up @@ -157,27 +153,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
})
}

pub(super) fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
where
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
{
self.normalize_with_category(value, location, ConstraintCategory::Boring)
}

#[instrument(skip(self), level = "debug")]
pub(super) fn normalize_with_category<T>(
&mut self,
value: T,
location: impl NormalizeLocation,
category: ConstraintCategory<'tcx>,
) -> T
pub(super) fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
where
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
{
let param_env = self.param_env;
self.fully_perform_op(
location.to_locations(),
category,
ConstraintCategory::Boring,
param_env.and(type_op::normalize::Normalize::new(value)),
)
.unwrap_or_else(|NoSolution| {
Expand Down
Loading

0 comments on commit 4d4e51e

Please sign in to comment.