Skip to content

Commit

Permalink
Tweak wording
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jun 1, 2019
1 parent 74fb3bb commit ebbe725
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 31 deletions.
32 changes: 13 additions & 19 deletions src/librustc/infer/error_reporting/need_type_info.rs
Expand Up @@ -148,13 +148,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// L | let b = Ok(4);
// | - ^^ cannot infer type for `E` in `std::result::Result<i32, E>`
// | |
// | consider giving `b` a type
// | consider giving `b` the type `std::result::Result<i32, E>` with the type
// | parameter `E` specified
// ```
let ty_msg = match &local_visitor.found_ty {
let (ty_msg, suffix) = match &local_visitor.found_ty {
Some(ty) if &ty.to_string() != "_" && ty.to_string() != name => {
format!(" in `{}`", ty_to_string(ty))
let ty = ty_to_string(ty);
(format!(" in `{}`", ty),
format!( "the type `{}` with the type parameter `{}` specified", ty, name))
}
_ => String::new(),
_ => (String::new(), "a type".to_owned()),
};
let mut labels = vec![(span, InferCtxt::missing_type_msg(&name, &ty_msg))];

Expand All @@ -177,25 +180,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// with the type parameter `_` specified
// ```
labels.clear();
labels.push((pattern.span, format!(
"consider giving this closure parameter {}",
match &local_visitor.found_ty {
Some(ty) if &ty.to_string() != "_" && ty.to_string() != name => {
format!(
"the type `{}` with the type parameter `{}` specified",
ty_to_string(ty),
name,
)
}
_ => "a type".to_owned(),
},
)));
labels.push((
pattern.span,
format!("consider giving this closure parameter {}", suffix),
));
} else if let Some(pattern) = local_visitor.found_local_pattern {
if let Some(simple_ident) = pattern.simple_ident() {
match pattern.span.compiler_desugaring_kind() {
None => labels.push((
pattern.span,
format!("consider giving `{}` a type", simple_ident),
format!("consider giving `{}` {}", simple_ident, suffix),
)),
Some(CompilerDesugaringKind::ForLoop) => labels.push((
pattern.span,
Expand All @@ -204,7 +198,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
_ => {}
}
} else {
labels.push((pattern.span, "consider giving the pattern a type".to_owned()));
labels.push((pattern.span, format!("consider giving this pattern {}", suffix)));
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-12187-1.stderr
Expand Up @@ -5,7 +5,7 @@ LL | let &v = new();
| -^
| ||
| |cannot infer type
| consider giving the pattern a type
| consider giving this pattern the type `&T` with the type parameter `_` specified

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-12187-2.stderr
Expand Up @@ -5,7 +5,7 @@ LL | let &v = new();
| -^
| ||
| |cannot infer type
| consider giving the pattern a type
| consider giving this pattern the type `&T` with the type parameter `_` specified

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-17551.stderr
Expand Up @@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `B<T>`
LL | let foo = B(marker::PhantomData);
| --- ^ cannot infer type for `T` in `B<T>`
| |
| consider giving `foo` a type
| consider giving `foo` the type `B<T>` with the type parameter `T` specified

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-25368.stderr
Expand Up @@ -2,7 +2,7 @@ error[E0282]: type annotations needed in `(std::sync::mpsc::Sender<Foo<T>>, std:
--> $DIR/issue-25368.rs:11:17
|
LL | let (tx, rx) = channel();
| -------- consider giving the pattern a type
| -------- consider giving this pattern the type `(std::sync::mpsc::Sender<Foo<T>>, std::sync::mpsc::Receiver<Foo<T>>)` with the type parameter `T` specified
...
LL | tx.send(Foo{ foo: PhantomData });
| ^^^ cannot infer type for `T` in `(std::sync::mpsc::Sender<Foo<T>>, std::sync::mpsc::Receiver<Foo<T>>)`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-7813.stderr
Expand Up @@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `&[_; 0]`
LL | let v = &[];
| - ^^^ cannot infer type
| |
| consider giving `v` a type
| consider giving `v` the type `&[_; 0]` with the type parameter `_` specified

error: aborting due to previous error

Expand Down
Expand Up @@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `std::vec::Vec<T>`
LL | let mut x = Vec::new();
| ----- ^^^^^^^^ cannot infer type for `T` in `std::vec::Vec<T>`
| |
| consider giving `x` a type
| consider giving `x` the type `std::vec::Vec<T>` with the type parameter `T` specified

error[E0308]: mismatched types
--> $DIR/method-ambig-one-trait-unknown-int-type.rs:33:20
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/span/issue-42234-unknown-receiver-type.stderr
Expand Up @@ -2,7 +2,7 @@ error[E0282]: type annotations needed in `std::option::Option<_>`
--> $DIR/issue-42234-unknown-receiver-type.rs:7:5
|
LL | let x: Option<_> = None;
| - consider giving `x` a type
| - consider giving `x` the type `std::option::Option<_>` with the type parameter `T` specified
LL | x.unwrap().method_that_could_exist_on_some_type();
| ^^^^^^^^^^ cannot infer type for `T` in `std::option::Option<_>`
|
Expand Down
Expand Up @@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `[_; 0]`
LL | let x = [];
| - ^^ cannot infer type
| |
| consider giving `x` a type
| consider giving `x` the type `[_; 0]` with the type parameter `_` specified

error: aborting due to previous error

Expand Down
Expand Up @@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `std::vec::Vec<T>`
LL | let x = vec![];
| - ^^^^^^ cannot infer type for `T` in `std::vec::Vec<T>`
| |
| consider giving `x` a type
| consider giving `x` the type `std::vec::Vec<T>` with the type parameter `T` specified
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Expand Down
Expand Up @@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `(std::vec::Vec<T>,)`
LL | let (x, ) = (vec![], );
| ----- ^^^^^^ cannot infer type for `T` in `(std::vec::Vec<T>,)`
| |
| consider giving the pattern a type
| consider giving this pattern the type `(std::vec::Vec<T>,)` with the type parameter `T` specified
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Expand Down
Expand Up @@ -2,7 +2,7 @@ error[E0282]: type annotations needed in `std::option::Option<T>`
--> $DIR/unboxed-closures-failed-recursive-fn-2.rs:16:32
|
LL | let mut closure0 = None;
| ------------ consider giving `closure0` a type
| ------------ consider giving `closure0` the type `std::option::Option<T>` with the type parameter `_` specified
...
LL | return c();
| ^^^ cannot infer type
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/vector-no-ann.stderr
Expand Up @@ -4,7 +4,7 @@ error[E0282]: type annotations needed in `std::vec::Vec<T>`
LL | let _foo = Vec::new();
| ---- ^^^^^^^^ cannot infer type for `T` in `std::vec::Vec<T>`
| |
| consider giving `_foo` a type
| consider giving `_foo` the type `std::vec::Vec<T>` with the type parameter `T` specified

error: aborting due to previous error

Expand Down

0 comments on commit ebbe725

Please sign in to comment.