more nits
This commit is contained in:
parent
ca49a37390
commit
0e20155662
5 changed files with 65 additions and 49 deletions
|
@ -231,10 +231,29 @@ fn overlap<'tcx>(
|
|||
COINDUCTIVE_OVERLAP_IN_COHERENCE,
|
||||
infcx.tcx.local_def_id_to_hir_id(first_local_impl),
|
||||
infcx.tcx.def_span(first_local_impl),
|
||||
"impls that are not considered to overlap may be considered to \
|
||||
overlap in the future",
|
||||
format!(
|
||||
"implementations {} will conflict in the future",
|
||||
match impl1_header.trait_ref {
|
||||
Some(trait_ref) => {
|
||||
let trait_ref = infcx.resolve_vars_if_possible(trait_ref);
|
||||
format!(
|
||||
"of `{}` for `{}`",
|
||||
trait_ref.print_only_trait_path(),
|
||||
trait_ref.self_ty()
|
||||
)
|
||||
}
|
||||
None => format!(
|
||||
"for `{}`",
|
||||
infcx.resolve_vars_if_possible(impl1_header.self_ty)
|
||||
),
|
||||
},
|
||||
),
|
||||
|lint| {
|
||||
lint.span_label(
|
||||
lint.note(
|
||||
"impls that are not considered to overlap may be considered to \
|
||||
overlap in the future",
|
||||
)
|
||||
.span_label(
|
||||
infcx.tcx.def_span(impl1_header.impl_def_id),
|
||||
"the first impl is here",
|
||||
)
|
||||
|
@ -245,8 +264,12 @@ fn overlap<'tcx>(
|
|||
if !failing_obligation.cause.span.is_dummy() {
|
||||
lint.span_label(
|
||||
failing_obligation.cause.span,
|
||||
"this where-clause causes a cycle, but it may be treated \
|
||||
as possibly holding in the future, causing the impls to overlap",
|
||||
format!(
|
||||
"`{}` may be considered to hold in future releases, \
|
||||
causing the impls to overlap",
|
||||
infcx
|
||||
.resolve_vars_if_possible(failing_obligation.predicate)
|
||||
),
|
||||
);
|
||||
}
|
||||
lint
|
||||
|
|
|
@ -202,10 +202,25 @@ enum BuiltinImplConditions<'tcx> {
|
|||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum TreatInductiveCycleAs {
|
||||
/// This is the previous behavior, where `Recur` represents an inductive
|
||||
/// cycle that is known not to hold. This is not forwards-compatible with
|
||||
/// coinduction, and will be deprecated. This is the default behavior
|
||||
/// of the old trait solver due to back-compat reasons.
|
||||
Recur,
|
||||
/// This is the behavior of the new trait solver, where inductive cycles
|
||||
/// are treated as ambiguous and possibly holding.
|
||||
Ambig,
|
||||
}
|
||||
|
||||
impl From<TreatInductiveCycleAs> for EvaluationResult {
|
||||
fn from(treat: TreatInductiveCycleAs) -> EvaluationResult {
|
||||
match treat {
|
||||
TreatInductiveCycleAs::Ambig => EvaluatedToUnknown,
|
||||
TreatInductiveCycleAs::Recur => EvaluatedToRecur,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
pub fn new(infcx: &'cx InferCtxt<'tcx>) -> SelectionContext<'cx, 'tcx> {
|
||||
SelectionContext {
|
||||
|
@ -223,6 +238,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
treat_inductive_cycle: TreatInductiveCycleAs,
|
||||
f: impl FnOnce(&mut Self) -> T,
|
||||
) -> T {
|
||||
// Should be executed in a context where caching is disabled,
|
||||
// otherwise the cache is poisoned with the temporary result.
|
||||
assert!(self.is_intercrate());
|
||||
let treat_inductive_cycle =
|
||||
std::mem::replace(&mut self.treat_inductive_cycle, treat_inductive_cycle);
|
||||
let value = f(self);
|
||||
|
@ -741,10 +759,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
stack.update_reached_depth(stack_arg.1);
|
||||
return Ok(EvaluatedToOk);
|
||||
} else {
|
||||
match self.treat_inductive_cycle {
|
||||
TreatInductiveCycleAs::Ambig => return Ok(EvaluatedToUnknown),
|
||||
TreatInductiveCycleAs::Recur => return Ok(EvaluatedToRecur),
|
||||
}
|
||||
return Ok(self.treat_inductive_cycle.into());
|
||||
}
|
||||
}
|
||||
return Ok(EvaluatedToOk);
|
||||
|
@ -862,10 +877,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
}
|
||||
}
|
||||
ProjectAndUnifyResult::FailedNormalization => Ok(EvaluatedToAmbig),
|
||||
ProjectAndUnifyResult::Recursive => match self.treat_inductive_cycle {
|
||||
TreatInductiveCycleAs::Ambig => return Ok(EvaluatedToUnknown),
|
||||
TreatInductiveCycleAs::Recur => return Ok(EvaluatedToRecur),
|
||||
},
|
||||
ProjectAndUnifyResult::Recursive => Ok(self.treat_inductive_cycle.into()),
|
||||
ProjectAndUnifyResult::MismatchedProjectionTypes(_) => Ok(EvaluatedToErr),
|
||||
}
|
||||
}
|
||||
|
@ -1179,10 +1191,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
Some(EvaluatedToOk)
|
||||
} else {
|
||||
debug!("evaluate_stack --> recursive, inductive");
|
||||
match self.treat_inductive_cycle {
|
||||
TreatInductiveCycleAs::Ambig => Some(EvaluatedToUnknown),
|
||||
TreatInductiveCycleAs::Recur => Some(EvaluatedToRecur),
|
||||
}
|
||||
Some(self.treat_inductive_cycle.into())
|
||||
}
|
||||
} else {
|
||||
None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue