Clean up dropck code a bit
- Remove `Result` that couldn't be Err on valid compilation. - Always compute errors on failure.
This commit is contained in:
parent
87e5969572
commit
49cf00c7c0
4 changed files with 38 additions and 55 deletions
|
@ -94,7 +94,7 @@ pub fn compute_dropck_outlives_inner<'tcx>(
|
|||
goal: ParamEnvAnd<'tcx, DropckOutlives<'tcx>>,
|
||||
span: Span,
|
||||
) -> Result<DropckOutlivesResult<'tcx>, NoSolution> {
|
||||
match compute_dropck_outlives_with_errors(ocx, goal, span, false) {
|
||||
match compute_dropck_outlives_with_errors(ocx, goal, span) {
|
||||
Ok(r) => Ok(r),
|
||||
Err(_) => Err(NoSolution),
|
||||
}
|
||||
|
@ -104,7 +104,6 @@ pub fn compute_dropck_outlives_with_errors<'tcx, E>(
|
|||
ocx: &ObligationCtxt<'_, 'tcx, E>,
|
||||
goal: ParamEnvAnd<'tcx, DropckOutlives<'tcx>>,
|
||||
span: Span,
|
||||
report_errors: bool,
|
||||
) -> Result<DropckOutlivesResult<'tcx>, Vec<E>>
|
||||
where
|
||||
E: FromSolverError<'tcx, NextSolverError<'tcx>>,
|
||||
|
@ -162,17 +161,14 @@ where
|
|||
result.overflows.len(),
|
||||
ty_stack.len()
|
||||
);
|
||||
match dtorck_constraint_for_ty_inner(
|
||||
dtorck_constraint_for_ty_inner(
|
||||
tcx,
|
||||
ocx.infcx.typing_env(param_env),
|
||||
span,
|
||||
depth,
|
||||
ty,
|
||||
&mut constraints,
|
||||
) {
|
||||
Err(_) => return Err(Vec::new()),
|
||||
_ => (),
|
||||
};
|
||||
);
|
||||
|
||||
// "outlives" represent types/regions that may be touched
|
||||
// by a destructor.
|
||||
|
@ -192,16 +188,7 @@ where
|
|||
// do not themselves define a destructor", more or less. We have
|
||||
// to push them onto the stack to be expanded.
|
||||
for ty in constraints.dtorck_types.drain(..) {
|
||||
let ty = if report_errors {
|
||||
let normalized_ty = ocx.deeply_normalize(&cause, param_env, ty)?;
|
||||
|
||||
let errors = ocx.select_where_possible();
|
||||
if !errors.is_empty() {
|
||||
debug!("failed to normalize dtorck type: {ty} ~> {errors:#?}");
|
||||
return Err(errors);
|
||||
}
|
||||
normalized_ty
|
||||
} else if let Ok(Normalized { value: ty, obligations }) =
|
||||
let ty = if let Ok(Normalized { value: ty, obligations }) =
|
||||
ocx.infcx.at(&cause, param_env).query_normalize(ty)
|
||||
{
|
||||
ocx.register_obligations(obligations);
|
||||
|
@ -209,7 +196,11 @@ where
|
|||
debug!("dropck_outlives: ty from dtorck_types = {:?}", ty);
|
||||
ty
|
||||
} else {
|
||||
return Err(Vec::new());
|
||||
ocx.deeply_normalize(&cause, param_env, ty)?;
|
||||
|
||||
let errors = ocx.select_where_possible();
|
||||
debug!("normalize errors: {ty} ~> {errors:#?}");
|
||||
return Err(errors);
|
||||
};
|
||||
|
||||
match ty.kind() {
|
||||
|
@ -246,14 +237,14 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>(
|
|||
depth: usize,
|
||||
ty: Ty<'tcx>,
|
||||
constraints: &mut DropckConstraint<'tcx>,
|
||||
) -> Result<(), NoSolution> {
|
||||
) {
|
||||
if !tcx.recursion_limit().value_within_limit(depth) {
|
||||
constraints.overflows.push(ty);
|
||||
return Ok(());
|
||||
return;
|
||||
}
|
||||
|
||||
if trivial_dropck_outlives(tcx, ty) {
|
||||
return Ok(());
|
||||
return;
|
||||
}
|
||||
|
||||
match ty.kind() {
|
||||
|
@ -277,22 +268,20 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>(
|
|||
// single-element containers, behave like their element
|
||||
rustc_data_structures::stack::ensure_sufficient_stack(|| {
|
||||
dtorck_constraint_for_ty_inner(tcx, typing_env, span, depth + 1, *ety, constraints)
|
||||
})?;
|
||||
});
|
||||
}
|
||||
|
||||
ty::Tuple(tys) => rustc_data_structures::stack::ensure_sufficient_stack(|| {
|
||||
for ty in tys.iter() {
|
||||
dtorck_constraint_for_ty_inner(tcx, typing_env, span, depth + 1, ty, constraints)?;
|
||||
dtorck_constraint_for_ty_inner(tcx, typing_env, span, depth + 1, ty, constraints);
|
||||
}
|
||||
Ok::<_, NoSolution>(())
|
||||
})?,
|
||||
}),
|
||||
|
||||
ty::Closure(_, args) => rustc_data_structures::stack::ensure_sufficient_stack(|| {
|
||||
for ty in args.as_closure().upvar_tys() {
|
||||
dtorck_constraint_for_ty_inner(tcx, typing_env, span, depth + 1, ty, constraints)?;
|
||||
dtorck_constraint_for_ty_inner(tcx, typing_env, span, depth + 1, ty, constraints);
|
||||
}
|
||||
Ok::<_, NoSolution>(())
|
||||
})?,
|
||||
}),
|
||||
|
||||
ty::CoroutineClosure(_, args) => {
|
||||
rustc_data_structures::stack::ensure_sufficient_stack(|| {
|
||||
|
@ -304,10 +293,9 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>(
|
|||
depth + 1,
|
||||
ty,
|
||||
constraints,
|
||||
)?;
|
||||
);
|
||||
}
|
||||
Ok::<_, NoSolution>(())
|
||||
})?
|
||||
})
|
||||
}
|
||||
|
||||
ty::Coroutine(_, args) => {
|
||||
|
@ -346,7 +334,7 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>(
|
|||
|
||||
ty::Adt(def, args) => {
|
||||
let DropckConstraint { dtorck_types, outlives, overflows } =
|
||||
tcx.at(span).adt_dtorck_constraint(def.did())?;
|
||||
tcx.at(span).adt_dtorck_constraint(def.did());
|
||||
// FIXME: we can try to recursively `dtorck_constraint_on_ty`
|
||||
// there, but that needs some way to handle cycles.
|
||||
constraints
|
||||
|
@ -379,9 +367,7 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>(
|
|||
ty::Placeholder(..) | ty::Bound(..) | ty::Infer(..) | ty::Error(_) => {
|
||||
// By the time this code runs, all type variables ought to
|
||||
// be fully resolved.
|
||||
return Err(NoSolution);
|
||||
tcx.dcx().span_delayed_bug(span, format!("Unresolved type in dropck: {:?}.", ty));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue