Skip to content

Commit 567ad74

Browse files
committedJul 15, 2020
Auto merge of #74175 - nnethercote:more-static-symbols, r=oli-obk
More static symbols These commits add some more static symbols and convert lots of places to use them. r? @oli-obk
2 parents 23744c8 + 5930081 commit 567ad74

File tree

67 files changed

+991
-745
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+991
-745
lines changed
 

‎src/librustc_ast/expand/allocator.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub enum AllocatorKind {
99
}
1010

1111
impl AllocatorKind {
12-
pub fn fn_name(&self, base: &str) -> String {
12+
pub fn fn_name(&self, base: Symbol) -> String {
1313
match *self {
1414
AllocatorKind::Global => format!("__rg_{}", base),
1515
AllocatorKind::Default => format!("__rdl_{}", base),
@@ -26,29 +26,29 @@ pub enum AllocatorTy {
2626
}
2727

2828
pub struct AllocatorMethod {
29-
pub name: &'static str,
29+
pub name: Symbol,
3030
pub inputs: &'static [AllocatorTy],
3131
pub output: AllocatorTy,
3232
}
3333

3434
pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
3535
AllocatorMethod {
36-
name: "alloc",
36+
name: sym::alloc,
3737
inputs: &[AllocatorTy::Layout],
3838
output: AllocatorTy::ResultPtr,
3939
},
4040
AllocatorMethod {
41-
name: "dealloc",
41+
name: sym::dealloc,
4242
inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout],
4343
output: AllocatorTy::Unit,
4444
},
4545
AllocatorMethod {
46-
name: "realloc",
46+
name: sym::realloc,
4747
inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout, AllocatorTy::Usize],
4848
output: AllocatorTy::ResultPtr,
4949
},
5050
AllocatorMethod {
51-
name: "alloc_zeroed",
51+
name: sym::alloc_zeroed,
5252
inputs: &[AllocatorTy::Layout],
5353
output: AllocatorTy::ResultPtr,
5454
},
@@ -70,7 +70,7 @@ pub fn global_allocator_spans(krate: &ast::Crate) -> Vec<Span> {
7070
}
7171
}
7272

73-
let name = Symbol::intern(&AllocatorKind::Global.fn_name("alloc"));
73+
let name = Symbol::intern(&AllocatorKind::Global.fn_name(sym::alloc));
7474
let mut f = Finder { name, spans: Vec::new() };
7575
visit::walk_crate(&mut f, krate);
7676
f.spans

‎src/librustc_ast/util/comments.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub use CommentStyle::*;
22

33
use crate::ast;
44
use rustc_span::source_map::SourceMap;
5-
use rustc_span::{BytePos, CharPos, FileName, Pos};
5+
use rustc_span::{BytePos, CharPos, FileName, Pos, Symbol};
66

77
use log::debug;
88

@@ -52,7 +52,8 @@ pub fn is_doc_comment(s: &str) -> bool {
5252
|| s.starts_with("/*!")
5353
}
5454

55-
pub fn doc_comment_style(comment: &str) -> ast::AttrStyle {
55+
pub fn doc_comment_style(comment: Symbol) -> ast::AttrStyle {
56+
let comment = &comment.as_str();
5657
assert!(is_doc_comment(comment));
5758
if comment.starts_with("//!") || comment.starts_with("/*!") {
5859
ast::AttrStyle::Inner
@@ -61,7 +62,9 @@ pub fn doc_comment_style(comment: &str) -> ast::AttrStyle {
6162
}
6263
}
6364

64-
pub fn strip_doc_comment_decoration(comment: &str) -> String {
65+
pub fn strip_doc_comment_decoration(comment: Symbol) -> String {
66+
let comment = &comment.as_str();
67+
6568
/// remove whitespace-only lines from the start/end of lines
6669
fn vertical_trim(lines: Vec<String>) -> Vec<String> {
6770
let mut i = 0;

0 commit comments

Comments
 (0)
Please sign in to comment.