Skip to content

Commit 30b5d76

Browse files
committed
Use Lrc<[u8]/str> instead of Lrc<Vec<u8>/String> in libsyntax
1 parent e3ff397 commit 30b5d76

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

src/libsyntax/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ pub enum LitKind {
12821282
/// A string literal (`"foo"`)
12831283
Str(Symbol, StrStyle),
12841284
/// A byte string (`b"foo"`)
1285-
ByteStr(Lrc<Vec<u8>>),
1285+
ByteStr(Lrc<[u8]>),
12861286
/// A byte char (`b'f'`)
12871287
Byte(u8),
12881288
/// A character literal (`'a'`)

src/libsyntax/ext/source_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Toke
184184
// dependency information, but don't enter it's contents
185185
cx.codemap().new_filemap_and_lines(&file, "");
186186

187-
base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes))))
187+
base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::from(bytes))))
188188
}
189189
}
190190
}

src/libsyntax/parse/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct StringReader<'a> {
6161
pub fatal_errs: Vec<DiagnosticBuilder<'a>>,
6262
// cache a direct reference to the source text, so that we don't have to
6363
// retrieve it via `self.filemap.src.as_ref().unwrap()` all the time.
64-
source_text: Lrc<String>,
64+
source_text: Lrc<str>,
6565
/// Stack of open delimiters and their spans. Used for error message.
6666
token: token::Token,
6767
span: Span,

src/libsyntax/parse/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ pub fn lit_token(lit: token::Lit, suf: Option<Symbol>, diag: Option<(Span, &Hand
428428
(true, Some(LitKind::ByteStr(byte_str_lit(&i.as_str()))))
429429
}
430430
token::ByteStrRaw(i, _) => {
431-
(true, Some(LitKind::ByteStr(Lrc::new(i.to_string().into_bytes()))))
431+
(true, Some(LitKind::ByteStr(Lrc::from(i.as_str().as_bytes()))))
432432
}
433433
}
434434
}
@@ -502,7 +502,7 @@ pub fn byte_lit(lit: &str) -> (u8, usize) {
502502
}
503503
}
504504

505-
pub fn byte_str_lit(lit: &str) -> Lrc<Vec<u8>> {
505+
pub fn byte_str_lit(lit: &str) -> Lrc<[u8]> {
506506
let mut res = Vec::with_capacity(lit.len());
507507

508508
let error = |i| format!("lexer should have rejected {} at {}", lit, i);
@@ -558,7 +558,7 @@ pub fn byte_str_lit(lit: &str) -> Lrc<Vec<u8>> {
558558
}
559559
}
560560

561-
Lrc::new(res)
561+
Lrc::from(res)
562562
}
563563

564564
pub fn integer_lit(s: &str, suffix: Option<Symbol>, diag: Option<(Span, &Handler)>)

src/libsyntax_pos/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ pub struct FileMap {
751751
/// Indicates which crate this FileMap was imported from.
752752
pub crate_of_origin: u32,
753753
/// The complete source code
754-
pub src: Option<Lrc<String>>,
754+
pub src: Option<Lrc<str>>,
755755
/// The source code's hash
756756
pub src_hash: u128,
757757
/// The external source code (used for external crates, which will have a `None`
@@ -937,7 +937,7 @@ impl FileMap {
937937
name_was_remapped,
938938
unmapped_path: Some(unmapped_path),
939939
crate_of_origin: 0,
940-
src: Some(Lrc::new(src)),
940+
src: Some(Lrc::from(src)),
941941
src_hash,
942942
external_src: Lock::new(ExternalSource::Unneeded),
943943
start_pos,

src/test/run-pass-fulldeps/issue-35829.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ fn run() {
3737

3838
// check byte string
3939
let byte_string = quote_expr!(&cx, b"one");
40-
let byte_string_lit_kind = LitKind::ByteStr(Lrc::new(b"one".to_vec()));
40+
let byte_string_lit_kind = LitKind::ByteStr(Lrc::from(&b"one"[..]));
4141
assert_eq!(byte_string.node, ExprKind::Lit(P(dummy_spanned(byte_string_lit_kind))));
4242

4343
// check raw byte string
4444
let raw_byte_string = quote_expr!(&cx, br###"#"two"#"###);
45-
let raw_byte_string_lit_kind = LitKind::ByteStr(Lrc::new(b"#\"two\"#".to_vec()));
45+
let raw_byte_string_lit_kind = LitKind::ByteStr(Lrc::from(&b"#\"two\"#"[..]));
4646
assert_eq!(raw_byte_string.node, ExprKind::Lit(P(dummy_spanned(raw_byte_string_lit_kind))));
4747

4848
// check dotdoteq

0 commit comments

Comments
 (0)