Skip to content

Commit 17438c2

Browse files
authored
Rollup merge of #161351 - fmease:mv-impl-dump-obj-lt-defs, r=JonathanBrouwer
Cleanup: Move impl of `#[rustc_dump_object_lifetime_defaults]` Module `rustc_passes::check_attr` hosts *validity checks* for attributes (that can't be impl'ed in `rustc_attr_parsing` (yet)). However on main, the *actual impl* of `#[rustc_dump_object_lifetime_defaults]` lives there, too, which is wrong. Move it closer to the provider of the corresponding query (`object_lifetime_defaults`) which lives in `rustc_hir_analysis`. IIRC the eventual goal is to remove `check_attr` entirely in favor of `rustc_attr_parsing` if possible, meaning the impl probably *has* to move in the future anyway. Let's do it now. <sub>(No LLM was used in the creation of this PR)</sub>
2 parents b320300 + 8ac67c5 commit 17438c2

3 files changed

Lines changed: 33 additions & 25 deletions

File tree

compiler/rustc_hir_analysis/src/collect/dump.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc_hir::def::DefKind;
33
use rustc_hir::def_id::LocalDefId;
44
use rustc_hir::{find_attr, intravisit};
55
use rustc_middle::hir::nested_filter;
6+
use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
67
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt, Unnormalized};
78
use rustc_span::sym;
89

@@ -25,6 +26,30 @@ pub(crate) fn generics(tcx: TyCtxt<'_>) {
2526
}
2627
}
2728

29+
pub(crate) fn object_lifetime_defaults(tcx: TyCtxt<'_>) {
30+
for def_id in tcx.hir_crate_items(()).definitions() {
31+
if def_id == hir::def_id::CRATE_DEF_ID {
32+
continue;
33+
}
34+
35+
if !find_attr!(tcx, def_id, RustcDumpObjectLifetimeDefaults) {
36+
continue;
37+
}
38+
39+
for param in &tcx.generics_of(def_id).own_params {
40+
let ty::GenericParamDefKind::Type { .. } = param.kind else { continue };
41+
let default = tcx.object_lifetime_default(param.def_id);
42+
let repr = match default {
43+
ObjectLifetimeDefault::Empty => "Empty".to_owned(),
44+
ObjectLifetimeDefault::Static => "'static".to_owned(),
45+
ObjectLifetimeDefault::Param(def_id) => tcx.item_name(def_id).to_string(),
46+
ObjectLifetimeDefault::Ambiguous => "Ambiguous".to_owned(),
47+
};
48+
tcx.dcx().span_err(tcx.def_span(param.def_id), repr);
49+
}
50+
}
51+
}
52+
2853
pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) {
2954
if !find_attr!(tcx, crate, RustcDumpHiddenTypeOfOpaques) {
3055
return;

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,16 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
203203

204204
if tcx.features().rustc_attrs() {
205205
tcx.sess.time("dumping_rustc_attr_data", || {
206-
outlives::dump::inferred_outlives(tcx);
207-
variance::dump::variances(tcx);
208-
collect::dump::generics(tcx);
209-
collect::dump::opaque_hidden_types(tcx);
206+
// tidy-alphabetical-start
210207
collect::dump::clauses_and_item_bounds(tcx);
211208
collect::dump::def_parents(tcx);
209+
collect::dump::generics(tcx);
210+
collect::dump::object_lifetime_defaults(tcx);
211+
collect::dump::opaque_hidden_types(tcx);
212212
collect::dump::vtables(tcx);
213+
outlives::dump::inferred_outlives(tcx);
214+
variance::dump::variances(tcx);
215+
// tidy-alphabetical-end
213216
});
214217
}
215218

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use rustc_hir::{
3030
};
3131
use rustc_macros::Diagnostic;
3232
use rustc_middle::hir::nested_filter;
33-
use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
3433
use rustc_middle::query::Providers;
3534
use rustc_middle::traits::ObligationCause;
3635
use rustc_middle::ty::error::{ExpectedFound, TypeError};
@@ -195,9 +194,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
195194
AttributeKind::Deprecated { span: attr_span, .. } => {
196195
self.check_deprecated(hir_id, *attr_span, target)
197196
}
198-
AttributeKind::RustcDumpObjectLifetimeDefaults => {
199-
self.check_dump_object_lifetime_defaults(hir_id);
200-
}
201197
AttributeKind::Naked(..) => self.check_naked(hir_id, target),
202198
AttributeKind::NonExhaustive(attr_span) => {
203199
self.check_non_exhaustive(*attr_span, span, target, item)
@@ -337,6 +333,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
337333
AttributeKind::RustcDumpInferredOutlives => (),
338334
AttributeKind::RustcDumpItemBounds => (),
339335
AttributeKind::RustcDumpLayout(..) => (),
336+
AttributeKind::RustcDumpObjectLifetimeDefaults => (),
340337
AttributeKind::RustcDumpSymbolName(..) => (),
341338
AttributeKind::RustcDumpUserArgs => (),
342339
AttributeKind::RustcDumpVariances => (),
@@ -785,23 +782,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
785782
}
786783
}
787784

788-
/// Debugging aid for the `object_lifetime_default` query.
789-
fn check_dump_object_lifetime_defaults(&self, hir_id: HirId) {
790-
let tcx = self.tcx;
791-
let Some(owner_id) = hir_id.as_owner() else { return };
792-
for param in &tcx.generics_of(owner_id.def_id).own_params {
793-
let ty::GenericParamDefKind::Type { .. } = param.kind else { continue };
794-
let default = tcx.object_lifetime_default(param.def_id);
795-
let repr = match default {
796-
ObjectLifetimeDefault::Empty => "Empty".to_owned(),
797-
ObjectLifetimeDefault::Static => "'static".to_owned(),
798-
ObjectLifetimeDefault::Param(def_id) => tcx.item_name(def_id).to_string(),
799-
ObjectLifetimeDefault::Ambiguous => "Ambiguous".to_owned(),
800-
};
801-
tcx.dcx().span_err(tcx.def_span(param.def_id), repr);
802-
}
803-
}
804-
805785
/// Checks if the `#[non_exhaustive]` attribute on an `item` is valid.
806786
fn check_non_exhaustive(
807787
&self,

0 commit comments

Comments
 (0)