Skip to content

Commit 3a904ef

Browse files
committed
Auto merge of #155447 - JonathanBrouwer:simplify-parse-limited, r=<try>
Simplify `parse_limited`
2 parents 8da2d28 + a5d0719 commit 3a904ef

15 files changed

Lines changed: 60 additions & 124 deletions

File tree

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::Attribute;
77
use rustc_hir::attrs::AttributeKind;
88
use rustc_session::Session;
99
use rustc_session::parse::{feature_err, feature_warn};
10-
use rustc_span::{DUMMY_SP, Span, Spanned, Symbol, sym};
10+
use rustc_span::{Span, Spanned, Symbol, sym};
1111
use thin_vec::ThinVec;
1212

1313
use crate::errors;
@@ -646,14 +646,7 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate)
646646
let mut errored = false;
647647

648648
if let Some(Attribute::Parsed(AttributeKind::Feature(feature_idents, first_span))) =
649-
AttributeParser::parse_limited(
650-
sess,
651-
&krate.attrs,
652-
&[sym::feature],
653-
DUMMY_SP,
654-
krate.id,
655-
Some(&features),
656-
)
649+
AttributeParser::parse_limited(sess, &krate.attrs, &[sym::feature])
657650
{
658651
// `feature(...)` used on non-nightly. This is definitely an error.
659652
let mut err = errors::FeatureOnNonNightly {

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unknown.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ impl OnUnknownParser {
1616
args: &ArgParser,
1717
mode: Mode,
1818
) {
19-
if !cx.features().diagnostic_on_unknown() {
19+
if let Some(features) = cx.features
20+
&& !features.diagnostic_on_unknown()
21+
{
2022
// `UnknownDiagnosticAttribute` is emitted in rustc_resolve/macros.rs
2123
return;
2224
}

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::convert::identity;
22

33
use rustc_ast as ast;
44
use rustc_ast::token::DocFragmentKind;
5-
use rustc_ast::{AttrItemKind, AttrStyle, NodeId, Safety};
5+
use rustc_ast::{AttrItemKind, AttrStyle, CRATE_NODE_ID, NodeId, Safety};
66
use rustc_errors::{DiagCtxtHandle, MultiSpan};
77
use rustc_feature::{AttributeTemplate, Features};
88
use rustc_hir::attrs::AttributeKind;
@@ -52,18 +52,16 @@ impl<'sess> AttributeParser<'sess, Early> {
5252
sess: &'sess Session,
5353
attrs: &[ast::Attribute],
5454
sym: &'static [Symbol],
55-
target_span: Span,
56-
target_node_id: NodeId,
57-
features: Option<&'sess Features>,
5855
) -> Option<Attribute> {
5956
Self::parse_limited_should_emit(
6057
sess,
6158
attrs,
6259
sym,
63-
target_span,
64-
target_node_id,
65-
Target::Crate, // Does not matter, we're not going to emit errors anyways
66-
features,
60+
// Because we're not emitting warnings/errors, the target should not matter
61+
DUMMY_SP,
62+
CRATE_NODE_ID,
63+
Target::Crate,
64+
None,
6765
ShouldEmit::Nothing,
6866
)
6967
}

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl<'a> TraitDef<'a> {
493493
match item {
494494
Annotatable::Item(item) => {
495495
let is_packed = matches!(
496-
AttributeParser::parse_limited(cx.sess, &item.attrs, &[sym::repr], item.span, item.id, None),
496+
AttributeParser::parse_limited(cx.sess, &item.attrs, &[sym::repr]),
497497
Some(Attribute::Parsed(AttributeKind::Repr { reprs, .. })) if reprs.iter().any(|(x, _)| matches!(x, ReprPacked(..)))
498498
);
499499

compiler/rustc_builtin_macros/src/proc_macro_harness.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{mem, slice};
22

33
use rustc_ast::visit::{self, Visitor};
4-
use rustc_ast::{self as ast, HasNodeId, NodeId, attr};
4+
use rustc_ast::{self as ast, NodeId, attr};
55
use rustc_ast_pretty::pprust;
66
use rustc_attr_parsing::AttributeParser;
77
use rustc_errors::DiagCtxtHandle;
@@ -109,9 +109,6 @@ impl<'a> CollectProcMacros<'a> {
109109
self.session,
110110
slice::from_ref(attr),
111111
&[sym::proc_macro_derive],
112-
item.span,
113-
item.node_id(),
114-
None,
115112
)
116113
else {
117114
return;

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use std::{assert_matches, iter};
55

6-
use rustc_ast::{self as ast, GenericParamKind, HasNodeId, attr, join_path_idents};
6+
use rustc_ast::{self as ast, GenericParamKind, attr, join_path_idents};
77
use rustc_ast_pretty::pprust;
88
use rustc_attr_parsing::AttributeParser;
99
use rustc_errors::{Applicability, Diag, Level};
@@ -480,14 +480,7 @@ fn should_ignore_message(i: &ast::Item) -> Option<Symbol> {
480480

481481
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
482482
if let Some(Attribute::Parsed(AttributeKind::ShouldPanic { reason, .. })) =
483-
AttributeParser::parse_limited(
484-
cx.sess,
485-
&i.attrs,
486-
&[sym::should_panic],
487-
i.span,
488-
i.node_id(),
489-
None,
490-
)
483+
AttributeParser::parse_limited(cx.sess, &i.attrs, &[sym::should_panic])
491484
{
492485
ShouldPanic::Yes(reason)
493486
} else {

compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn inject(
6161

6262
// Do this here so that the test_runner crate attribute gets marked as used
6363
// even in non-test builds
64-
let test_runner = get_test_runner(sess, features, krate);
64+
let test_runner = get_test_runner(sess, krate);
6565

6666
if sess.is_test_crate() {
6767
let panic_strategy = match (panic_strategy, sess.opts.unstable_opts.panic_abort_tests) {
@@ -387,15 +387,8 @@ fn get_test_name(i: &ast::Item) -> Option<Symbol> {
387387
attr::first_attr_value_str_by_name(&i.attrs, sym::rustc_test_marker)
388388
}
389389

390-
fn get_test_runner(sess: &Session, features: &Features, krate: &ast::Crate) -> Option<ast::Path> {
391-
match AttributeParser::parse_limited(
392-
sess,
393-
&krate.attrs,
394-
&[sym::test_runner],
395-
krate.spans.inner_span,
396-
krate.id,
397-
Some(features),
398-
) {
390+
fn get_test_runner(sess: &Session, krate: &ast::Crate) -> Option<ast::Path> {
391+
match AttributeParser::parse_limited(sess, &krate.attrs, &[sym::test_runner]) {
399392
Some(rustc_hir::Attribute::Parsed(AttributeKind::TestRunner(path))) => Some(path),
400393
_ => None,
401394
}

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,7 @@ fn print_crate_info(
712712
let crate_name = passes::get_crate_name(sess, attrs);
713713
let lint_store = crate::unerased_lint_store(sess);
714714
let features = rustc_expand::config::features(sess, attrs, crate_name);
715-
let registered_tools =
716-
rustc_resolve::registered_tools_ast(sess.dcx(), attrs, sess, &features);
715+
let registered_tools = rustc_resolve::registered_tools_ast(sess.dcx(), attrs, sess);
717716
let lint_levels = rustc_lint::LintLevelsBuilder::crate_root(
718717
sess,
719718
&features,

compiler/rustc_expand/src/config.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use rustc_ast::tokenstream::{
77
AttrTokenStream, AttrTokenTree, LazyAttrTokenStream, Spacing, TokenTree,
88
};
99
use rustc_ast::{
10-
self as ast, AttrItemKind, AttrKind, AttrStyle, Attribute, DUMMY_NODE_ID, EarlyParsedAttribute,
11-
HasAttrs, HasTokens, MetaItem, MetaItemInner, NodeId, NormalAttr,
10+
self as ast, AttrItemKind, AttrKind, AttrStyle, Attribute, EarlyParsedAttribute, HasAttrs,
11+
HasTokens, MetaItem, MetaItemInner, NodeId, NormalAttr,
1212
};
1313
use rustc_attr_parsing::parser::AllowExprMetavar;
1414
use rustc_attr_parsing::{
@@ -28,7 +28,7 @@ use rustc_hir::{
2828
use rustc_parse::parser::Recovery;
2929
use rustc_session::Session;
3030
use rustc_session::parse::feature_err;
31-
use rustc_span::{DUMMY_SP, STDLIB_STABLE_CRATES, Span, Symbol, sym};
31+
use rustc_span::{STDLIB_STABLE_CRATES, Span, Symbol, sym};
3232
use tracing::instrument;
3333

3434
use crate::errors::{
@@ -51,14 +51,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
5151
let mut features = Features::default();
5252

5353
if let Some(hir::Attribute::Parsed(AttributeKind::Feature(feature_idents, _))) =
54-
AttributeParser::parse_limited(
55-
sess,
56-
krate_attrs,
57-
&[sym::feature],
58-
DUMMY_SP,
59-
DUMMY_NODE_ID,
60-
Some(&features),
61-
)
54+
AttributeParser::parse_limited(sess, krate_attrs, &[sym::feature])
6255
{
6356
for feature_ident in feature_idents {
6457
// If the enabled feature has been removed, issue an error.

compiler/rustc_lint/src/builtin.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,6 @@ impl EarlyLintPass for UnsafeCode {
313313
cx.builder.sess(),
314314
&it.attrs,
315315
&[sym::allow_internal_unsafe],
316-
it.span,
317-
DUMMY_NODE_ID,
318-
Some(cx.builder.features()),
319316
)
320317
{
321318
self.report_unsafe(cx, span, BuiltinUnsafe::AllowInternalUnsafe);

0 commit comments

Comments
 (0)