Skip to content

Commit eb84141

Browse files
arielb1Ariel Ben-Yehuda
authored and
Ariel Ben-Yehuda
committed
select: treat ErrorCandidate as a real error
Otherwise, projection can result in type errors that are unified into the trait inputs. We should probably refactor the `normalize_to_error` mess.
1 parent edf2198 commit eb84141

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/librustc/middle/traits/select.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
628628
}
629629

630630
match self.candidate_from_obligation(stack) {
631-
Ok(Some(c)) => self.evaluate_candidate(stack, &c),
631+
Err(..) | Ok(Some(ErrorCandidate)) => EvaluatedToErr,
632632
Ok(None) => EvaluatedToAmbig,
633-
Err(..) => EvaluatedToErr
633+
Ok(Some(c)) => self.evaluate_candidate(stack, &c),
634634
}
635635
}
636636

@@ -754,7 +754,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
754754
stack: &TraitObligationStack<'o, 'tcx>)
755755
-> SelectionResult<'tcx, SelectionCandidate<'tcx>>
756756
{
757-
if stack.obligation.predicate.0.self_ty().references_error() {
757+
if stack.obligation.predicate.references_error() {
758758
return Ok(Some(ErrorCandidate));
759759
}
760760

src/test/run-pass/issue-29857.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
// check that we don't go mad when there are errors in trait evaluation
12+
13+
use std::marker::PhantomData;
14+
15+
pub trait Foo { type Output: 'static; }
16+
pub trait Bar<P> {}
17+
pub trait Baz<P> {}
18+
pub struct Qux<T>(PhantomData<*mut T>);
19+
20+
impl<P, T: Baz<P>> Bar<P> for Option<T> {}
21+
impl<T> Bar<*mut T> for Option<Qux<T>> {}
22+
23+
impl<T: 'static, W: Foo<Output=T>> Baz<*mut T> for W {}
24+
25+
fn main() {}

0 commit comments

Comments
 (0)