Skip to content

Commit 6b870d5

Browse files
committed
WIP
1 parent 0efc743 commit 6b870d5

File tree

29 files changed

+74
-66
lines changed

29 files changed

+74
-66
lines changed

src/librustc_ast/attr/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ impl Attribute {
177177
/// If it matches, then the attribute is marked as used.
178178
/// Should only be used by rustc, other tools can use `has_name` instead.
179179
pub fn check_name(&self, name: Symbol) -> bool {
180+
self.has_name(name)
181+
}
182+
183+
pub fn check_name2(&self, name: Symbol) -> bool {
180184
let matches = self.has_name(name);
181185
if matches {
182186
mark_used(self);
@@ -413,18 +417,34 @@ pub fn contains_name(attrs: &[Attribute], name: Symbol) -> bool {
413417
attrs.iter().any(|item| item.check_name(name))
414418
}
415419

420+
pub fn contains_name2(attrs: &[Attribute], name: Symbol) -> bool {
421+
attrs.iter().any(|item| item.check_name2(name))
422+
}
423+
416424
pub fn find_by_name(attrs: &[Attribute], name: Symbol) -> Option<&Attribute> {
417425
attrs.iter().find(|attr| attr.check_name(name))
418426
}
419427

428+
pub fn find_by_name2(attrs: &[Attribute], name: Symbol) -> Option<&Attribute> {
429+
attrs.iter().find(|attr| attr.check_name2(name))
430+
}
431+
420432
pub fn filter_by_name(attrs: &[Attribute], name: Symbol) -> impl Iterator<Item = &Attribute> {
421433
attrs.iter().filter(move |attr| attr.check_name(name))
422434
}
423435

436+
pub fn filter_by_name2(attrs: &[Attribute], name: Symbol) -> impl Iterator<Item = &Attribute> {
437+
attrs.iter().filter(move |attr| attr.check_name2(name))
438+
}
439+
424440
pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: Symbol) -> Option<Symbol> {
425441
attrs.iter().find(|at| at.check_name(name)).and_then(|at| at.value_str())
426442
}
427443

444+
pub fn first_attr_value_str_by_name2(attrs: &[Attribute], name: Symbol) -> Option<Symbol> {
445+
attrs.iter().find(|at| at.check_name2(name)).and_then(|at| at.value_str())
446+
}
447+
428448
impl MetaItem {
429449
fn token_trees_and_joints(&self) -> Vec<TreeAndJoint> {
430450
let mut idents = vec![];

src/librustc_ast_lowering/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22362236
hir_id: self.lower_node_id(param.id),
22372237
name,
22382238
span: param.ident.span,
2239-
pure_wrt_drop: attr::contains_name(&param.attrs, sym::may_dangle),
2239+
pure_wrt_drop: attr::contains_name2(&param.attrs, sym::may_dangle),
22402240
attrs: self.lower_attrs(&param.attrs),
22412241
bounds: self.arena.alloc_from_iter(bounds),
22422242
kind,

src/librustc_attr/builtin.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Parsing and validation of builtin attributes
22
3-
use super::{find_by_name, mark_used};
3+
use super::find_by_name;
44

55
use rustc_ast::ast::{self, Attribute, Lit, LitKind, MetaItem, MetaItemKind, NestedMetaItem};
66
use rustc_ast_pretty::pprust;
@@ -214,8 +214,6 @@ where
214214
continue; // not a stability level
215215
}
216216

217-
mark_used(attr);
218-
219217
let meta = attr.meta();
220218

221219
if attr.has_name(sym::rustc_promotable) {
@@ -650,7 +648,7 @@ where
650648
let diagnostic = &sess.span_diagnostic;
651649

652650
'outer: for attr in attrs_iter {
653-
if !(attr.check_name(sym::deprecated) || attr.check_name(sym::rustc_deprecated)) {
651+
if !(attr.check_name2(sym::deprecated) || attr.check_name(sym::rustc_deprecated)) {
654652
continue;
655653
}
656654

@@ -773,8 +771,6 @@ where
773771
}
774772
}
775773

776-
mark_used(&attr);
777-
778774
let is_since_rustc_version = attr.check_name(sym::rustc_deprecated);
779775
depr = Some(Deprecation { since, note, suggestion, is_since_rustc_version });
780776
}
@@ -823,9 +819,8 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
823819

824820
let mut acc = Vec::new();
825821
let diagnostic = &sess.span_diagnostic;
826-
if attr.has_name(sym::repr) {
822+
if attr.check_name2(sym::repr) {
827823
if let Some(items) = attr.meta_item_list() {
828-
mark_used(attr);
829824
for item in items {
830825
if !item.is_meta_item() {
831826
handle_errors(

src/librustc_builtin_macros/deriving/generic/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,6 @@ impl<'a> TraitDef<'a> {
676676
let self_type = cx.ty_path(path);
677677

678678
let attr = cx.attribute(cx.meta_word(self.span, sym::automatically_derived));
679-
// Just mark it now since we know that it'll end up used downstream
680-
attr::mark_used(&attr);
681679
let opt_trait_ref = Some(trait_ref);
682680
let unused_qual = {
683681
let word = rustc_ast::attr::mk_nested_word_item(Ident::new(

src/librustc_builtin_macros/proc_macro_harness.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
264264

265265
for attr in &item.attrs {
266266
if is_proc_macro_attr(&attr) {
267+
attr::mark_used(attr);
267268
if let Some(prev_attr) = found_attr {
268269
let prev_item = prev_attr.get_normal_item();
269270
let item = attr.get_normal_item();

src/librustc_builtin_macros/standard_library_imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ pub fn inject(
1717
let rust_2018 = sess.edition >= Edition::Edition2018;
1818

1919
// the first name in this list is the crate name of the crate with the prelude
20-
let names: &[Symbol] = if attr::contains_name(&krate.attrs, sym::no_core) {
20+
let names: &[Symbol] = if attr::contains_name2(&krate.attrs, sym::no_core) {
2121
return (krate, None);
22-
} else if attr::contains_name(&krate.attrs, sym::no_std) {
22+
} else if attr::contains_name2(&krate.attrs, sym::no_std) {
2323
if attr::contains_name(&krate.attrs, sym::compiler_builtins) {
2424
&[sym::core]
2525
} else {

src/librustc_builtin_macros/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,15 @@ enum ShouldPanic {
319319
}
320320

321321
fn should_ignore(i: &ast::Item) -> bool {
322-
attr::contains_name(&i.attrs, sym::ignore)
322+
attr::contains_name2(&i.attrs, sym::ignore)
323323
}
324324

325325
fn should_fail(i: &ast::Item) -> bool {
326-
attr::contains_name(&i.attrs, sym::allow_fail)
326+
attr::contains_name2(&i.attrs, sym::allow_fail)
327327
}
328328

329329
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
330-
match attr::find_by_name(&i.attrs, sym::should_panic) {
330+
match attr::find_by_name2(&i.attrs, sym::should_panic) {
331331
Some(attr) => {
332332
let sd = &cx.parse_sess.span_diagnostic;
333333

src/librustc_builtin_macros/test_harness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn inject(
5151
// unconditional, so that the attribute is still marked as used in
5252
// non-test builds.
5353
let reexport_test_harness_main =
54-
attr::first_attr_value_str_by_name(&krate.attrs, sym::reexport_test_harness_main);
54+
attr::first_attr_value_str_by_name2(&krate.attrs, sym::reexport_test_harness_main);
5555

5656
// Do this here so that the test_runner crate attribute gets marked as used
5757
// even in non-test builds
@@ -344,7 +344,7 @@ fn is_test_case(i: &ast::Item) -> bool {
344344
}
345345

346346
fn get_test_runner(sd: &rustc_errors::Handler, krate: &ast::Crate) -> Option<ast::Path> {
347-
let test_attr = attr::find_by_name(&krate.attrs, sym::test_runner)?;
347+
let test_attr = attr::find_by_name2(&krate.attrs, sym::test_runner)?;
348348
let meta_list = test_attr.meta_item_list()?;
349349
let span = test_attr.span;
350350
match &*meta_list {

src/librustc_expand/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ impl SyntaxExtension {
818818
kind,
819819
span,
820820
allow_internal_unstable,
821-
allow_internal_unsafe: attr::contains_name(attrs, sym::allow_internal_unsafe),
821+
allow_internal_unsafe: attr::contains_name2(attrs, sym::allow_internal_unsafe),
822822
local_inner_macros,
823823
stability,
824824
deprecation: attr::find_deprecation(&sess, attrs, span),

src/librustc_expand/config.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn get_features(
7070
// Process the edition umbrella feature-gates first, to ensure
7171
// `edition_enabled_features` is completed before it's queried.
7272
for attr in krate_attrs {
73-
if !attr.check_name(sym::feature) {
73+
if !attr.check_name2(sym::feature) {
7474
continue;
7575
}
7676

@@ -280,9 +280,6 @@ impl<'a> StripUnconfigured<'a> {
280280
return vec![attr];
281281
}
282282

283-
// At this point we know the attribute is considered used.
284-
attr::mark_used(&attr);
285-
286283
if !attr::cfg_matches(&cfg_predicate, self.sess, self.features) {
287284
return vec![];
288285
}
@@ -528,5 +525,5 @@ impl<'a> MutVisitor for StripUnconfigured<'a> {
528525
}
529526

530527
fn is_cfg(attr: &Attribute) -> bool {
531-
attr.check_name(sym::cfg)
528+
attr.check_name2(sym::cfg)
532529
}

0 commit comments

Comments
 (0)