Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
14 changes: 6 additions & 8 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,19 +853,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
self.eval_if_eq(infcx, generic_ty, lower_bound, *verify_if_eq_b)
}

VerifyBound::IsEmpty => {
let lower_bound_scc = self.constraint_sccs.scc(lower_bound);
self.scc_values.elements_contained_in(lower_bound_scc).next().is_none()
}

VerifyBound::OutlivedBy(r) => {
let r_vid = self.to_region_vid(*r);
self.eval_outlives(r_vid, lower_bound)
}

VerifyBound::AnyBound(verify_bounds) => verify_bounds.iter().any(|verify_bound| {
self.eval_verify_bound(infcx, generic_ty, lower_bound, verify_bound)
}),
VerifyBound::AnyBound(verify_bounds) => {
!verify_bounds.is_empty()
Comment thread
amandasystems marked this conversation as resolved.
&& verify_bounds.iter().any(|verify_bound| {
self.eval_verify_bound(infcx, generic_ty, lower_bound, verify_bound)
})
}

VerifyBound::AllBounds(verify_bounds) => verify_bounds.iter().all(|verify_bound| {
self.eval_verify_bound(infcx, generic_ty, lower_bound, verify_bound)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use rustc_infer::infer::outlives::env::RegionBoundPairs;
use rustc_infer::infer::outlives::obligations::{TypeOutlives, TypeOutlivesDelegate};
use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound};
use rustc_infer::traits::query::type_op::DeeplyNormalize;
use rustc_middle::bug;
use rustc_middle::ty::{
self, GenericArgKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, elaborate, fold_regions,
};
use rustc_middle::{bug, span_bug};
use rustc_span::Span;
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
use tracing::{debug, instrument};
Expand Down Expand Up @@ -240,6 +240,11 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
verify_bound: VerifyBound<'tcx>,
) -> TypeTest<'tcx> {
let lower_bound = self.to_region_vid(region);
if let VerifyBound::AnyBound(bs) = &verify_bound
&& bs.is_empty()
{
span_bug!(self.span, "No empty any bound should make it to borrow check!");
}
TypeTest { generic_kind, lower_bound, span: self.span, verify_bound }
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
self.sub_region_values(a, b)
}

VerifyBound::IsEmpty => match min.kind() {
// An empty bound holds for an empty variable.
VerifyBound::AnyBound(bs) if bs.is_empty() => match min.kind() {
ty::ReVar(rid) => match var_values.values[rid] {
VarValue::ErrorValue => false,
VarValue::Empty(_) => true,
Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_infer/src/infer/outlives/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,10 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
param_bounds.push(VerifyBound::OutlivedBy(r));
}

if param_bounds.is_empty() {
// We know that all types `T` outlive `'empty`, so if we
// can find no other bound, then check that the region
// being tested is `'empty`.
VerifyBound::IsEmpty
} else if param_bounds.len() == 1 {
if param_bounds.len() == 1 {
// Micro-opt: no need to store the vector if it's just len 1
param_bounds.pop().unwrap()
} else {
// If we can find any other bound `R` such that `T: R`, then
// we don't need to check for `'empty`, because `R: 'empty`.
VerifyBound::AnyBound(param_bounds)
}
}
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_infer/src/infer/region_constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ pub enum VerifyBound<'tcx> {
/// if `R: min`, then by transitivity `G: min`.
OutlivedBy(Region<'tcx>),

/// Given a region `R`, true if it is `'empty`.
IsEmpty,

/// Given a set of bounds `B`, expands to the function:
///
/// ```ignore (pseudo-rust)
Expand Down Expand Up @@ -690,18 +687,16 @@ impl<'tcx> VerifyBound<'tcx> {
match self {
VerifyBound::IfEq(..) => false,
VerifyBound::OutlivedBy(re) => re.is_static(),
VerifyBound::IsEmpty => false,
VerifyBound::AnyBound(bs) => bs.iter().any(|b| b.must_hold()),
VerifyBound::AnyBound(bs) => !bs.is_empty() && bs.iter().any(|b| b.must_hold()),
VerifyBound::AllBounds(bs) => bs.iter().all(|b| b.must_hold()),
}
}

pub fn cannot_hold(&self) -> bool {
match self {
VerifyBound::IfEq(..) => false,
VerifyBound::IsEmpty => false,
VerifyBound::OutlivedBy(_) => false,
VerifyBound::AnyBound(bs) => bs.iter().all(|b| b.cannot_hold()),
VerifyBound::AnyBound(bs) => !bs.is_empty() && bs.iter().all(|b| b.cannot_hold()),
Comment thread
amandasystems marked this conversation as resolved.
Outdated
VerifyBound::AllBounds(bs) => bs.iter().any(|b| b.cannot_hold()),
}
}
Expand Down
Loading