Skip to content

Commit 28c4813

Browse files
committed
use literal span for concrete type suggestion
Fixes rust-lang#51874.
1 parent ab8a67c commit 28c4813

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/librustc_typeck/check/method/suggest.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
245245
"f32"
246246
};
247247
match expr.node {
248-
hir::ExprLit(_) => { // numeric literal
249-
let snippet = tcx.sess.codemap().span_to_snippet(expr.span)
248+
hir::ExprLit(ref lit) => { // numeric literal
249+
let snippet = tcx.sess.codemap().span_to_snippet(lit.span)
250250
.unwrap_or("<numeric literal>".to_string());
251-
// FIXME: use the literal for missing snippet
252251

253-
err.span_suggestion(expr.span,
252+
err.span_suggestion(lit.span,
254253
&format!("you must specify a concrete type for \
255254
this numeric value, like `{}`",
256255
concrete_type),

src/test/ui/issue-51874.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let a = (1.0).pow(1.0); //~ ERROR can't call method `pow` on ambiguous numeric type
13+
}

src/test/ui/issue-51874.stderr

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0689]: can't call method `pow` on ambiguous numeric type `{float}`
2+
--> $DIR/issue-51874.rs:12:19
3+
|
4+
LL | let a = (1.0).pow(1.0); //~ ERROR can't call method `pow` on ambiguous numeric type
5+
| ^^^
6+
help: you must specify a concrete type for this numeric value, like `f32`
7+
|
8+
LL | let a = (1.0_f32).pow(1.0); //~ ERROR can't call method `pow` on ambiguous numeric type
9+
| ^^^^^^^
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0689`.

0 commit comments

Comments
 (0)