}
cx.struct_span_lint(OVERFLOWING_LITERALS, e.span, |lint| {
- lint.build(&format!("literal out of range for `{}`", t.name_str()))
- .note(&format!(
- "the literal `{}` does not fit into the type `{}` whose range is `{}..={}`",
- cx.sess()
- .source_map()
- .span_to_snippet(lit.span)
- .expect("must get snippet from literal"),
- t.name_str(),
- min,
- max,
- ))
- .emit();
+ let mut err = lint.build(&format!("literal out of range for `{}`", t.name_str()));
+ err.note(&format!(
+ "the literal `{}` does not fit into the type `{}` whose range is `{}..={}`",
+ cx.sess()
+ .source_map()
+ .span_to_snippet(lit.span)
+ .expect("must get snippet from literal"),
+ t.name_str(),
+ min,
+ max,
+ ));
+ if let Some(sugg_ty) =
+ get_type_suggestion(&cx.typeck_results().node_type(e.hir_id), v, negative)
+ {
+ err.help(&format!("consider using `{}` instead", sugg_ty));
+ }
+ err.emit();
});
}
}
LL | #![deny(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
= note: the literal `223` does not fit into the type `i8` whose range is `-128..=127`
+ = help: consider using `u8` instead
error: literal out of range for `i16`
--> $DIR/enum-discrim-too-small2.rs:15:12
| ^^^^^
|
= note: the literal `55555` does not fit into the type `i16` whose range is `-32768..=32767`
+ = help: consider using `u16` instead
error: literal out of range for `i32`
--> $DIR/enum-discrim-too-small2.rs:22:12
| ^^^^^^^^^^^^^
|
= note: the literal `3_000_000_000` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
+ = help: consider using `u32` instead
error: literal out of range for `i64`
--> $DIR/enum-discrim-too-small2.rs:29:12
| ^^^^^^^^^^^^^^^^^^^
|
= note: the literal `9223372036854775809` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807`
+ = help: consider using `u64` instead
error: aborting due to 4 previous errors
| ^^^
|
= note: the literal `128` does not fit into the type `i8` whose range is `-128..=127`
+ = help: consider using `u8` instead
error: literal out of range for `i8`
--> $DIR/lint-type-overflow.rs:18:19
| ^^^
|
= note: the literal `129` does not fit into the type `i8` whose range is `-128..=127`
+ = help: consider using `i16` instead
error: literal out of range for `i8`
--> $DIR/lint-type-overflow.rs:19:19
| ^^^^^
|
= note: the literal `129` does not fit into the type `i8` whose range is `-128..=127`
+ = help: consider using `i16` instead
error: literal out of range for `i8`
--> $DIR/lint-type-overflow.rs:20:20
| ^^^
|
= note: the literal `129` does not fit into the type `i8` whose range is `-128..=127`
+ = help: consider using `u8` instead
error: literal out of range for `i8`
--> $DIR/lint-type-overflow.rs:22:10
| ^^^^
|
= note: the literal `1000` does not fit into the type `i8` whose range is `-128..=127`
+ = help: consider using `i16` instead
error: literal out of range for `i8`
--> $DIR/lint-type-overflow.rs:24:13
| ^^^^^^
|
= note: the literal `128_i8` does not fit into the type `i8` whose range is `-128..=127`
+ = help: consider using `u8` instead
error: literal out of range for `i8`
--> $DIR/lint-type-overflow.rs:28:14
| ^^^^^^
|
= note: the literal `129_i8` does not fit into the type `i8` whose range is `-128..=127`
+ = help: consider using `i16` instead
error: literal out of range for `i32`
--> $DIR/lint-type-overflow.rs:32:18
| ^^^^^^^^^^
|
= note: the literal `2147483648` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
+ = help: consider using `u32` instead
error: literal out of range for `i32`
--> $DIR/lint-type-overflow.rs:33:13
| ^^^^^^^^^^^^^^
|
= note: the literal `2147483648_i32` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
+ = help: consider using `u32` instead
error: literal out of range for `i32`
--> $DIR/lint-type-overflow.rs:36:19
| ^^^^^^^^^^
|
= note: the literal `2147483649` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
+ = help: consider using `i64` instead
error: literal out of range for `i32`
--> $DIR/lint-type-overflow.rs:37:14
| ^^^^^^^^^^^^^^
|
= note: the literal `2147483649_i32` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
+ = help: consider using `i64` instead
error: literal out of range for `i32`
--> $DIR/lint-type-overflow.rs:38:13
| ^^^^^^^^^^
|
= note: the literal `2147483648` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
+ = help: consider using `u32` instead
error: literal out of range for `i64`
--> $DIR/lint-type-overflow.rs:40:13
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the literal `9223372036854775808_i64` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807`
+ = help: consider using `u64` instead
error: literal out of range for `i64`
--> $DIR/lint-type-overflow.rs:42:13
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the literal `18446744073709551615_i64` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807`
+ = help: consider using `u64` instead
error: literal out of range for `i64`
--> $DIR/lint-type-overflow.rs:43:19
| ^^^^^^^^^^^^^^^^^^^
|
= note: the literal `9223372036854775809` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807`
+ = help: consider using `i128` instead
error: literal out of range for `i64`
--> $DIR/lint-type-overflow.rs:44:14
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the literal `9223372036854775809_i64` does not fit into the type `i64` whose range is `-9223372036854775808..=9223372036854775807`
+ = help: consider using `i128` instead
error: aborting due to 18 previous errors