Skip to content

Commit ebbe725

Browse files
committed
Tweak wording
1 parent 74fb3bb commit ebbe725

13 files changed

+25
-31
lines changed

src/librustc/infer/error_reporting/need_type_info.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
148148
// L | let b = Ok(4);
149149
// | - ^^ cannot infer type for `E` in `std::result::Result<i32, E>`
150150
// | |
151-
// | consider giving `b` a type
151+
// | consider giving `b` the type `std::result::Result<i32, E>` with the type
152+
// | parameter `E` specified
152153
// ```
153-
let ty_msg = match &local_visitor.found_ty {
154+
let (ty_msg, suffix) = match &local_visitor.found_ty {
154155
Some(ty) if &ty.to_string() != "_" && ty.to_string() != name => {
155-
format!(" in `{}`", ty_to_string(ty))
156+
let ty = ty_to_string(ty);
157+
(format!(" in `{}`", ty),
158+
format!( "the type `{}` with the type parameter `{}` specified", ty, name))
156159
}
157-
_ => String::new(),
160+
_ => (String::new(), "a type".to_owned()),
158161
};
159162
let mut labels = vec![(span, InferCtxt::missing_type_msg(&name, &ty_msg))];
160163

@@ -177,25 +180,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
177180
// with the type parameter `_` specified
178181
// ```
179182
labels.clear();
180-
labels.push((pattern.span, format!(
181-
"consider giving this closure parameter {}",
182-
match &local_visitor.found_ty {
183-
Some(ty) if &ty.to_string() != "_" && ty.to_string() != name => {
184-
format!(
185-
"the type `{}` with the type parameter `{}` specified",
186-
ty_to_string(ty),
187-
name,
188-
)
189-
}
190-
_ => "a type".to_owned(),
191-
},
192-
)));
183+
labels.push((
184+
pattern.span,
185+
format!("consider giving this closure parameter {}", suffix),
186+
));
193187
} else if let Some(pattern) = local_visitor.found_local_pattern {
194188
if let Some(simple_ident) = pattern.simple_ident() {
195189
match pattern.span.compiler_desugaring_kind() {
196190
None => labels.push((
197191
pattern.span,
198-
format!("consider giving `{}` a type", simple_ident),
192+
format!("consider giving `{}` {}", simple_ident, suffix),
199193
)),
200194
Some(CompilerDesugaringKind::ForLoop) => labels.push((
201195
pattern.span,
@@ -204,7 +198,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
204198
_ => {}
205199
}
206200
} else {
207-
labels.push((pattern.span, "consider giving the pattern a type".to_owned()));
201+
labels.push((pattern.span, format!("consider giving this pattern {}", suffix)));
208202
}
209203
};
210204

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let &v = new();
55
| -^
66
| ||
77
| |cannot infer type
8-
| consider giving the pattern a type
8+
| consider giving this pattern the type `&T` with the type parameter `_` specified
99

1010
error: aborting due to previous error
1111

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let &v = new();
55
| -^
66
| ||
77
| |cannot infer type
8-
| consider giving the pattern a type
8+
| consider giving this pattern the type `&T` with the type parameter `_` specified
99

1010
error: aborting due to previous error
1111

src/test/ui/issues/issue-17551.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `B<T>`
44
LL | let foo = B(marker::PhantomData);
55
| --- ^ cannot infer type for `T` in `B<T>`
66
| |
7-
| consider giving `foo` a type
7+
| consider giving `foo` the type `B<T>` with the type parameter `T` specified
88

99
error: aborting due to previous error
1010

src/test/ui/issues/issue-25368.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed in `(std::sync::mpsc::Sender<Foo<T>>, std:
22
--> $DIR/issue-25368.rs:11:17
33
|
44
LL | let (tx, rx) = channel();
5-
| -------- consider giving the pattern a type
5+
| -------- consider giving this pattern the type `(std::sync::mpsc::Sender<Foo<T>>, std::sync::mpsc::Receiver<Foo<T>>)` with the type parameter `T` specified
66
...
77
LL | tx.send(Foo{ foo: PhantomData });
88
| ^^^ cannot infer type for `T` in `(std::sync::mpsc::Sender<Foo<T>>, std::sync::mpsc::Receiver<Foo<T>>)`

src/test/ui/issues/issue-7813.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `&[_; 0]`
44
LL | let v = &[];
55
| - ^^^ cannot infer type
66
| |
7-
| consider giving `v` a type
7+
| consider giving `v` the type `&[_; 0]` with the type parameter `_` specified
88

99
error: aborting due to previous error
1010

src/test/ui/methods/method-ambig-one-trait-unknown-int-type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `std::vec::Vec<T>`
44
LL | let mut x = Vec::new();
55
| ----- ^^^^^^^^ cannot infer type for `T` in `std::vec::Vec<T>`
66
| |
7-
| consider giving `x` a type
7+
| consider giving `x` the type `std::vec::Vec<T>` with the type parameter `T` specified
88

99
error[E0308]: mismatched types
1010
--> $DIR/method-ambig-one-trait-unknown-int-type.rs:33:20

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed in `std::option::Option<_>`
22
--> $DIR/issue-42234-unknown-receiver-type.rs:7:5
33
|
44
LL | let x: Option<_> = None;
5-
| - consider giving `x` a type
5+
| - consider giving `x` the type `std::option::Option<_>` with the type parameter `T` specified
66
LL | x.unwrap().method_that_could_exist_on_some_type();
77
| ^^^^^^^^^^ cannot infer type for `T` in `std::option::Option<_>`
88
|

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `[_; 0]`
44
LL | let x = [];
55
| - ^^ cannot infer type
66
| |
7-
| consider giving `x` a type
7+
| consider giving `x` the type `[_; 0]` with the type parameter `_` specified
88

99
error: aborting due to previous error
1010

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `std::vec::Vec<T>`
44
LL | let x = vec![];
55
| - ^^^^^^ cannot infer type for `T` in `std::vec::Vec<T>`
66
| |
7-
| consider giving `x` a type
7+
| consider giving `x` the type `std::vec::Vec<T>` with the type parameter `T` specified
88
|
99
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1010

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `(std::vec::Vec<T>,)`
44
LL | let (x, ) = (vec![], );
55
| ----- ^^^^^^ cannot infer type for `T` in `(std::vec::Vec<T>,)`
66
| |
7-
| consider giving the pattern a type
7+
| consider giving this pattern the type `(std::vec::Vec<T>,)` with the type parameter `T` specified
88
|
99
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1010

src/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed in `std::option::Option<T>`
22
--> $DIR/unboxed-closures-failed-recursive-fn-2.rs:16:32
33
|
44
LL | let mut closure0 = None;
5-
| ------------ consider giving `closure0` a type
5+
| ------------ consider giving `closure0` the type `std::option::Option<T>` with the type parameter `_` specified
66
...
77
LL | return c();
88
| ^^^ cannot infer type

src/test/ui/vector-no-ann.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `std::vec::Vec<T>`
44
LL | let _foo = Vec::new();
55
| ---- ^^^^^^^^ cannot infer type for `T` in `std::vec::Vec<T>`
66
| |
7-
| consider giving `_foo` a type
7+
| consider giving `_foo` the type `std::vec::Vec<T>` with the type parameter `T` specified
88

99
error: aborting due to previous error
1010

0 commit comments

Comments
 (0)