diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2023-03-05 15:03:22 +0000 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2023-05-02 10:30:09 +0000 |
| commit | 37127b8d7018ecc4af69ebdee06adeff9527f757 (patch) | |
| tree | 6b6c0e8e85544a0381c305cc5090875cb14154d6 | |
| parent | eac589b4e4f12d95d8ec49226eb4a7e9d93556d0 (diff) | |
| download | rust-37127b8d7018ecc4af69ebdee06adeff9527f757.tar.gz rust-37127b8d7018ecc4af69ebdee06adeff9527f757.zip | |
initial step towards implementing C string literals
| -rw-r--r-- | clippy_lints/src/matches/match_same_arms.rs | 1 | ||||
| -rw-r--r-- | clippy_lints/src/utils/author.rs | 5 | ||||
| -rw-r--r-- | clippy_utils/src/consts.rs | 1 |
3 files changed, 7 insertions, 0 deletions
diff --git a/clippy_lints/src/matches/match_same_arms.rs b/clippy_lints/src/matches/match_same_arms.rs index 158e6caa4de..a48f4c77f85 100644 --- a/clippy_lints/src/matches/match_same_arms.rs +++ b/clippy_lints/src/matches/match_same_arms.rs @@ -284,6 +284,7 @@ impl<'a> NormalizedPat<'a> { LitKind::Str(sym, _) => Self::LitStr(sym), LitKind::ByteStr(ref bytes, _) => Self::LitBytes(bytes), LitKind::Byte(val) => Self::LitInt(val.into()), + LitKind::CStr(ref bytes, _) => Self::LitBytes(bytes), LitKind::Char(val) => Self::LitInt(val.into()), LitKind::Int(val, _) => Self::LitInt(val), LitKind::Bool(val) => Self::LitBool(val), diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 01927b6b5f1..f75dff46624 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -304,6 +304,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { kind!("ByteStr(ref {vec})"); chain!(self, "let [{:?}] = **{vec}", vec.value); }, + LitKind::CStr(ref vec, _) => { + bind!(self, vec); + kind!("CStr(ref {vec})"); + chain!(self, "let [{:?}] = **{vec}", vec.value); + } LitKind::Str(s, _) => { bind!(self, s); kind!("Str({s}, _)"); diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index 99bfc4b5717..7c7ec6d334d 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -211,6 +211,7 @@ pub fn lit_to_mir_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant { LitKind::Str(ref is, _) => Constant::Str(is.to_string()), LitKind::Byte(b) => Constant::Int(u128::from(b)), LitKind::ByteStr(ref s, _) => Constant::Binary(Lrc::clone(s)), + LitKind::CStr(ref s, _) => Constant::Binary(Lrc::clone(s)), LitKind::Char(c) => Constant::Char(c), LitKind::Int(n, _) => Constant::Int(n), LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty { |
