Skip to content

Commit 5073886

Browse files
committed
Gate checking rustc attrs on the feature.
1 parent dccc075 commit 5073886

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
511511
// Untranslatable diagnostics are okay for rustc internals
512512
#[allow(rustc::untranslatable_diagnostic)]
513513
#[allow(rustc::diagnostic_outside_of_impl)]
514-
if self.tcx.has_attr(def_id, sym::rustc_evaluate_where_clauses) {
514+
if self.has_rustc_attrs
515+
&& self.tcx.has_attr(def_id, sym::rustc_evaluate_where_clauses)
516+
{
515517
let predicates = self.tcx.predicates_of(def_id);
516518
let predicates = predicates.instantiate(self.tcx, args);
517519
for (predicate, predicate_span) in predicates {
@@ -894,7 +896,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
894896
}
895897

896898
// If we have `rustc_do_not_const_check`, do not check `[const]` bounds.
897-
if self.tcx.has_attr(self.body_id, sym::rustc_do_not_const_check) {
899+
if self.has_rustc_attrs && self.tcx.has_attr(self.body_id, sym::rustc_do_not_const_check) {
898900
return;
899901
}
900902

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ pub(crate) struct FnCtxt<'a, 'tcx> {
126126
/// These are stored here so we may collect them when canonicalizing user
127127
/// type ascriptions later.
128128
pub(super) trait_ascriptions: RefCell<ItemLocalMap<Vec<ty::Clause<'tcx>>>>,
129+
130+
/// Whether the current crate enables the `rustc_attrs` feature.
131+
/// This allows to skip processing attributes in many places.
132+
pub(super) has_rustc_attrs: bool,
129133
}
130134

131135
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@@ -154,6 +158,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
154158
diverging_fallback_behavior,
155159
diverging_block_behavior,
156160
trait_ascriptions: Default::default(),
161+
has_rustc_attrs: root_ctxt.tcx.features().rustc_attrs(),
157162
}
158163
}
159164

@@ -525,10 +530,13 @@ fn parse_never_type_options_attr(
525530
let mut fallback = None;
526531
let mut block = None;
527532

528-
let items = tcx
529-
.get_attr(CRATE_DEF_ID, sym::rustc_never_type_options)
530-
.map(|attr| attr.meta_item_list().unwrap())
531-
.unwrap_or_default();
533+
let items = if tcx.features().rustc_attrs() {
534+
tcx.get_attr(CRATE_DEF_ID, sym::rustc_never_type_options)
535+
.map(|attr| attr.meta_item_list().unwrap())
536+
} else {
537+
None
538+
};
539+
let items = items.unwrap_or_default();
532540

533541
for item in items {
534542
if item.has_name(sym::fallback) && fallback.is_none() {

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17471747
}
17481748

17491749
fn should_log_capture_analysis(&self, closure_def_id: LocalDefId) -> bool {
1750-
self.tcx.has_attr(closure_def_id, sym::rustc_capture_analysis)
1750+
self.has_rustc_attrs && self.tcx.has_attr(closure_def_id, sym::rustc_capture_analysis)
17511751
}
17521752

17531753
fn log_capture_analysis_first_pass(

compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4545

4646
// This attribute causes us to dump some writeback information
4747
// in the form of errors, which is used for unit tests.
48-
let rustc_dump_user_args = self.tcx.has_attr(item_def_id, sym::rustc_dump_user_args);
48+
let rustc_dump_user_args =
49+
self.has_rustc_attrs && self.tcx.has_attr(item_def_id, sym::rustc_dump_user_args);
4950

5051
let mut wbcx = WritebackCx::new(self, body, rustc_dump_user_args);
5152
for param in body.params {

0 commit comments

Comments
 (0)