Avoid suggesting literal formatting that turns into member access
Fixes #90974
This commit is contained in:
parent
891ca5f63c
commit
a7261c32f4
@ -317,6 +317,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
.span_to_snippet(lit.span)
|
||||
.unwrap_or_else(|_| "<numeric literal>".to_owned());
|
||||
|
||||
// If this is a floating point literal that ends with '.',
|
||||
// get rid of it to stop this from becoming a member access.
|
||||
let snippet = snippet.strip_suffix('.').unwrap_or(&snippet);
|
||||
|
||||
err.span_suggestion(
|
||||
lit.span,
|
||||
&format!(
|
||||
@ -324,7 +328,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
like `{}`",
|
||||
concrete_type
|
||||
),
|
||||
format!("{}_{}", snippet, concrete_type),
|
||||
format!("{snippet}_{concrete_type}"),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
|
3
src/test/ui/suggestions/issue-90974.rs
Normal file
3
src/test/ui/suggestions/issue-90974.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("{}", (3.).recip()); //~ERROR
|
||||
}
|
14
src/test/ui/suggestions/issue-90974.stderr
Normal file
14
src/test/ui/suggestions/issue-90974.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error[E0689]: can't call method `recip` on ambiguous numeric type `{float}`
|
||||
--> $DIR/issue-90974.rs:2:25
|
||||
|
|
||||
LL | println!("{}", (3.).recip());
|
||||
| ^^^^^
|
||||
|
|
||||
help: you must specify a concrete type for this numeric value, like `f32`
|
||||
|
|
||||
LL | println!("{}", (3_f32).recip());
|
||||
| ~~~~~
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0689`.
|
Loading…
x
Reference in New Issue
Block a user