diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2019-12-10 14:15:38 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2019-12-10 14:15:38 -0800 |
| commit | 94ab9ec36bd3401b3185aff7b623ff0317b96356 (patch) | |
| tree | 1119f01aa3cd68f4cfeb516fe86c94b07708d234 | |
| parent | 860c7e425ba07a4f5f9a5d5990227a857378a8e0 (diff) | |
| download | rust-94ab9ec36bd3401b3185aff7b623ff0317b96356.tar.gz rust-94ab9ec36bd3401b3185aff7b623ff0317b96356.zip | |
Avoid invalid suggestion by checking the snippet in const fn call
| -rw-r--r-- | src/librustc/traits/error_reporting.rs | 23 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-54954.stderr | 5 |
2 files changed, 23 insertions, 5 deletions
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index b8200a8e173..233d195766f 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1999,7 +1999,28 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &obligation.cause.code, ) { let generics = self.tcx.generics_of(*def_id); - if !generics.params.is_empty() { + if !generics.params.is_empty() && !snippet.ends_with('>'){ + // FIXME: To avoid spurious suggestions in functions where type arguments + // where already supplied, we check the snippet to make sure it doesn't + // end with a turbofish. Ideally we would have access to a `PathSegment` + // instead. Otherwise we would produce the following output: + // + // error[E0283]: type annotations needed + // --> $DIR/issue-54954.rs:3:24 + // | + // LL | const ARR_LEN: usize = Tt::const_val::<[i8; 123]>(); + // | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + // | | + // | cannot infer type + // | help: consider specifying the type argument + // | in the function call: + // | `Tt::const_val::<[i8; 123]>::<T>` + // ... + // LL | const fn const_val<T: Sized>() -> usize { + // | --------- - required by this bound in `Tt::const_val` + // | + // = note: cannot resolve `_: Tt` + err.span_suggestion( span, &format!( diff --git a/src/test/ui/issues/issue-54954.stderr b/src/test/ui/issues/issue-54954.stderr index 21909baf3ba..d99a5772e8a 100644 --- a/src/test/ui/issues/issue-54954.stderr +++ b/src/test/ui/issues/issue-54954.stderr @@ -8,10 +8,7 @@ error[E0283]: type annotations needed --> $DIR/issue-54954.rs:3:24 | LL | const ARR_LEN: usize = Tt::const_val::<[i8; 123]>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | cannot infer type - | help: consider specifying the type argument in the function call: `Tt::const_val::<[i8; 123]>::<T>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type ... LL | const fn const_val<T: Sized>() -> usize { | --------- - required by this bound in `Tt::const_val` |
