Rollup merge of #65892 - pnkfelix:trim-special-derives, r=petrochenkov
Remove `PartialEq` and `Eq` from the `SpecialDerives`. Now that PR #65519 landed, this is the follow-on work of removing `PartialEq` and `Eq` from the set of `SpecialDerives` .
This commit is contained in:
commit
5910116b17
@ -65,7 +65,6 @@ use syntax::ast;
|
|||||||
use syntax::ptr::P as AstP;
|
use syntax::ptr::P as AstP;
|
||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
use syntax::errors;
|
use syntax::errors;
|
||||||
use syntax::expand::SpecialDerives;
|
|
||||||
use syntax::print::pprust;
|
use syntax::print::pprust;
|
||||||
use syntax::parse::token::{self, Nonterminal, Token};
|
use syntax::parse::token::{self, Nonterminal, Token};
|
||||||
use syntax::tokenstream::{TokenStream, TokenTree};
|
use syntax::tokenstream::{TokenStream, TokenTree};
|
||||||
@ -184,8 +183,6 @@ pub trait Resolver {
|
|||||||
ns: Namespace,
|
ns: Namespace,
|
||||||
) -> (ast::Path, Res<NodeId>);
|
) -> (ast::Path, Res<NodeId>);
|
||||||
|
|
||||||
fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool;
|
|
||||||
|
|
||||||
fn lint_buffer(&mut self) -> &mut lint::LintBuffer;
|
fn lint_buffer(&mut self) -> &mut lint::LintBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ use smallvec::SmallVec;
|
|||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
use syntax::visit::{self, Visitor};
|
use syntax::visit::{self, Visitor};
|
||||||
use syntax::expand::SpecialDerives;
|
|
||||||
use syntax::source_map::{respan, DesugaringKind, Spanned};
|
use syntax::source_map::{respan, DesugaringKind, Spanned};
|
||||||
use syntax::symbol::{kw, sym};
|
use syntax::symbol::{kw, sym};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
@ -227,13 +226,7 @@ impl LoweringContext<'_> {
|
|||||||
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item> {
|
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item> {
|
||||||
let mut ident = i.ident;
|
let mut ident = i.ident;
|
||||||
let mut vis = self.lower_visibility(&i.vis, None);
|
let mut vis = self.lower_visibility(&i.vis, None);
|
||||||
let mut attrs = self.lower_attrs_extendable(&i.attrs);
|
let attrs = self.lower_attrs(&i.attrs);
|
||||||
if self.resolver.has_derives(i.id, SpecialDerives::PARTIAL_EQ | SpecialDerives::EQ) {
|
|
||||||
// Add `#[structural_match]` if the item derived both `PartialEq` and `Eq`.
|
|
||||||
let ident = Ident::new(sym::structural_match, i.span);
|
|
||||||
attrs.push(attr::mk_attr_outer(attr::mk_word_item(ident)));
|
|
||||||
}
|
|
||||||
let attrs = attrs.into();
|
|
||||||
|
|
||||||
if let ItemKind::MacroDef(ref def) = i.kind {
|
if let ItemKind::MacroDef(ref def) = i.kind {
|
||||||
if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) {
|
if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) {
|
||||||
|
@ -36,7 +36,6 @@ use rustc_metadata::creader::CrateLoader;
|
|||||||
use rustc_metadata::cstore::CStore;
|
use rustc_metadata::cstore::CStore;
|
||||||
|
|
||||||
use syntax::{struct_span_err, unwrap_or};
|
use syntax::{struct_span_err, unwrap_or};
|
||||||
use syntax::expand::SpecialDerives;
|
|
||||||
use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
|
use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
|
||||||
use syntax::ast::{CRATE_NODE_ID, Crate};
|
use syntax::ast::{CRATE_NODE_ID, Crate};
|
||||||
use syntax::ast::{ItemKind, Path};
|
use syntax::ast::{ItemKind, Path};
|
||||||
@ -934,12 +933,10 @@ pub struct Resolver<'a> {
|
|||||||
multi_segment_macro_resolutions: Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'a>,
|
multi_segment_macro_resolutions: Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'a>,
|
||||||
Option<Res>)>,
|
Option<Res>)>,
|
||||||
builtin_attrs: Vec<(Ident, ParentScope<'a>)>,
|
builtin_attrs: Vec<(Ident, ParentScope<'a>)>,
|
||||||
/// Some built-in derives mark items they are applied to so they are treated specially later.
|
/// `derive(Copy)` marks items they are applied to so they are treated specially later.
|
||||||
/// Derive macros cannot modify the item themselves and have to store the markers in the global
|
/// Derive macros cannot modify the item themselves and have to store the markers in the global
|
||||||
/// context, so they attach the markers to derive container IDs using this resolver table.
|
/// context, so they attach the markers to derive container IDs using this resolver table.
|
||||||
/// FIXME: Find a way for `PartialEq` and `Eq` to emulate `#[structural_match]`
|
containers_deriving_copy: FxHashSet<ExpnId>,
|
||||||
/// by marking the produced impls rather than the original items.
|
|
||||||
special_derives: FxHashMap<ExpnId, SpecialDerives>,
|
|
||||||
/// Parent scopes in which the macros were invoked.
|
/// Parent scopes in which the macros were invoked.
|
||||||
/// FIXME: `derives` are missing in these parent scopes and need to be taken from elsewhere.
|
/// FIXME: `derives` are missing in these parent scopes and need to be taken from elsewhere.
|
||||||
invocation_parent_scopes: FxHashMap<ExpnId, ParentScope<'a>>,
|
invocation_parent_scopes: FxHashMap<ExpnId, ParentScope<'a>>,
|
||||||
@ -1078,12 +1075,6 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
|
|||||||
&mut self.definitions
|
&mut self.definitions
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool {
|
|
||||||
let def_id = self.definitions.local_def_id(node_id);
|
|
||||||
let expn_id = self.definitions.expansion_that_defined(def_id.index);
|
|
||||||
self.has_derives(expn_id, derives)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn lint_buffer(&mut self) -> &mut lint::LintBuffer {
|
fn lint_buffer(&mut self) -> &mut lint::LintBuffer {
|
||||||
&mut self.lint_buffer
|
&mut self.lint_buffer
|
||||||
}
|
}
|
||||||
@ -1228,7 +1219,7 @@ impl<'a> Resolver<'a> {
|
|||||||
single_segment_macro_resolutions: Default::default(),
|
single_segment_macro_resolutions: Default::default(),
|
||||||
multi_segment_macro_resolutions: Default::default(),
|
multi_segment_macro_resolutions: Default::default(),
|
||||||
builtin_attrs: Default::default(),
|
builtin_attrs: Default::default(),
|
||||||
special_derives: Default::default(),
|
containers_deriving_copy: Default::default(),
|
||||||
active_features:
|
active_features:
|
||||||
features.declared_lib_features.iter().map(|(feat, ..)| *feat)
|
features.declared_lib_features.iter().map(|(feat, ..)| *feat)
|
||||||
.chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat))
|
.chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat))
|
||||||
@ -1314,10 +1305,6 @@ impl<'a> Resolver<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_derives(&self, expn_id: ExpnId, markers: SpecialDerives) -> bool {
|
|
||||||
self.special_derives.get(&expn_id).map_or(false, |m| m.contains(markers))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Entry point to crate resolution.
|
/// Entry point to crate resolution.
|
||||||
pub fn resolve_crate(&mut self, krate: &Crate) {
|
pub fn resolve_crate(&mut self, krate: &Crate) {
|
||||||
let _prof_timer =
|
let _prof_timer =
|
||||||
|
@ -14,7 +14,6 @@ use rustc::{ty, lint, span_bug};
|
|||||||
use syntax::ast::{self, NodeId, Ident};
|
use syntax::ast::{self, NodeId, Ident};
|
||||||
use syntax::attr::StabilityLevel;
|
use syntax::attr::StabilityLevel;
|
||||||
use syntax::edition::Edition;
|
use syntax::edition::Edition;
|
||||||
use syntax::expand::SpecialDerives;
|
|
||||||
use syntax::feature_gate::{emit_feature_err, is_builtin_attr_name};
|
use syntax::feature_gate::{emit_feature_err, is_builtin_attr_name};
|
||||||
use syntax::feature_gate::GateIssue;
|
use syntax::feature_gate::GateIssue;
|
||||||
use syntax::print::pprust;
|
use syntax::print::pprust;
|
||||||
@ -255,12 +254,12 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_derives(&self, expn_id: ExpnId, derives: SpecialDerives) -> bool {
|
fn has_derive_copy(&self, expn_id: ExpnId) -> bool {
|
||||||
self.has_derives(expn_id, derives)
|
self.containers_deriving_copy.contains(&expn_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_derives(&mut self, expn_id: ExpnId, derives: SpecialDerives) {
|
fn add_derive_copy(&mut self, expn_id: ExpnId) {
|
||||||
*self.special_derives.entry(expn_id).or_default() |= derives;
|
self.containers_deriving_copy.insert(expn_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,16 +5,6 @@ use syntax_pos::symbol::sym;
|
|||||||
|
|
||||||
pub mod allocator;
|
pub mod allocator;
|
||||||
|
|
||||||
bitflags::bitflags! {
|
|
||||||
/// Built-in derives that need some extra tracking beyond the usual macro functionality.
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct SpecialDerives: u8 {
|
|
||||||
const PARTIAL_EQ = 1 << 0;
|
|
||||||
const EQ = 1 << 1;
|
|
||||||
const COPY = 1 << 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_proc_macro_attr(attr: &Attribute) -> bool {
|
pub fn is_proc_macro_attr(attr: &Attribute) -> bool {
|
||||||
[sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive]
|
[sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive]
|
||||||
.iter().any(|kind| attr.check_name(*kind))
|
.iter().any(|kind| attr.check_name(*kind))
|
||||||
|
@ -13,7 +13,6 @@ use syntax::symbol::{kw, sym, Ident, Symbol};
|
|||||||
use syntax::{ThinVec, MACRO_ARGUMENTS};
|
use syntax::{ThinVec, MACRO_ARGUMENTS};
|
||||||
use syntax::tokenstream::{self, TokenStream};
|
use syntax::tokenstream::{self, TokenStream};
|
||||||
use syntax::visit::Visitor;
|
use syntax::visit::Visitor;
|
||||||
crate use syntax::expand::SpecialDerives;
|
|
||||||
|
|
||||||
use errors::{DiagnosticBuilder, DiagnosticId};
|
use errors::{DiagnosticBuilder, DiagnosticId};
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
@ -860,8 +859,8 @@ pub trait Resolver {
|
|||||||
|
|
||||||
fn check_unused_macros(&mut self);
|
fn check_unused_macros(&mut self);
|
||||||
|
|
||||||
fn has_derives(&self, expn_id: ExpnId, derives: SpecialDerives) -> bool;
|
fn has_derive_copy(&self, expn_id: ExpnId) -> bool;
|
||||||
fn add_derives(&mut self, expn_id: ExpnId, derives: SpecialDerives);
|
fn add_derive_copy(&mut self, expn_id: ExpnId);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -432,7 +432,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||||||
// can be in scope for all code produced by that container's expansion.
|
// can be in scope for all code produced by that container's expansion.
|
||||||
item.visit_with(&mut MarkAttrs(&helper_attrs));
|
item.visit_with(&mut MarkAttrs(&helper_attrs));
|
||||||
if has_copy {
|
if has_copy {
|
||||||
self.cx.resolver.add_derives(invoc.expansion_data.id, SpecialDerives::COPY);
|
self.cx.resolver.add_derive_copy(invoc.expansion_data.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut derive_placeholders = Vec::with_capacity(derives.len());
|
let mut derive_placeholders = Vec::with_capacity(derives.len());
|
||||||
|
@ -3,7 +3,6 @@ use crate::deriving::generic::*;
|
|||||||
use crate::deriving::generic::ty::*;
|
use crate::deriving::generic::ty::*;
|
||||||
|
|
||||||
use syntax::ast::{self, Expr, GenericArg, Generics, ItemKind, MetaItem, VariantData};
|
use syntax::ast::{self, Expr, GenericArg, Generics, ItemKind, MetaItem, VariantData};
|
||||||
use syntax::expand::SpecialDerives;
|
|
||||||
use syntax_expand::base::{Annotatable, ExtCtxt};
|
use syntax_expand::base::{Annotatable, ExtCtxt};
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::symbol::{kw, sym, Symbol};
|
use syntax::symbol::{kw, sym, Symbol};
|
||||||
@ -37,7 +36,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
|
|||||||
ItemKind::Struct(_, Generics { ref params, .. }) |
|
ItemKind::Struct(_, Generics { ref params, .. }) |
|
||||||
ItemKind::Enum(_, Generics { ref params, .. }) => {
|
ItemKind::Enum(_, Generics { ref params, .. }) => {
|
||||||
let container_id = cx.current_expansion.id.expn_data().parent;
|
let container_id = cx.current_expansion.id.expn_data().parent;
|
||||||
if cx.resolver.has_derives(container_id, SpecialDerives::COPY) &&
|
if cx.resolver.has_derive_copy(container_id) &&
|
||||||
!params.iter().any(|param| match param.kind {
|
!params.iter().any(|param| match param.kind {
|
||||||
ast::GenericParamKind::Type { .. } => true,
|
ast::GenericParamKind::Type { .. } => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
@ -3,7 +3,6 @@ use crate::deriving::generic::*;
|
|||||||
use crate::deriving::generic::ty::*;
|
use crate::deriving::generic::ty::*;
|
||||||
|
|
||||||
use syntax::ast::{self, Ident, Expr, MetaItem, GenericArg};
|
use syntax::ast::{self, Ident, Expr, MetaItem, GenericArg};
|
||||||
use syntax::expand::SpecialDerives;
|
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::symbol::{sym, Symbol};
|
use syntax::symbol::{sym, Symbol};
|
||||||
use syntax_expand::base::{Annotatable, ExtCtxt};
|
use syntax_expand::base::{Annotatable, ExtCtxt};
|
||||||
@ -14,8 +13,6 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>,
|
|||||||
mitem: &MetaItem,
|
mitem: &MetaItem,
|
||||||
item: &Annotatable,
|
item: &Annotatable,
|
||||||
push: &mut dyn FnMut(Annotatable)) {
|
push: &mut dyn FnMut(Annotatable)) {
|
||||||
cx.resolver.add_derives(cx.current_expansion.id.expn_data().parent, SpecialDerives::EQ);
|
|
||||||
|
|
||||||
let inline = cx.meta_word(span, sym::inline);
|
let inline = cx.meta_word(span, sym::inline);
|
||||||
let hidden = syntax::attr::mk_nested_word_item(Ident::new(sym::hidden, span));
|
let hidden = syntax::attr::mk_nested_word_item(Ident::new(sym::hidden, span));
|
||||||
let doc = syntax::attr::mk_list_item(Ident::new(sym::doc, span), vec![hidden]);
|
let doc = syntax::attr::mk_list_item(Ident::new(sym::doc, span), vec![hidden]);
|
||||||
|
@ -3,7 +3,6 @@ use crate::deriving::generic::*;
|
|||||||
use crate::deriving::generic::ty::*;
|
use crate::deriving::generic::ty::*;
|
||||||
|
|
||||||
use syntax::ast::{BinOpKind, Expr, MetaItem};
|
use syntax::ast::{BinOpKind, Expr, MetaItem};
|
||||||
use syntax::expand::SpecialDerives;
|
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::symbol::sym;
|
use syntax::symbol::sym;
|
||||||
use syntax_expand::base::{Annotatable, ExtCtxt};
|
use syntax_expand::base::{Annotatable, ExtCtxt};
|
||||||
@ -14,8 +13,6 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>,
|
|||||||
mitem: &MetaItem,
|
mitem: &MetaItem,
|
||||||
item: &Annotatable,
|
item: &Annotatable,
|
||||||
push: &mut dyn FnMut(Annotatable)) {
|
push: &mut dyn FnMut(Annotatable)) {
|
||||||
cx.resolver.add_derives(cx.current_expansion.id.expn_data().parent, SpecialDerives::PARTIAL_EQ);
|
|
||||||
|
|
||||||
// structures are equal if all fields are equal, and non equal, if
|
// structures are equal if all fields are equal, and non equal, if
|
||||||
// any fields are not equal or if the enum variants are different
|
// any fields are not equal or if the enum variants are different
|
||||||
fn cs_op(cx: &mut ExtCtxt<'_>,
|
fn cs_op(cx: &mut ExtCtxt<'_>,
|
||||||
|
@ -186,7 +186,6 @@ use rustc_target::spec::abi::Abi;
|
|||||||
use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind};
|
use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind};
|
||||||
use syntax::ast::{VariantData, GenericParamKind, GenericArg};
|
use syntax::ast::{VariantData, GenericParamKind, GenericArg};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::expand::SpecialDerives;
|
|
||||||
use syntax::source_map::respan;
|
use syntax::source_map::respan;
|
||||||
use syntax::util::map_in_place::MapInPlace;
|
use syntax::util::map_in_place::MapInPlace;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
@ -427,10 +426,8 @@ impl<'a> TraitDef<'a> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let container_id = cx.current_expansion.id.expn_data().parent;
|
let container_id = cx.current_expansion.id.expn_data().parent;
|
||||||
let is_always_copy =
|
let always_copy = has_no_type_params && cx.resolver.has_derive_copy(container_id);
|
||||||
cx.resolver.has_derives(container_id, SpecialDerives::COPY) &&
|
let use_temporaries = is_packed && always_copy;
|
||||||
has_no_type_params;
|
|
||||||
let use_temporaries = is_packed && is_always_copy;
|
|
||||||
|
|
||||||
let newitem = match item.kind {
|
let newitem = match item.kind {
|
||||||
ast::ItemKind::Struct(ref struct_def, ref generics) => {
|
ast::ItemKind::Struct(ref struct_def, ref generics) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user