1
Fork 0

Revert "Use Predicate ConstraintCategory when normalizing"

This reverts commit aae37f8763.
This commit is contained in:
Jack Huey 2022-09-16 09:01:28 -04:00
parent df34db9b03
commit bba514b7b4
14 changed files with 15 additions and 172 deletions

View file

@ -21,7 +21,10 @@ pub(crate) struct OutlivesConstraintSet<'tcx> {
impl<'tcx> OutlivesConstraintSet<'tcx> { impl<'tcx> OutlivesConstraintSet<'tcx> {
pub(crate) fn push(&mut self, constraint: OutlivesConstraint<'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 { if constraint.sup == constraint.sub {
// 'a: 'a is pretty uninteresting // 'a: 'a is pretty uninteresting
return; return;

View file

@ -31,7 +31,7 @@ use crate::session_diagnostics::{
}; };
use super::{OutlivesSuggestionBuilder, RegionName}; use super::{OutlivesSuggestionBuilder, RegionName};
use crate::region_infer::{BlameConstraint, ExtraConstraintInfo}; use crate::region_infer::BlameConstraint;
use crate::{ use crate::{
nll::ConstraintDescription, nll::ConstraintDescription,
region_infer::{values::RegionElement, TypeTest}, region_infer::{values::RegionElement, TypeTest},
@ -354,11 +354,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
) { ) {
debug!("report_region_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr); debug!("report_region_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
let (blame_constraint, extra_info) = let BlameConstraint { category, cause, variance_info, .. } = self
self.regioncx.best_blame_constraint(fr, fr_origin, |r| { .regioncx
.best_blame_constraint(fr, fr_origin, |r| {
self.regioncx.provides_universal_region(r, fr, outlived_fr) self.regioncx.provides_universal_region(r, fr, outlived_fr)
}); })
let BlameConstraint { category, cause, variance_info, .. } = blame_constraint; .0;
debug!("report_region_error: category={:?} {:?} {:?}", category, cause, variance_info); debug!("report_region_error: category={:?} {:?} {:?}", category, cause, variance_info);
@ -467,14 +468,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); self.buffer_error(diag);
} }
@ -566,7 +559,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
/// LL | ref_obj(x) /// LL | ref_obj(x)
/// | ^^^^^^^^^^ `x` escapes the function body here /// | ^^^^^^^^^^ `x` escapes the function body here
/// ``` /// ```
#[instrument(level = "debug", skip(self))]
fn report_escaping_data_error( fn report_escaping_data_error(
&self, &self,
errci: &ErrorConstraintInfo<'tcx>, errci: &ErrorConstraintInfo<'tcx>,

View file

@ -104,7 +104,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
); );
} }
#[instrument(level = "debug", skip(self))]
pub(super) fn normalize_and_prove_instantiated_predicates( pub(super) fn normalize_and_prove_instantiated_predicates(
&mut self, &mut self,
// Keep this parameter for now, in case we start using // Keep this parameter for now, in case we start using
@ -119,9 +118,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
.zip(instantiated_predicates.spans.into_iter()) .zip(instantiated_predicates.spans.into_iter())
{ {
debug!(?predicate); debug!(?predicate);
let category = ConstraintCategory::Predicate(span); let predicate = self.normalize(predicate, locations);
let predicate = self.normalize_with_category(predicate, locations, category); self.prove_predicate(predicate, locations, ConstraintCategory::Predicate(span));
self.prove_predicate(predicate, locations, category);
} }
} }
@ -157,27 +155,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")] #[instrument(skip(self), level = "debug")]
pub(super) fn normalize_with_category<T>( pub(super) fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
&mut self,
value: T,
location: impl NormalizeLocation,
category: ConstraintCategory<'tcx>,
) -> T
where where
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx, T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
{ {
let param_env = self.param_env; let param_env = self.param_env;
self.fully_perform_op( self.fully_perform_op(
location.to_locations(), location.to_locations(),
category, ConstraintCategory::Boring,
param_env.and(type_op::normalize::Normalize::new(value)), param_env.and(type_op::normalize::Normalize::new(value)),
) )
.unwrap_or_else(|NoSolution| { .unwrap_or_else(|NoSolution| {

View file

@ -312,8 +312,6 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
} }
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) { fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
debug!(?constant, ?location, "visit_constant");
self.super_constant(constant, location); self.super_constant(constant, location);
let ty = self.sanitize_type(constant, constant.literal.ty()); let ty = self.sanitize_type(constant, constant.literal.ty());
@ -1813,8 +1811,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
} }
fn check_operand(&mut self, op: &Operand<'tcx>, location: Location) { fn check_operand(&mut self, op: &Operand<'tcx>, location: Location) {
debug!(?op, ?location, "check_operand");
if let Operand::Constant(constant) = op { if let Operand::Constant(constant) = op {
let maybe_uneval = match constant.literal { let maybe_uneval = match constant.literal {
ConstantKind::Ty(ct) => match ct.kind() { ConstantKind::Ty(ct) => match ct.kind() {

View file

@ -48,11 +48,10 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> {
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
debug!( debug!(
"normalize::<{}>(value={:?}, param_env={:?}, cause={:?})", "normalize::<{}>(value={:?}, param_env={:?})",
std::any::type_name::<T>(), std::any::type_name::<T>(),
value, value,
self.param_env, self.param_env,
self.cause,
); );
if !needs_normalization(&value, self.param_env.reveal()) { if !needs_normalization(&value, self.param_env.reveal()) {
return Ok(Normalized { value, obligations: vec![] }); return Ok(Normalized { value, obligations: vec![] });

View file

@ -1,40 +0,0 @@
// check-fail
// known-bug
// This gives us problems because `for<'a> I::Item<'a>: Debug` should mean "for
// all 'a where I::Item<'a> is WF", but really means "for all 'a possible"
trait LendingIterator: Sized {
type Item<'a>
where
Self: 'a;
fn next(&mut self) -> Self::Item<'_>;
}
fn fails<I: LendingIterator, F>(iter: &mut I, f: F) -> bool
where
F: FnMut(I::Item<'_>),
{
let mut iter2 = Eat(iter, f);
let _next = iter2.next();
//~^ borrowed data escapes
true
}
impl<I: LendingIterator> LendingIterator for &mut I {
type Item<'a> = I::Item<'a> where Self:'a;
fn next(&mut self) -> Self::Item<'_> {
(**self).next()
}
}
struct Eat<I, F>(I, F);
impl<I: LendingIterator, F> Iterator for Eat<I, F>
where
F: FnMut(I::Item<'_>),
{
type Item = ();
fn next(&mut self) -> Option<Self::Item> {
None
}
}
fn main() {}

View file

@ -1,22 +0,0 @@
error[E0521]: borrowed data escapes outside of function
--> $DIR/hrtb-implied-2.rs:18:17
|
LL | fn fails<I: LendingIterator, F>(iter: &mut I, f: F) -> bool
| ---- - let's call the lifetime of this reference `'1`
| |
| `iter` is a reference that is only valid in the function body
...
LL | let _next = iter2.next();
| ^^^^^^^^^^^^
| |
| `iter` escapes the function body here
| argument requires that `'1` must outlive `'static`
|
= note: requirement occurs because of a mutable reference to `Eat<&mut I, F>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
= note: due to current limitations in the borrow checker, this implies a `'static` lifetime
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View file

@ -1,23 +0,0 @@
trait LendingIterator {
type Item<'a>
where
Self: 'a;
}
impl LendingIterator for &str {
type Item<'a> = () where Self:'a;
}
fn trivial_bound<I>(_: I)
where
I: LendingIterator,
for<'a> I::Item<'a>: Sized,
{
}
fn fails(iter: &str) {
trivial_bound(iter);
//~^ borrowed data escapes
}
fn main() {}

View file

@ -1,22 +0,0 @@
error[E0521]: borrowed data escapes outside of function
--> $DIR/hrtb-implied-3.rs:19:5
|
LL | fn fails(iter: &str) {
| ---- - let's call the lifetime of this reference `'1`
| |
| `iter` is a reference that is only valid in the function body
LL | trivial_bound(iter);
| ^^^^^^^^^^^^^^^^^^^
| |
| `iter` escapes the function body here
| argument requires that `'1` must outlive `'static`
|
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
--> $DIR/hrtb-implied-3.rs:14:26
|
LL | for<'a> I::Item<'a>: Sized,
| ^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View file

@ -11,8 +11,6 @@ LL | x.size_hint().0
| | | |
| `x` escapes the function body here | `x` escapes the function body here
| argument requires that `'1` must outlive `'static` | argument requires that `'1` must outlive `'static`
|
= note: due to current limitations in the borrow checker, this implies a `'static` lifetime
error: aborting due to previous error error: aborting due to previous error

View file

@ -14,12 +14,6 @@ LL | fn give_some<'a>() {
| -- lifetime `'a` defined here | -- lifetime `'a` defined here
LL | want_hrtb::<&'a u32>() LL | want_hrtb::<&'a u32>()
| ^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` | ^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
|
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
--> $DIR/hrtb-just-for-static.rs:9:15
|
LL | where T : for<'a> Foo<&'a isize>
| ^^^^^^^^^^^^^^^^^^^^^^
error: implementation of `Foo` is not general enough error: implementation of `Foo` is not general enough
--> $DIR/hrtb-just-for-static.rs:30:5 --> $DIR/hrtb-just-for-static.rs:30:5

View file

@ -46,12 +46,6 @@ LL | fn foo_hrtb_bar_not<'b, T>(mut t: T)
... ...
LL | foo_hrtb_bar_not(&mut t); LL | foo_hrtb_bar_not(&mut t);
| ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static` | ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'static`
|
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
--> $DIR/hrtb-perfect-forwarding.rs:37:8
|
LL | T: for<'a> Foo<&'a isize> + Bar<&'b isize>,
| ^^^^^^^^^^^^^^^^^^^^^^
error: implementation of `Bar` is not general enough error: implementation of `Bar` is not general enough
--> $DIR/hrtb-perfect-forwarding.rs:43:5 --> $DIR/hrtb-perfect-forwarding.rs:43:5

View file

@ -5,12 +5,6 @@ LL | fn bar<'a>() {
| -- lifetime `'a` defined here | -- lifetime `'a` defined here
LL | foo::<&'a i32>(); LL | foo::<&'a i32>();
| ^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` | ^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
|
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
--> $DIR/issue-26217.rs:1:30
|
LL | fn foo<T>() where for<'a> T: 'a {}
| ^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -11,12 +11,6 @@ LL | fn test2<'a>() {
| -- lifetime `'a` defined here | -- lifetime `'a` defined here
LL | outlives_forall::<Value<'a>>(); LL | outlives_forall::<Value<'a>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
|
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
--> $DIR/type-test-universe.rs:6:16
|
LL | for<'u> T: 'u,
| ^^
error: aborting due to 2 previous errors error: aborting due to 2 previous errors