Fix fallback note

This commit is contained in:
Andrew Cann 2018-03-14 12:03:33 +08:00
parent 5b32211e62
commit 00a52a2be3

View File

@ -539,7 +539,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
fallback_has_occurred: bool) fallback_has_occurred: bool)
{ {
let span = obligation.cause.span; let span = obligation.cause.span;
let _ = fallback_has_occurred;
let mut err = match *error { let mut err = match *error {
SelectionError::Unimplemented => { SelectionError::Unimplemented => {
@ -623,9 +622,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
self.report_similar_impl_candidates(impl_candidates, &mut err); self.report_similar_impl_candidates(impl_candidates, &mut err);
} }
// If this error is due to `!: !Trait` but `(): Trait` then add a note // If this error is due to `!: Trait` not implemented but `(): Trait` is
// about the fallback behaviour change. // implemented, and fallback has occured, then it could be due to a
if trait_predicate.skip_binder().self_ty().is_never() { // variable that used to fallback to `()` now falling back to `!`. Issue a
// note informing about the change in behaviour.
if trait_predicate.skip_binder().self_ty().is_never()
&& fallback_has_occurred
{
let predicate = trait_predicate.map_bound(|mut trait_pred| { let predicate = trait_predicate.map_bound(|mut trait_pred| {
{ {
let trait_ref = &mut trait_pred.trait_ref; let trait_ref = &mut trait_pred.trait_ref;
@ -638,13 +641,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
trait_pred trait_pred
}); });
let unit_obligation = Obligation { let unit_obligation = Obligation {
cause: obligation.cause.clone(), predicate: ty::Predicate::Trait(predicate),
param_env: obligation.param_env, .. obligation.clone()
recursion_depth: obligation.recursion_depth,
predicate,
}; };
let mut selcx = SelectionContext::new(self); let mut selcx = SelectionContext::new(self);
if let Ok(Some(..)) = selcx.select(&unit_obligation) { if selcx.evaluate_obligation(&unit_obligation) {
err.note("the trait is implemented for `()`. \ err.note("the trait is implemented for `()`. \
Possibly this error has been caused by changes to \ Possibly this error has been caused by changes to \
Rust's type-inference algorithm \ Rust's type-inference algorithm \