diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-10-06 16:26:11 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-06 16:26:11 +0900 |
| commit | 5c1e01196dcfaea2ce8df4271ff398d20ac123e9 (patch) | |
| tree | e65ff642ee85e8c3fff185097399357f13332f4b | |
| parent | 2970af8e288d95a39b56b6b0784f9d4e664e7644 (diff) | |
| parent | 62f7712a1fd500604f76442f627ea35ce7217177 (diff) | |
| download | rust-5c1e01196dcfaea2ce8df4271ff398d20ac123e9.tar.gz rust-5c1e01196dcfaea2ce8df4271ff398d20ac123e9.zip | |
Rollup merge of #77560 - rschoon:fix-litkind-rc-bytebuf, r=lcnr
Fix LitKind's byte buffer to use refcounted slice While working on adding a new lint for clippy (see https://github.com/rust-lang/rust-clippy/pull/6044) for avoiding shared ownership of "mutable buffer" types (such as using `Rc<Vec<T>>` instead of `Rc<[T]>`), I noticed a type exported from rustc_ast and used by clippy gets caught by the lint. This PR fixes the exported type. This PR includes the actual change to clippy too, but I will open a PR directly against clippy for that part (although it will currently fail to build there).
| -rw-r--r-- | compiler/rustc_ast/src/ast.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_ast/src/util/literal.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_builtin_macros/src/source_util.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_mir_build/src/thir/constant.rs | 2 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/consts.rs | 2 |
5 files changed, 6 insertions, 9 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 95abf552915..492d5788fc0 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1606,7 +1606,7 @@ pub enum LitKind { /// A string literal (`"foo"`). Str(Symbol, StrStyle), /// A byte string (`b"foo"`). - ByteStr(Lrc<Vec<u8>>), + ByteStr(Lrc<[u8]>), /// A byte char (`b'f'`). Byte(u8), /// A character literal (`'a'`). diff --git a/compiler/rustc_ast/src/util/literal.rs b/compiler/rustc_ast/src/util/literal.rs index 597e5b437fc..f6f1ad0a9c3 100644 --- a/compiler/rustc_ast/src/util/literal.rs +++ b/compiler/rustc_ast/src/util/literal.rs @@ -4,7 +4,6 @@ use crate::ast::{self, Lit, LitKind}; use crate::token::{self, Token}; use crate::tokenstream::TokenTree; -use rustc_data_structures::sync::Lrc; use rustc_lexer::unescape::{unescape_byte, unescape_char}; use rustc_lexer::unescape::{unescape_byte_literal, unescape_literal, Mode}; use rustc_span::symbol::{kw, sym, Symbol}; @@ -108,7 +107,7 @@ impl LitKind { }); error?; buf.shrink_to_fit(); - LitKind::ByteStr(Lrc::new(buf)) + LitKind::ByteStr(buf.into()) } token::ByteStrRaw(_) => { let s = symbol.as_str(); @@ -128,7 +127,7 @@ impl LitKind { symbol.to_string().into_bytes() }; - LitKind::ByteStr(Lrc::new(bytes)) + LitKind::ByteStr(bytes.into()) } token::Err => LitKind::Err(symbol), }) diff --git a/compiler/rustc_builtin_macros/src/source_util.rs b/compiler/rustc_builtin_macros/src/source_util.rs index 70753208af3..f76bbd83819 100644 --- a/compiler/rustc_builtin_macros/src/source_util.rs +++ b/compiler/rustc_builtin_macros/src/source_util.rs @@ -13,8 +13,6 @@ use rustc_span::{self, Pos, Span}; use smallvec::SmallVec; use std::rc::Rc; -use rustc_data_structures::sync::Lrc; - // These macros all relate to the file system; they either return // the column/row/filename of the expression, or they include // a given file into the current one. @@ -216,7 +214,7 @@ pub fn expand_include_bytes( } }; match cx.source_map().load_binary_file(&file) { - Ok(bytes) => base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes)))), + Ok(bytes) => base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(bytes.into()))), Err(e) => { cx.span_err(sp, &format!("couldn't read {}: {}", file.display(), e)); DummyResult::any(sp) diff --git a/compiler/rustc_mir_build/src/thir/constant.rs b/compiler/rustc_mir_build/src/thir/constant.rs index a7bb2864daf..b71ff6e7557 100644 --- a/compiler/rustc_mir_build/src/thir/constant.rs +++ b/compiler/rustc_mir_build/src/thir/constant.rs @@ -31,7 +31,7 @@ crate fn lit_to_const<'tcx>( (ast::LitKind::ByteStr(data), ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Slice(_)) => { - let allocation = Allocation::from_byte_aligned_bytes(data as &Vec<u8>); + let allocation = Allocation::from_byte_aligned_bytes(data as &[u8]); let allocation = tcx.intern_const_alloc(allocation); ConstValue::Slice { data: allocation, start: 0, end: data.len() } } diff --git a/src/tools/clippy/clippy_lints/src/consts.rs b/src/tools/clippy/clippy_lints/src/consts.rs index 0000d39263e..062c9bd2d9e 100644 --- a/src/tools/clippy/clippy_lints/src/consts.rs +++ b/src/tools/clippy/clippy_lints/src/consts.rs @@ -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::from(s.as_slice())), + LitKind::ByteStr(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 { |
