Skip to content

Commit 3ed2cd7

Browse files
Rollup merge of #126686 - fmease:dump-preds-n-item-bounds, r=compiler-errors
Add `#[rustc_dump_{predicates,item_bounds}]` Conflicts with #126668. As discussed r? compiler-errors CC ``@fee1-dead``
2 parents 07e8b3a + 38bd7a0 commit 3ed2cd7

File tree

17 files changed

+187
-104
lines changed

17 files changed

+187
-104
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,14 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
10881088
ErrorFollowing, EncodeCrossCrate::No,
10891089
"the `#[custom_mir]` attribute is just used for the Rust test suite",
10901090
),
1091+
rustc_attr!(
1092+
TEST, rustc_dump_item_bounds, Normal, template!(Word),
1093+
WarnFollowing, EncodeCrossCrate::No
1094+
),
1095+
rustc_attr!(
1096+
TEST, rustc_dump_predicates, Normal, template!(Word),
1097+
WarnFollowing, EncodeCrossCrate::No
1098+
),
10911099
rustc_attr!(
10921100
TEST, rustc_object_lifetime_default, Normal, template!(Word),
10931101
WarnFollowing, EncodeCrossCrate::No

compiler/rustc_hir_analysis/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ hir_analysis_ty_param_some = type parameter `{$param}` must be used as the type
510510
.note = implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
511511
.only_note = only traits defined in the current crate can be implemented for a type parameter
512512
513-
hir_analysis_type_of = {$type_of}
513+
hir_analysis_type_of = {$ty}
514514
515515
hir_analysis_typeof_reserved_keyword_used =
516516
`typeof` is a reserved keyword but unimplemented
@@ -566,7 +566,7 @@ hir_analysis_value_of_associated_struct_already_specified =
566566
hir_analysis_variadic_function_compatible_convention = C-variadic function must have a compatible calling convention, like {$conventions}
567567
.label = C-variadic function must have a compatible calling convention
568568
569-
hir_analysis_variances_of = {$variances_of}
569+
hir_analysis_variances_of = {$variances}
570570
571571
hir_analysis_where_clause_on_main = `main` function is not allowed to have a `where` clause
572572
.label = `main` cannot have a `where` clause

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ use std::ops::Bound;
4545
use crate::check::intrinsic::intrinsic_operation_unsafety;
4646
use crate::errors;
4747
use crate::hir_ty_lowering::{HirTyLowerer, RegionInferReason};
48-
pub use type_of::test_opaque_hidden_types;
4948

49+
pub(crate) mod dump;
5050
mod generics_of;
5151
mod item_bounds;
5252
mod predicates_of;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use rustc_hir::def::DefKind;
2+
use rustc_hir::def_id::CRATE_DEF_ID;
3+
use rustc_middle::ty::TyCtxt;
4+
use rustc_span::sym;
5+
6+
pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) {
7+
if !tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) {
8+
return;
9+
}
10+
11+
for id in tcx.hir().items() {
12+
let DefKind::OpaqueTy = tcx.def_kind(id.owner_id) else { continue };
13+
14+
let ty = tcx.type_of(id.owner_id).instantiate_identity();
15+
16+
tcx.dcx().emit_err(crate::errors::TypeOf { span: tcx.def_span(id.owner_id), ty });
17+
}
18+
}
19+
20+
pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) {
21+
for id in tcx.hir_crate_items(()).owners() {
22+
if tcx.has_attr(id, sym::rustc_dump_predicates) {
23+
let preds = tcx.predicates_of(id).instantiate_identity(tcx).predicates;
24+
let span = tcx.def_span(id);
25+
26+
let mut diag = tcx.dcx().struct_span_err(span, sym::rustc_dump_predicates.as_str());
27+
for pred in preds {
28+
diag.note(format!("{pred:?}"));
29+
}
30+
diag.emit();
31+
}
32+
if tcx.has_attr(id, sym::rustc_dump_item_bounds) {
33+
let bounds = tcx.item_bounds(id).instantiate_identity();
34+
let span = tcx.def_span(id);
35+
36+
let mut diag = tcx.dcx().struct_span_err(span, sym::rustc_dump_item_bounds.as_str());
37+
for bound in bounds {
38+
diag.note(format!("{bound:?}"));
39+
}
40+
diag.emit();
41+
}
42+
}
43+
}

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::errors::TypeofReservedKeywordUsed;
1515

1616
use super::bad_placeholder;
1717
use super::ItemCtxt;
18-
pub use opaque::test_opaque_hidden_types;
1918

2019
mod opaque;
2120

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
11
use rustc_errors::StashKey;
22
use rustc_hir::def::DefKind;
3-
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
3+
use rustc_hir::def_id::LocalDefId;
44
use rustc_hir::intravisit::{self, Visitor};
55
use rustc_hir::{self as hir, def, Expr, ImplItem, Item, Node, TraitItem};
66
use rustc_middle::bug;
77
use rustc_middle::hir::nested_filter;
88
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
9-
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
9+
use rustc_span::DUMMY_SP;
1010

11-
use crate::errors::{TaitForwardCompat, TaitForwardCompat2, TypeOf, UnconstrainedOpaqueType};
12-
13-
pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
14-
let mut res = Ok(());
15-
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) {
16-
for id in tcx.hir().items() {
17-
if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) {
18-
let type_of = tcx.type_of(id.owner_id).instantiate_identity();
19-
20-
res = Err(tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of }));
21-
}
22-
}
23-
}
24-
res
25-
}
11+
use crate::errors::{TaitForwardCompat, TaitForwardCompat2, UnconstrainedOpaqueType};
2612

2713
/// Checks "defining uses" of opaque `impl Trait` in associated types.
2814
/// These can only be defined by associated items of the same trait.

compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,15 +682,15 @@ pub(crate) enum CannotCaptureLateBound {
682682
pub(crate) struct VariancesOf {
683683
#[primary_span]
684684
pub span: Span,
685-
pub variances_of: String,
685+
pub variances: String,
686686
}
687687

688688
#[derive(Diagnostic)]
689689
#[diag(hir_analysis_type_of)]
690690
pub(crate) struct TypeOf<'tcx> {
691691
#[primary_span]
692692
pub span: Span,
693-
pub type_of: Ty<'tcx>,
693+
pub ty: Ty<'tcx>,
694694
}
695695

696696
#[derive(Diagnostic)]

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ pub fn provide(providers: &mut Providers) {
151151
pub fn check_crate(tcx: TyCtxt<'_>) {
152152
let _prof_timer = tcx.sess.timer("type_check_crate");
153153

154-
if tcx.features().rustc_attrs {
155-
let _ = tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx));
156-
}
157-
158154
tcx.sess.time("coherence_checking", || {
159155
tcx.hir().par_for_each_module(|module| {
160156
let _ = tcx.ensure().check_mod_type_wf(module);
@@ -169,11 +165,10 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
169165
});
170166

171167
if tcx.features().rustc_attrs {
172-
let _ = tcx.sess.time("variance_testing", || variance::test::test_variance(tcx));
173-
}
174-
175-
if tcx.features().rustc_attrs {
176-
let _ = collect::test_opaque_hidden_types(tcx);
168+
tcx.sess.time("outlives_dumping", || outlives::dump::inferred_outlives(tcx));
169+
tcx.sess.time("variance_dumping", || variance::dump::variances(tcx));
170+
collect::dump::opaque_hidden_types(tcx);
171+
collect::dump::predicates_and_item_bounds(tcx);
177172
}
178173

179174
// Make sure we evaluate all static and (non-associated) const items, even if unused.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use rustc_middle::bug;
2+
use rustc_middle::ty::{self, TyCtxt};
3+
use rustc_span::sym;
4+
5+
pub(crate) fn inferred_outlives(tcx: TyCtxt<'_>) {
6+
for id in tcx.hir().items() {
7+
if !tcx.has_attr(id.owner_id, sym::rustc_outlives) {
8+
continue;
9+
}
10+
11+
let preds = tcx.inferred_outlives_of(id.owner_id);
12+
let mut preds: Vec<_> = preds
13+
.iter()
14+
.map(|(pred, _)| match pred.kind().skip_binder() {
15+
ty::ClauseKind::RegionOutlives(p) => p.to_string(),
16+
ty::ClauseKind::TypeOutlives(p) => p.to_string(),
17+
err => bug!("unexpected clause {:?}", err),
18+
})
19+
.collect();
20+
preds.sort();
21+
22+
let span = tcx.def_span(id.owner_id);
23+
let mut err = tcx.dcx().struct_span_err(span, sym::rustc_outlives.as_str());
24+
for pred in preds {
25+
err.note(pred);
26+
}
27+
err.emit();
28+
}
29+
}

compiler/rustc_hir_analysis/src/outlives/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use rustc_middle::ty::GenericArgKind;
55
use rustc_middle::ty::{self, CratePredicatesMap, TyCtxt, Upcast};
66
use rustc_span::Span;
77

8+
pub(crate) mod dump;
89
mod explicit;
910
mod implicit_infer;
10-
/// Code to write unit test for outlives.
11-
pub mod test;
1211
mod utils;
1312

1413
pub fn provide(providers: &mut Providers) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy