Skip to content

Commit 50573ed

Browse files
committed
Gate checking rustc attrs on the feature.
1 parent c0c4898 commit 50573ed

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
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/method/probe.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
777777

778778
self.assemble_inherent_candidates_from_object(generalized_self_ty);
779779
self.assemble_inherent_impl_candidates_for_type(p.def_id(), receiver_steps);
780-
if self.tcx.has_attr(p.def_id(), sym::rustc_has_incoherent_inherent_impls) {
780+
if self.has_rustc_attrs
781+
&& self.tcx.has_attr(p.def_id(), sym::rustc_has_incoherent_inherent_impls)
782+
{
781783
self.assemble_inherent_candidates_for_incoherent_ty(
782784
raw_self_ty,
783785
receiver_steps,
@@ -787,7 +789,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
787789
ty::Adt(def, _) => {
788790
let def_id = def.did();
789791
self.assemble_inherent_impl_candidates_for_type(def_id, receiver_steps);
790-
if self.tcx.has_attr(def_id, sym::rustc_has_incoherent_inherent_impls) {
792+
if self.has_rustc_attrs
793+
&& self.tcx.has_attr(def_id, sym::rustc_has_incoherent_inherent_impls)
794+
{
791795
self.assemble_inherent_candidates_for_incoherent_ty(
792796
raw_self_ty,
793797
receiver_steps,
@@ -796,7 +800,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
796800
}
797801
ty::Foreign(did) => {
798802
self.assemble_inherent_impl_candidates_for_type(did, receiver_steps);
799-
if self.tcx.has_attr(did, sym::rustc_has_incoherent_inherent_impls) {
803+
if self.has_rustc_attrs
804+
&& self.tcx.has_attr(did, sym::rustc_has_incoherent_inherent_impls)
805+
{
800806
self.assemble_inherent_candidates_for_incoherent_ty(
801807
raw_self_ty,
802808
receiver_steps,

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)