Patch projection to not be so eager to unify type variables. This code

is still probably wrong since it fails to incorporate the ambiguity
resolution measures that `select` uses. Also, made more complicated by
the fact that trait object types do not impl their own traits yet.
This commit is contained in:
Niko Matsakis 2014-12-30 09:55:11 -05:00
parent 84f5ad8679
commit 4f05ec7d2c
2 changed files with 55 additions and 10 deletions

View File

@ -125,21 +125,14 @@ pub fn project_type<'cx,'tcx>(
ambiguous: false,
};
let () = assemble_candidates_from_param_env(selcx,
obligation,
&mut candidates);
let () = assemble_candidates_from_object_type(selcx,
obligation,
&mut candidates);
if candidates.vec.is_empty() {
// FIXME(#20297) -- In `select.rs` there is similar logic that
// gives precedence to where-clauses, but it's a bit more
// fine-grained. I was lazy here and just always give
// precedence to where-clauses or other such sources over
// actually dredging through impls. This logic probably should
// be tightened up.
let () = assemble_candidates_from_param_env(selcx,
obligation,
&mut candidates);
let () = try!(assemble_candidates_from_impls(selcx,
obligation,

View File

@ -0,0 +1,52 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test how resolving a projection interacts with inference. In this
// case, we were eagerly unifying the type variable for the iterator
// type with `I` from the where clause, ignoring the in-scope `impl`
// for `ByRef`. The right answer was to consider the result ambiguous
// until more type information was available.
#![feature(associated_types, lang_items, unboxed_closures)]
#![no_implicit_prelude]
use std::option::Option::{None, Some, mod};
trait Iterator {
type Item;
fn next(&mut self) -> Option<Self::Item>;
}
trait IteratorExt: Iterator {
fn by_ref(&mut self) -> ByRef<Self> {
ByRef(self)
}
}
impl<I> IteratorExt for I where I: Iterator {}
struct ByRef<'a, I: 'a + Iterator>(&'a mut I);
impl<'a, A, I> Iterator for ByRef<'a, I> where I: Iterator<Item=A> {
type Item = A;
fn next(&mut self) -> Option< <I as Iterator>::Item > {
self.0.next()
}
}
fn is_iterator_of<A, I: Iterator<Item=A>>(_: &I) {}
fn test<A, I: Iterator<Item=A>>(mut it: I) {
is_iterator_of::<A, _>(&it.by_ref());
}
fn main() { }