Skip to content

Commit b402c43

Browse files
committed
Auto merge of #25123 - arielb1:self-inhibiting-error, r=nikomatsakis
Fix #25076. r? @nikomatsakis
2 parents 5ae026e + ea37479 commit b402c43

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

src/librustc/middle/traits/error_reporting.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ pub fn report_projection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
5656
{
5757
let predicate =
5858
infcx.resolve_type_vars_if_possible(&obligation.predicate);
59-
if !predicate.references_error() {
59+
// The ty_err created by normalize_to_error can end up being unified
60+
// into all obligations: for example, if our obligation is something
61+
// like `$X = <() as Foo<$X>>::Out` and () does not implement Foo<_>,
62+
// then $X will be unified with ty_err, but the error still needs to be
63+
// reported.
64+
if !infcx.tcx.sess.has_errors() || !predicate.references_error() {
6065
span_err!(infcx.tcx.sess, obligation.cause.span, E0271,
6166
"type mismatch resolving `{}`: {}",
6267
predicate.user_string(infcx.tcx),
@@ -183,7 +188,8 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
183188
let trait_predicate =
184189
infcx.resolve_type_vars_if_possible(trait_predicate);
185190

186-
if !trait_predicate.references_error() {
191+
if !infcx.tcx.sess.has_errors() ||
192+
!trait_predicate.references_error() {
187193
let trait_ref = trait_predicate.to_poly_trait_ref();
188194
span_err!(infcx.tcx.sess, obligation.cause.span, E0277,
189195
"the trait `{}` is not implemented for the type `{}`",

src/librustc/middle/traits/project.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ fn opt_normalize_projection_type<'a,'b,'tcx>(
408408
}
409409

410410
/// in various error cases, we just set ty_err and return an obligation
411-
/// that, when fulfilled, will lead to an error
411+
/// that, when fulfilled, will lead to an error.
412+
///
413+
/// FIXME: the ty_err created here can enter the obligation we create,
414+
/// leading to error messages involving ty_err.
412415
fn normalize_to_error<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
413416
projection_ty: ty::ProjectionTy<'tcx>,
414417
cause: ObligationCause<'tcx>,

src/test/compile-fail/issue-23966.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
"".chars().fold(|_, _| (), ());
13-
//~^ ERROR cannot determine a type for this expression: unconstrained type
12+
"".chars().fold(|_, _| (), ()); //~ ERROR is not implemented for the type `()`
1413
}

src/test/compile-fail/issue-25076.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct S;
12+
13+
trait InOut<T> { type Out; }
14+
15+
fn do_fold<B, F: InOut<B, Out=B>>(init: B, f: F) {}
16+
17+
fn bot<T>() -> T { loop {} }
18+
19+
fn main() {
20+
do_fold(bot(), ()); //~ ERROR is not implemented for the type `()`
21+
}

0 commit comments

Comments
 (0)