Skip to content

Commit f04e866

Browse files
committed
Add and use more static symbols.
Note that the output of `unpretty-debug.stdout` has changed. In that test the hash values are normalized from a symbol numbers to small numbers like "0#0" and "0#1". The increase in the number of static symbols must have caused the original numbers to contain more digits, resulting in different pretty-printing prior to normalization.
1 parent e284f5d commit f04e866

File tree

44 files changed

+794
-579
lines changed

Some content is hidden

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

44 files changed

+794
-579
lines changed

src/librustc_ast/expand/allocator.rs

Lines changed: 7 additions & 7 deletions
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_attr/builtin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,10 +1041,10 @@ pub fn find_transparency(
10411041
break;
10421042
} else if let Some(value) = attr.value_str() {
10431043
transparency = Some((
1044-
match &*value.as_str() {
1045-
"transparent" => Transparency::Transparent,
1046-
"semitransparent" => Transparency::SemiTransparent,
1047-
"opaque" => Transparency::Opaque,
1044+
match value {
1045+
sym::transparent => Transparency::Transparent,
1046+
sym::semitransparent => Transparency::SemiTransparent,
1047+
sym::opaque => Transparency::Opaque,
10481048
_ => {
10491049
error = Some(TransparencyError::UnknownTransparency(value, attr.span));
10501050
continue;

src/librustc_builtin_macros/deriving/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub fn expand_deriving_clone(
8484
is_unsafe: false,
8585
supports_unions: true,
8686
methods: vec![MethodDef {
87-
name: "clone",
87+
name: sym::clone,
8888
generics: LifetimeBounds::empty(),
8989
explicit_self: borrowed_explicit_self(),
9090
args: Vec::new(),

src/librustc_builtin_macros/deriving/cmp/eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn expand_deriving_eq(
2828
is_unsafe: false,
2929
supports_unions: true,
3030
methods: vec![MethodDef {
31-
name: "assert_receiver_is_total_eq",
31+
name: sym::assert_receiver_is_total_eq,
3232
generics: LifetimeBounds::empty(),
3333
explicit_self: borrowed_explicit_self(),
3434
args: vec![],

src/librustc_builtin_macros/deriving/cmp/ord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn expand_deriving_ord(
2626
is_unsafe: false,
2727
supports_unions: false,
2828
methods: vec![MethodDef {
29-
name: "cmp",
29+
name: sym::cmp,
3030
generics: LifetimeBounds::empty(),
3131
explicit_self: borrowed_explicit_self(),
3232
args: vec![(borrowed_self(), "other")],

src/librustc_builtin_macros/deriving/cmp/partial_eq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ pub fn expand_deriving_partial_eq(
9292
// avoid defining `ne` if we can
9393
// c-like enums, enums without any fields and structs without fields
9494
// can safely define only `eq`.
95-
let mut methods = vec![md!("eq", cs_eq)];
95+
let mut methods = vec![md!(sym::eq, cs_eq)];
9696
if !is_type_without_fields(item) {
97-
methods.push(md!("ne", cs_ne));
97+
methods.push(md!(sym::ne, cs_ne));
9898
}
9999

100100
let trait_def = TraitDef {

src/librustc_builtin_macros/deriving/cmp/partial_ord.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn expand_deriving_partial_ord(
4949
let attrs = vec![cx.attribute(inline)];
5050

5151
let partial_cmp_def = MethodDef {
52-
name: "partial_cmp",
52+
name: sym::partial_cmp,
5353
generics: LifetimeBounds::empty(),
5454
explicit_self: borrowed_explicit_self(),
5555
args: vec![(borrowed_self(), "other")],
@@ -70,10 +70,10 @@ pub fn expand_deriving_partial_ord(
7070
} else {
7171
vec![
7272
partial_cmp_def,
73-
md!("lt", true, false),
74-
md!("le", true, true),
75-
md!("gt", false, false),
76-
md!("ge", false, true),
73+
md!(sym::lt, true, false),
74+
md!(sym::le, true, true),
75+
md!(sym::gt, false, false),
76+
md!(sym::ge, false, true),
7777
]
7878
};
7979

@@ -108,14 +108,14 @@ pub fn some_ordering_collapsed(
108108
) -> P<ast::Expr> {
109109
let lft = cx.expr_ident(span, self_arg_tags[0]);
110110
let rgt = cx.expr_addr_of(span, cx.expr_ident(span, self_arg_tags[1]));
111-
let op_str = match op {
112-
PartialCmpOp => "partial_cmp",
113-
LtOp => "lt",
114-
LeOp => "le",
115-
GtOp => "gt",
116-
GeOp => "ge",
111+
let op_sym = match op {
112+
PartialCmpOp => sym::partial_cmp,
113+
LtOp => sym::lt,
114+
LeOp => sym::le,
115+
GtOp => sym::gt,
116+
GeOp => sym::ge,
117117
};
118-
cx.expr_method_call(span, lft, cx.ident_of(op_str, span), vec![rgt])
118+
cx.expr_method_call(span, lft, Ident::new(op_sym, span), vec![rgt])
119119
}
120120

121121
pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {

src/librustc_builtin_macros/deriving/debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn expand_deriving_debug(
2929
is_unsafe: false,
3030
supports_unions: false,
3131
methods: vec![MethodDef {
32-
name: "fmt",
32+
name: sym::fmt,
3333
generics: LifetimeBounds::empty(),
3434
explicit_self: borrowed_explicit_self(),
3535
args: vec![(fmtr, "f")],

src/librustc_builtin_macros/deriving/decodable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_ast::ast;
88
use rustc_ast::ast::{Expr, MetaItem, Mutability};
99
use rustc_ast::ptr::P;
1010
use rustc_expand::base::{Annotatable, ExtCtxt};
11-
use rustc_span::symbol::Symbol;
11+
use rustc_span::symbol::{sym, Symbol};
1212
use rustc_span::Span;
1313

1414
pub fn expand_deriving_rustc_decodable(
@@ -30,7 +30,7 @@ pub fn expand_deriving_rustc_decodable(
3030
is_unsafe: false,
3131
supports_unions: false,
3232
methods: vec![MethodDef {
33-
name: "decode",
33+
name: sym::decode,
3434
generics: LifetimeBounds {
3535
lifetimes: Vec::new(),
3636
bounds: vec![(

src/librustc_builtin_macros/deriving/default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn expand_deriving_default(
2727
is_unsafe: false,
2828
supports_unions: false,
2929
methods: vec![MethodDef {
30-
name: "default",
30+
name: kw::Default,
3131
generics: LifetimeBounds::empty(),
3232
explicit_self: None,
3333
args: Vec::new(),

0 commit comments

Comments
 (0)