mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Rollup merge of #61003 - nnethercote:rm-InternedString-PartialEq-impls, r=petrochenkov
Remove impls for `InternedString`/string equality. `Symbol` received the same treatment in #60630. Also, we can derive `PartialEq` for `InternedString`. r? @petrochenkov
This commit is contained in:
commit
44cb86bdc8
@ -6,7 +6,7 @@ use crate::ty::query::Providers;
|
||||
|
||||
use rustc_target::spec::abi::Abi::RustIntrinsic;
|
||||
use rustc_data_structures::indexed_vec::Idx;
|
||||
use syntax_pos::Span;
|
||||
use syntax_pos::{Span, sym};
|
||||
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
use crate::hir;
|
||||
|
||||
@ -69,7 +69,7 @@ fn unpack_option_like<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
impl<'a, 'tcx> ExprVisitor<'a, 'tcx> {
|
||||
fn def_id_is_transmute(&self, def_id: DefId) -> bool {
|
||||
self.tcx.fn_sig(def_id).abi() == RustIntrinsic &&
|
||||
self.tcx.item_name(def_id) == "transmute"
|
||||
self.tcx.item_name(def_id) == sym::transmute
|
||||
}
|
||||
|
||||
fn check_transmute(&self, span: Span, from: Ty<'tcx>, to: Ty<'tcx>) {
|
||||
|
@ -243,15 +243,15 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
|
||||
// `{Self}` is allowed
|
||||
Position::ArgumentNamed(s) if s == "Self" => (),
|
||||
// `{ThisTraitsName}` is allowed
|
||||
Position::ArgumentNamed(s) if s == name => (),
|
||||
Position::ArgumentNamed(s) if s == name.as_str() => (),
|
||||
// `{from_method}` is allowed
|
||||
Position::ArgumentNamed(s) if s == "from_method" => (),
|
||||
// `{from_desugaring}` is allowed
|
||||
Position::ArgumentNamed(s) if s == "from_desugaring" => (),
|
||||
// So is `{A}` if A is a type parameter
|
||||
Position::ArgumentNamed(s) => match generics.params.iter().find(|param|
|
||||
param.name == s
|
||||
) {
|
||||
Position::ArgumentNamed(s) => match generics.params.iter().find(|param| {
|
||||
param.name.as_str() == s
|
||||
}) {
|
||||
Some(_) => (),
|
||||
None => {
|
||||
span_err!(tcx.sess, span, E0230,
|
||||
@ -301,7 +301,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
|
||||
Piece::NextArgument(a) => match a.position {
|
||||
Position::ArgumentNamed(s) => match generic_map.get(s) {
|
||||
Some(val) => val,
|
||||
None if s == name => {
|
||||
None if s == name.as_str() => {
|
||||
&trait_str
|
||||
}
|
||||
None => {
|
||||
|
@ -2981,9 +2981,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn item_name(self, id: DefId) -> InternedString {
|
||||
pub fn item_name(self, id: DefId) -> Symbol {
|
||||
if id.index == CRATE_DEF_INDEX {
|
||||
self.original_crate_name(id.krate).as_interned_str()
|
||||
self.original_crate_name(id.krate)
|
||||
} else {
|
||||
let def_key = self.def_key(id);
|
||||
match def_key.disambiguated_data.data {
|
||||
@ -2995,7 +2995,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
}),
|
||||
_ => def_key.disambiguated_data.data.get_opt_name().unwrap_or_else(|| {
|
||||
bug!("item_name: no name for {:?}", self.def_path(id));
|
||||
}),
|
||||
}).as_symbol(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1140,14 +1140,16 @@ impl<F: fmt::Write> PrettyPrinter<'gcx, 'tcx> for FmtPrinter<'_, 'gcx, 'tcx, F>
|
||||
|
||||
match *region {
|
||||
ty::ReEarlyBound(ref data) => {
|
||||
data.name != "" && data.name != "'_"
|
||||
data.name.as_symbol() != keywords::Invalid.name() &&
|
||||
data.name.as_symbol() != keywords::UnderscoreLifetime.name()
|
||||
}
|
||||
|
||||
ty::ReLateBound(_, br) |
|
||||
ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
|
||||
ty::RePlaceholder(ty::Placeholder { name: br, .. }) => {
|
||||
if let ty::BrNamed(_, name) = br {
|
||||
if name != "" && name != "'_" {
|
||||
if name.as_symbol() != keywords::Invalid.name() &&
|
||||
name.as_symbol() != keywords::UnderscoreLifetime.name() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1203,7 +1205,7 @@ impl<F: fmt::Write> FmtPrinter<'_, '_, '_, F> {
|
||||
// `explain_region()` or `note_and_explain_region()`.
|
||||
match *region {
|
||||
ty::ReEarlyBound(ref data) => {
|
||||
if data.name != "" {
|
||||
if data.name.as_symbol() != keywords::Invalid.name() {
|
||||
p!(write("{}", data.name));
|
||||
return Ok(self);
|
||||
}
|
||||
@ -1212,7 +1214,8 @@ impl<F: fmt::Write> FmtPrinter<'_, '_, '_, F> {
|
||||
ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
|
||||
ty::RePlaceholder(ty::Placeholder { name: br, .. }) => {
|
||||
if let ty::BrNamed(_, name) = br {
|
||||
if name != "" && name != "'_" {
|
||||
if name.as_symbol() != keywords::Invalid.name() &&
|
||||
name.as_symbol() != keywords::UnderscoreLifetime.name() {
|
||||
p!(write("{}", name));
|
||||
return Ok(self);
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ fn compute_symbol_name(tcx: TyCtxt<'_, 'tcx, 'tcx>, instance: Instance<'tcx>) ->
|
||||
return name.as_interned_str();
|
||||
}
|
||||
// Don't mangle foreign items.
|
||||
return tcx.item_name(def_id);
|
||||
return tcx.item_name(def_id).as_interned_str();
|
||||
}
|
||||
|
||||
if let Some(name) = &attrs.export_name {
|
||||
@ -274,7 +274,7 @@ fn compute_symbol_name(tcx: TyCtxt<'_, 'tcx, 'tcx>, instance: Instance<'tcx>) ->
|
||||
|
||||
if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) {
|
||||
// Don't mangle
|
||||
return tcx.item_name(def_id);
|
||||
return tcx.item_name(def_id).as_interned_str();
|
||||
}
|
||||
|
||||
// We want to compute the "type" of this item. Unfortunately, some
|
||||
|
@ -929,7 +929,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
|
||||
|
||||
fn def_id_is_transmute(cx: &LateContext<'_, '_>, def_id: DefId) -> bool {
|
||||
cx.tcx.fn_sig(def_id).abi() == RustIntrinsic &&
|
||||
cx.tcx.item_name(def_id) == "transmute"
|
||||
cx.tcx.item_name(def_id) == sym::transmute
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -432,7 +432,7 @@ impl cstore::CStore {
|
||||
let data = self.get_crate_data(id.krate);
|
||||
if let Some(ref proc_macros) = data.proc_macros {
|
||||
return LoadedMacro::ProcMacro(proc_macros[id.index.to_proc_macro_index()].1.clone());
|
||||
} else if data.name == sym::proc_macro && data.item_name(id.index) == "quote" {
|
||||
} else if data.name == sym::proc_macro && data.item_name(id.index) == sym::quote {
|
||||
use syntax::ext::base::SyntaxExtension;
|
||||
use syntax_ext::proc_macro_impl::BangProcMacro;
|
||||
|
||||
|
@ -29,7 +29,7 @@ use rustc_serialize::{Decodable, Decoder, SpecializedDecoder, opaque};
|
||||
use syntax::attr;
|
||||
use syntax::ast::{self, Ident};
|
||||
use syntax::source_map;
|
||||
use syntax::symbol::{InternedString, sym};
|
||||
use syntax::symbol::{Symbol, sym};
|
||||
use syntax::ext::base::{MacroKind, SyntaxExtension};
|
||||
use syntax::ext::hygiene::Mark;
|
||||
use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP, NO_EXPANSION};
|
||||
@ -497,12 +497,13 @@ impl<'a, 'tcx> CrateMetadata {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn item_name(&self, item_index: DefIndex) -> InternedString {
|
||||
pub fn item_name(&self, item_index: DefIndex) -> Symbol {
|
||||
self.def_key(item_index)
|
||||
.disambiguated_data
|
||||
.data
|
||||
.get_opt_name()
|
||||
.expect("no name in item_name")
|
||||
.as_symbol()
|
||||
}
|
||||
|
||||
pub fn def_kind(&self, index: DefIndex) -> Option<DefKind> {
|
||||
@ -568,7 +569,7 @@ impl<'a, 'tcx> CrateMetadata {
|
||||
|
||||
ty::VariantDef::new(
|
||||
tcx,
|
||||
Ident::from_interned_str(self.item_name(index)),
|
||||
Ident::with_empty_ctxt(self.item_name(index)),
|
||||
variant_did,
|
||||
ctor_did,
|
||||
data.discr,
|
||||
@ -576,7 +577,7 @@ impl<'a, 'tcx> CrateMetadata {
|
||||
let f = self.entry(index);
|
||||
ty::FieldDef {
|
||||
did: self.local_def_id(index),
|
||||
ident: Ident::from_interned_str(self.item_name(index)),
|
||||
ident: Ident::with_empty_ctxt(self.item_name(index)),
|
||||
vis: f.visibility.decode(self)
|
||||
}
|
||||
}).collect(),
|
||||
@ -787,7 +788,7 @@ impl<'a, 'tcx> CrateMetadata {
|
||||
if let Some(kind) = self.def_kind(child_index) {
|
||||
callback(def::Export {
|
||||
res: Res::Def(kind, self.local_def_id(child_index)),
|
||||
ident: Ident::from_interned_str(self.item_name(child_index)),
|
||||
ident: Ident::with_empty_ctxt(self.item_name(child_index)),
|
||||
vis: self.get_visibility(child_index),
|
||||
span: self.entry(child_index).span.decode((self, sess)),
|
||||
});
|
||||
@ -982,7 +983,7 @@ impl<'a, 'tcx> CrateMetadata {
|
||||
self.entry(id)
|
||||
.children
|
||||
.decode(self)
|
||||
.map(|index| self.item_name(index).as_symbol())
|
||||
.map(|index| self.item_name(index))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ use rustc::ty::query::Providers;
|
||||
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
|
||||
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use syntax_pos::Span;
|
||||
use syntax_pos::{Span, sym};
|
||||
|
||||
use std::fmt;
|
||||
use std::iter;
|
||||
@ -100,9 +100,9 @@ fn make_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
}
|
||||
ty::InstanceDef::CloneShim(def_id, ty) => {
|
||||
let name = tcx.item_name(def_id);
|
||||
if name == "clone" {
|
||||
if name == sym::clone {
|
||||
build_clone_shim(tcx, def_id, ty)
|
||||
} else if name == "clone_from" {
|
||||
} else if name == sym::clone_from {
|
||||
debug!("make_shim({:?}: using default trait implementation", instance);
|
||||
return tcx.optimized_mir(def_id);
|
||||
} else {
|
||||
|
@ -223,7 +223,7 @@ fn is_rustc_peek<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
if let ty::FnDef(def_id, _) = func.ty.sty {
|
||||
let abi = tcx.fn_sig(def_id).abi();
|
||||
let name = tcx.item_name(def_id);
|
||||
if abi == Abi::RustIntrinsic && name == "rustc_peek" {
|
||||
if abi == Abi::RustIntrinsic && name == sym::rustc_peek {
|
||||
return Some((args, source_info.span));
|
||||
}
|
||||
}
|
||||
|
@ -1702,7 +1702,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
|
||||
let stripped_typarams = gens.params.iter().filter_map(|param| match param.kind {
|
||||
ty::GenericParamDefKind::Lifetime => None,
|
||||
ty::GenericParamDefKind::Type { .. } => {
|
||||
if param.name == keywords::SelfUpper.name().as_str() {
|
||||
if param.name.as_symbol() == keywords::SelfUpper.name() {
|
||||
assert_eq!(param.index, 0);
|
||||
return None;
|
||||
}
|
||||
|
@ -1147,7 +1147,7 @@ impl Encodable for LocalInternedString {
|
||||
/// assert_ne!(Symbol::gensym("x"), Symbol::gensym("x"))
|
||||
/// assert_eq!(Symbol::gensym("x").as_interned_str(), Symbol::gensym("x").as_interned_str())
|
||||
/// ```
|
||||
#[derive(Clone, Copy, Eq)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub struct InternedString {
|
||||
symbol: Symbol,
|
||||
}
|
||||
@ -1212,42 +1212,6 @@ impl Ord for InternedString {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: std::ops::Deref<Target = str>> PartialEq<T> for InternedString {
|
||||
fn eq(&self, other: &T) -> bool {
|
||||
self.with(|string| string == other.deref())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<InternedString> for InternedString {
|
||||
fn eq(&self, other: &InternedString) -> bool {
|
||||
self.symbol == other.symbol
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<InternedString> for str {
|
||||
fn eq(&self, other: &InternedString) -> bool {
|
||||
other.with(|string| self == string)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PartialEq<InternedString> for &'a str {
|
||||
fn eq(&self, other: &InternedString) -> bool {
|
||||
other.with(|string| *self == string)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<InternedString> for String {
|
||||
fn eq(&self, other: &InternedString) -> bool {
|
||||
other.with(|string| self == string)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PartialEq<InternedString> for &'a String {
|
||||
fn eq(&self, other: &InternedString) -> bool {
|
||||
other.with(|string| *self == string)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for InternedString {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.with(|str| fmt::Debug::fmt(&str, f))
|
||||
|
Loading…
Reference in New Issue
Block a user