Skip to content

Commit 9c63817

Browse files
fix tests
1 parent 19fb17c commit 9c63817

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
@@ -283,15 +283,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
283283

284284
Some(steps)
285285
}
286-
287-
pub fn find_attr(&self, def_id: DefId, attr_name: &str) -> Option<ast::Attribute> {
288-
for item in self.tcx.get_attrs(def_id).iter() {
289-
if item.check_name(attr_name) {
290-
return Some(item.clone());
291-
}
292-
}
293-
None
294-
}
295286
}
296287

297288
impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
@@ -926,21 +917,21 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
926917
Some(Ok(p)) => p.iter().map(|p| p.item.container().id()).collect(),
927918
Some(Err(MethodError::Ambiguity(v))) => {
928919
v.into_iter()
929-
.map(|source| {
930-
match source {
931-
TraitSource(id) => id,
932-
ImplSource(impl_id) => {
933-
match tcx.trait_id_of_impl(impl_id) {
934-
Some(id) => id,
935-
None => {
936-
span_bug!(span,
937-
"found inherent method when looking at traits")
938-
}
920+
.map(|source| {
921+
match source {
922+
TraitSource(id) => id,
923+
ImplSource(impl_id) => {
924+
match tcx.trait_id_of_impl(impl_id) {
925+
Some(id) => id,
926+
None => {
927+
span_bug!(span,
928+
"found inherent method when looking at traits")
939929
}
940930
}
941931
}
942-
})
943-
.collect()
932+
}
933+
})
934+
.collect()
944935
}
945936
Some(Err(MethodError::NoMatch(NoMatchData { out_of_scope_traits: others, .. }))) => {
946937
assert!(others.is_empty());
@@ -965,25 +956,27 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
965956

966957
fn pick_core(&mut self) -> Option<PickResult<'tcx>> {
967958
let steps = self.steps.clone();
968-
let mut ret = Vec::new();
969959

970-
for step in steps.iter() {
971-
match self.pick_step(step) {
972-
Some(Ok(mut elems)) => ret.append(&mut elems),
973-
Some(Err(elem)) => {
974-
match self.looking_for {
975-
LookingFor::MethodName(_) => return Some(Err(elem)),
976-
LookingFor::ReturnType(_) => {}
960+
match self.looking_for {
961+
LookingFor::MethodName(_) => steps.iter()
962+
.filter_map(|step| self.pick_step(step))
963+
.next(),
964+
LookingFor::ReturnType(_) => {
965+
let mut ret = Vec::new();
966+
967+
for step in steps.iter() {
968+
match self.pick_step(step) {
969+
Some(Ok(mut elems)) => ret.append(&mut elems),
970+
_ => {}
977971
}
978972
}
979-
_ => {}
973+
if ret.len() < 1 {
974+
None
975+
} else {
976+
Some(Ok(ret))
977+
}
980978
}
981979
}
982-
if ret.len() < 1 {
983-
None
984-
} else {
985-
Some(Ok(ret))
986-
}
987980
}
988981

989982
fn pick_step(&mut self, step: &CandidateStep<'tcx>) -> Option<PickResult<'tcx>> {
@@ -1036,12 +1029,12 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
10361029
// In general, during probing we erase regions. See
10371030
// `impl_self_ty()` for an explanation.
10381031
let region = tcx.mk_region(ty::ReErased);
1039-
let mut res = Vec::new();
10401032

10411033
// Search through mutabilities in order to find one where pick works:
1042-
for _ in [hir::MutImmutable, hir::MutMutable]
1043-
.iter()
1044-
.filter_map(|&m| {
1034+
let mut elements = [hir::MutImmutable, hir::MutMutable];
1035+
let mut it = elements
1036+
.iter_mut()
1037+
.filter_map(|&mut m| {
10451038
let autoref_ty = tcx.mk_ref(region,
10461039
ty::TypeAndMut {
10471040
ty: step.self_ty,
@@ -1058,15 +1051,24 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
10581051
None
10591052
};
10601053
}
1061-
res.append(&mut picks);
1054+
picks
10621055
})
10631056
})
1064-
}) {}
1065-
1066-
if res.len() < 1 {
1067-
None
1068-
} else {
1069-
Some(Ok(res))
1057+
});
1058+
match self.looking_for {
1059+
LookingFor::MethodName(_) => it.nth(0),
1060+
LookingFor::ReturnType(_) => {
1061+
let mut ret = Vec::new();
1062+
it.filter_map(|entry| entry.ok())
1063+
.map(|mut v| { ret.append(&mut v); })
1064+
.all(|_| true);
1065+
1066+
if ret.len() < 1 {
1067+
None
1068+
} else {
1069+
Some(Ok(ret))
1070+
}
1071+
}
10701072
}
10711073
}
10721074

@@ -1097,7 +1099,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
10971099
probes: &[Candidate<'tcx>],
10981100
possibly_unsatisfied_predicates: &mut Vec<TraitRef<'tcx>>)
10991101
-> Option<PickResult<'tcx>> {
1100-
let applicable_candidates: Vec<_> = probes.iter()
1102+
let mut applicable_candidates: Vec<_> = probes.iter()
11011103
.filter(|&probe| self.consider_probe(self_ty, probe, possibly_unsatisfied_predicates))
11021104
.collect();
11031105

@@ -1117,14 +1119,21 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
11171119
return Some(Err(MethodError::Ambiguity(sources)));
11181120
}
11191121

1120-
let ret: Vec<_> = applicable_candidates.iter()
1121-
.map(|probe| probe.to_unadjusted_pick())
1122-
.collect();
1123-
1124-
if ret.len() < 1 {
1125-
None
1126-
} else {
1127-
Some(Ok(ret))
1122+
match self.looking_for {
1123+
LookingFor::MethodName(_) => applicable_candidates
1124+
.pop()
1125+
.map(|probe| Ok(vec![probe.to_unadjusted_pick()])),
1126+
LookingFor::ReturnType(_) => {
1127+
let ret: Vec<_> = applicable_candidates.iter()
1128+
.map(|probe| probe.to_unadjusted_pick())
1129+
.collect();
1130+
1131+
if ret.len() < 1 {
1132+
None
1133+
} else {
1134+
Some(Ok(ret))
1135+
}
1136+
}
11281137
}
11291138
}
11301139

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)