]> git.lizzy.rs Git - rust.git/commitdiff
Satisfy rc_buffer lint in Constant::Binary byte string by copying data
authorRobin Schoonover <robin@cornhooves.org>
Wed, 23 Sep 2020 02:34:38 +0000 (20:34 -0600)
committerRobin Schoonover <robin@cornhooves.org>
Wed, 23 Sep 2020 02:35:54 +0000 (20:35 -0600)
We can avoid the data copy again by fixing rustc_ast::ast::LitKind
later.

clippy_lints/src/consts.rs

index 3ee022e4e68a0e5d20357b081eedcb5225b47525..0000d39263ed388013927885c1004db3dce5673b 100644 (file)
@@ -21,7 +21,7 @@ pub enum Constant {
     /// A `String` (e.g., "abc").
     Str(String),
     /// A binary string (e.g., `b"abc"`).
-    Binary(Lrc<Vec<u8>>),
+    Binary(Lrc<[u8]>),
     /// A single `char` (e.g., `'a'`).
     Char(char),
     /// An integer's bit representation.
@@ -155,7 +155,7 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
     match *lit {
         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::ByteStr(ref s) => Constant::Binary(Lrc::from(s.as_slice())),
         LitKind::Char(c) => Constant::Char(c),
         LitKind::Int(n, _) => Constant::Int(n),
         LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {