From 00a52a2be36fd80e8430a524e8c0dad7b249af41 Mon Sep 17 00:00:00 2001 From: Andrew Cann Date: Wed, 14 Mar 2018 12:03:33 +0800 Subject: [PATCH] Fix fallback note --- src/librustc/traits/error_reporting.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index b19935b8c4f..206a4bf6689 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -539,7 +539,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { fallback_has_occurred: bool) { let span = obligation.cause.span; - let _ = fallback_has_occurred; let mut err = match *error { SelectionError::Unimplemented => { @@ -623,9 +622,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { self.report_similar_impl_candidates(impl_candidates, &mut err); } - // If this error is due to `!: !Trait` but `(): Trait` then add a note - // about the fallback behaviour change. - if trait_predicate.skip_binder().self_ty().is_never() { + // If this error is due to `!: Trait` not implemented but `(): Trait` is + // implemented, and fallback has occured, then it could be due to a + // 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 trait_ref = &mut trait_pred.trait_ref; @@ -638,13 +641,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { trait_pred }); let unit_obligation = Obligation { - cause: obligation.cause.clone(), - param_env: obligation.param_env, - recursion_depth: obligation.recursion_depth, - predicate, + predicate: ty::Predicate::Trait(predicate), + .. obligation.clone() }; 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 `()`. \ Possibly this error has been caused by changes to \ Rust's type-inference algorithm \