Skip to content

Commit 0dfe0ed

Browse files
committed
Review feedback: Remove more stuff! Simplify simplify simplify!
1 parent 7d7fbcb commit 0dfe0ed

File tree

8 files changed

+13
-41
lines changed

8 files changed

+13
-41
lines changed

src/librustc/hir/lowering.rs

-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ use syntax::ast;
6565
use syntax::ptr::P as AstP;
6666
use syntax::ast::*;
6767
use syntax::errors;
68-
use syntax::expand::SpecialDerives;
6968
use syntax::print::pprust;
7069
use syntax::parse::token::{self, Nonterminal, Token};
7170
use syntax::tokenstream::{TokenStream, TokenTree};
@@ -184,8 +183,6 @@ pub trait Resolver {
184183
ns: Namespace,
185184
) -> (ast::Path, Res<NodeId>);
186185

187-
fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool;
188-
189186
fn lint_buffer(&mut self) -> &mut lint::LintBuffer;
190187
}
191188

src/librustc_resolve/lib.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use rustc_metadata::creader::CrateLoader;
3636
use rustc_metadata::cstore::CStore;
3737

3838
use syntax::{struct_span_err, unwrap_or};
39-
use syntax::expand::SpecialDerives;
4039
use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
4140
use syntax::ast::{CRATE_NODE_ID, Crate};
4241
use syntax::ast::{ItemKind, Path};
@@ -934,10 +933,10 @@ pub struct Resolver<'a> {
934933
multi_segment_macro_resolutions: Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'a>,
935934
Option<Res>)>,
936935
builtin_attrs: Vec<(Ident, ParentScope<'a>)>,
937-
/// Some built-in derives mark items they are applied to so they are treated specially later.
936+
/// `derive(Copy)` marks items they are applied to so they are treated specially later.
938937
/// Derive macros cannot modify the item themselves and have to store the markers in the global
939938
/// context, so they attach the markers to derive container IDs using this resolver table.
940-
special_derives: FxHashMap<ExpnId, SpecialDerives>,
939+
copy_derives: FxHashSet<ExpnId>,
941940
/// Parent scopes in which the macros were invoked.
942941
/// FIXME: `derives` are missing in these parent scopes and need to be taken from elsewhere.
943942
invocation_parent_scopes: FxHashMap<ExpnId, ParentScope<'a>>,
@@ -1076,12 +1075,6 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
10761075
&mut self.definitions
10771076
}
10781077

1079-
fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool {
1080-
let def_id = self.definitions.local_def_id(node_id);
1081-
let expn_id = self.definitions.expansion_that_defined(def_id.index);
1082-
self.has_derives(expn_id, derives)
1083-
}
1084-
10851078
fn lint_buffer(&mut self) -> &mut lint::LintBuffer {
10861079
&mut self.lint_buffer
10871080
}
@@ -1226,7 +1219,7 @@ impl<'a> Resolver<'a> {
12261219
single_segment_macro_resolutions: Default::default(),
12271220
multi_segment_macro_resolutions: Default::default(),
12281221
builtin_attrs: Default::default(),
1229-
special_derives: Default::default(),
1222+
copy_derives: Default::default(),
12301223
active_features:
12311224
features.declared_lib_features.iter().map(|(feat, ..)| *feat)
12321225
.chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat))
@@ -1312,10 +1305,6 @@ impl<'a> Resolver<'a> {
13121305
}
13131306
}
13141307

1315-
fn has_derives(&self, expn_id: ExpnId, markers: SpecialDerives) -> bool {
1316-
self.special_derives.get(&expn_id).map_or(false, |m| m.contains(markers))
1317-
}
1318-
13191308
/// Entry point to crate resolution.
13201309
pub fn resolve_crate(&mut self, krate: &Crate) {
13211310
let _prof_timer =

src/librustc_resolve/macros.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc::{ty, lint, span_bug};
1414
use syntax::ast::{self, NodeId, Ident};
1515
use syntax::attr::StabilityLevel;
1616
use syntax::edition::Edition;
17-
use syntax::expand::SpecialDerives;
1817
use syntax::feature_gate::{emit_feature_err, is_builtin_attr_name};
1918
use syntax::feature_gate::GateIssue;
2019
use syntax::print::pprust;
@@ -255,12 +254,12 @@ impl<'a> base::Resolver for Resolver<'a> {
255254
}
256255
}
257256

258-
fn has_derives(&self, expn_id: ExpnId, derives: SpecialDerives) -> bool {
259-
self.has_derives(expn_id, derives)
257+
fn has_derive_copy(&self, expn_id: ExpnId) -> bool {
258+
self.copy_derives.contains(&expn_id)
260259
}
261260

262-
fn add_derives(&mut self, expn_id: ExpnId, derives: SpecialDerives) {
263-
*self.special_derives.entry(expn_id).or_default() |= derives;
261+
fn add_derive_copy(&mut self, expn_id: ExpnId) {
262+
self.copy_derives.insert(expn_id);
264263
}
265264
}
266265

src/libsyntax/expand/mod.rs

-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ use syntax_pos::symbol::sym;
55

66
pub mod allocator;
77

8-
bitflags::bitflags! {
9-
/// Built-in derives that need some extra tracking beyond the usual macro functionality.
10-
#[derive(Default)]
11-
pub struct SpecialDerives: u8 {
12-
const COPY = 1 << 2;
13-
}
14-
}
15-
168
pub fn is_proc_macro_attr(attr: &Attribute) -> bool {
179
[sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive]
1810
.iter().any(|kind| attr.check_name(*kind))

src/libsyntax_expand/base.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use syntax::symbol::{kw, sym, Ident, Symbol};
1313
use syntax::{ThinVec, MACRO_ARGUMENTS};
1414
use syntax::tokenstream::{self, TokenStream};
1515
use syntax::visit::Visitor;
16-
crate use syntax::expand::SpecialDerives;
1716

1817
use errors::{DiagnosticBuilder, DiagnosticId};
1918
use smallvec::{smallvec, SmallVec};
@@ -860,8 +859,8 @@ pub trait Resolver {
860859

861860
fn check_unused_macros(&mut self);
862861

863-
fn has_derives(&self, expn_id: ExpnId, derives: SpecialDerives) -> bool;
864-
fn add_derives(&mut self, expn_id: ExpnId, derives: SpecialDerives);
862+
fn has_derive_copy(&self, expn_id: ExpnId) -> bool;
863+
fn add_derive_copy(&mut self, expn_id: ExpnId);
865864
}
866865

867866
#[derive(Clone)]

src/libsyntax_expand/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
432432
// can be in scope for all code produced by that container's expansion.
433433
item.visit_with(&mut MarkAttrs(&helper_attrs));
434434
if has_copy {
435-
self.cx.resolver.add_derives(invoc.expansion_data.id, SpecialDerives::COPY);
435+
self.cx.resolver.add_derive_copy(invoc.expansion_data.id);
436436
}
437437

438438
let mut derive_placeholders = Vec::with_capacity(derives.len());

src/libsyntax_ext/deriving/clone.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::deriving::generic::*;
33
use crate::deriving::generic::ty::*;
44

55
use syntax::ast::{self, Expr, GenericArg, Generics, ItemKind, MetaItem, VariantData};
6-
use syntax::expand::SpecialDerives;
76
use syntax_expand::base::{Annotatable, ExtCtxt};
87
use syntax::ptr::P;
98
use syntax::symbol::{kw, sym, Symbol};
@@ -37,7 +36,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
3736
ItemKind::Struct(_, Generics { ref params, .. }) |
3837
ItemKind::Enum(_, Generics { ref params, .. }) => {
3938
let container_id = cx.current_expansion.id.expn_data().parent;
40-
if cx.resolver.has_derives(container_id, SpecialDerives::COPY) &&
39+
if cx.resolver.has_derive_copy(container_id) &&
4140
!params.iter().any(|param| match param.kind {
4241
ast::GenericParamKind::Type { .. } => true,
4342
_ => false,

src/libsyntax_ext/deriving/generic/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ use rustc_target::spec::abi::Abi;
186186
use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind};
187187
use syntax::ast::{VariantData, GenericParamKind, GenericArg};
188188
use syntax::attr;
189-
use syntax::expand::SpecialDerives;
190189
use syntax::source_map::respan;
191190
use syntax::util::map_in_place::MapInPlace;
192191
use syntax::ptr::P;
@@ -427,10 +426,8 @@ impl<'a> TraitDef<'a> {
427426
}
428427
};
429428
let container_id = cx.current_expansion.id.expn_data().parent;
430-
let is_always_copy =
431-
cx.resolver.has_derives(container_id, SpecialDerives::COPY) &&
432-
has_no_type_params;
433-
let use_temporaries = is_packed && is_always_copy;
429+
let always_copy = has_no_type_params && cx.resolver.has_derive_copy(container_id);
430+
let use_temporaries = is_packed && always_copy;
434431

435432
let newitem = match item.kind {
436433
ast::ItemKind::Struct(ref struct_def, ref generics) => {

0 commit comments

Comments
 (0)