Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
.inspect(|vid| {
let origin = self.float_var_origin(*vid);
// Show the entire literal in the suggestion to make it clearer.
let literal = self.tcx.sess.source_map().span_to_snippet(origin.span).ok();
let mut literal = self.tcx.sess.source_map().span_to_snippet(origin.span).ok();
// A `.` at the end of the literal is no longer necessary if `f32` is explicitly specified
if let Some(ref mut literal) = literal
&& literal.ends_with('.')
{
literal.pop();
}
self.tcx.emit_node_span_lint(
FLOAT_LITERAL_F32_FALLBACK,
origin.lint_id.unwrap_or(CRATE_HIR_ID),
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/float/f32-into-f32.next-solver.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ fn main() {
foo(1e5_f32);
//~^ WARN falling back to `f32`
//~| WARN this was previously accepted
foo(0_f32);
//~^ WARN falling back to `f32`
//~| WARN this was previously accepted
foo(4f32); // no warning
let x = -4.0_f32;
//~^ WARN falling back to `f32`
Expand Down
13 changes: 11 additions & 2 deletions tests/ui/float/f32-into-f32.next-solver.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ LL | foo(1e5);
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>

warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
--> $DIR/f32-into-f32.rs:19:14
--> $DIR/f32-into-f32.rs:18:9
|
LL | foo(0.);
| ^^ help: explicitly specify the type as `f32`: `0_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>

warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
--> $DIR/f32-into-f32.rs:22:14
|
LL | let x = -4.0;
| ^^^ help: explicitly specify the type as `f32`: `4.0_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>

warning: 4 warnings emitted
warning: 5 warnings emitted

3 changes: 3 additions & 0 deletions tests/ui/float/f32-into-f32.old-solver.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ fn main() {
foo(1e5_f32);
//~^ WARN falling back to `f32`
//~| WARN this was previously accepted
foo(0_f32);
//~^ WARN falling back to `f32`
//~| WARN this was previously accepted
foo(4f32); // no warning
let x = -4.0_f32;
//~^ WARN falling back to `f32`
Expand Down
13 changes: 11 additions & 2 deletions tests/ui/float/f32-into-f32.old-solver.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ LL | foo(1e5);
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>

warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
--> $DIR/f32-into-f32.rs:19:14
--> $DIR/f32-into-f32.rs:18:9
|
LL | foo(0.);
| ^^ help: explicitly specify the type as `f32`: `0_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>

warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
--> $DIR/f32-into-f32.rs:22:14
|
LL | let x = -4.0;
| ^^^ help: explicitly specify the type as `f32`: `4.0_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>

warning: 4 warnings emitted
warning: 5 warnings emitted

3 changes: 3 additions & 0 deletions tests/ui/float/f32-into-f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ fn main() {
foo(1e5);
//~^ WARN falling back to `f32`
//~| WARN this was previously accepted
foo(0.);
//~^ WARN falling back to `f32`
//~| WARN this was previously accepted
foo(4f32); // no warning
let x = -4.0;
//~^ WARN falling back to `f32`
Expand Down
Loading