Place types inside backticks

This commit is contained in:
varkor 2019-04-27 12:56:57 +01:00
parent c5fdff26b5
commit 218982bef0
17 changed files with 95 additions and 97 deletions

View file

@ -106,7 +106,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
cx.span_lint(
OVERFLOWING_LITERALS,
e.span,
&format!("literal out of range for {:?}", t),
&format!("literal out of range for `{:?}`", t),
);
return;
}
@ -136,11 +136,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
let mut err = cx.struct_span_lint(
OVERFLOWING_LITERALS,
parent_expr.span,
"only u8 can be cast into char",
"only `u8` can be cast into `char`",
);
err.span_suggestion(
parent_expr.span,
&"use a char literal instead",
&"use a `char` literal instead",
format!("'\\u{{{:X}}}'", lit_val),
Applicability::MachineApplicable,
);
@ -165,7 +165,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
parent_expr.span,
&format!(
"range endpoint is out of range \
for {:?}",
for `{:?}`",
t,
),
);
@ -206,7 +206,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
cx.span_lint(
OVERFLOWING_LITERALS,
e.span,
&format!("literal out of range for {:?}", t),
&format!("literal out of range for `{:?}`", t),
);
}
}
@ -224,7 +224,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
if is_infinite == Ok(true) {
cx.span_lint(OVERFLOWING_LITERALS,
e.span,
&format!("literal out of range for {:?}", t));
&format!("literal out of range for `{:?}`", t));
}
}
_ => (),

View file

@ -2,9 +2,9 @@
fn main() {
const XYZ: char = 0x1F888 as char;
//~^ ERROR only u8 can be cast into char
//~^ ERROR only `u8` can be cast into `char`
const XY: char = 129160 as char;
//~^ ERROR only u8 can be cast into char
//~^ ERROR only `u8` can be cast into `char`
const ZYX: char = '\u{01F888}';
println!("{}", XYZ);
}

View file

@ -1,8 +1,8 @@
error: only u8 can be cast into char
error: only `u8` can be cast into `char`
--> $DIR/cast_char.rs:4:23
|
LL | const XYZ: char = 0x1F888 as char;
| ^^^^^^^^^^^^^^^ help: use a char literal instead: `'\u{1F888}'`
| ^^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{1F888}'`
|
note: lint level defined here
--> $DIR/cast_char.rs:1:9
@ -10,11 +10,11 @@ note: lint level defined here
LL | #![deny(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
error: only u8 can be cast into char
error: only `u8` can be cast into `char`
--> $DIR/cast_char.rs:6:22
|
LL | const XY: char = 129160 as char;
| ^^^^^^^^^^^^^^ help: use a char literal instead: `'\u{1F888}'`
| ^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{1F888}'`
error: aborting due to 2 previous errors

View file

@ -5,28 +5,28 @@
enum Ei8 {
Ai8 = 23,
Bi8 = -23,
Ci8 = 223, //~ ERROR literal out of range for i8
Ci8 = 223, //~ ERROR literal out of range for `i8`
}
#[repr(i16)]
enum Ei16 {
Ai16 = 23,
Bi16 = -22333,
Ci16 = 55555, //~ ERROR literal out of range for i16
Ci16 = 55555, //~ ERROR literal out of range for `i16`
}
#[repr(i32)]
enum Ei32 {
Ai32 = 23,
Bi32 = -2_000_000_000,
Ci32 = 3_000_000_000, //~ ERROR literal out of range for i32
Ci32 = 3_000_000_000, //~ ERROR literal out of range for `i32`
}
#[repr(i64)]
enum Ei64 {
Ai64 = 23,
Bi64 = -9223372036854775808,
Ci64 = 9223372036854775809, //~ ERROR literal out of range for i64
Ci64 = 9223372036854775809, //~ ERROR literal out of range for `i64`
}
// u64 currently allows negative numbers, and i64 allows numbers greater than `1<<63`. This is a

View file

@ -1,4 +1,4 @@
error: literal out of range for i8
error: literal out of range for `i8`
--> $DIR/enum-discrim-too-small2.rs:8:11
|
LL | Ci8 = 223,
@ -10,19 +10,19 @@ note: lint level defined here
LL | #![deny(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
error: literal out of range for i16
error: literal out of range for `i16`
--> $DIR/enum-discrim-too-small2.rs:15:12
|
LL | Ci16 = 55555,
| ^^^^^
error: literal out of range for i32
error: literal out of range for `i32`
--> $DIR/enum-discrim-too-small2.rs:22:12
|
LL | Ci32 = 3_000_000_000,
| ^^^^^^^^^^^^^
error: literal out of range for i64
error: literal out of range for `i64`
--> $DIR/enum-discrim-too-small2.rs:29:12
|
LL | Ci64 = 9223372036854775809,

View file

@ -1,4 +1,4 @@
fn main() {
let x: u8 = 256;
//~^ error: literal out of range for u8
//~^ error: literal out of range for `u8`
}

View file

@ -1,4 +1,4 @@
error: literal out of range for u8
error: literal out of range for `u8`
--> $DIR/deny-overflowing-literals.rs:2:17
|
LL | let x: u8 = 256;

View file

@ -1,11 +1,11 @@
#![deny(overflowing_literals)]
fn main() {
let range_a = 0..256; //~ ERROR range endpoint is out of range for u8
let range_a = 0..256; //~ ERROR range endpoint is out of range for `u8`
let range_b = 0..=255; // ok
let range_c = 0..=256; //~ ERROR literal out of range for u8
let range_d = 256..5; //~ ERROR literal out of range for u8
let range_e = 0..257; //~ ERROR literal out of range for u8
let range_c = 0..=256; //~ ERROR literal out of range for `u8`
let range_d = 256..5; //~ ERROR literal out of range for `u8`
let range_e = 0..257; //~ ERROR literal out of range for `u8`
range_a.collect::<Vec<u8>>();
range_b.collect::<Vec<u8>>();

View file

@ -1,4 +1,4 @@
error: range endpoint is out of range for u8
error: range endpoint is out of range for `u8`
--> $DIR/lint-range-endpoint-overflow.rs:4:19
|
LL | let range_a = 0..256;
@ -10,19 +10,19 @@ note: lint level defined here
LL | #![deny(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
error: literal out of range for u8
error: literal out of range for `u8`
--> $DIR/lint-range-endpoint-overflow.rs:6:23
|
LL | let range_c = 0..=256;
| ^^^
error: literal out of range for u8
error: literal out of range for `u8`
--> $DIR/lint-range-endpoint-overflow.rs:7:19
|
LL | let range_d = 256..5;
| ^^^
error: literal out of range for u8
error: literal out of range for `u8`
--> $DIR/lint-range-endpoint-overflow.rs:8:22
|
LL | let range_e = 0..257;

View file

@ -11,5 +11,5 @@ fn bar() -> i8 {
fn baz() -> bool {
128 > bar() //~ ERROR comparison is useless due to type limits
//~| WARN literal out of range for i8
//~| WARN literal out of range for `i8`
}

View file

@ -6,7 +6,7 @@ LL | 128 > bar()
|
= note: requested on the command line with `-D unused-comparisons`
warning: literal out of range for i8
warning: literal out of range for `i8`
--> $DIR/lint-type-limits2.rs:13:5
|
LL | 128 > bar()

View file

@ -7,7 +7,7 @@ fn main() { }
fn qux() {
let mut i = 1i8;
while 200 != i { //~ ERROR comparison is useless due to type limits
//~| WARN literal out of range for i8
//~| WARN literal out of range for `i8`
i += 1;
}
}

View file

@ -6,7 +6,7 @@ LL | while 200 != i {
|
= note: requested on the command line with `-D unused-comparisons`
warning: literal out of range for i8
warning: literal out of range for `i8`
--> $DIR/lint-type-limits3.rs:9:11
|
LL | while 200 != i {

View file

@ -1,5 +1,3 @@
//
#![deny(overflowing_literals)]
fn test(x: i8) {
@ -9,39 +7,39 @@ fn test(x: i8) {
#[allow(unused_variables)]
fn main() {
let x1: u8 = 255; // should be OK
let x1: u8 = 256; //~ error: literal out of range for u8
let x1: u8 = 256; //~ error: literal out of range for `u8`
let x1 = 255_u8; // should be OK
let x1 = 256_u8; //~ error: literal out of range for u8
let x1 = 256_u8; //~ error: literal out of range for `u8`
let x2: i8 = -128; // should be OK
let x1: i8 = 128; //~ error: literal out of range for i8
let x1: i8 = 128; //~ error: literal out of range for `i8`
let x3: i8 = -129; //~ error: literal out of range for i8
let x3: i8 = -(129); //~ error: literal out of range for i8
let x3: i8 = -{129}; //~ error: literal out of range for i8
let x3: i8 = -129; //~ error: literal out of range for `i8`
let x3: i8 = -(129); //~ error: literal out of range for `i8`
let x3: i8 = -{129}; //~ error: literal out of range for `i8`
test(1000); //~ error: literal out of range for i8
test(1000); //~ error: literal out of range for `i8`
let x = 128_i8; //~ error: literal out of range for i8
let x = 128_i8; //~ error: literal out of range for `i8`
let x = 127_i8;
let x = -128_i8;
let x = -(128_i8);
let x = -129_i8; //~ error: literal out of range for i8
let x = -129_i8; //~ error: literal out of range for `i8`
let x: i32 = 2147483647; // should be OK
let x = 2147483647_i32; // should be OK
let x: i32 = 2147483648; //~ error: literal out of range for i32
let x = 2147483648_i32; //~ error: literal out of range for i32
let x: i32 = 2147483648; //~ error: literal out of range for `i32`
let x = 2147483648_i32; //~ error: literal out of range for `i32`
let x: i32 = -2147483648; // should be OK
let x = -2147483648_i32; // should be OK
let x: i32 = -2147483649; //~ error: literal out of range for i32
let x = -2147483649_i32; //~ error: literal out of range for i32
let x = 2147483648; //~ error: literal out of range for i32
let x: i32 = -2147483649; //~ error: literal out of range for `i32`
let x = -2147483649_i32; //~ error: literal out of range for `i32`
let x = 2147483648; //~ error: literal out of range for `i32`
let x = 9223372036854775808_i64; //~ error: literal out of range for i64
let x = 9223372036854775808_i64; //~ error: literal out of range for `i64`
let x = -9223372036854775808_i64; // should be OK
let x = 18446744073709551615_i64; //~ error: literal out of range for i64
let x: i64 = -9223372036854775809; //~ error: literal out of range for i64
let x = -9223372036854775809_i64; //~ error: literal out of range for i64
let x = 18446744073709551615_i64; //~ error: literal out of range for `i64`
let x: i64 = -9223372036854775809; //~ error: literal out of range for `i64`
let x = -9223372036854775809_i64; //~ error: literal out of range for `i64`
}

View file

@ -1,113 +1,113 @@
error: literal out of range for u8
--> $DIR/lint-type-overflow.rs:12:18
error: literal out of range for `u8`
--> $DIR/lint-type-overflow.rs:10:18
|
LL | let x1: u8 = 256;
| ^^^
|
note: lint level defined here
--> $DIR/lint-type-overflow.rs:3:9
--> $DIR/lint-type-overflow.rs:1:9
|
LL | #![deny(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
error: literal out of range for u8
--> $DIR/lint-type-overflow.rs:15:14
error: literal out of range for `u8`
--> $DIR/lint-type-overflow.rs:13:14
|
LL | let x1 = 256_u8;
| ^^^^^^
error: literal out of range for i8
--> $DIR/lint-type-overflow.rs:18:18
error: literal out of range for `i8`
--> $DIR/lint-type-overflow.rs:16:18
|
LL | let x1: i8 = 128;
| ^^^
error: literal out of range for i8
--> $DIR/lint-type-overflow.rs:20:19
error: literal out of range for `i8`
--> $DIR/lint-type-overflow.rs:18:19
|
LL | let x3: i8 = -129;
| ^^^
error: literal out of range for i8
--> $DIR/lint-type-overflow.rs:21:19
error: literal out of range for `i8`
--> $DIR/lint-type-overflow.rs:19:19
|
LL | let x3: i8 = -(129);
| ^^^^^
error: literal out of range for i8
--> $DIR/lint-type-overflow.rs:22:20
error: literal out of range for `i8`
--> $DIR/lint-type-overflow.rs:20:20
|
LL | let x3: i8 = -{129};
| ^^^
error: literal out of range for i8
--> $DIR/lint-type-overflow.rs:24:10
error: literal out of range for `i8`
--> $DIR/lint-type-overflow.rs:22:10
|
LL | test(1000);
| ^^^^
error: literal out of range for i8
--> $DIR/lint-type-overflow.rs:26:13
error: literal out of range for `i8`
--> $DIR/lint-type-overflow.rs:24:13
|
LL | let x = 128_i8;
| ^^^^^^
error: literal out of range for i8
--> $DIR/lint-type-overflow.rs:30:14
error: literal out of range for `i8`
--> $DIR/lint-type-overflow.rs:28:14
|
LL | let x = -129_i8;
| ^^^^^^
error: literal out of range for i32
--> $DIR/lint-type-overflow.rs:34:18
error: literal out of range for `i32`
--> $DIR/lint-type-overflow.rs:32:18
|
LL | let x: i32 = 2147483648;
| ^^^^^^^^^^
error: literal out of range for i32
--> $DIR/lint-type-overflow.rs:35:13
error: literal out of range for `i32`
--> $DIR/lint-type-overflow.rs:33:13
|
LL | let x = 2147483648_i32;
| ^^^^^^^^^^^^^^
error: literal out of range for i32
--> $DIR/lint-type-overflow.rs:38:19
error: literal out of range for `i32`
--> $DIR/lint-type-overflow.rs:36:19
|
LL | let x: i32 = -2147483649;
| ^^^^^^^^^^
error: literal out of range for i32
--> $DIR/lint-type-overflow.rs:39:14
error: literal out of range for `i32`
--> $DIR/lint-type-overflow.rs:37:14
|
LL | let x = -2147483649_i32;
| ^^^^^^^^^^^^^^
error: literal out of range for i32
--> $DIR/lint-type-overflow.rs:40:13
error: literal out of range for `i32`
--> $DIR/lint-type-overflow.rs:38:13
|
LL | let x = 2147483648;
| ^^^^^^^^^^
error: literal out of range for i64
--> $DIR/lint-type-overflow.rs:42:13
error: literal out of range for `i64`
--> $DIR/lint-type-overflow.rs:40:13
|
LL | let x = 9223372036854775808_i64;
| ^^^^^^^^^^^^^^^^^^^^^^^
error: literal out of range for i64
--> $DIR/lint-type-overflow.rs:44:13
error: literal out of range for `i64`
--> $DIR/lint-type-overflow.rs:42:13
|
LL | let x = 18446744073709551615_i64;
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: literal out of range for i64
--> $DIR/lint-type-overflow.rs:45:19
error: literal out of range for `i64`
--> $DIR/lint-type-overflow.rs:43:19
|
LL | let x: i64 = -9223372036854775809;
| ^^^^^^^^^^^^^^^^^^^
error: literal out of range for i64
--> $DIR/lint-type-overflow.rs:46:14
error: literal out of range for `i64`
--> $DIR/lint-type-overflow.rs:44:14
|
LL | let x = -9223372036854775809_i64;
| ^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,4 +1,4 @@
warning: literal out of range for i8
warning: literal out of range for `i8`
--> $DIR/lint-type-overflow2.rs:9:20
|
LL | let x2: i8 = --128;
@ -10,25 +10,25 @@ note: lint level defined here
LL | #![warn(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
warning: literal out of range for f32
warning: literal out of range for `f32`
--> $DIR/lint-type-overflow2.rs:11:14
|
LL | let x = -3.40282357e+38_f32;
| ^^^^^^^^^^^^^^^^^^
warning: literal out of range for f32
warning: literal out of range for `f32`
--> $DIR/lint-type-overflow2.rs:12:14
|
LL | let x = 3.40282357e+38_f32;
| ^^^^^^^^^^^^^^^^^^
warning: literal out of range for f64
warning: literal out of range for `f64`
--> $DIR/lint-type-overflow2.rs:13:14
|
LL | let x = -1.7976931348623159e+308_f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: literal out of range for f64
warning: literal out of range for `f64`
--> $DIR/lint-type-overflow2.rs:14:14
|
LL | let x = 1.7976931348623159e+308_f64;

View file

@ -1,4 +1,4 @@
warning: literal out of range for i8
warning: literal out of range for `i8`
--> $DIR/type-overflow.rs:5:17
|
LL | let error = 255i8;