Skip to content

Commit 82cdbf1

Browse files
authored
Rollup merge of rust-lang#52507 - estebank:infer-type, r=nikomatsakis
Reword when `_` couldn't be inferred r? @nikomatsakis
2 parents 180ad53 + 70e7e7d commit 82cdbf1

16 files changed

+24
-17
lines changed

src/librustc/infer/error_reporting/need_type_info.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
9797
let name = self.extract_type_name(&ty);
9898

9999
let mut err_span = span;
100-
let mut labels = vec![(span, format!("cannot infer type for `{}`", name))];
100+
let mut labels = vec![(
101+
span,
102+
if &name == "_" {
103+
"cannot infer type".to_string()
104+
} else {
105+
format!("cannot infer type for `{}`", name)
106+
},
107+
)];
101108

102109
let mut local_visitor = FindLocalByTypeVisitor {
103110
infcx: &self,

src/test/ui/error-codes/E0282.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed
44
LL | let x = "hello".chars().rev().collect(); //~ ERROR E0282
55
| ^
66
| |
7-
| cannot infer type for `_`
7+
| cannot infer type
88
| consider giving `x` a type
99

1010
error: aborting due to previous error

src/test/ui/issue-12187-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed
44
LL | let &v = new();
55
| -^
66
| ||
7-
| |cannot infer type for `_`
7+
| |cannot infer type
88
| consider giving the pattern a type
99

1010
error: aborting due to previous error

src/test/ui/issue-12187-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed
44
LL | let &v = new();
55
| -^
66
| ||
7-
| |cannot infer type for `_`
7+
| |cannot infer type
88
| consider giving the pattern a type
99

1010
error: aborting due to previous error

src/test/ui/issue-15965.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed
44
LL | / { return () }
55
LL | | //~^ ERROR type annotations needed [E0282]
66
LL | | ()
7-
| |______^ cannot infer type for `_`
7+
| |______^ cannot infer type
88
|
99
= note: type must be known at this point
1010

src/test/ui/issue-18159.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed
44
LL | let x; //~ ERROR type annotations needed
55
| ^
66
| |
7-
| cannot infer type for `_`
7+
| cannot infer type
88
| consider giving `x` a type
99

1010
error: aborting due to previous error

src/test/ui/issue-20261.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed
44
LL | for (ref i,) in [].iter() {
55
| --------- the element type for this iterator is not specified
66
LL | i.clone();
7-
| ^^^^^ cannot infer type for `_`
7+
| ^^^^^ cannot infer type
88
|
99
= note: type must be known at this point
1010

src/test/ui/issue-2151.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed
44
LL | let x = panic!();
55
| - consider giving `x` a type
66
LL | x.clone(); //~ ERROR type annotations needed
7-
| ^ cannot infer type for `_`
7+
| ^ cannot infer type
88
|
99
= note: type must be known at this point
1010

src/test/ui/issue-23041.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
22
--> $DIR/issue-23041.rs:16:22
33
|
44
LL | b.downcast_ref::<fn(_)->_>(); //~ ERROR E0282
5-
| ^^^^^^^^ cannot infer type for `_`
5+
| ^^^^^^^^ cannot infer type
66

77
error: aborting due to previous error
88

src/test/ui/issue-24013.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
22
--> $DIR/issue-24013.rs:15:20
33
|
44
LL | unsafe {swap::<&mut _>(transmute(&a), transmute(&b))};
5-
| ^^^^^^ cannot infer type for `_`
5+
| ^^^^^^ cannot infer type
66

77
error: aborting due to previous error
88

src/test/ui/issue-51116.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() {
1515
//~^ NOTE the element type for this iterator is not specified
1616
*tile = 0;
1717
//~^ ERROR type annotations needed
18-
//~| NOTE cannot infer type for `_`
18+
//~| NOTE cannot infer type
1919
//~| NOTE type must be known at this point
2020
}
2121
}

src/test/ui/issue-51116.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | for tile in row {
55
| --- the element type for this iterator is not specified
66
LL | //~^ NOTE the element type for this iterator is not specified
77
LL | *tile = 0;
8-
| ^^^^^ cannot infer type for `_`
8+
| ^^^^^ cannot infer type
99
|
1010
= note: type must be known at this point
1111

src/test/ui/issue-7813.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
22
--> $DIR/issue-7813.rs:12:13
33
|
44
LL | let v = &[]; //~ ERROR type annotations needed
5-
| - ^^^ cannot infer type for `_`
5+
| - ^^^ cannot infer type
66
| |
77
| consider giving `v` a type
88

src/test/ui/span/issue-42234-unknown-receiver-type.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ error[E0282]: type annotations needed
1313
|
1414
LL | / data.iter() //~ ERROR 22:5: 23:20: type annotations needed
1515
LL | | .sum::<_>()
16-
| |___________________^ cannot infer type for `_`
16+
| |___________________^ cannot infer type
1717
|
1818
= note: type must be known at this point
1919

src/test/ui/span/method-and-field-eager-resolution.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed
44
LL | let mut x = Default::default();
55
| ----- consider giving `x` a type
66
LL | x.0;
7-
| ^ cannot infer type for `_`
7+
| ^ cannot infer type
88
|
99
= note: type must be known at this point
1010

@@ -14,7 +14,7 @@ error[E0282]: type annotations needed
1414
LL | let mut x = Default::default();
1515
| ----- consider giving `x` a type
1616
LL | x[0];
17-
| ^ cannot infer type for `_`
17+
| ^ cannot infer type
1818
|
1919
= note: type must be known at this point
2020

src/test/ui/type-check/cannot_infer_local_or_array.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
22
--> $DIR/cannot_infer_local_or_array.rs:12:13
33
|
44
LL | let x = []; //~ ERROR type annotations needed
5-
| - ^^ cannot infer type for `_`
5+
| - ^^ cannot infer type
66
| |
77
| consider giving `x` a type
88

0 commit comments

Comments
 (0)