Skip to content

Commit 00a52a2

Browse files
committed
Fix fallback note
1 parent 5b32211 commit 00a52a2

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/librustc/traits/error_reporting.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
539539
fallback_has_occurred: bool)
540540
{
541541
let span = obligation.cause.span;
542-
let _ = fallback_has_occurred;
543542

544543
let mut err = match *error {
545544
SelectionError::Unimplemented => {
@@ -623,9 +622,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
623622
self.report_similar_impl_candidates(impl_candidates, &mut err);
624623
}
625624

626-
// If this error is due to `!: !Trait` but `(): Trait` then add a note
627-
// about the fallback behaviour change.
628-
if trait_predicate.skip_binder().self_ty().is_never() {
625+
// If this error is due to `!: Trait` not implemented but `(): Trait` is
626+
// implemented, and fallback has occured, then it could be due to a
627+
// variable that used to fallback to `()` now falling back to `!`. Issue a
628+
// note informing about the change in behaviour.
629+
if trait_predicate.skip_binder().self_ty().is_never()
630+
&& fallback_has_occurred
631+
{
629632
let predicate = trait_predicate.map_bound(|mut trait_pred| {
630633
{
631634
let trait_ref = &mut trait_pred.trait_ref;
@@ -638,13 +641,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
638641
trait_pred
639642
});
640643
let unit_obligation = Obligation {
641-
cause: obligation.cause.clone(),
642-
param_env: obligation.param_env,
643-
recursion_depth: obligation.recursion_depth,
644-
predicate,
644+
predicate: ty::Predicate::Trait(predicate),
645+
.. obligation.clone()
645646
};
646647
let mut selcx = SelectionContext::new(self);
647-
if let Ok(Some(..)) = selcx.select(&unit_obligation) {
648+
if selcx.evaluate_obligation(&unit_obligation) {
648649
err.note("the trait is implemented for `()`. \
649650
Possibly this error has been caused by changes to \
650651
Rust's type-inference algorithm \

0 commit comments

Comments
 (0)