Skip to content

Commit cd8b437

Browse files
committed
Auto merge of #59227 - Zoxc:fix-get, r=eddyb
Fix lifetime on LocalInternedString::get function cc @eddyb @nnethercote
2 parents 3de0106 + 5ea959d commit cd8b437

File tree

5 files changed

+23
-17
lines changed

5 files changed

+23
-17
lines changed

src/librustc/hir/print.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl<'a> State<'a> {
622622
}
623623
hir::ItemKind::GlobalAsm(ref ga) => {
624624
self.head(visibility_qualified(&item.vis, "global asm"))?;
625-
self.s.word(ga.asm.as_str().get())?;
625+
self.s.word(ga.asm.as_str().to_string())?;
626626
self.end()?
627627
}
628628
hir::ItemKind::Ty(ref ty, ref generics) => {
@@ -1591,7 +1591,7 @@ impl<'a> State<'a> {
15911591
if ident.is_raw_guess() {
15921592
self.s.word(format!("r#{}", ident.name))?;
15931593
} else {
1594-
self.s.word(ident.as_str().get())?;
1594+
self.s.word(ident.as_str().to_string())?;
15951595
}
15961596
self.ann.post(self, AnnNode::Name(&ident.name))
15971597
}
@@ -1998,7 +1998,7 @@ impl<'a> State<'a> {
19981998
self.commasep(Inconsistent, &decl.inputs, |s, ty| {
19991999
s.ibox(indent_unit)?;
20002000
if let Some(arg_name) = arg_names.get(i) {
2001-
s.s.word(arg_name.as_str().get())?;
2001+
s.s.word(arg_name.as_str().to_string())?;
20022002
s.s.word(":")?;
20032003
s.s.space()?;
20042004
} else if let Some(body_id) = body_id {

src/libsyntax/parse/parser.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2165,9 +2165,11 @@ impl<'a> Parser<'a> {
21652165
suffix,
21662166
) = self.token {
21672167
let suffix = suffix.and_then(|s| {
2168-
let s = s.as_str().get();
2169-
if ["f32", "f64"].contains(&s) {
2170-
Some(s)
2168+
let s = s.as_str();
2169+
if s == "f32" {
2170+
Some("f32")
2171+
} else if s == "f64" {
2172+
Some("f64")
21712173
} else {
21722174
None
21732175
}

src/libsyntax/print/pprust.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ pub trait PrintState<'a> {
645645
ast::LitKind::Float(ref f, t) => {
646646
self.writer().word(format!("{}{}", &f, t.ty_to_string()))
647647
}
648-
ast::LitKind::FloatUnsuffixed(ref f) => self.writer().word(f.as_str().get()),
648+
ast::LitKind::FloatUnsuffixed(ref f) => self.writer().word(f.as_str().to_string()),
649649
ast::LitKind::Bool(val) => {
650650
if val { self.writer().word("true") } else { self.writer().word("false") }
651651
}
@@ -731,7 +731,7 @@ pub trait PrintState<'a> {
731731
if segment.ident.name == keywords::DollarCrate.name() {
732732
self.print_dollar_crate(segment.ident)?;
733733
} else {
734-
self.writer().word(segment.ident.as_str().get())?;
734+
self.writer().word(segment.ident.as_str().to_string())?;
735735
}
736736
}
737737
}
@@ -749,7 +749,7 @@ pub trait PrintState<'a> {
749749
}
750750
self.maybe_print_comment(attr.span.lo())?;
751751
if attr.is_sugared_doc {
752-
self.writer().word(attr.value_str().unwrap().as_str().get())?;
752+
self.writer().word(attr.value_str().unwrap().as_str().to_string())?;
753753
self.writer().hardbreak()
754754
} else {
755755
match attr.style {
@@ -858,7 +858,7 @@ pub trait PrintState<'a> {
858858
if !ast::Ident::with_empty_ctxt(name).is_path_segment_keyword() {
859859
self.writer().word("::")?;
860860
}
861-
self.writer().word(name.as_str().get())
861+
self.writer().word(name.as_str().to_string())
862862
}
863863
}
864864

@@ -1300,7 +1300,7 @@ impl<'a> State<'a> {
13001300
}
13011301
ast::ItemKind::GlobalAsm(ref ga) => {
13021302
self.head(visibility_qualified(&item.vis, "global_asm!"))?;
1303-
self.s.word(ga.asm.as_str().get())?;
1303+
self.s.word(ga.asm.as_str().to_string())?;
13041304
self.end()?;
13051305
}
13061306
ast::ItemKind::Ty(ref ty, ref generics) => {
@@ -2437,7 +2437,7 @@ impl<'a> State<'a> {
24372437
if ident.is_raw_guess() {
24382438
self.s.word(format!("r#{}", ident))?;
24392439
} else {
2440-
self.s.word(ident.as_str().get())?;
2440+
self.s.word(ident.as_str().to_string())?;
24412441
}
24422442
self.ann.post(self, AnnNode::Ident(&ident))
24432443
}
@@ -2447,7 +2447,7 @@ impl<'a> State<'a> {
24472447
}
24482448

24492449
pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> {
2450-
self.s.word(name.as_str().get())?;
2450+
self.s.word(name.as_str().to_string())?;
24512451
self.ann.post(self, AnnNode::Name(&name))
24522452
}
24532453

src/libsyntax_ext/proc_macro_server.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ impl Ident {
336336
}
337337
}
338338
fn new(sym: Symbol, is_raw: bool, span: Span) -> Ident {
339-
let string = sym.as_str().get();
340-
if !Self::is_valid(string) {
339+
let string = sym.as_str();
340+
if !Self::is_valid(&string) {
341341
panic!("`{:?}` is not a valid identifier", string)
342342
}
343-
if is_raw && !ast::Ident::from_str(string).can_be_raw() {
343+
if is_raw && !ast::Ident::from_interned_str(sym.as_interned_str()).can_be_raw() {
344344
panic!("`{}` cannot be a raw identifier", string);
345345
}
346346
Ident { sym, is_raw, span }

src/libsyntax_pos/symbol.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,11 @@ impl LocalInternedString {
524524
}
525525
}
526526

527-
pub fn get(&self) -> &'static str {
527+
pub fn get(&self) -> &str {
528+
// This returns a valid string since we ensure that `self` outlives the interner
529+
// by creating the interner on a thread which outlives threads which can access it.
530+
// This type cannot move to a thread which outlives the interner since it does
531+
// not implement Send.
528532
self.string
529533
}
530534
}

0 commit comments

Comments
 (0)