pacify the mercilous tidy with rustfmt
This commit is contained in:
parent
be02f74ea9
commit
f419077811
3 changed files with 120 additions and 117 deletions
|
|
@ -50,7 +50,6 @@ use self::region_constraints::{RegionConstraintCollector, RegionSnapshot};
|
|||
use self::type_variable::TypeVariableOrigin;
|
||||
use self::unify_key::ToType;
|
||||
|
||||
pub mod opaque_types;
|
||||
pub mod at;
|
||||
pub mod canonical;
|
||||
mod combine;
|
||||
|
|
@ -63,6 +62,7 @@ mod higher_ranked;
|
|||
pub mod lattice;
|
||||
mod lexical_region_resolve;
|
||||
mod lub;
|
||||
pub mod opaque_types;
|
||||
pub mod outlives;
|
||||
pub mod region_constraints;
|
||||
pub mod resolve;
|
||||
|
|
@ -87,7 +87,7 @@ pub type FixupResult<T> = Result<T, FixupError>; // "fixup result"
|
|||
/// NLL borrow checker will also do -- it might be set to true.
|
||||
#[derive(Copy, Clone, Default, Debug)]
|
||||
pub struct SuppressRegionErrors {
|
||||
suppressed: bool
|
||||
suppressed: bool,
|
||||
}
|
||||
|
||||
impl SuppressRegionErrors {
|
||||
|
|
@ -101,15 +101,11 @@ impl SuppressRegionErrors {
|
|||
pub fn when_nll_is_enabled(tcx: TyCtxt<'_, '_, '_>) -> Self {
|
||||
match tcx.borrowck_mode() {
|
||||
// If we're on AST or Migrate mode, report AST region errors
|
||||
BorrowckMode::Ast | BorrowckMode::Migrate => SuppressRegionErrors {
|
||||
suppressed: false
|
||||
},
|
||||
BorrowckMode::Ast | BorrowckMode::Migrate => SuppressRegionErrors { suppressed: false },
|
||||
|
||||
// If we're on MIR or Compare mode, don't report AST region errors as they should
|
||||
// be reported by NLL
|
||||
BorrowckMode::Compare | BorrowckMode::Mir => SuppressRegionErrors {
|
||||
suppressed: true
|
||||
},
|
||||
BorrowckMode::Compare | BorrowckMode::Mir => SuppressRegionErrors { suppressed: true },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -512,13 +508,13 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
|
|||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
self.enter(|infcx| {
|
||||
let (value, subst) = infcx.instantiate_canonical_with_fresh_inference_vars(span, canonical);
|
||||
let (value, subst) =
|
||||
infcx.instantiate_canonical_with_fresh_inference_vars(span, canonical);
|
||||
f(infcx, value, subst)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn enter<R>(&'tcx mut self, f: impl for<'b> FnOnce(InferCtxt<'b, 'gcx, 'tcx>) -> R) -> R
|
||||
{
|
||||
pub fn enter<R>(&'tcx mut self, f: impl for<'b> FnOnce(InferCtxt<'b, 'gcx, 'tcx>) -> R) -> R {
|
||||
let InferCtxtBuilder {
|
||||
global_tcx,
|
||||
ref arena,
|
||||
|
|
|
|||
|
|
@ -34,117 +34,121 @@ fn dropck_outlives<'tcx>(
|
|||
) -> Result<Lrc<Canonical<'tcx, QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>>, NoSolution> {
|
||||
debug!("dropck_outlives(goal={:#?})", canonical_goal);
|
||||
|
||||
tcx.infer_ctxt().enter_with_canonical(DUMMY_SP, &canonical_goal, |ref infcx, goal, canonical_inference_vars| {
|
||||
let tcx = infcx.tcx;
|
||||
let ParamEnvAnd {
|
||||
param_env,
|
||||
value: for_ty,
|
||||
} = goal;
|
||||
tcx.infer_ctxt().enter_with_canonical(
|
||||
DUMMY_SP,
|
||||
&canonical_goal,
|
||||
|ref infcx, goal, canonical_inference_vars| {
|
||||
let tcx = infcx.tcx;
|
||||
let ParamEnvAnd {
|
||||
param_env,
|
||||
value: for_ty,
|
||||
} = goal;
|
||||
|
||||
let mut result = DropckOutlivesResult {
|
||||
kinds: vec![],
|
||||
overflows: vec![],
|
||||
};
|
||||
let mut result = DropckOutlivesResult {
|
||||
kinds: vec![],
|
||||
overflows: vec![],
|
||||
};
|
||||
|
||||
// A stack of types left to process. Each round, we pop
|
||||
// something from the stack and invoke
|
||||
// `dtorck_constraint_for_ty`. This may produce new types that
|
||||
// have to be pushed on the stack. This continues until we have explored
|
||||
// all the reachable types from the type `for_ty`.
|
||||
//
|
||||
// Example: Imagine that we have the following code:
|
||||
//
|
||||
// ```rust
|
||||
// struct A {
|
||||
// value: B,
|
||||
// children: Vec<A>,
|
||||
// }
|
||||
//
|
||||
// struct B {
|
||||
// value: u32
|
||||
// }
|
||||
//
|
||||
// fn f() {
|
||||
// let a: A = ...;
|
||||
// ..
|
||||
// } // here, `a` is dropped
|
||||
// ```
|
||||
//
|
||||
// at the point where `a` is dropped, we need to figure out
|
||||
// which types inside of `a` contain region data that may be
|
||||
// accessed by any destructors in `a`. We begin by pushing `A`
|
||||
// onto the stack, as that is the type of `a`. We will then
|
||||
// invoke `dtorck_constraint_for_ty` which will expand `A`
|
||||
// into the types of its fields `(B, Vec<A>)`. These will get
|
||||
// pushed onto the stack. Eventually, expanding `Vec<A>` will
|
||||
// lead to us trying to push `A` a second time -- to prevent
|
||||
// infinite recursion, we notice that `A` was already pushed
|
||||
// once and stop.
|
||||
let mut ty_stack = vec![(for_ty, 0)];
|
||||
// A stack of types left to process. Each round, we pop
|
||||
// something from the stack and invoke
|
||||
// `dtorck_constraint_for_ty`. This may produce new types that
|
||||
// have to be pushed on the stack. This continues until we have explored
|
||||
// all the reachable types from the type `for_ty`.
|
||||
//
|
||||
// Example: Imagine that we have the following code:
|
||||
//
|
||||
// ```rust
|
||||
// struct A {
|
||||
// value: B,
|
||||
// children: Vec<A>,
|
||||
// }
|
||||
//
|
||||
// struct B {
|
||||
// value: u32
|
||||
// }
|
||||
//
|
||||
// fn f() {
|
||||
// let a: A = ...;
|
||||
// ..
|
||||
// } // here, `a` is dropped
|
||||
// ```
|
||||
//
|
||||
// at the point where `a` is dropped, we need to figure out
|
||||
// which types inside of `a` contain region data that may be
|
||||
// accessed by any destructors in `a`. We begin by pushing `A`
|
||||
// onto the stack, as that is the type of `a`. We will then
|
||||
// invoke `dtorck_constraint_for_ty` which will expand `A`
|
||||
// into the types of its fields `(B, Vec<A>)`. These will get
|
||||
// pushed onto the stack. Eventually, expanding `Vec<A>` will
|
||||
// lead to us trying to push `A` a second time -- to prevent
|
||||
// infinite recursion, we notice that `A` was already pushed
|
||||
// once and stop.
|
||||
let mut ty_stack = vec![(for_ty, 0)];
|
||||
|
||||
// Set used to detect infinite recursion.
|
||||
let mut ty_set = FxHashSet();
|
||||
// Set used to detect infinite recursion.
|
||||
let mut ty_set = FxHashSet();
|
||||
|
||||
let fulfill_cx = &mut FulfillmentContext::new();
|
||||
let fulfill_cx = &mut FulfillmentContext::new();
|
||||
|
||||
let cause = ObligationCause::dummy();
|
||||
while let Some((ty, depth)) = ty_stack.pop() {
|
||||
let DtorckConstraint {
|
||||
dtorck_types,
|
||||
outlives,
|
||||
overflows,
|
||||
} = dtorck_constraint_for_ty(tcx, DUMMY_SP, for_ty, depth, ty)?;
|
||||
let cause = ObligationCause::dummy();
|
||||
while let Some((ty, depth)) = ty_stack.pop() {
|
||||
let DtorckConstraint {
|
||||
dtorck_types,
|
||||
outlives,
|
||||
overflows,
|
||||
} = dtorck_constraint_for_ty(tcx, DUMMY_SP, for_ty, depth, ty)?;
|
||||
|
||||
// "outlives" represent types/regions that may be touched
|
||||
// by a destructor.
|
||||
result.kinds.extend(outlives);
|
||||
result.overflows.extend(overflows);
|
||||
// "outlives" represent types/regions that may be touched
|
||||
// by a destructor.
|
||||
result.kinds.extend(outlives);
|
||||
result.overflows.extend(overflows);
|
||||
|
||||
// dtorck types are "types that will get dropped but which
|
||||
// do not themselves define a destructor", more or less. We have
|
||||
// to push them onto the stack to be expanded.
|
||||
for ty in dtorck_types {
|
||||
match infcx.at(&cause, param_env).normalize(&ty) {
|
||||
Ok(Normalized {
|
||||
value: ty,
|
||||
obligations,
|
||||
}) => {
|
||||
fulfill_cx.register_predicate_obligations(infcx, obligations);
|
||||
// dtorck types are "types that will get dropped but which
|
||||
// do not themselves define a destructor", more or less. We have
|
||||
// to push them onto the stack to be expanded.
|
||||
for ty in dtorck_types {
|
||||
match infcx.at(&cause, param_env).normalize(&ty) {
|
||||
Ok(Normalized {
|
||||
value: ty,
|
||||
obligations,
|
||||
}) => {
|
||||
fulfill_cx.register_predicate_obligations(infcx, obligations);
|
||||
|
||||
debug!("dropck_outlives: ty from dtorck_types = {:?}", ty);
|
||||
debug!("dropck_outlives: ty from dtorck_types = {:?}", ty);
|
||||
|
||||
match ty.sty {
|
||||
// All parameters live for the duration of the
|
||||
// function.
|
||||
ty::Param(..) => {}
|
||||
match ty.sty {
|
||||
// All parameters live for the duration of the
|
||||
// function.
|
||||
ty::Param(..) => {}
|
||||
|
||||
// A projection that we couldn't resolve - it
|
||||
// might have a destructor.
|
||||
ty::Projection(..) | ty::Opaque(..) => {
|
||||
result.kinds.push(ty.into());
|
||||
}
|
||||
// A projection that we couldn't resolve - it
|
||||
// might have a destructor.
|
||||
ty::Projection(..) | ty::Opaque(..) => {
|
||||
result.kinds.push(ty.into());
|
||||
}
|
||||
|
||||
_ => {
|
||||
if ty_set.insert(ty) {
|
||||
ty_stack.push((ty, depth + 1));
|
||||
_ => {
|
||||
if ty_set.insert(ty) {
|
||||
ty_stack.push((ty, depth + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We don't actually expect to fail to normalize.
|
||||
// That implies a WF error somewhere else.
|
||||
Err(NoSolution) => {
|
||||
return Err(NoSolution);
|
||||
// We don't actually expect to fail to normalize.
|
||||
// That implies a WF error somewhere else.
|
||||
Err(NoSolution) => {
|
||||
return Err(NoSolution);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debug!("dropck_outlives: result = {:#?}", result);
|
||||
debug!("dropck_outlives: result = {:#?}", result);
|
||||
|
||||
infcx.make_canonicalized_query_response(canonical_inference_vars, result, fulfill_cx)
|
||||
})
|
||||
infcx.make_canonicalized_query_response(canonical_inference_vars, result, fulfill_cx)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Return a set of constraints that needs to be satisfied in
|
||||
|
|
@ -192,8 +196,7 @@ fn dtorck_constraint_for_ty<'a, 'gcx, 'tcx>(
|
|||
dtorck_constraint_for_ty(tcx, span, for_ty, depth + 1, ety)
|
||||
}
|
||||
|
||||
ty::Tuple(tys) => tys
|
||||
.iter()
|
||||
ty::Tuple(tys) => tys.iter()
|
||||
.map(|ty| dtorck_constraint_for_ty(tcx, span, for_ty, depth + 1, ty))
|
||||
.collect(),
|
||||
|
||||
|
|
@ -305,8 +308,7 @@ crate fn adt_dtorck_constraint<'a, 'tcx>(
|
|||
return Ok(result);
|
||||
}
|
||||
|
||||
let mut result = def
|
||||
.all_fields()
|
||||
let mut result = def.all_fields()
|
||||
.map(|field| tcx.type_of(field.did))
|
||||
.map(|fty| dtorck_constraint_for_ty(tcx, span, fty, 0, fty))
|
||||
.collect::<Result<DtorckConstraint, NoSolution>>()?;
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use rustc::traits::{EvaluationResult, Obligation, ObligationCause,
|
||||
OverflowError, SelectionContext, TraitQueryMode};
|
||||
use rustc::traits::query::CanonicalPredicateGoal;
|
||||
use rustc::traits::{
|
||||
EvaluationResult, Obligation, ObligationCause, OverflowError, SelectionContext, TraitQueryMode,
|
||||
};
|
||||
use rustc::ty::query::Providers;
|
||||
use rustc::ty::{ParamEnvAnd, TyCtxt};
|
||||
use syntax::source_map::DUMMY_SP;
|
||||
|
|
@ -26,15 +27,19 @@ fn evaluate_obligation<'tcx>(
|
|||
tcx: TyCtxt<'_, 'tcx, 'tcx>,
|
||||
canonical_goal: CanonicalPredicateGoal<'tcx>,
|
||||
) -> Result<EvaluationResult, OverflowError> {
|
||||
tcx.infer_ctxt().enter_with_canonical(DUMMY_SP, &canonical_goal, |ref infcx, goal, _canonical_inference_vars| {
|
||||
let ParamEnvAnd {
|
||||
param_env,
|
||||
value: predicate,
|
||||
} = goal;
|
||||
tcx.infer_ctxt().enter_with_canonical(
|
||||
DUMMY_SP,
|
||||
&canonical_goal,
|
||||
|ref infcx, goal, _canonical_inference_vars| {
|
||||
let ParamEnvAnd {
|
||||
param_env,
|
||||
value: predicate,
|
||||
} = goal;
|
||||
|
||||
let mut selcx = SelectionContext::with_query_mode(&infcx, TraitQueryMode::Canonical);
|
||||
let obligation = Obligation::new(ObligationCause::dummy(), param_env, predicate);
|
||||
let mut selcx = SelectionContext::with_query_mode(&infcx, TraitQueryMode::Canonical);
|
||||
let obligation = Obligation::new(ObligationCause::dummy(), param_env, predicate);
|
||||
|
||||
selcx.evaluate_obligation_recursively(&obligation)
|
||||
})
|
||||
selcx.evaluate_obligation_recursively(&obligation)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue