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> {
@ -918,21 +909,21 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
//Some(Ok(p)) => p.iter().map(|p| p.item.container().id()).collect(), //Some(Ok(p)) => p.iter().map(|p| p.item.container().id()).collect(),
Some(Err(MethodError::Ambiguity(v))) => { Some(Err(MethodError::Ambiguity(v))) => {
v.into_iter() v.into_iter()
.map(|source| { .map(|source| {
match source { match source {
TraitSource(id) => id, TraitSource(id) => id,
ImplSource(impl_id) => { ImplSource(impl_id) => {
match tcx.trait_id_of_impl(impl_id) { match tcx.trait_id_of_impl(impl_id) {
Some(id) => id, Some(id) => id,
None => { None => {
span_bug!(span, span_bug!(span,
"found inherent method when looking at traits") "found inherent method when looking at traits")
}
} }
} }
} }
}) }
.collect() })
.collect()
} }
Some(Err(MethodError::NoMatch(NoMatchData { out_of_scope_traits: others, .. }))) => { Some(Err(MethodError::NoMatch(NoMatchData { out_of_scope_traits: others, .. }))) => {
assert!(others.is_empty()); assert!(others.is_empty());
@ -957,25 +948,27 @@ 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();
let mut ret = Vec::new();
for step in steps.iter() { match self.looking_for {
match self.pick_step(step) { LookingFor::MethodName(_) => steps.iter()
Some(Ok(mut elems)) => ret.append(&mut elems), .filter_map(|step| self.pick_step(step))
Some(Err(elem)) => { .next(),
match self.looking_for { LookingFor::ReturnType(_) => {
LookingFor::MethodName(_) => return Some(Err(elem)), let mut ret = Vec::new();
LookingFor::ReturnType(_) => {}
for step in steps.iter() {
match self.pick_step(step) {
Some(Ok(mut elems)) => ret.append(&mut elems),
_ => {}
} }
} }
_ => {} if ret.len() < 1 {
None
} else {
Some(Ok(ret))
}
} }
} }
if ret.len() < 1 {
None
} else {
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>> {
@ -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,14 +1111,21 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
return Some(Err(MethodError::Ambiguity(sources))); return Some(Err(MethodError::Ambiguity(sources)));
} }
let ret: Vec<_> = applicable_candidates.iter() match self.looking_for {
.map(|probe| probe.to_unadjusted_pick()) LookingFor::MethodName(_) => applicable_candidates
.collect(); .pop()
.map(|probe| Ok(vec![probe.to_unadjusted_pick()])),
LookingFor::ReturnType(_) => {
let ret: Vec<_> = applicable_candidates.iter()
.map(|probe| probe.to_unadjusted_pick())
.collect();
if ret.len() < 1 { if ret.len() < 1 {
None None
} else { } else {
Some(Ok(ret)) Some(Ok(ret))
}
}
} }
} }

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)`
} }