diff --git a/src/librustc_builtin_macros/deriving/bounds.rs b/src/librustc_builtin_macros/deriving/bounds.rs index a1c818caff3bf02dd1c8e1f600ba2dd3fa37090c..cef0da60a61c8c642693d930fc9079d9d9089e88 100644 --- a/src/librustc_builtin_macros/deriving/bounds.rs +++ b/src/librustc_builtin_macros/deriving/bounds.rs @@ -16,9 +16,9 @@ pub fn expand_deriving_copy( let trait_def = TraitDef { span, attributes: Vec::new(), - path: path_std!(cx, marker::Copy), + path: path_std!(marker::Copy), additional_bounds: Vec::new(), - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), is_unsafe: false, supports_unions: true, methods: Vec::new(), diff --git a/src/librustc_builtin_macros/deriving/clone.rs b/src/librustc_builtin_macros/deriving/clone.rs index 5a8648f2aaa4cf61e6ebafaa1f1ddf34e3c24bb4..b307ee26c91d518e513cc31379a77f69698e2573 100644 --- a/src/librustc_builtin_macros/deriving/clone.rs +++ b/src/librustc_builtin_macros/deriving/clone.rs @@ -56,7 +56,7 @@ pub fn expand_deriving_clone( } } ItemKind::Union(..) => { - bounds = vec![Literal(path_std!(cx, marker::Copy))]; + bounds = vec![Literal(path_std!(marker::Copy))]; is_shallow = true; substructure = combine_substructure(Box::new(|c, s, sub| { cs_clone_shallow("Clone", c, s, sub, true) @@ -78,14 +78,14 @@ pub fn expand_deriving_clone( let trait_def = TraitDef { span, attributes: Vec::new(), - path: path_std!(cx, clone::Clone), + path: path_std!(clone::Clone), additional_bounds: bounds, - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), is_unsafe: false, supports_unions: true, methods: vec![MethodDef { name: sym::clone, - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), explicit_self: borrowed_explicit_self(), args: Vec::new(), ret_ty: Self_, diff --git a/src/librustc_builtin_macros/deriving/cmp/eq.rs b/src/librustc_builtin_macros/deriving/cmp/eq.rs index e1677ae70ccabf6203df756ed875bfeb2086920e..d1b799cd6a112d841614ccba3f1d9731f70b76ef 100644 --- a/src/librustc_builtin_macros/deriving/cmp/eq.rs +++ b/src/librustc_builtin_macros/deriving/cmp/eq.rs @@ -22,14 +22,14 @@ pub fn expand_deriving_eq( let trait_def = TraitDef { span, attributes: Vec::new(), - path: path_std!(cx, cmp::Eq), + path: path_std!(cmp::Eq), additional_bounds: Vec::new(), - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), is_unsafe: false, supports_unions: true, methods: vec![MethodDef { name: sym::assert_receiver_is_total_eq, - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), explicit_self: borrowed_explicit_self(), args: vec![], ret_ty: nil_ty(), @@ -43,13 +43,7 @@ pub fn expand_deriving_eq( associated_types: Vec::new(), }; - super::inject_impl_of_structural_trait( - cx, - span, - item, - path_std!(cx, marker::StructuralEq), - push, - ); + super::inject_impl_of_structural_trait(cx, span, item, path_std!(marker::StructuralEq), push); trait_def.expand_ext(cx, mitem, item, push, true) } diff --git a/src/librustc_builtin_macros/deriving/cmp/ord.rs b/src/librustc_builtin_macros/deriving/cmp/ord.rs index a9bc03db8b70605e54542c7e86fdb5b15f104636..3bf3860d32307d52c3f53d07fccf571f58ddf346 100644 --- a/src/librustc_builtin_macros/deriving/cmp/ord.rs +++ b/src/librustc_builtin_macros/deriving/cmp/ord.rs @@ -20,17 +20,17 @@ pub fn expand_deriving_ord( let trait_def = TraitDef { span, attributes: Vec::new(), - path: path_std!(cx, cmp::Ord), + path: path_std!(cmp::Ord), additional_bounds: Vec::new(), - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), is_unsafe: false, supports_unions: false, methods: vec![MethodDef { name: sym::cmp, - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), explicit_self: borrowed_explicit_self(), - args: vec![(borrowed_self(), "other")], - ret_ty: Literal(path_std!(cx, cmp::Ordering)), + args: vec![(borrowed_self(), sym::other)], + ret_ty: Literal(path_std!(cmp::Ordering)), attributes: attrs, is_unsafe: false, unify_fieldless_variants: true, diff --git a/src/librustc_builtin_macros/deriving/cmp/partial_eq.rs b/src/librustc_builtin_macros/deriving/cmp/partial_eq.rs index e7d8f78118098063f750aa44f9d8a8575c6d4cb2..d8edd641acd52dd945f038f942d2ce7ed61877d6 100644 --- a/src/librustc_builtin_macros/deriving/cmp/partial_eq.rs +++ b/src/librustc_builtin_macros/deriving/cmp/partial_eq.rs @@ -69,9 +69,9 @@ fn cs_ne(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P let attrs = vec![cx.attribute(inline)]; MethodDef { name: $name, - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), explicit_self: borrowed_explicit_self(), - args: vec![(borrowed_self(), "other")], + args: vec![(borrowed_self(), sym::other)], ret_ty: Literal(path_local!(bool)), attributes: attrs, is_unsafe: false, @@ -85,7 +85,7 @@ fn cs_ne(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P cx, span, item, - path_std!(cx, marker::StructuralPartialEq), + path_std!(marker::StructuralPartialEq), push, ); @@ -100,9 +100,9 @@ fn cs_ne(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P let trait_def = TraitDef { span, attributes: Vec::new(), - path: path_std!(cx, cmp::PartialEq), + path: path_std!(cmp::PartialEq), additional_bounds: Vec::new(), - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), is_unsafe: false, supports_unions: false, methods, diff --git a/src/librustc_builtin_macros/deriving/cmp/partial_ord.rs b/src/librustc_builtin_macros/deriving/cmp/partial_ord.rs index a3eb96fb782e531f2b548d8065952c8c5f5043b4..39a747c856839455077a808c190eb83224299072 100644 --- a/src/librustc_builtin_macros/deriving/cmp/partial_ord.rs +++ b/src/librustc_builtin_macros/deriving/cmp/partial_ord.rs @@ -23,9 +23,9 @@ pub fn expand_deriving_partial_ord( let attrs = vec![cx.attribute(inline)]; MethodDef { name: $name, - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), explicit_self: borrowed_explicit_self(), - args: vec![(borrowed_self(), "other")], + args: vec![(borrowed_self(), sym::other)], ret_ty: Literal(path_local!(bool)), attributes: attrs, is_unsafe: false, @@ -37,9 +37,9 @@ pub fn expand_deriving_partial_ord( }}; } - let ordering_ty = Literal(path_std!(cx, cmp::Ordering)); + let ordering_ty = Literal(path_std!(cmp::Ordering)); let ret_ty = Literal(Path::new_( - pathvec_std!(cx, option::Option), + pathvec_std!(option::Option), None, vec![Box::new(ordering_ty)], PathKind::Std, @@ -50,9 +50,9 @@ pub fn expand_deriving_partial_ord( let partial_cmp_def = MethodDef { name: sym::partial_cmp, - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), explicit_self: borrowed_explicit_self(), - args: vec![(borrowed_self(), "other")], + args: vec![(borrowed_self(), sym::other)], ret_ty, attributes: attrs, is_unsafe: false, @@ -80,9 +80,9 @@ pub fn expand_deriving_partial_ord( let trait_def = TraitDef { span, attributes: vec![], - path: path_std!(cx, cmp::PartialOrd), + path: path_std!(cmp::PartialOrd), additional_bounds: vec![], - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), is_unsafe: false, supports_unions: false, methods, diff --git a/src/librustc_builtin_macros/deriving/debug.rs b/src/librustc_builtin_macros/deriving/debug.rs index 6befeb746bd6d1dfc37069a7a846f3ca9d40e3f2..76e21bc43c52d84ec614ded321737770031e515d 100644 --- a/src/librustc_builtin_macros/deriving/debug.rs +++ b/src/librustc_builtin_macros/deriving/debug.rs @@ -18,22 +18,22 @@ pub fn expand_deriving_debug( ) { // &mut ::std::fmt::Formatter let fmtr = - Ptr(Box::new(Literal(path_std!(cx, fmt::Formatter))), Borrowed(None, ast::Mutability::Mut)); + Ptr(Box::new(Literal(path_std!(fmt::Formatter))), Borrowed(None, ast::Mutability::Mut)); let trait_def = TraitDef { span, attributes: Vec::new(), - path: path_std!(cx, fmt::Debug), + path: path_std!(fmt::Debug), additional_bounds: Vec::new(), - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), is_unsafe: false, supports_unions: false, methods: vec![MethodDef { name: sym::fmt, - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), explicit_self: borrowed_explicit_self(), - args: vec![(fmtr, "f")], - ret_ty: Literal(path_std!(cx, fmt::Result)), + args: vec![(fmtr, sym::f)], + ret_ty: Literal(path_std!(fmt::Result)), attributes: Vec::new(), is_unsafe: false, unify_fieldless_variants: false, @@ -62,7 +62,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_> // We want to make sure we have the ctxt set so that we can use unstable methods let span = cx.with_def_site_ctxt(span); let name = cx.expr_lit(span, ast::LitKind::Str(ident.name, ast::StrStyle::Cooked)); - let builder = cx.ident_of("debug_trait_builder", span); + let builder = Ident::new(sym::debug_trait_builder, span); let builder_expr = cx.expr_ident(span, builder); let fmt = substr.nonself_args[0].clone(); @@ -71,7 +71,8 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_> match vdata { ast::VariantData::Tuple(..) | ast::VariantData::Unit(..) => { // tuple struct/"normal" variant - let expr = cx.expr_method_call(span, fmt, cx.ident_of("debug_tuple", span), vec![name]); + let expr = + cx.expr_method_call(span, fmt, Ident::new(sym::debug_tuple, span), vec![name]); stmts.push(cx.stmt_let(span, true, builder, expr)); for field in fields { @@ -94,7 +95,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_> ast::VariantData::Struct(..) => { // normal struct/struct variant let expr = - cx.expr_method_call(span, fmt, cx.ident_of("debug_struct", span), vec![name]); + cx.expr_method_call(span, fmt, Ident::new(sym::debug_struct, span), vec![name]); stmts.push(cx.stmt_let(DUMMY_SP, true, builder, expr)); for field in fields { @@ -117,7 +118,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_> } } - let expr = cx.expr_method_call(span, builder_expr, cx.ident_of("finish", span), vec![]); + let expr = cx.expr_method_call(span, builder_expr, Ident::new(sym::finish, span), vec![]); stmts.push(cx.stmt_expr(expr)); let block = cx.block(span, stmts); diff --git a/src/librustc_builtin_macros/deriving/decodable.rs b/src/librustc_builtin_macros/deriving/decodable.rs index 0792be73263317ddfc1bf4b4c2ffe8be2147a483..ce8c2dfe4d5a099ebc5890ab5b4ea9e40db82a4f 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::{Expr, MetaItem, Mutability}; use rustc_ast::ptr::P; use rustc_expand::base::{Annotatable, ExtCtxt}; -use rustc_span::symbol::{sym, Symbol}; +use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::Span; pub fn expand_deriving_rustc_decodable( @@ -18,38 +18,37 @@ pub fn expand_deriving_rustc_decodable( item: &Annotatable, push: &mut dyn FnMut(Annotatable), ) { - let krate = "rustc_serialize"; - let typaram = "__D"; + let krate = sym::rustc_serialize; + let typaram = sym::__D; let trait_def = TraitDef { span, attributes: Vec::new(), - path: Path::new_(vec![krate, "Decodable"], None, vec![], PathKind::Global), + path: Path::new_(vec![krate, sym::Decodable], None, vec![], PathKind::Global), additional_bounds: Vec::new(), - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), is_unsafe: false, supports_unions: false, methods: vec![MethodDef { name: sym::decode, - generics: LifetimeBounds { - lifetimes: Vec::new(), + generics: Bounds { bounds: vec![( typaram, - vec![Path::new_(vec![krate, "Decoder"], None, vec![], PathKind::Global)], + vec![Path::new_(vec![krate, sym::Decoder], None, vec![], PathKind::Global)], )], }, explicit_self: None, args: vec![( Ptr(Box::new(Literal(Path::new_local(typaram))), Borrowed(None, Mutability::Mut)), - "d", + sym::d, )], ret_ty: Literal(Path::new_( - pathvec_std!(cx, result::Result), + pathvec_std!(result::Result), None, vec![ Box::new(Self_), Box::new(Literal(Path::new_( - vec![typaram, "Error"], + vec![typaram, sym::Error], None, vec![], PathKind::Local, @@ -74,17 +73,17 @@ fn decodable_substructure( cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructure<'_>, - krate: &str, + krate: Symbol, ) -> P { let decoder = substr.nonself_args[0].clone(); let recurse = vec![ - cx.ident_of(krate, trait_span), - cx.ident_of("Decodable", trait_span), - cx.ident_of("decode", trait_span), + Ident::new(krate, trait_span), + Ident::new(sym::Decodable, trait_span), + Ident::new(sym::decode, trait_span), ]; let exprdecode = cx.expr_path(cx.path_global(trait_span, recurse)); // throw an underscore in front to suppress unused variable warnings - let blkarg = cx.ident_of("_d", trait_span); + let blkarg = Ident::new(sym::_d, trait_span); let blkdecoder = cx.expr_ident(trait_span, blkarg); match *substr.fields { @@ -93,7 +92,7 @@ fn decodable_substructure( Unnamed(ref fields, _) => fields.len(), Named(ref fields) => fields.len(), }; - let read_struct_field = cx.ident_of("read_struct_field", trait_span); + let read_struct_field = Ident::new(sym::read_struct_field, trait_span); let path = cx.path_ident(trait_span, substr.type_ident); let result = @@ -116,7 +115,7 @@ fn decodable_substructure( cx.expr_method_call( trait_span, decoder, - cx.ident_of("read_struct", trait_span), + Ident::new(sym::read_struct, trait_span), vec![ cx.expr_str(trait_span, substr.type_ident.name), cx.expr_usize(trait_span, nfields), @@ -125,11 +124,11 @@ fn decodable_substructure( ) } StaticEnum(_, ref fields) => { - let variant = cx.ident_of("i", trait_span); + let variant = Ident::new(sym::i, trait_span); let mut arms = Vec::with_capacity(fields.len() + 1); let mut variants = Vec::with_capacity(fields.len()); - let rvariant_arg = cx.ident_of("read_enum_variant_arg", trait_span); + let rvariant_arg = Ident::new(sym::read_enum_variant_arg, trait_span); for (i, &(ident, v_span, ref parts)) in fields.iter().enumerate() { variants.push(cx.expr_str(v_span, ident.name)); @@ -164,13 +163,13 @@ fn decodable_substructure( let result = cx.expr_method_call( trait_span, blkdecoder, - cx.ident_of("read_enum_variant", trait_span), + Ident::new(sym::read_enum_variant, trait_span), vec![variant_vec, lambda], ); cx.expr_method_call( trait_span, decoder, - cx.ident_of("read_enum", trait_span), + Ident::new(sym::read_enum, trait_span), vec![ cx.expr_str(trait_span, substr.type_ident.name), cx.lambda1(trait_span, result, blkarg), diff --git a/src/librustc_builtin_macros/deriving/default.rs b/src/librustc_builtin_macros/deriving/default.rs index 5dfb0e8f37c63a81807642c342e179a70af61ecf..8ca1be1efb635f7685382e853d35e7e57e34d55f 100644 --- a/src/librustc_builtin_macros/deriving/default.rs +++ b/src/librustc_builtin_macros/deriving/default.rs @@ -1,6 +1,5 @@ use crate::deriving::generic::ty::*; use crate::deriving::generic::*; -use crate::deriving::path_std; use rustc_ast::ast::{Expr, MetaItem}; use rustc_ast::ptr::P; @@ -21,14 +20,14 @@ pub fn expand_deriving_default( let trait_def = TraitDef { span, attributes: Vec::new(), - path: path_std!(cx, default::Default), + path: Path::new(vec![kw::Default, sym::Default]), additional_bounds: Vec::new(), - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), is_unsafe: false, supports_unions: false, methods: vec![MethodDef { name: kw::Default, - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), explicit_self: None, args: Vec::new(), ret_ty: Self_, diff --git a/src/librustc_builtin_macros/deriving/encodable.rs b/src/librustc_builtin_macros/deriving/encodable.rs index 4a90b7a193886793e7b5093798ef4cd6e9db47bc..7a880357a594740939a7fd55bfe129668047d994 100644 --- a/src/librustc_builtin_macros/deriving/encodable.rs +++ b/src/librustc_builtin_macros/deriving/encodable.rs @@ -92,7 +92,7 @@ use rustc_ast::ast::{Expr, ExprKind, MetaItem, Mutability}; use rustc_ast::ptr::P; use rustc_expand::base::{Annotatable, ExtCtxt}; -use rustc_span::symbol::{sym, Symbol}; +use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::Span; pub fn expand_deriving_rustc_encodable( @@ -102,38 +102,42 @@ pub fn expand_deriving_rustc_encodable( item: &Annotatable, push: &mut dyn FnMut(Annotatable), ) { - let krate = "rustc_serialize"; - let typaram = "__S"; + let krate = sym::rustc_serialize; + let typaram = sym::__S; let trait_def = TraitDef { span, attributes: Vec::new(), - path: Path::new_(vec![krate, "Encodable"], None, vec![], PathKind::Global), + path: Path::new_(vec![krate, sym::Encodable], None, vec![], PathKind::Global), additional_bounds: Vec::new(), - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), is_unsafe: false, supports_unions: false, methods: vec![MethodDef { name: sym::encode, - generics: LifetimeBounds { - lifetimes: Vec::new(), + generics: Bounds { bounds: vec![( typaram, - vec![Path::new_(vec![krate, "Encoder"], None, vec![], PathKind::Global)], + vec![Path::new_(vec![krate, sym::Encoder], None, vec![], PathKind::Global)], )], }, explicit_self: borrowed_explicit_self(), args: vec![( Ptr(Box::new(Literal(Path::new_local(typaram))), Borrowed(None, Mutability::Mut)), - "s", + // FIXME: we could use `sym::s` here, but making `s` a static + // symbol changes the symbol index ordering in a way that makes + // ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.rs + // fail. The linting code should be fixed so that its output + // does not depend on the symbol index ordering. + Symbol::intern("s"), )], ret_ty: Literal(Path::new_( - pathvec_std!(cx, result::Result), + pathvec_std!(result::Result), None, vec![ Box::new(Tuple(Vec::new())), Box::new(Literal(Path::new_( - vec![typaram, "Error"], + vec![typaram, sym::Error], None, vec![], PathKind::Local, @@ -158,24 +162,24 @@ fn encodable_substructure( cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructure<'_>, - krate: &'static str, + krate: Symbol, ) -> P { let encoder = substr.nonself_args[0].clone(); // throw an underscore in front to suppress unused variable warnings - let blkarg = cx.ident_of("_e", trait_span); + let blkarg = Ident::new(sym::_e, trait_span); let blkencoder = cx.expr_ident(trait_span, blkarg); let fn_path = cx.expr_path(cx.path_global( trait_span, vec![ - cx.ident_of(krate, trait_span), - cx.ident_of("Encodable", trait_span), - cx.ident_of("encode", trait_span), + Ident::new(krate, trait_span), + Ident::new(sym::Encodable, trait_span), + Ident::new(sym::encode, trait_span), ], )); match *substr.fields { Struct(_, ref fields) => { - let emit_struct_field = cx.ident_of("emit_struct_field", trait_span); + let emit_struct_field = Ident::new(sym::emit_struct_field, trait_span); let mut stmts = Vec::new(); for (i, &FieldInfo { name, ref self_, span, .. }) in fields.iter().enumerate() { let name = match name { @@ -215,7 +219,7 @@ fn encodable_substructure( cx.expr_method_call( trait_span, encoder, - cx.ident_of("emit_struct", trait_span), + Ident::new(sym::emit_struct, trait_span), vec![ cx.expr_str(trait_span, substr.type_ident.name), cx.expr_usize(trait_span, fields.len()), @@ -231,7 +235,7 @@ fn encodable_substructure( // actually exist. let me = cx.stmt_let(trait_span, false, blkarg, encoder); let encoder = cx.expr_ident(trait_span, blkarg); - let emit_variant_arg = cx.ident_of("emit_enum_variant_arg", trait_span); + let emit_variant_arg = Ident::new(sym::emit_enum_variant_arg, trait_span); let mut stmts = Vec::new(); if !fields.is_empty() { let last = fields.len() - 1; @@ -264,7 +268,7 @@ fn encodable_substructure( let call = cx.expr_method_call( trait_span, blkencoder, - cx.ident_of("emit_enum_variant", trait_span), + Ident::new(sym::emit_enum_variant, trait_span), vec![ name, cx.expr_usize(trait_span, idx), @@ -276,7 +280,7 @@ fn encodable_substructure( let ret = cx.expr_method_call( trait_span, encoder, - cx.ident_of("emit_enum", trait_span), + Ident::new(sym::emit_enum, trait_span), vec![cx.expr_str(trait_span, substr.type_ident.name), blk], ); cx.expr_block(cx.block(trait_span, vec![me, cx.stmt_expr(ret)])) diff --git a/src/librustc_builtin_macros/deriving/generic/mod.rs b/src/librustc_builtin_macros/deriving/generic/mod.rs index 050774aa24c969e9c62f159fcc26263026f42909..c43d1cf1888c494a012873b554e5c6b1a004a9c4 100644 --- a/src/librustc_builtin_macros/deriving/generic/mod.rs +++ b/src/librustc_builtin_macros/deriving/generic/mod.rs @@ -191,7 +191,7 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::Span; -use ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty}; +use ty::{Bounds, Path, Ptr, PtrTy, Self_, Ty}; use crate::deriving; @@ -204,14 +204,14 @@ pub struct TraitDef<'a> { pub attributes: Vec, /// Path of the trait, including any type parameters - pub path: Path<'a>, + pub path: Path, /// Additional bounds required of any type parameters of the type, /// other than the current trait - pub additional_bounds: Vec>, + pub additional_bounds: Vec, /// Any extra lifetimes and/or bounds, e.g., `D: serialize::Decoder` - pub generics: LifetimeBounds<'a>, + pub generics: Bounds, /// Is it an `unsafe` trait? pub is_unsafe: bool, @@ -221,14 +221,14 @@ pub struct TraitDef<'a> { pub methods: Vec>, - pub associated_types: Vec<(Ident, Ty<'a>)>, + pub associated_types: Vec<(Ident, Ty)>, } pub struct MethodDef<'a> { /// name of the method pub name: Symbol, /// List of generics, e.g., `R: rand::Rng` - pub generics: LifetimeBounds<'a>, + pub generics: Bounds, /// Whether there is a self argument (outer Option) i.e., whether /// this is a static function, and whether it is a pointer (inner @@ -236,10 +236,10 @@ pub struct MethodDef<'a> { pub explicit_self: Option>, /// Arguments other than the self argument - pub args: Vec<(Ty<'a>, &'a str)>, + pub args: Vec<(Ty, Symbol)>, /// Returns type - pub ret_ty: Ty<'a>, + pub ret_ty: Ty, pub attributes: Vec, @@ -865,7 +865,7 @@ fn split_self_nonself_args( for (ty, name) in self.args.iter() { let ast_ty = ty.to_ty(cx, trait_.span, type_ident, generics); - let ident = cx.ident_of(name, trait_.span); + let ident = Ident::new(*name, trait_.span); arg_tys.push((ident, ast_ty)); let arg_expr = cx.expr_ident(trait_.span, ident); @@ -1170,8 +1170,10 @@ fn build_enum_match_tuple<'b>( ) .collect::>(); - let self_arg_idents = - self_arg_names.iter().map(|name| cx.ident_of(name, sp)).collect::>(); + let self_arg_idents = self_arg_names + .iter() + .map(|name| Ident::from_str_and_span(name, sp)) + .collect::>(); // The `vi_idents` will be bound, solely in the catch-all, to // a series of let statements mapping each self_arg to an int @@ -1180,7 +1182,7 @@ fn build_enum_match_tuple<'b>( .iter() .map(|name| { let vi_suffix = format!("{}_vi", &name[..]); - cx.ident_of(&vi_suffix[..], trait_.span) + Ident::from_str_and_span(&vi_suffix, trait_.span) }) .collect::>(); @@ -1568,7 +1570,7 @@ fn create_struct_pattern( let mut ident_exprs = Vec::new(); for (i, struct_field) in struct_def.fields().iter().enumerate() { let sp = struct_field.span.with_ctxt(self.span.ctxt()); - let ident = cx.ident_of(&format!("{}_{}", prefix, i), self.span); + let ident = Ident::from_str_and_span(&format!("{}_{}", prefix, i), self.span); paths.push(ident.with_span_pos(sp)); let val = cx.expr_path(cx.path_ident(sp, ident)); let val = if use_temporaries { val } else { cx.expr_deref(sp, val) }; diff --git a/src/librustc_builtin_macros/deriving/generic/ty.rs b/src/librustc_builtin_macros/deriving/generic/ty.rs index 609feb6f259d6a9647de777421155b398b347340..51314dbcffc06e5d50358f6f846632f16a53d499 100644 --- a/src/librustc_builtin_macros/deriving/generic/ty.rs +++ b/src/librustc_builtin_macros/deriving/generic/ty.rs @@ -8,7 +8,7 @@ use rustc_ast::ptr::P; use rustc_expand::base::ExtCtxt; use rustc_span::source_map::{respan, DUMMY_SP}; -use rustc_span::symbol::{kw, Ident}; +use rustc_span::symbol::{kw, Ident, Symbol}; use rustc_span::Span; /// The types of pointers @@ -24,10 +24,10 @@ pub enum PtrTy { /// A path, e.g., `::std::option::Option::` (global). Has support /// for type parameters and a lifetime. #[derive(Clone)] -pub struct Path<'a> { - path: Vec<&'a str>, +pub struct Path { + path: Vec, lifetime: Option, - params: Vec>>, + params: Vec>, kind: PathKind, } @@ -38,19 +38,19 @@ pub enum PathKind { Std, } -impl<'a> Path<'a> { - pub fn new(path: Vec<&str>) -> Path<'_> { +impl Path { + pub fn new(path: Vec) -> Path { Path::new_(path, None, Vec::new(), PathKind::Std) } - pub fn new_local(path: &str) -> Path<'_> { + pub fn new_local(path: Symbol) -> Path { Path::new_(vec![path], None, Vec::new(), PathKind::Local) } - pub fn new_<'r>( - path: Vec<&'r str>, + pub fn new_( + path: Vec, lifetime: Option, - params: Vec>>, + params: Vec>, kind: PathKind, - ) -> Path<'r> { + ) -> Path { Path { path, lifetime, params, kind } } @@ -70,7 +70,7 @@ pub fn to_path( self_ty: Ident, self_generics: &Generics, ) -> ast::Path { - let mut idents = self.path.iter().map(|s| cx.ident_of(*s, span)).collect(); + let mut idents = self.path.iter().map(|s| Ident::new(*s, span)).collect(); let lt = mk_lifetimes(cx, span, &self.lifetime); let tys: Vec> = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect(); @@ -94,21 +94,21 @@ pub fn to_path( /// A type. Supports pointers, Self, and literals. #[derive(Clone)] -pub enum Ty<'a> { +pub enum Ty { Self_, /// &/Box/ Ty - Ptr(Box>, PtrTy), + Ptr(Box, PtrTy), /// `mod::mod::Type<[lifetime], [Params...]>`, including a plain type /// parameter, and things like `i32` - Literal(Path<'a>), + Literal(Path), /// includes unit - Tuple(Vec>), + Tuple(Vec), } pub fn borrowed_ptrty() -> PtrTy { Borrowed(None, ast::Mutability::Not) } -pub fn borrowed(ty: Box>) -> Ty<'_> { +pub fn borrowed(ty: Box) -> Ty { Ptr(ty, borrowed_ptrty()) } @@ -116,11 +116,11 @@ pub fn borrowed_explicit_self() -> Option> { Some(Some(borrowed_ptrty())) } -pub fn borrowed_self<'r>() -> Ty<'r> { +pub fn borrowed_self() -> Ty { borrowed(Box::new(Self_)) } -pub fn nil_ty<'r>() -> Ty<'r> { +pub fn nil_ty() -> Ty { Tuple(Vec::new()) } @@ -132,7 +132,7 @@ fn mk_lifetimes(cx: &ExtCtxt<'_>, span: Span, lt: &Option) -> Vec Ty<'a> { +impl Ty { pub fn to_ty( &self, cx: &ExtCtxt<'_>, @@ -199,9 +199,9 @@ pub fn to_path( fn mk_ty_param( cx: &ExtCtxt<'_>, span: Span, - name: &str, + name: Symbol, attrs: &[ast::Attribute], - bounds: &[Path<'_>], + bounds: &[Path], self_ident: Ident, self_generics: &Generics, ) -> ast::GenericParam { @@ -212,7 +212,7 @@ fn mk_ty_param( cx.trait_bound(path) }) .collect(); - cx.typaram(span, cx.ident_of(name, span), attrs.to_owned(), bounds, None) + cx.typaram(span, Ident::new(name, span), attrs.to_owned(), bounds, None) } fn mk_generics(params: Vec, span: Span) -> Generics { @@ -223,16 +223,15 @@ fn mk_generics(params: Vec, span: Span) -> Generics { } } -/// Lifetimes and bounds on type parameters +/// Bounds on type parameters. #[derive(Clone)] -pub struct LifetimeBounds<'a> { - pub lifetimes: Vec<(&'a str, Vec<&'a str>)>, - pub bounds: Vec<(&'a str, Vec>)>, +pub struct Bounds { + pub bounds: Vec<(Symbol, Vec)>, } -impl<'a> LifetimeBounds<'a> { - pub fn empty() -> LifetimeBounds<'a> { - LifetimeBounds { lifetimes: Vec::new(), bounds: Vec::new() } +impl Bounds { + pub fn empty() -> Bounds { + Bounds { bounds: Vec::new() } } pub fn to_generics( &self, @@ -242,18 +241,12 @@ pub fn to_generics( self_generics: &Generics, ) -> Generics { let generic_params = self - .lifetimes + .bounds .iter() - .map(|&(lt, ref bounds)| { - let bounds = bounds - .iter() - .map(|b| ast::GenericBound::Outlives(cx.lifetime(span, Ident::from_str(b)))); - cx.lifetime_def(span, Ident::from_str(lt), vec![], bounds.collect()) - }) - .chain(self.bounds.iter().map(|t| { + .map(|t| { let (name, ref bounds) = *t; mk_ty_param(cx, span, name, &[], &bounds, self_ty, self_generics) - })) + }) .collect(); mk_generics(generic_params, span) diff --git a/src/librustc_builtin_macros/deriving/hash.rs b/src/librustc_builtin_macros/deriving/hash.rs index f975b75f0be13daa842c521d4029c21a67637371..d7195188085f01fc3df926a2c77b92e42329fd44 100644 --- a/src/librustc_builtin_macros/deriving/hash.rs +++ b/src/librustc_builtin_macros/deriving/hash.rs @@ -15,9 +15,9 @@ pub fn expand_deriving_hash( item: &Annotatable, push: &mut dyn FnMut(Annotatable), ) { - let path = Path::new_(pathvec_std!(cx, hash::Hash), None, vec![], PathKind::Std); + let path = Path::new_(pathvec_std!(hash::Hash), None, vec![], PathKind::Std); - let typaram = "__H"; + let typaram = sym::__H; let arg = Path::new_local(typaram); let hash_trait_def = TraitDef { @@ -25,17 +25,14 @@ pub fn expand_deriving_hash( attributes: Vec::new(), path, additional_bounds: Vec::new(), - generics: LifetimeBounds::empty(), + generics: Bounds::empty(), is_unsafe: false, supports_unions: false, methods: vec![MethodDef { name: sym::hash, - generics: LifetimeBounds { - lifetimes: Vec::new(), - bounds: vec![(typaram, vec![path_std!(cx, hash::Hasher)])], - }, + generics: Bounds { bounds: vec![(typaram, vec![path_std!(hash::Hasher)])] }, explicit_self: borrowed_explicit_self(), - args: vec![(Ptr(Box::new(Literal(arg)), Borrowed(None, Mutability::Mut)), "state")], + args: vec![(Ptr(Box::new(Literal(arg)), Borrowed(None, Mutability::Mut)), sym::state)], ret_ty: nil_ty(), attributes: vec![], is_unsafe: false, diff --git a/src/librustc_builtin_macros/deriving/mod.rs b/src/librustc_builtin_macros/deriving/mod.rs index 6cee21fc6e69d4c35e995daee9e9b41ebbda0a35..33c0edde98f0ba91854e82dcffe64aa32090c9b0 100644 --- a/src/librustc_builtin_macros/deriving/mod.rs +++ b/src/librustc_builtin_macros/deriving/mod.rs @@ -7,11 +7,11 @@ use rustc_span::Span; macro path_local($x:ident) { - generic::ty::Path::new_local(stringify!($x)) + generic::ty::Path::new_local(sym::$x) } -macro pathvec_std($cx:expr, $($rest:ident)::+) {{ - vec![ $( stringify!($rest) ),+ ] +macro pathvec_std($($rest:ident)::+) {{ + vec![ $( sym::$rest ),+ ] }} macro path_std($($x:tt)*) { @@ -84,7 +84,7 @@ fn inject_impl_of_structural_trait( cx: &mut ExtCtxt<'_>, span: Span, item: &Annotatable, - structural_path: generic::ty::Path<'_>, + structural_path: generic::ty::Path, push: &mut dyn FnMut(Annotatable), ) { let item = match *item { diff --git a/src/librustc_builtin_macros/format.rs b/src/librustc_builtin_macros/format.rs index 2becbe2f6758a8b0264f0e152054982cc853de07..55eab24b8a5105def8d34e6bfc591bd39c721bff 100644 --- a/src/librustc_builtin_macros/format.rs +++ b/src/librustc_builtin_macros/format.rs @@ -578,31 +578,31 @@ fn build_index_map(&mut self) { self.count_args_index_offset = sofar; } - fn rtpath(ecx: &ExtCtxt<'_>, s: &str) -> Vec { - ecx.std_path(&[sym::fmt, sym::rt, sym::v1, Symbol::intern(s)]) + fn rtpath(ecx: &ExtCtxt<'_>, s: Symbol) -> Vec { + ecx.std_path(&[sym::fmt, sym::rt, sym::v1, s]) } fn build_count(&self, c: parse::Count) -> P { let sp = self.macsp; let count = |c, arg| { - let mut path = Context::rtpath(self.ecx, "Count"); - path.push(self.ecx.ident_of(c, sp)); + let mut path = Context::rtpath(self.ecx, sym::Count); + path.push(Ident::new(c, sp)); match arg { Some(arg) => self.ecx.expr_call_global(sp, path, vec![arg]), None => self.ecx.expr_path(self.ecx.path_global(sp, path)), } }; match c { - parse::CountIs(i) => count("Is", Some(self.ecx.expr_usize(sp, i))), + parse::CountIs(i) => count(sym::Is, Some(self.ecx.expr_usize(sp, i))), parse::CountIsParam(i) => { // This needs mapping too, as `i` is referring to a macro // argument. If `i` is not found in `count_positions` then // the error had already been emitted elsewhere. let i = self.count_positions.get(&i).cloned().unwrap_or(0) + self.count_args_index_offset; - count("Param", Some(self.ecx.expr_usize(sp, i))) + count(sym::Param, Some(self.ecx.expr_usize(sp, i))) } - parse::CountImplied => count("Implied", None), + parse::CountImplied => count(sym::Implied, None), // should never be the case, names are already resolved parse::CountIsName(_) => panic!("should never happen"), } @@ -690,40 +690,40 @@ fn build_piece( // Build the format let fill = self.ecx.expr_lit(sp, ast::LitKind::Char(fill)); let align = |name| { - let mut p = Context::rtpath(self.ecx, "Alignment"); - p.push(self.ecx.ident_of(name, sp)); + let mut p = Context::rtpath(self.ecx, sym::Alignment); + p.push(Ident::new(name, sp)); self.ecx.path_global(sp, p) }; let align = match arg.format.align { - parse::AlignLeft => align("Left"), - parse::AlignRight => align("Right"), - parse::AlignCenter => align("Center"), - parse::AlignUnknown => align("Unknown"), + parse::AlignLeft => align(sym::Left), + parse::AlignRight => align(sym::Right), + parse::AlignCenter => align(sym::Center), + parse::AlignUnknown => align(sym::Unknown), }; let align = self.ecx.expr_path(align); let flags = self.ecx.expr_u32(sp, arg.format.flags); let prec = self.build_count(arg.format.precision); let width = self.build_count(arg.format.width); - let path = self.ecx.path_global(sp, Context::rtpath(self.ecx, "FormatSpec")); + let path = self.ecx.path_global(sp, Context::rtpath(self.ecx, sym::FormatSpec)); let fmt = self.ecx.expr_struct( sp, path, vec![ - self.ecx.field_imm(sp, self.ecx.ident_of("fill", sp), fill), - self.ecx.field_imm(sp, self.ecx.ident_of("align", sp), align), - self.ecx.field_imm(sp, self.ecx.ident_of("flags", sp), flags), - self.ecx.field_imm(sp, self.ecx.ident_of("precision", sp), prec), - self.ecx.field_imm(sp, self.ecx.ident_of("width", sp), width), + self.ecx.field_imm(sp, Ident::new(sym::fill, sp), fill), + self.ecx.field_imm(sp, Ident::new(sym::align, sp), align), + self.ecx.field_imm(sp, Ident::new(sym::flags, sp), flags), + self.ecx.field_imm(sp, Ident::new(sym::precision, sp), prec), + self.ecx.field_imm(sp, Ident::new(sym::width, sp), width), ], ); - let path = self.ecx.path_global(sp, Context::rtpath(self.ecx, "Argument")); + let path = self.ecx.path_global(sp, Context::rtpath(self.ecx, sym::Argument)); Some(self.ecx.expr_struct( sp, path, vec![ - self.ecx.field_imm(sp, self.ecx.ident_of("position", sp), pos), - self.ecx.field_imm(sp, self.ecx.ident_of("format", sp), fmt), + self.ecx.field_imm(sp, Ident::new(sym::position, sp), pos), + self.ecx.field_imm(sp, Ident::new(sym::format, sp), fmt), ], )) } @@ -740,7 +740,7 @@ fn into_expr(self) -> P { let mut heads = Vec::with_capacity(self.args.len()); let names_pos: Vec<_> = (0..self.args.len()) - .map(|i| self.ecx.ident_of(&format!("arg{}", i), self.macsp)) + .map(|i| Ident::from_str_and_span(&format!("arg{}", i), self.macsp)) .collect(); // First, build up the static array which will become our precompiled diff --git a/src/librustc_builtin_macros/global_allocator.rs b/src/librustc_builtin_macros/global_allocator.rs index f8a9a97b2a50e15b8a1f492b398bac9c2be8c90b..89446a1aa96f9a79346ef5421910b41154890f61 100644 --- a/src/librustc_builtin_macros/global_allocator.rs +++ b/src/librustc_builtin_macros/global_allocator.rs @@ -58,7 +58,7 @@ fn allocator_fn(&self, method: &AllocatorMethod) -> Stmt { let mut abi_args = Vec::new(); let mut i = 0; let mut mk = || { - let name = self.cx.ident_of(&format!("arg{}", i), self.span); + let name = Ident::from_str_and_span(&format!("arg{}", i), self.span); i += 1; name }; @@ -72,7 +72,7 @@ fn allocator_fn(&self, method: &AllocatorMethod) -> Stmt { let kind = ItemKind::Fn(ast::Defaultness::Final, sig, Generics::default(), block); let item = self.cx.item( self.span, - self.cx.ident_of(&self.kind.fn_name(method.name), self.span), + Ident::from_str_and_span(&self.kind.fn_name(method.name), self.span), self.attrs(), kind, ); diff --git a/src/librustc_builtin_macros/proc_macro_harness.rs b/src/librustc_builtin_macros/proc_macro_harness.rs index 7cc9c1f76631e1b80290bd9659489af32dc5c433..f044ce41e879ee8ff3782550c620f334beddcd9e 100644 --- a/src/librustc_builtin_macros/proc_macro_harness.rs +++ b/src/librustc_builtin_macros/proc_macro_harness.rs @@ -384,12 +384,12 @@ fn mk_decls( let proc_macro = Ident::new(sym::proc_macro, span); let krate = cx.item(span, proc_macro, Vec::new(), ast::ItemKind::ExternCrate(None)); - let bridge = cx.ident_of("bridge", span); - let client = cx.ident_of("client", span); - let proc_macro_ty = cx.ident_of("ProcMacro", span); - let custom_derive = cx.ident_of("custom_derive", span); - let attr = cx.ident_of("attr", span); - let bang = cx.ident_of("bang", span); + let bridge = Ident::new(sym::bridge, span); + let client = Ident::new(sym::client, span); + let proc_macro_ty = Ident::new(sym::ProcMacro, span); + let custom_derive = Ident::new(sym::custom_derive, span); + let attr = Ident::new(sym::attr, span); + let bang = Ident::new(sym::bang, span); let krate_ref = RefCell::new(ast_krate); @@ -447,7 +447,7 @@ fn mk_decls( let decls_static = cx .item_static( span, - cx.ident_of("_DECLS", span), + Ident::new(sym::_DECLS, span), cx.ty_rptr( span, cx.ty( diff --git a/src/librustc_builtin_macros/test.rs b/src/librustc_builtin_macros/test.rs index d62f34bab1a31e41685071989d2a4160de90b709..460f947a792af5975b7627f6e7f003ec7b81d021 100644 --- a/src/librustc_builtin_macros/test.rs +++ b/src/librustc_builtin_macros/test.rs @@ -108,22 +108,38 @@ pub fn expand_test_or_bench( let test_id = Ident::new(sym::test, attr_sp); // creates test::$name - let test_path = |name| cx.path(sp, vec![test_id, cx.ident_of(name, sp)]); + let test_path = |name| cx.path(sp, vec![test_id, Ident::from_str_and_span(name, sp)]); // creates test::ShouldPanic::$name - let should_panic_path = - |name| cx.path(sp, vec![test_id, cx.ident_of("ShouldPanic", sp), cx.ident_of(name, sp)]); + let should_panic_path = |name| { + cx.path( + sp, + vec![ + test_id, + Ident::from_str_and_span("ShouldPanic", sp), + Ident::from_str_and_span(name, sp), + ], + ) + }; // creates test::TestType::$name - let test_type_path = - |name| cx.path(sp, vec![test_id, cx.ident_of("TestType", sp), cx.ident_of(name, sp)]); + let test_type_path = |name| { + cx.path( + sp, + vec![ + test_id, + Ident::from_str_and_span("TestType", sp), + Ident::from_str_and_span(name, sp), + ], + ) + }; // creates $name: $expr - let field = |name, expr| cx.field_imm(sp, cx.ident_of(name, sp), expr); + let field = |name, expr| cx.field_imm(sp, Ident::from_str_and_span(name, sp), expr); let test_fn = if is_bench { // A simple ident for a lambda - let b = cx.ident_of("b", attr_sp); + let b = Ident::from_str_and_span("b", attr_sp); cx.expr_call( sp, diff --git a/src/librustc_builtin_macros/test_harness.rs b/src/librustc_builtin_macros/test_harness.rs index 98e42ebf46f2a0bd83b483711730e4af583dbba7..98c5c6936d779d07199d701029e647d529e8700f 100644 --- a/src/librustc_builtin_macros/test_harness.rs +++ b/src/librustc_builtin_macros/test_harness.rs @@ -270,7 +270,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P { let mut test_runner = cx .test_runner .clone() - .unwrap_or(ecx.path(sp, vec![test_id, ecx.ident_of(runner_name, sp)])); + .unwrap_or(ecx.path(sp, vec![test_id, Ident::from_str_and_span(runner_name, sp)])); test_runner.span = sp; diff --git a/src/librustc_expand/base.rs b/src/librustc_expand/base.rs index 3e48224ef9f2006995ec15c49e33b3cc5325d282..64e2d5b3a467c84fd18b28223e40141680d8431b 100644 --- a/src/librustc_expand/base.rs +++ b/src/librustc_expand/base.rs @@ -1061,9 +1061,6 @@ pub fn trace_macros(&self) -> bool { pub fn set_trace_macros(&mut self, x: bool) { self.ecfg.trace_mac = x } - pub fn ident_of(&self, st: &str, sp: Span) -> Ident { - Ident::from_str_and_span(st, sp) - } pub fn std_path(&self, components: &[Symbol]) -> Vec { let def_site = self.with_def_site_ctxt(DUMMY_SP); iter::once(Ident::new(kw::DollarCrate, def_site)) diff --git a/src/librustc_expand/build.rs b/src/librustc_expand/build.rs index 20d2ea0a215d4ac8ced615dda3f0443944b7a9dd..81ff4b3157845e94b65b29cf19aa757ba8265a92 100644 --- a/src/librustc_expand/build.rs +++ b/src/librustc_expand/build.rs @@ -368,7 +368,7 @@ pub fn expr_try(&self, sp: Span, head: P) -> P { let err = self.std_path(&[sym::result, sym::Result, sym::Err]); let err_path = self.path_global(sp, err); - let binding_variable = self.ident_of("__try_var", sp); + let binding_variable = Ident::new(sym::__try_var, sp); let binding_pat = self.pat_ident(sp, binding_variable); let binding_expr = self.expr_ident(sp, binding_variable); diff --git a/src/librustc_middle/mir/query.rs b/src/librustc_middle/mir/query.rs index 560a8421c17972cc1520fcba5ce382ae768b47f9..b311f8344bb6dc787f12a51db651f0489a8d8f24 100644 --- a/src/librustc_middle/mir/query.rs +++ b/src/librustc_middle/mir/query.rs @@ -8,7 +8,7 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_index::bit_set::BitMatrix; use rustc_index::vec::IndexVec; -use rustc_span::{Span, Symbol}; +use rustc_span::Span; use rustc_target::abi::VariantIdx; use smallvec::SmallVec; use std::cell::Cell; @@ -18,7 +18,7 @@ #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable)] pub enum UnsafetyViolationKind { - /// Only permitted in regular `fn`s, prohibitted in `const fn`s. + /// Only permitted in regular `fn`s, prohibited in `const fn`s. General, /// Permitted both in `const fn`s and regular `fn`s. GeneralAndConstFn, @@ -35,13 +35,97 @@ pub enum UnsafetyViolationKind { UnsafeFnBorrowPacked, } +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable)] +pub enum UnsafetyViolationDetails { + CallToUnsafeFunction, + UseOfInlineAssembly, + InitializingTypeWith, + CastOfPointerToInt, + BorrowOfPackedField, + UseOfMutableStatic, + UseOfExternStatic, + DerefOfRawPointer, + AssignToNonCopyUnionField, + AccessToUnionField, + MutationOfLayoutConstrainedField, + BorrowOfLayoutConstrainedField, + CallToFunctionWith, +} + +impl UnsafetyViolationDetails { + pub fn description_and_note(&self) -> (&'static str, &'static str) { + use UnsafetyViolationDetails::*; + match self { + CallToUnsafeFunction => ( + "call to unsafe function", + "consult the function's documentation for information on how to avoid undefined \ + behavior", + ), + UseOfInlineAssembly => ( + "use of inline assembly", + "inline assembly is entirely unchecked and can cause undefined behavior", + ), + InitializingTypeWith => ( + "initializing type with `rustc_layout_scalar_valid_range` attr", + "initializing a layout restricted type's field with a value outside the valid \ + range is undefined behavior", + ), + CastOfPointerToInt => { + ("cast of pointer to int", "casting pointers to integers in constants") + } + BorrowOfPackedField => ( + "borrow of packed field", + "fields of packed structs might be misaligned: dereferencing a misaligned pointer \ + or even just creating a misaligned reference is undefined behavior", + ), + UseOfMutableStatic => ( + "use of mutable static", + "mutable statics can be mutated by multiple threads: aliasing violations or data \ + races will cause undefined behavior", + ), + UseOfExternStatic => ( + "use of extern static", + "extern statics are not controlled by the Rust type system: invalid data, \ + aliasing violations or data races will cause undefined behavior", + ), + DerefOfRawPointer => ( + "dereference of raw pointer", + "raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules \ + and cause data races: all of these are undefined behavior", + ), + AssignToNonCopyUnionField => ( + "assignment to non-`Copy` union field", + "the previous content of the field will be dropped, which causes undefined \ + behavior if the field was not properly initialized", + ), + AccessToUnionField => ( + "access to union field", + "the field may not be properly initialized: using uninitialized data will cause \ + undefined behavior", + ), + MutationOfLayoutConstrainedField => ( + "mutation of layout constrained field", + "mutating layout constrained fields cannot statically be checked for valid values", + ), + BorrowOfLayoutConstrainedField => ( + "borrow of layout constrained field with interior mutability", + "references to fields of layout constrained fields lose the constraints. Coupled \ + with interior mutability, the field can be changed to invalid values", + ), + CallToFunctionWith => ( + "call to function with `#[target_feature]`", + "can only be called if the required target features are available", + ), + } + } +} + #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable)] pub struct UnsafetyViolation { pub source_info: SourceInfo, pub lint_root: hir::HirId, - pub description: Symbol, - pub details: Symbol, pub kind: UnsafetyViolationKind, + pub details: UnsafetyViolationDetails, } #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs index b50d2852c1c5c50640f92fb5a305bf2dc58be816..043d85cb6efa632f7800517b8db3a03918ac5957 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -1440,12 +1440,12 @@ fn path_append( // FIXME(eddyb) `name` should never be empty, but it // currently is for `extern { ... }` "foreign modules". - let name = disambiguated_data.data.as_symbol().as_str(); - if !name.is_empty() { + let name = disambiguated_data.data.as_symbol(); + if name != kw::Invalid { if !self.empty_path { write!(self, "::")?; } - if Ident::from_str(&name).is_raw_guess() { + if Ident::with_dummy_span(name).is_raw_guess() { write!(self, "r#")?; } write!(self, "{}", name)?; diff --git a/src/librustc_middle/ty/query/profiling_support.rs b/src/librustc_middle/ty/query/profiling_support.rs index 3c44662441890431f15e70a74d318aa4f4015759..0683dc0201129bddca91b54fc36d3a10b1df3c7f 100644 --- a/src/librustc_middle/ty/query/profiling_support.rs +++ b/src/librustc_middle/ty/query/profiling_support.rs @@ -60,12 +60,12 @@ fn def_id_to_string_id(&mut self, def_id: DefId) -> StringId { match def_key.disambiguated_data.data { DefPathData::CrateRoot => { - name = self.tcx.original_crate_name(def_id.krate).as_str(); + name = self.tcx.original_crate_name(def_id.krate); dis = ""; end_index = 3; } other => { - name = other.as_symbol().as_str(); + name = other.as_symbol(); if def_key.disambiguated_data.disambiguator == 0 { dis = ""; end_index = 3; @@ -79,10 +79,11 @@ fn def_id_to_string_id(&mut self, def_id: DefId) -> StringId { } } + let name = &*name.as_str(); let components = [ StringComponent::Ref(parent_string_id), StringComponent::Value("::"), - StringComponent::Value(&name[..]), + StringComponent::Value(name), StringComponent::Value(dis), ]; diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 2605d45f8101e3ab97934aa2f0136c92b36a4c48..81d7ac089262206aa24957a226f5c50ea627701e 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -12,7 +12,7 @@ use rustc_middle::ty::{self, TyCtxt}; use rustc_session::lint::builtin::{SAFE_PACKED_BORROWS, UNSAFE_OP_IN_UNSAFE_FN, UNUSED_UNSAFE}; use rustc_session::lint::Level; -use rustc_span::symbol::{sym, Symbol}; +use rustc_span::symbol::sym; use std::ops::Bound; @@ -86,10 +86,8 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location let sig = func_ty.fn_sig(self.tcx); if let hir::Unsafety::Unsafe = sig.unsafety() { self.require_unsafe( - "call to unsafe function", - "consult the function's documentation for information on how to avoid \ - undefined behavior", UnsafetyViolationKind::GeneralAndConstFn, + UnsafetyViolationDetails::CallToUnsafeFunction, ) } @@ -99,9 +97,8 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location } TerminatorKind::InlineAsm { .. } => self.require_unsafe( - "use of inline assembly", - "inline assembly is entirely unchecked and can cause undefined behavior", UnsafetyViolationKind::General, + UnsafetyViolationDetails::UseOfInlineAssembly, ), } self.super_terminator(terminator, location); @@ -122,9 +119,8 @@ fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) { } StatementKind::LlvmInlineAsm { .. } => self.require_unsafe( - "use of inline assembly", - "inline assembly is entirely unchecked and can cause undefined behavior", UnsafetyViolationKind::General, + UnsafetyViolationDetails::UseOfInlineAssembly, ), } self.super_statement(statement, location); @@ -138,10 +134,8 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { match self.tcx.layout_scalar_valid_range(def.did) { (Bound::Unbounded, Bound::Unbounded) => {} _ => self.require_unsafe( - "initializing type with `rustc_layout_scalar_valid_range` attr", - "initializing a layout restricted type's field with a value \ - outside the valid range is undefined behavior", UnsafetyViolationKind::GeneralAndConstFn, + UnsafetyViolationDetails::InitializingTypeWith, ), } } @@ -163,9 +157,8 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { match (cast_in, cast_out) { (CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) => { self.require_unsafe( - "cast of pointer to int", - "casting pointers to integers in constants", UnsafetyViolationKind::General, + UnsafetyViolationDetails::CastOfPointerToInt, ); } _ => {} @@ -190,11 +183,8 @@ fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: if context.is_borrow() { if util::is_disaligned(self.tcx, self.body, self.param_env, *place) { self.require_unsafe( - "borrow of packed field", - "fields of packed structs might be misaligned: dereferencing a \ - misaligned pointer or even just creating a misaligned reference \ - is undefined behavior", UnsafetyViolationKind::BorrowPacked, + UnsafetyViolationDetails::BorrowOfPackedField, ); } } @@ -204,11 +194,8 @@ fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: if context.is_borrow() { if util::is_disaligned(self.tcx, self.body, self.param_env, *place) { self.require_unsafe( - "borrow of packed field", - "fields of packed structs might be misaligned: dereferencing a \ - misaligned pointer or even just creating a misaligned reference \ - is undefined behavior", UnsafetyViolationKind::BorrowPacked, + UnsafetyViolationDetails::BorrowOfPackedField, ); } } @@ -219,19 +206,14 @@ fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: if let Some(box LocalInfo::StaticRef { def_id, .. }) = decl.local_info { if self.tcx.is_mutable_static(def_id) { self.require_unsafe( - "use of mutable static", - "mutable statics can be mutated by multiple threads: aliasing \ - violations or data races will cause undefined behavior", UnsafetyViolationKind::General, + UnsafetyViolationDetails::UseOfMutableStatic, ); return; } else if self.tcx.is_foreign_item(def_id) { self.require_unsafe( - "use of extern static", - "extern statics are not controlled by the Rust type system: \ - invalid data, aliasing violations or data races will cause \ - undefined behavior", UnsafetyViolationKind::General, + UnsafetyViolationDetails::UseOfExternStatic, ); return; } @@ -246,11 +228,8 @@ fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: let base_ty = Place::ty_from(place.local, proj_base, self.body, self.tcx).ty; match base_ty.kind { ty::RawPtr(..) => self.require_unsafe( - "dereference of raw pointer", - "raw pointers may be NULL, dangling or unaligned; they can violate \ - aliasing rules and cause data races: all of these are undefined \ - behavior", UnsafetyViolationKind::General, + UnsafetyViolationDetails::DerefOfRawPointer, ), ty::Adt(adt, _) => { if adt.is_union() { @@ -271,21 +250,16 @@ fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: self.param_env, ) { self.require_unsafe( - "assignment to non-`Copy` union field", - "the previous content of the field will be dropped, which \ - causes undefined behavior if the field was not properly \ - initialized", UnsafetyViolationKind::GeneralAndConstFn, + UnsafetyViolationDetails::AssignToNonCopyUnionField, ) } else { // write to non-move union, safe } } else { self.require_unsafe( - "access to union field", - "the field may not be properly initialized: using \ - uninitialized data will cause undefined behavior", UnsafetyViolationKind::GeneralAndConstFn, + UnsafetyViolationDetails::AccessToUnionField, ) } } @@ -298,12 +272,7 @@ fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: } impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { - fn require_unsafe( - &mut self, - description: &'static str, - details: &'static str, - kind: UnsafetyViolationKind, - ) { + fn require_unsafe(&mut self, kind: UnsafetyViolationKind, details: UnsafetyViolationDetails) { let source_info = self.source_info; let lint_root = self.body.source_scopes[self.source_info.scope] .local_data @@ -311,13 +280,7 @@ fn require_unsafe( .assert_crate_local() .lint_root; self.register_violations( - &[UnsafetyViolation { - source_info, - lint_root, - description: Symbol::intern(description), - details: Symbol::intern(details), - kind, - }], + &[UnsafetyViolation { source_info, lint_root, kind, details }], &[], ); } @@ -434,12 +397,8 @@ fn check_mut_borrowing_layout_constrained_field( if self.tcx.layout_scalar_valid_range(def.did) != (Bound::Unbounded, Bound::Unbounded) { - let (description, details) = if is_mut_use { - ( - "mutation of layout constrained field", - "mutating layout constrained fields cannot statically be \ - checked for valid values", - ) + let details = if is_mut_use { + UnsafetyViolationDetails::MutationOfLayoutConstrainedField // Check `is_freeze` as late as possible to avoid cycle errors // with opaque types. @@ -448,21 +407,11 @@ fn check_mut_borrowing_layout_constrained_field( .ty .is_freeze(self.tcx.at(self.source_info.span), self.param_env) { - ( - "borrow of layout constrained field with interior \ - mutability", - "references to fields of layout constrained fields \ - lose the constraints. Coupled with interior mutability, \ - the field can be changed to invalid values", - ) + UnsafetyViolationDetails::BorrowOfLayoutConstrainedField } else { continue; }; - self.require_unsafe( - description, - details, - UnsafetyViolationKind::GeneralAndConstFn, - ); + self.require_unsafe(UnsafetyViolationKind::GeneralAndConstFn, details); } } } @@ -480,9 +429,8 @@ fn check_target_features(&mut self, func_did: DefId) { // Is `callee_features` a subset of `calling_features`? if !callee_features.iter().all(|feature| self_features.contains(feature)) { self.require_unsafe( - "call to function with `#[target_feature]`", - "can only be called if the required target features are available", UnsafetyViolationKind::GeneralAndConstFn, + UnsafetyViolationDetails::CallToFunctionWith, ) } } @@ -675,9 +623,9 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) { let UnsafetyCheckResult { violations, unsafe_blocks } = tcx.unsafety_check_result(def_id); - for &UnsafetyViolation { source_info, lint_root, description, details, kind } in - violations.iter() - { + for &UnsafetyViolation { source_info, lint_root, kind, details } in violations.iter() { + let (description, note) = details.description_and_note(); + // Report an error. let unsafe_fn_msg = if unsafe_op_in_unsafe_fn_allowed(tcx, lint_root) { " function or" } else { "" }; @@ -693,8 +641,8 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) { description, unsafe_fn_msg, ) - .span_label(source_info.span, &*description.as_str()) - .note(&details.as_str()) + .span_label(source_info.span, description) + .note(note) .emit(); } UnsafetyViolationKind::BorrowPacked => { @@ -712,7 +660,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) { "{} is unsafe and requires unsafe{} block (error E0133)", description, unsafe_fn_msg, )) - .note(&details.as_str()) + .note(note) .emit() }, ) @@ -727,8 +675,8 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) { "{} is unsafe and requires unsafe block (error E0133)", description, )) - .span_label(source_info.span, &*description.as_str()) - .note(&details.as_str()) + .span_label(source_info.span, description) + .note(note) .emit(); }, ), @@ -756,8 +704,8 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) { "{} is unsafe and requires unsafe block (error E0133)", description, )) - .span_label(source_info.span, &*description.as_str()) - .note(&details.as_str()) + .span_label(source_info.span, description) + .note(note) .emit(); }) } diff --git a/src/librustc_span/symbol.rs b/src/librustc_span/symbol.rs index ccb6ccb57fa404c8538e62f5d43b2056d7347a98..5d332ddf5f3df1ccecf1165219bd67d875fdd1b9 100644 --- a/src/librustc_span/symbol.rs +++ b/src/librustc_span/symbol.rs @@ -122,19 +122,28 @@ // There is currently no checking that all symbols are used; that would be // nice to have. Symbols { + Alignment, Arc, + Argument, ArgumentV1, Arguments, C, + Center, Clone, Copy, + Count, Debug, Decodable, + Decoder, Default, Encodable, + Encoder, Eq, Equal, Err, + Error, + FormatSpec, + Formatter, From, Future, FxHashMap, @@ -143,11 +152,15 @@ Hash, HashMap, HashSet, + Hasher, + Implied, Input, IntoIterator, + Is, ItemContext, Iterator, Layout, + Left, LintPass, None, Ok, @@ -155,11 +168,13 @@ Ord, Ordering, Output, + Param, PartialEq, PartialOrd, Pending, Pin, Poll, + ProcMacro, ProcMacroHack, ProceduralMasqueradeDummyType, Range, @@ -172,20 +187,31 @@ Ready, Result, Return, + Right, RustcDecodable, RustcEncodable, Send, Some, + StructuralEq, + StructuralPartialEq, Sync, Target, Try, Ty, TyCtxt, TyKind, + Unknown, Vec, Yield, + _DECLS, _Self, + __D, + __H, + __S, __next, + __try_var, + _d, + _e, _task_context, aarch64_target_feature, abi, @@ -226,6 +252,7 @@ allowed, always, and, + and_then, any, arbitrary_enum_discriminant, arbitrary_self_types, @@ -256,6 +283,7 @@ automatically_derived, avx512_target_feature, await_macro, + bang, begin_panic, bench, bin, @@ -278,6 +306,7 @@ box_syntax, braced_empty_structs, breakpoint, + bridge, bswap, c_variadic, call, @@ -299,6 +328,7 @@ cfg_target_vendor, cfg_version, char, + client, clippy, clone, clone_closures, @@ -370,11 +400,15 @@ custom_derive, custom_inner_attributes, custom_test_frameworks, + d, dead_code, dealloc, debug, debug_assertions, + debug_struct, debug_trait, + debug_trait_builder, + debug_tuple, decl_macro, declare_lint_pass, decode, @@ -421,6 +455,11 @@ dyn_trait, eh_catch_typeinfo, eh_personality, + emit_enum, + emit_enum_variant, + emit_enum_variant_arg, + emit_struct, + emit_struct_field, enable, enclosing_scope, encode, @@ -448,6 +487,7 @@ extern_prelude, extern_types, external_doc, + f, f16c_target_feature, f32, f32_runtime, @@ -464,6 +504,9 @@ field, field_init_shorthand, file, + fill, + finish, + flags, float_to_int_unchecked, floorf32, floorf64, @@ -478,6 +521,7 @@ fn_once_output, forbid, forget, + format, format_args, format_args_capture, format_args_nl, @@ -519,6 +563,7 @@ html_no_source, html_playground_url, html_root_url, + i, i128, i128_type, i16, @@ -606,6 +651,7 @@ main, managed_boxes, manually_drop, + map, marker, marker_trait_attr, masked, @@ -708,6 +754,7 @@ options, or, or_patterns, + other, out, overlapping_marker_traits, owned_box, @@ -739,6 +786,7 @@ plugins, pointer, poll, + position, post_dash_lto: "post-lto", powerpc_target_feature, powf32, @@ -747,6 +795,7 @@ powif64, pre_dash_lto: "pre-lto", precise_pointer_size_matching, + precision, pref_align_of, prefetch_read_data, prefetch_read_instruction, @@ -783,6 +832,11 @@ raw_identifiers, raw_ref_op, re_rebalance_coherence, + read_enum, + read_enum_variant, + read_enum_variant_arg, + read_struct, + read_struct_field, readonly, realloc, reason, @@ -872,6 +926,7 @@ rustc_promotable, rustc_regions, rustc_reservation_impl, + rustc_serialize, rustc_specialization_trait, rustc_stable, rustc_std_internal_symbol, @@ -976,6 +1031,7 @@ stable, staged_api, start, + state, static_in_const, static_nobundle, static_recursion, @@ -1123,6 +1179,7 @@ wasm_import_module, wasm_target_feature, while_let, + width, windows, windows_subsystem, wrapping_add, diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index 79d5c148ce4fe9a5a096e9b122ca35b9bdc68a34..a9b045cee6087ce599742d817f77b58eb8532d57 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -26,7 +26,7 @@ TypeFoldable, WithConstness, }; use rustc_session::DiagnosticMessageId; -use rustc_span::symbol::sym; +use rustc_span::symbol::{kw, sym}; use rustc_span::{ExpnKind, MultiSpan, Span, DUMMY_SP}; use std::fmt; @@ -1524,7 +1524,7 @@ fn maybe_report_ambiguity( (self.tcx.sess.source_map().span_to_snippet(span), &obligation.cause.code) { let generics = self.tcx.generics_of(*def_id); - if generics.params.iter().any(|p| p.name.as_str() != "Self") + if generics.params.iter().any(|p| p.name != kw::SelfUpper) && !snippet.ends_with('>') { // FIXME: To avoid spurious suggestions in functions where type arguments diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 9a9630f09588698fc551517f3c8286641d016e27..f575548ddd6382bb7da09921310e6c286b22ceb6 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -322,12 +322,12 @@ fn can_use_as_ref(&self, expr: &hir::Expr<'_>) -> Option<(Span, &'static str, St let self_ty = self.tables.borrow().node_type(method_expr[0].hir_id); let self_ty = format!("{:?}", self_ty); - let name = method_path.ident.as_str(); + let name = method_path.ident.name; let is_as_ref_able = (self_ty.starts_with("&std::option::Option") || self_ty.starts_with("&std::result::Result") || self_ty.starts_with("std::option::Option") || self_ty.starts_with("std::result::Result")) - && (name == "map" || name == "and_then"); + && (name == sym::map || name == sym::and_then); match (is_as_ref_able, self.sess().source_map().span_to_snippet(*method_span)) { (true, Ok(src)) => { let suggestion = format!("as_ref().{}", src); diff --git a/src/tools/clippy/clippy_lints/src/non_expressive_names.rs b/src/tools/clippy/clippy_lints/src/non_expressive_names.rs index 7128fee9bcf5157c238e089486bdf75db299a080..1d4772bb3d606a41a5dd4af3d1b9d9d8dd332ee1 100644 --- a/src/tools/clippy/clippy_lints/src/non_expressive_names.rs +++ b/src/tools/clippy/clippy_lints/src/non_expressive_names.rs @@ -8,7 +8,7 @@ use rustc_middle::lint::in_external_macro; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; -use rustc_span::symbol::{Ident, SymbolStr}; +use rustc_span::symbol::{Ident, Symbol}; use std::cmp::Ordering; declare_clippy_lint! { @@ -75,7 +75,7 @@ pub struct NonExpressiveNames { impl_lint_pass!(NonExpressiveNames => [SIMILAR_NAMES, MANY_SINGLE_CHAR_NAMES, JUST_UNDERSCORES_AND_DIGITS]); struct ExistingName { - interned: SymbolStr, + interned: Symbol, span: Span, len: usize, exemptions: &'static [&'static str], @@ -218,18 +218,19 @@ fn check_ident(&mut self, ident: Ident) { let mut split_at = None; match existing_name.len.cmp(&count) { Ordering::Greater => { - if existing_name.len - count != 1 || levenstein_not_1(&interned_name, &existing_name.interned) { + if existing_name.len - count != 1 || levenstein_not_1(&interned_name, &existing_name.interned.as_str()) { continue; } }, Ordering::Less => { - if count - existing_name.len != 1 || levenstein_not_1(&existing_name.interned, &interned_name) { + if count - existing_name.len != 1 || levenstein_not_1(&existing_name.interned.as_str(), &interned_name) { continue; } }, Ordering::Equal => { let mut interned_chars = interned_name.chars(); - let mut existing_chars = existing_name.interned.chars(); + let interned_str = existing_name.interned.as_str(); + let mut existing_chars = interned_str.chars(); let first_i = interned_chars.next().expect("we know we have at least one char"); let first_e = existing_chars.next().expect("we know we have at least one char"); let eq_or_numeric = |(a, b): (char, char)| a == b || a.is_numeric() && b.is_numeric(); @@ -302,7 +303,7 @@ fn check_ident(&mut self, ident: Ident) { } self.0.names.push(ExistingName { exemptions: get_exemptions(&interned_name).unwrap_or(&[]), - interned: interned_name, + interned: ident.name, span: ident.span, len: count, }); diff --git a/src/tools/clippy/clippy_lints/src/unsafe_removed_from_name.rs b/src/tools/clippy/clippy_lints/src/unsafe_removed_from_name.rs index 735800e7e74160ee079aefcdaf3a20b65189122a..154082a0fdb530b8e81d1d4e47f3abced3f96b6b 100644 --- a/src/tools/clippy/clippy_lints/src/unsafe_removed_from_name.rs +++ b/src/tools/clippy/clippy_lints/src/unsafe_removed_from_name.rs @@ -3,7 +3,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; -use rustc_span::symbol::{Ident, SymbolStr}; +use rustc_span::symbol::Ident; declare_clippy_lint! { /// **What it does:** Checks for imports that remove "unsafe" from an item's @@ -73,6 +73,6 @@ fn unsafe_to_safe_check(old_name: Ident, new_name: Ident, cx: &EarlyContext<'_>, } #[must_use] -fn contains_unsafe(name: &SymbolStr) -> bool { +fn contains_unsafe(name: &str) -> bool { name.contains("Unsafe") || name.contains("unsafe") }