Auto merge of #4418 - euclio:byte-lit-suggestion, r=flip1995
use a structured suggestion for char-lit-as-u8 changelog: use a structured suggestion for char-lit-as-u8
This commit is contained in:
commit
9d2772207e
7 changed files with 89 additions and 25 deletions
|
|
@ -1,5 +1,5 @@
|
|||
#![warn(clippy::char_lit_as_u8)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
fn main() {
|
||||
let c = 'a' as u8;
|
||||
let _ = '❤' as u8; // no suggestion, since a byte literal won't work.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
error: casting character literal to u8. `char`s are 4 bytes wide in rust, so casting to u8 truncates them
|
||||
error: casting a character literal to `u8` truncates
|
||||
--> $DIR/char_lit_as_u8.rs:4:13
|
||||
|
|
||||
LL | let c = 'a' as u8;
|
||||
LL | let _ = '❤' as u8; // no suggestion, since a byte literal won't work.
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::char-lit-as-u8` implied by `-D warnings`
|
||||
= help: Consider using a byte literal instead:
|
||||
b'a'
|
||||
= note: `char` is four bytes wide, but `u8` is a single byte
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
10
tests/ui/char_lit_as_u8_suggestions.fixed
Normal file
10
tests/ui/char_lit_as_u8_suggestions.fixed
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// run-rustfix
|
||||
|
||||
#![warn(clippy::char_lit_as_u8)]
|
||||
|
||||
fn main() {
|
||||
let _ = b'a';
|
||||
let _ = b'\n';
|
||||
let _ = b'\0';
|
||||
let _ = b'\x01';
|
||||
}
|
||||
10
tests/ui/char_lit_as_u8_suggestions.rs
Normal file
10
tests/ui/char_lit_as_u8_suggestions.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// run-rustfix
|
||||
|
||||
#![warn(clippy::char_lit_as_u8)]
|
||||
|
||||
fn main() {
|
||||
let _ = 'a' as u8;
|
||||
let _ = '\n' as u8;
|
||||
let _ = '\0' as u8;
|
||||
let _ = '\x01' as u8;
|
||||
}
|
||||
35
tests/ui/char_lit_as_u8_suggestions.stderr
Normal file
35
tests/ui/char_lit_as_u8_suggestions.stderr
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
error: casting a character literal to `u8` truncates
|
||||
--> $DIR/char_lit_as_u8_suggestions.rs:6:13
|
||||
|
|
||||
LL | let _ = 'a' as u8;
|
||||
| ^^^^^^^^^ help: use a byte literal instead: `b'a'`
|
||||
|
|
||||
= note: `-D clippy::char-lit-as-u8` implied by `-D warnings`
|
||||
= note: `char` is four bytes wide, but `u8` is a single byte
|
||||
|
||||
error: casting a character literal to `u8` truncates
|
||||
--> $DIR/char_lit_as_u8_suggestions.rs:7:13
|
||||
|
|
||||
LL | let _ = '/n' as u8;
|
||||
| ^^^^^^^^^^ help: use a byte literal instead: `b'/n'`
|
||||
|
|
||||
= note: `char` is four bytes wide, but `u8` is a single byte
|
||||
|
||||
error: casting a character literal to `u8` truncates
|
||||
--> $DIR/char_lit_as_u8_suggestions.rs:8:13
|
||||
|
|
||||
LL | let _ = '/0' as u8;
|
||||
| ^^^^^^^^^^ help: use a byte literal instead: `b'/0'`
|
||||
|
|
||||
= note: `char` is four bytes wide, but `u8` is a single byte
|
||||
|
||||
error: casting a character literal to `u8` truncates
|
||||
--> $DIR/char_lit_as_u8_suggestions.rs:9:13
|
||||
|
|
||||
LL | let _ = '/x01' as u8;
|
||||
| ^^^^^^^^^^^^ help: use a byte literal instead: `b'/x01'`
|
||||
|
|
||||
= note: `char` is four bytes wide, but `u8` is a single byte
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue