Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 23dde9b

Browse files
Auto merge of #144841 - cjgillot:typeck-no-attrs, r=<try>
Access less HIR attributes from typeck
2 parents 6d091b2 + d414182 commit 23dde9b

File tree

6 files changed

+34
-20
lines changed

6 files changed

+34
-20
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/lib.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ use rustc_data_structures::unord::UnordSet;
4646
use rustc_errors::codes::*;
4747
use rustc_errors::{Applicability, ErrorGuaranteed, pluralize, struct_span_code_err};
4848
use rustc_hir as hir;
49-
use rustc_hir::attrs::AttributeKind;
5049
use rustc_hir::def::{DefKind, Res};
51-
use rustc_hir::{HirId, HirIdMap, Node, find_attr};
50+
use rustc_hir::{HirId, HirIdMap, Node};
5251
use rustc_hir_analysis::check::{check_abi, check_custom_abi};
5352
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
5453
use rustc_infer::traits::{ObligationCauseCode, ObligationInspector, WellFormedLoc};
54+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
5555
use rustc_middle::query::Providers;
5656
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
5757
use rustc_middle::{bug, span_bug};
@@ -174,7 +174,7 @@ fn typeck_with_inspect<'tcx>(
174174
.map(|(idx, ty)| fcx.normalize(arg_span(idx), ty)),
175175
);
176176

177-
if find_attr!(tcx.get_all_attrs(def_id),AttributeKind::Naked(..)) {
177+
if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NAKED) {
178178
naked_functions::typeck_naked_fn(tcx, def_id, body);
179179
}
180180

‎compiler/rustc_hir_typeck/src/method/probe.rs‎

Lines changed: 12 additions & 9 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,
@@ -2373,17 +2379,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
23732379
if !self.is_relevant_kind_for_mode(x.kind) {
23742380
return false;
23752381
}
2376-
if self.matches_by_doc_alias(x.def_id) {
2377-
return true;
2378-
}
2379-
match edit_distance_with_substrings(
2382+
if let Some(d) = edit_distance_with_substrings(
23802383
name.as_str(),
23812384
x.name().as_str(),
23822385
max_dist,
23832386
) {
2384-
Some(d) => d > 0,
2385-
None => false,
2387+
return d > 0;
23862388
}
2389+
self.matches_by_doc_alias(x.def_id)
23872390
})
23882391
.copied()
23892392
.collect()

‎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)

AltStyle によって変換されたページ (->オリジナル) /