1
Fork 0

fix tests

This commit is contained in:
Guillaume Gomez 2016-10-30 23:06:30 +01:00
parent 66057a7f72
commit eaa2ddb04f
6 changed files with 92 additions and 73 deletions

View file

@ -285,15 +285,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Some(steps) Some(steps)
} }
pub fn find_attr(&self, def_id: DefId, attr_name: &str) -> Option<ast::Attribute> {
for item in self.tcx.get_attrs(def_id).iter() {
if item.check_name(attr_name) {
return Some(item.clone());
}
}
None
}
} }
impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
@ -957,17 +948,17 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
fn pick_core(&mut self) -> Option<PickResult<'tcx>> { fn pick_core(&mut self) -> Option<PickResult<'tcx>> {
let steps = self.steps.clone(); let steps = self.steps.clone();
match self.looking_for {
LookingFor::MethodName(_) => steps.iter()
.filter_map(|step| self.pick_step(step))
.next(),
LookingFor::ReturnType(_) => {
let mut ret = Vec::new(); let mut ret = Vec::new();
for step in steps.iter() { for step in steps.iter() {
match self.pick_step(step) { match self.pick_step(step) {
Some(Ok(mut elems)) => ret.append(&mut elems), Some(Ok(mut elems)) => ret.append(&mut elems),
Some(Err(elem)) => {
match self.looking_for {
LookingFor::MethodName(_) => return Some(Err(elem)),
LookingFor::ReturnType(_) => {}
}
}
_ => {} _ => {}
} }
} }
@ -977,6 +968,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
Some(Ok(ret)) Some(Ok(ret))
} }
} }
}
}
fn pick_step(&mut self, step: &CandidateStep<'tcx>) -> Option<PickResult<'tcx>> { fn pick_step(&mut self, step: &CandidateStep<'tcx>) -> Option<PickResult<'tcx>> {
debug!("pick_step: step={:?}", step); debug!("pick_step: step={:?}", step);
@ -1028,12 +1021,12 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
// In general, during probing we erase regions. See // In general, during probing we erase regions. See
// `impl_self_ty()` for an explanation. // `impl_self_ty()` for an explanation.
let region = tcx.mk_region(ty::ReErased); let region = tcx.mk_region(ty::ReErased);
let mut res = Vec::new();
// Search through mutabilities in order to find one where pick works: // Search through mutabilities in order to find one where pick works:
for _ in [hir::MutImmutable, hir::MutMutable] let mut elements = [hir::MutImmutable, hir::MutMutable];
.iter() let mut it = elements
.filter_map(|&m| { .iter_mut()
.filter_map(|&mut m| {
let autoref_ty = tcx.mk_ref(region, let autoref_ty = tcx.mk_ref(region,
ty::TypeAndMut { ty::TypeAndMut {
ty: step.self_ty, ty: step.self_ty,
@ -1050,15 +1043,24 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
None None
}; };
} }
res.append(&mut picks); picks
}) })
}) })
}) {} });
match self.looking_for {
LookingFor::MethodName(_) => it.nth(0),
LookingFor::ReturnType(_) => {
let mut ret = Vec::new();
it.filter_map(|entry| entry.ok())
.map(|mut v| { ret.append(&mut v); })
.all(|_| true);
if res.len() < 1 { if ret.len() < 1 {
None None
} else { } else {
Some(Ok(res)) Some(Ok(ret))
}
}
} }
} }
@ -1089,7 +1091,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
probes: &[Candidate<'tcx>], probes: &[Candidate<'tcx>],
possibly_unsatisfied_predicates: &mut Vec<TraitRef<'tcx>>) possibly_unsatisfied_predicates: &mut Vec<TraitRef<'tcx>>)
-> Option<PickResult<'tcx>> { -> Option<PickResult<'tcx>> {
let applicable_candidates: Vec<_> = probes.iter() let mut applicable_candidates: Vec<_> = probes.iter()
.filter(|&probe| self.consider_probe(self_ty, probe, possibly_unsatisfied_predicates)) .filter(|&probe| self.consider_probe(self_ty, probe, possibly_unsatisfied_predicates))
.collect(); .collect();
@ -1109,6 +1111,11 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
return Some(Err(MethodError::Ambiguity(sources))); return Some(Err(MethodError::Ambiguity(sources)));
} }
match self.looking_for {
LookingFor::MethodName(_) => applicable_candidates
.pop()
.map(|probe| Ok(vec![probe.to_unadjusted_pick()])),
LookingFor::ReturnType(_) => {
let ret: Vec<_> = applicable_candidates.iter() let ret: Vec<_> = applicable_candidates.iter()
.map(|probe| probe.to_unadjusted_pick()) .map(|probe| probe.to_unadjusted_pick())
.collect(); .collect();
@ -1119,6 +1126,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
Some(Ok(ret)) Some(Ok(ret))
} }
} }
}
}
fn consider_probe(&self, fn consider_probe(&self,
self_ty: Ty<'tcx>, self_ty: Ty<'tcx>,

View file

@ -8,34 +8,40 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(box_syntax)]
fn test(_x: &mut String) {} fn test(_x: &mut String) {}
fn test2(_x: &mut i32) {} fn test2(_x: &mut i32) {}
fn main() { fn main() {
let x: usize = String::new(); let x: usize = String::new();
//^ ERROR E0308 //~^ ERROR E0308
//| NOTE expected type `usize` //~| NOTE expected usize, found struct `std::string::String`
//| NOTE found type `std::string::String` //~| NOTE expected type `usize`
//| NOTE here are some functions which might fulfill your needs: //~| NOTE found type `std::string::String`
//~| HELP here are some functions which might fulfill your needs:
let x: &str = String::new(); let x: &str = String::new();
//^ ERROR E0308 //~^ ERROR E0308
//| NOTE expected type `&str` //~| NOTE expected &str, found struct `std::string::String`
//| NOTE found type `std::string::String` //~| NOTE expected type `&str`
//| NOTE try with `&String::new()` //~| NOTE found type `std::string::String`
//~| HELP try with `&String::new()`
let y = String::new(); let y = String::new();
test(&y); test(&y);
//^ ERROR E0308 //~^ ERROR E0308
//| NOTE expected type `&mut std::string::String` //~| NOTE types differ in mutability
//| NOTE found type `&std::string::String` //~| NOTE expected type `&mut std::string::String`
//| NOTE try with `&mut y` //~| NOTE found type `&std::string::String`
//~| HELP try with `&mut y`
test2(&y); test2(&y);
//^ ERROR E0308 //~^ ERROR E0308
//| NOTE expected type `&mut i32` //~| NOTE types differ in mutability
//| NOTE found type `&std::string::String` //~| NOTE expected type `&mut i32`
//| NOTE try with `&mut y` //~| NOTE found type `&std::string::String`
let f; let f;
f = box f; f = box f;
//^ ERROR E0308 //~^ ERROR E0308
//| NOTE expected type `_` //~| NOTE cyclic type of infinite size
//| NOTE found type `Box<_>` //~| NOTE expected type `_`
//~| NOTE found type `Box<_>`
} }

View file

@ -14,6 +14,6 @@ fn main() {
let _: &[i32] = [0]; let _: &[i32] = [0];
//~^ ERROR mismatched types //~^ ERROR mismatched types
//~| expected type `&[i32]` //~| expected type `&[i32]`
//~| found type `[{integer}; 1]` //~| found type `[i32; 1]`
//~| expected &[i32], found array of 1 elements //~| expected &[i32], found array of 1 elements
} }

View file

@ -22,4 +22,5 @@ pub fn main() {
//~| expected type `&Trait` //~| expected type `&Trait`
//~| found type `Box<Trait>` //~| found type `Box<Trait>`
//~| expected &Trait, found box //~| expected &Trait, found box
//~^^^^ ERROR E0277
} }

View file

@ -23,11 +23,13 @@ pub fn main() {
let x: *const S = &S; let x: *const S = &S;
let y: &S = x; //~ ERROR mismatched types let y: &S = x; //~ ERROR mismatched types
let y: &T = x; //~ ERROR mismatched types let y: &T = x; //~ ERROR mismatched types
//~^ ERROR E0277
// Test that we cannot convert from *-ptr to &S and &T (mut version) // Test that we cannot convert from *-ptr to &S and &T (mut version)
let x: *mut S = &mut S; let x: *mut S = &mut S;
let y: &S = x; //~ ERROR mismatched types let y: &S = x; //~ ERROR mismatched types
let y: &T = x; //~ ERROR mismatched types let y: &T = x; //~ ERROR mismatched types
//~^ ERROR E0277
// Test that we cannot convert an immutable ptr to a mutable one using *-ptrs // Test that we cannot convert an immutable ptr to a mutable one using *-ptrs
let x: &mut T = &S; //~ ERROR mismatched types let x: &mut T = &S; //~ ERROR mismatched types

View file

@ -36,4 +36,5 @@ fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &T) -> bool
fn main() { fn main() {
check((3, 5)); check((3, 5));
//~^ ERROR mismatched types //~^ ERROR mismatched types
//~| HELP try with `&(3, 5)`
} }