diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2020-07-08 11:04:10 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2020-07-15 08:42:59 +1000 |
| commit | f04e866e5752f47e0896550faf40e19fea22d8ea (patch) | |
| tree | dc192030f27fb19c6c842775f931f6a7494a0020 /src/librustc_builtin_macros/deriving | |
| parent | e284f5d050029906d32667635af9c839fafd3eca (diff) | |
| download | rust-f04e866e5752f47e0896550faf40e19fea22d8ea.tar.gz rust-f04e866e5752f47e0896550faf40e19fea22d8ea.zip | |
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.
Diffstat (limited to 'src/librustc_builtin_macros/deriving')
| -rw-r--r-- | src/librustc_builtin_macros/deriving/clone.rs | 2 | ||||
| -rw-r--r-- | src/librustc_builtin_macros/deriving/cmp/eq.rs | 2 | ||||
| -rw-r--r-- | src/librustc_builtin_macros/deriving/cmp/ord.rs | 2 | ||||
| -rw-r--r-- | src/librustc_builtin_macros/deriving/cmp/partial_eq.rs | 4 | ||||
| -rw-r--r-- | src/librustc_builtin_macros/deriving/cmp/partial_ord.rs | 24 | ||||
| -rw-r--r-- | src/librustc_builtin_macros/deriving/debug.rs | 2 | ||||
| -rw-r--r-- | src/librustc_builtin_macros/deriving/decodable.rs | 4 | ||||
| -rw-r--r-- | src/librustc_builtin_macros/deriving/default.rs | 2 | ||||
| -rw-r--r-- | src/librustc_builtin_macros/deriving/encodable.rs | 4 | ||||
| -rw-r--r-- | src/librustc_builtin_macros/deriving/generic/mod.rs | 14 | ||||
| -rw-r--r-- | src/librustc_builtin_macros/deriving/hash.rs | 4 | ||||
| -rw-r--r-- | src/librustc_builtin_macros/deriving/mod.rs | 4 |
12 files changed, 34 insertions, 34 deletions
diff --git a/src/librustc_builtin_macros/deriving/clone.rs b/src/librustc_builtin_macros/deriving/clone.rs index 5dbf3825ce6..5a8648f2aaa 100644 --- a/src/librustc_builtin_macros/deriving/clone.rs +++ b/src/librustc_builtin_macros/deriving/clone.rs @@ -84,7 +84,7 @@ pub fn expand_deriving_clone( is_unsafe: false, supports_unions: true, methods: vec![MethodDef { - name: "clone", + name: sym::clone, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: Vec::new(), diff --git a/src/librustc_builtin_macros/deriving/cmp/eq.rs b/src/librustc_builtin_macros/deriving/cmp/eq.rs index b3b15b89782..e1677ae70cc 100644 --- a/src/librustc_builtin_macros/deriving/cmp/eq.rs +++ b/src/librustc_builtin_macros/deriving/cmp/eq.rs @@ -28,7 +28,7 @@ pub fn expand_deriving_eq( is_unsafe: false, supports_unions: true, methods: vec![MethodDef { - name: "assert_receiver_is_total_eq", + name: sym::assert_receiver_is_total_eq, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: vec![], diff --git a/src/librustc_builtin_macros/deriving/cmp/ord.rs b/src/librustc_builtin_macros/deriving/cmp/ord.rs index 030d2c83742..a9bc03db8b7 100644 --- a/src/librustc_builtin_macros/deriving/cmp/ord.rs +++ b/src/librustc_builtin_macros/deriving/cmp/ord.rs @@ -26,7 +26,7 @@ pub fn expand_deriving_ord( is_unsafe: false, supports_unions: false, methods: vec![MethodDef { - name: "cmp", + name: sym::cmp, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: vec![(borrowed_self(), "other")], diff --git a/src/librustc_builtin_macros/deriving/cmp/partial_eq.rs b/src/librustc_builtin_macros/deriving/cmp/partial_eq.rs index d3f1a9c15f4..e7d8f781180 100644 --- a/src/librustc_builtin_macros/deriving/cmp/partial_eq.rs +++ b/src/librustc_builtin_macros/deriving/cmp/partial_eq.rs @@ -92,9 +92,9 @@ pub fn expand_deriving_partial_eq( // avoid defining `ne` if we can // c-like enums, enums without any fields and structs without fields // can safely define only `eq`. - let mut methods = vec![md!("eq", cs_eq)]; + let mut methods = vec![md!(sym::eq, cs_eq)]; if !is_type_without_fields(item) { - methods.push(md!("ne", cs_ne)); + methods.push(md!(sym::ne, cs_ne)); } let trait_def = TraitDef { diff --git a/src/librustc_builtin_macros/deriving/cmp/partial_ord.rs b/src/librustc_builtin_macros/deriving/cmp/partial_ord.rs index f29f91e8231..a3eb96fb782 100644 --- a/src/librustc_builtin_macros/deriving/cmp/partial_ord.rs +++ b/src/librustc_builtin_macros/deriving/cmp/partial_ord.rs @@ -49,7 +49,7 @@ pub fn expand_deriving_partial_ord( let attrs = vec![cx.attribute(inline)]; let partial_cmp_def = MethodDef { - name: "partial_cmp", + name: sym::partial_cmp, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: vec![(borrowed_self(), "other")], @@ -70,10 +70,10 @@ pub fn expand_deriving_partial_ord( } else { vec![ partial_cmp_def, - md!("lt", true, false), - md!("le", true, true), - md!("gt", false, false), - md!("ge", false, true), + md!(sym::lt, true, false), + md!(sym::le, true, true), + md!(sym::gt, false, false), + md!(sym::ge, false, true), ] }; @@ -108,14 +108,14 @@ pub fn some_ordering_collapsed( ) -> P<ast::Expr> { let lft = cx.expr_ident(span, self_arg_tags[0]); let rgt = cx.expr_addr_of(span, cx.expr_ident(span, self_arg_tags[1])); - let op_str = match op { - PartialCmpOp => "partial_cmp", - LtOp => "lt", - LeOp => "le", - GtOp => "gt", - GeOp => "ge", + let op_sym = match op { + PartialCmpOp => sym::partial_cmp, + LtOp => sym::lt, + LeOp => sym::le, + GtOp => sym::gt, + GeOp => sym::ge, }; - cx.expr_method_call(span, lft, cx.ident_of(op_str, span), vec![rgt]) + cx.expr_method_call(span, lft, Ident::new(op_sym, span), vec![rgt]) } pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> { diff --git a/src/librustc_builtin_macros/deriving/debug.rs b/src/librustc_builtin_macros/deriving/debug.rs index 99c2b6f8a4e..6befeb746bd 100644 --- a/src/librustc_builtin_macros/deriving/debug.rs +++ b/src/librustc_builtin_macros/deriving/debug.rs @@ -29,7 +29,7 @@ pub fn expand_deriving_debug( is_unsafe: false, supports_unions: false, methods: vec![MethodDef { - name: "fmt", + name: sym::fmt, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: vec![(fmtr, "f")], diff --git a/src/librustc_builtin_macros/deriving/decodable.rs b/src/librustc_builtin_macros/deriving/decodable.rs index 64a810bdcf6..0792be73263 100644 --- a/src/librustc_builtin_macros/deriving/decodable.rs +++ b/src/librustc_builtin_macros/deriving/decodable.rs @@ -8,7 +8,7 @@ use rustc_ast::ast; use rustc_ast::ast::{Expr, MetaItem, Mutability}; use rustc_ast::ptr::P; use rustc_expand::base::{Annotatable, ExtCtxt}; -use rustc_span::symbol::Symbol; +use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; pub fn expand_deriving_rustc_decodable( @@ -30,7 +30,7 @@ pub fn expand_deriving_rustc_decodable( is_unsafe: false, supports_unions: false, methods: vec![MethodDef { - name: "decode", + name: sym::decode, generics: LifetimeBounds { lifetimes: Vec::new(), bounds: vec![( diff --git a/src/librustc_builtin_macros/deriving/default.rs b/src/librustc_builtin_macros/deriving/default.rs index 27d52633200..5dfb0e8f37c 100644 --- a/src/librustc_builtin_macros/deriving/default.rs +++ b/src/librustc_builtin_macros/deriving/default.rs @@ -27,7 +27,7 @@ pub fn expand_deriving_default( is_unsafe: false, supports_unions: false, methods: vec![MethodDef { - name: "default", + name: kw::Default, generics: LifetimeBounds::empty(), explicit_self: None, args: Vec::new(), diff --git a/src/librustc_builtin_macros/deriving/encodable.rs b/src/librustc_builtin_macros/deriving/encodable.rs index 54926ec3fd5..4a90b7a1938 100644 --- a/src/librustc_builtin_macros/deriving/encodable.rs +++ b/src/librustc_builtin_macros/deriving/encodable.rs @@ -92,7 +92,7 @@ use crate::deriving::pathvec_std; use rustc_ast::ast::{Expr, ExprKind, MetaItem, Mutability}; use rustc_ast::ptr::P; use rustc_expand::base::{Annotatable, ExtCtxt}; -use rustc_span::symbol::Symbol; +use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; pub fn expand_deriving_rustc_encodable( @@ -114,7 +114,7 @@ pub fn expand_deriving_rustc_encodable( is_unsafe: false, supports_unions: false, methods: vec![MethodDef { - name: "encode", + name: sym::encode, generics: LifetimeBounds { lifetimes: Vec::new(), bounds: vec![( diff --git a/src/librustc_builtin_macros/deriving/generic/mod.rs b/src/librustc_builtin_macros/deriving/generic/mod.rs index a9567f20d69..050774aa24c 100644 --- a/src/librustc_builtin_macros/deriving/generic/mod.rs +++ b/src/librustc_builtin_macros/deriving/generic/mod.rs @@ -226,7 +226,7 @@ pub struct TraitDef<'a> { pub struct MethodDef<'a> { /// name of the method - pub name: &'a str, + pub name: Symbol, /// List of generics, e.g., `R: rand::Rng` pub generics: LifetimeBounds<'a>, @@ -681,7 +681,7 @@ impl<'a> TraitDef<'a> { let opt_trait_ref = Some(trait_ref); let unused_qual = { let word = rustc_ast::attr::mk_nested_word_item(Ident::new( - Symbol::intern("unused_qualifications"), + sym::unused_qualifications, self.span, )); let list = rustc_ast::attr::mk_list_item(Ident::new(sym::allow, self.span), vec![word]); @@ -818,7 +818,7 @@ impl<'a> MethodDef<'a> { ) -> P<Expr> { let substructure = Substructure { type_ident, - method_ident: cx.ident_of(self.name, trait_.span), + method_ident: Ident::new(self.name, trait_.span), self_args, nonself_args, fields, @@ -913,7 +913,7 @@ impl<'a> MethodDef<'a> { let ret_type = self.get_ret_ty(cx, trait_, generics, type_ident); - let method_ident = cx.ident_of(self.name, trait_.span); + let method_ident = Ident::new(self.name, trait_.span); let fn_decl = cx.fn_decl(args, ast::FnRetTy::Ty(ret_type)); let body_block = cx.block_expr(body); @@ -1315,7 +1315,7 @@ impl<'a> MethodDef<'a> { // Since we know that all the arguments will match if we reach // the match expression we add the unreachable intrinsics as the // result of the catch all which should help llvm in optimizing it - Some(deriving::call_intrinsic(cx, sp, "unreachable", vec![])) + Some(deriving::call_intrinsic(cx, sp, sym::unreachable, vec![])) } _ => None, }; @@ -1363,7 +1363,7 @@ impl<'a> MethodDef<'a> { for (&ident, self_arg) in vi_idents.iter().zip(&self_args) { let self_addr = cx.expr_addr_of(sp, self_arg.clone()); let variant_value = - deriving::call_intrinsic(cx, sp, "discriminant_value", vec![self_addr]); + deriving::call_intrinsic(cx, sp, sym::discriminant_value, vec![self_addr]); let let_stmt = cx.stmt_let(sp, false, ident, variant_value); index_let_stmts.push(let_stmt); @@ -1464,7 +1464,7 @@ impl<'a> MethodDef<'a> { // derive Debug on such a type could here generate code // that needs the feature gate enabled.) - deriving::call_intrinsic(cx, sp, "unreachable", vec![]) + deriving::call_intrinsic(cx, sp, sym::unreachable, vec![]) } else { // Final wrinkle: the self_args are expressions that deref // down to desired places, but we cannot actually deref diff --git a/src/librustc_builtin_macros/deriving/hash.rs b/src/librustc_builtin_macros/deriving/hash.rs index 8776e7ef507..f975b75f0be 100644 --- a/src/librustc_builtin_macros/deriving/hash.rs +++ b/src/librustc_builtin_macros/deriving/hash.rs @@ -29,7 +29,7 @@ pub fn expand_deriving_hash( is_unsafe: false, supports_unions: false, methods: vec![MethodDef { - name: "hash", + name: sym::hash, generics: LifetimeBounds { lifetimes: Vec::new(), bounds: vec![(typaram, vec![path_std!(cx, hash::Hasher)])], @@ -73,7 +73,7 @@ fn hash_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructu let variant_value = deriving::call_intrinsic( cx, trait_span, - "discriminant_value", + sym::discriminant_value, vec![cx.expr_self(trait_span)], ); diff --git a/src/librustc_builtin_macros/deriving/mod.rs b/src/librustc_builtin_macros/deriving/mod.rs index dc21be3b296..6cee21fc6e6 100644 --- a/src/librustc_builtin_macros/deriving/mod.rs +++ b/src/librustc_builtin_macros/deriving/mod.rs @@ -62,11 +62,11 @@ impl MultiItemModifier for BuiltinDerive { fn call_intrinsic( cx: &ExtCtxt<'_>, span: Span, - intrinsic: &str, + intrinsic: Symbol, args: Vec<P<ast::Expr>>, ) -> P<ast::Expr> { let span = cx.with_def_site_ctxt(span); - let path = cx.std_path(&[sym::intrinsics, Symbol::intern(intrinsic)]); + let path = cx.std_path(&[sym::intrinsics, intrinsic]); let call = cx.expr_call_global(span, path, args); cx.expr_block(P(ast::Block { |
