Skip to content

Commit eaa2ddb

Browse files
fix tests
1 parent 66057a7 commit eaa2ddb

File tree

6 files changed

+94
-75
lines changed

6 files changed

+94
-75
lines changed

src/librustc_typeck/check/method/probe.rs

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
285285

286286
Some(steps)
287287
}
288-
289-
pub fn find_attr(&self, def_id: DefId, attr_name: &str) -> Option<ast::Attribute> {
290-
for item in self.tcx.get_attrs(def_id).iter() {
291-
if item.check_name(attr_name) {
292-
return Some(item.clone());
293-
}
294-
}
295-
None
296-
}
297288
}
298289

299290
impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
@@ -918,21 +909,21 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
918909
//Some(Ok(p)) => p.iter().map(|p| p.item.container().id()).collect(),
919910
Some(Err(MethodError::Ambiguity(v))) => {
920911
v.into_iter()
921-
.map(|source| {
922-
match source {
923-
TraitSource(id) => id,
924-
ImplSource(impl_id) => {
925-
match tcx.trait_id_of_impl(impl_id) {
926-
Some(id) => id,
927-
None => {
928-
span_bug!(span,
929-
"found inherent method when looking at traits")
930-
}
912+
.map(|source| {
913+
match source {
914+
TraitSource(id) => id,
915+
ImplSource(impl_id) => {
916+
match tcx.trait_id_of_impl(impl_id) {
917+
Some(id) => id,
918+
None => {
919+
span_bug!(span,
920+
"found inherent method when looking at traits")
931921
}
932922
}
933923
}
934-
})
935-
.collect()
924+
}
925+
})
926+
.collect()
936927
}
937928
Some(Err(MethodError::NoMatch(NoMatchData { out_of_scope_traits: others, .. }))) => {
938929
assert!(others.is_empty());
@@ -957,25 +948,27 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
957948

958949
fn pick_core(&mut self) -> Option<PickResult<'tcx>> {
959950
let steps = self.steps.clone();
960-
let mut ret = Vec::new();
961951

962-
for step in steps.iter() {
963-
match self.pick_step(step) {
964-
Some(Ok(mut elems)) => ret.append(&mut elems),
965-
Some(Err(elem)) => {
966-
match self.looking_for {
967-
LookingFor::MethodName(_) => return Some(Err(elem)),
968-
LookingFor::ReturnType(_) => {}
952+
match self.looking_for {
953+
LookingFor::MethodName(_) => steps.iter()
954+
.filter_map(|step| self.pick_step(step))
955+
.next(),
956+
LookingFor::ReturnType(_) => {
957+
let mut ret = Vec::new();
958+
959+
for step in steps.iter() {
960+
match self.pick_step(step) {
961+
Some(Ok(mut elems)) => ret.append(&mut elems),
962+
_ => {}
969963
}
970964
}
971-
_ => {}
965+
if ret.len() < 1 {
966+
None
967+
} else {
968+
Some(Ok(ret))
969+
}
972970
}
973971
}
974-
if ret.len() < 1 {
975-
None
976-
} else {
977-
Some(Ok(ret))
978-
}
979972
}
980973

981974
fn pick_step(&mut self, step: &CandidateStep<'tcx>) -> Option<PickResult<'tcx>> {
@@ -1028,12 +1021,12 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
10281021
// In general, during probing we erase regions. See
10291022
// `impl_self_ty()` for an explanation.
10301023
let region = tcx.mk_region(ty::ReErased);
1031-
let mut res = Vec::new();
10321024

10331025
// Search through mutabilities in order to find one where pick works:
1034-
for _ in [hir::MutImmutable, hir::MutMutable]
1035-
.iter()
1036-
.filter_map(|&m| {
1026+
let mut elements = [hir::MutImmutable, hir::MutMutable];
1027+
let mut it = elements
1028+
.iter_mut()
1029+
.filter_map(|&mut m| {
10371030
let autoref_ty = tcx.mk_ref(region,
10381031
ty::TypeAndMut {
10391032
ty: step.self_ty,
@@ -1050,15 +1043,24 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
10501043
None
10511044
};
10521045
}
1053-
res.append(&mut picks);
1046+
picks
10541047
})
10551048
})
1056-
}) {}
1057-
1058-
if res.len() < 1 {
1059-
None
1060-
} else {
1061-
Some(Ok(res))
1049+
});
1050+
match self.looking_for {
1051+
LookingFor::MethodName(_) => it.nth(0),
1052+
LookingFor::ReturnType(_) => {
1053+
let mut ret = Vec::new();
1054+
it.filter_map(|entry| entry.ok())
1055+
.map(|mut v| { ret.append(&mut v); })
1056+
.all(|_| true);
1057+
1058+
if ret.len() < 1 {
1059+
None
1060+
} else {
1061+
Some(Ok(ret))
1062+
}
1063+
}
10621064
}
10631065
}
10641066

@@ -1089,7 +1091,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
10891091
probes: &[Candidate<'tcx>],
10901092
possibly_unsatisfied_predicates: &mut Vec<TraitRef<'tcx>>)
10911093
-> Option<PickResult<'tcx>> {
1092-
let applicable_candidates: Vec<_> = probes.iter()
1094+
let mut applicable_candidates: Vec<_> = probes.iter()
10931095
.filter(|&probe| self.consider_probe(self_ty, probe, possibly_unsatisfied_predicates))
10941096
.collect();
10951097

@@ -1109,14 +1111,21 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
11091111
return Some(Err(MethodError::Ambiguity(sources)));
11101112
}
11111113

1112-
let ret: Vec<_> = applicable_candidates.iter()
1113-
.map(|probe| probe.to_unadjusted_pick())
1114-
.collect();
1115-
1116-
if ret.len() < 1 {
1117-
None
1118-
} else {
1119-
Some(Ok(ret))
1114+
match self.looking_for {
1115+
LookingFor::MethodName(_) => applicable_candidates
1116+
.pop()
1117+
.map(|probe| Ok(vec![probe.to_unadjusted_pick()])),
1118+
LookingFor::ReturnType(_) => {
1119+
let ret: Vec<_> = applicable_candidates.iter()
1120+
.map(|probe| probe.to_unadjusted_pick())
1121+
.collect();
1122+
1123+
if ret.len() < 1 {
1124+
None
1125+
} else {
1126+
Some(Ok(ret))
1127+
}
1128+
}
11201129
}
11211130
}
11221131

src/test/compile-fail/coerce_suggestions.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,40 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(box_syntax)]
12+
1113
fn test(_x: &mut String) {}
1214
fn test2(_x: &mut i32) {}
1315

1416
fn main() {
1517
let x: usize = String::new();
16-
//^ ERROR E0308
17-
//| NOTE expected type `usize`
18-
//| NOTE found type `std::string::String`
19-
//| NOTE here are some functions which might fulfill your needs:
18+
//~^ ERROR E0308
19+
//~| NOTE expected usize, found struct `std::string::String`
20+
//~| NOTE expected type `usize`
21+
//~| NOTE found type `std::string::String`
22+
//~| HELP here are some functions which might fulfill your needs:
2023
let x: &str = String::new();
21-
//^ ERROR E0308
22-
//| NOTE expected type `&str`
23-
//| NOTE found type `std::string::String`
24-
//| NOTE try with `&String::new()`
24+
//~^ ERROR E0308
25+
//~| NOTE expected &str, found struct `std::string::String`
26+
//~| NOTE expected type `&str`
27+
//~| NOTE found type `std::string::String`
28+
//~| HELP try with `&String::new()`
2529
let y = String::new();
2630
test(&y);
27-
//^ ERROR E0308
28-
//| NOTE expected type `&mut std::string::String`
29-
//| NOTE found type `&std::string::String`
30-
//| NOTE try with `&mut y`
31+
//~^ ERROR E0308
32+
//~| NOTE types differ in mutability
33+
//~| NOTE expected type `&mut std::string::String`
34+
//~| NOTE found type `&std::string::String`
35+
//~| HELP try with `&mut y`
3136
test2(&y);
32-
//^ ERROR E0308
33-
//| NOTE expected type `&mut i32`
34-
//| NOTE found type `&std::string::String`
35-
//| NOTE try with `&mut y`
37+
//~^ ERROR E0308
38+
//~| NOTE types differ in mutability
39+
//~| NOTE expected type `&mut i32`
40+
//~| NOTE found type `&std::string::String`
3641
let f;
3742
f = box f;
38-
//^ ERROR E0308
39-
//| NOTE expected type `_`
40-
//| NOTE found type `Box<_>`
43+
//~^ ERROR E0308
44+
//~| NOTE cyclic type of infinite size
45+
//~| NOTE expected type `_`
46+
//~| NOTE found type `Box<_>`
4147
}

src/test/compile-fail/coercion-slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ fn main() {
1414
let _: &[i32] = [0];
1515
//~^ ERROR mismatched types
1616
//~| expected type `&[i32]`
17-
//~| found type `[{integer}; 1]`
17+
//~| found type `[i32; 1]`
1818
//~| expected &[i32], found array of 1 elements
1919
}

src/test/compile-fail/cross-borrow-trait.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ pub fn main() {
2222
//~| expected type `&Trait`
2323
//~| found type `Box<Trait>`
2424
//~| expected &Trait, found box
25+
//~^^^^ ERROR E0277
2526
}

src/test/compile-fail/dst-bad-coercions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ pub fn main() {
2323
let x: *const S = &S;
2424
let y: &S = x; //~ ERROR mismatched types
2525
let y: &T = x; //~ ERROR mismatched types
26+
//~^ ERROR E0277
2627

2728
// Test that we cannot convert from *-ptr to &S and &T (mut version)
2829
let x: *mut S = &mut S;
2930
let y: &S = x; //~ ERROR mismatched types
3031
let y: &T = x; //~ ERROR mismatched types
32+
//~^ ERROR E0277
3133

3234
// Test that we cannot convert an immutable ptr to a mutable one using *-ptrs
3335
let x: &mut T = &S; //~ ERROR mismatched types

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &T) -> bool
3636
fn main() {
3737
check((3, 5));
3838
//~^ ERROR mismatched types
39+
//~| HELP try with `&(3, 5)`
3940
}

0 commit comments

Comments
 (0)