Skip to content

Commit 6d50672

Browse files
author
Esteban Küber
committed
Reword when _ couldn't be inferred
1 parent 29ee654 commit 6d50672

14 files changed

+22
-15
lines changed

src/librustc/infer/error_reporting/need_type_info.rs

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

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

101108
let mut local_visitor = FindLocalByTypeVisitor {
102109
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
| -------- consider giving `__next` a type
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-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)