Skip to content

Commit 38bd7a0

Browse files
committed
Add #[rustc_dump_{predicates,item_bounds}]
1 parent bc12972 commit 38bd7a0

File tree

6 files changed

+95
-0
lines changed

6 files changed

+95
-0
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/src/collect/dump.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,28 @@ pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) {
1616
tcx.dcx().emit_err(crate::errors::TypeOf { span: tcx.def_span(id.owner_id), ty });
1717
}
1818
}
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/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
168168
tcx.sess.time("outlives_dumping", || outlives::dump::inferred_outlives(tcx));
169169
tcx.sess.time("variance_dumping", || variance::dump::variances(tcx));
170170
collect::dump::opaque_hidden_types(tcx);
171+
collect::dump::predicates_and_item_bounds(tcx);
171172
}
172173

173174
// Make sure we evaluate all static and (non-associated) const items, even if unused.

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,8 @@ symbols! {
15921592
rustc_do_not_const_check,
15931593
rustc_doc_primitive,
15941594
rustc_dummy,
1595+
rustc_dump_item_bounds,
1596+
rustc_dump_predicates,
15951597
rustc_dump_user_args,
15961598
rustc_dump_vtable,
15971599
rustc_effective_visibility,

tests/ui/attributes/dump-preds.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ normalize-stderr-test "DefId\(.+?\)" -> "DefId(..)"
2+
3+
#![feature(rustc_attrs)]
4+
5+
#[rustc_dump_predicates]
6+
trait Trait<T>: Iterator<Item: Copy>
7+
//~^ ERROR rustc_dump_predicates
8+
where
9+
String: From<T>
10+
{
11+
#[rustc_dump_predicates]
12+
#[rustc_dump_item_bounds]
13+
type Assoc<P: Eq>: std::ops::Deref<Target = ()>
14+
//~^ ERROR rustc_dump_predicates
15+
//~| ERROR rustc_dump_item_bounds
16+
where
17+
Self::Assoc<()>: Copy;
18+
}
19+
20+
fn main() {}

tests/ui/attributes/dump-preds.stderr

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error: rustc_dump_predicates
2+
--> $DIR/dump-preds.rs:6:1
3+
|
4+
LL | trait Trait<T>: Iterator<Item: Copy>
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: Binder { value: TraitPredicate(<Self as std::iter::Iterator>, polarity:Positive), bound_vars: [] }
8+
= note: Binder { value: TraitPredicate(<<Self as std::iter::Iterator>::Item as std::marker::Copy>, polarity:Positive), bound_vars: [] }
9+
= note: Binder { value: TraitPredicate(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] }
10+
= note: Binder { value: TraitPredicate(<std::string::String as std::convert::From<T>>, polarity:Positive), bound_vars: [] }
11+
= note: Binder { value: TraitPredicate(<Self as Trait<T>>, polarity:Positive), bound_vars: [] }
12+
13+
error: rustc_dump_predicates
14+
--> $DIR/dump-preds.rs:13:5
15+
|
16+
LL | type Assoc<P: Eq>: std::ops::Deref<Target = ()>
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
|
19+
= note: Binder { value: TraitPredicate(<Self as std::iter::Iterator>, polarity:Positive), bound_vars: [] }
20+
= note: Binder { value: TraitPredicate(<<Self as std::iter::Iterator>::Item as std::marker::Copy>, polarity:Positive), bound_vars: [] }
21+
= note: Binder { value: TraitPredicate(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] }
22+
= note: Binder { value: TraitPredicate(<std::string::String as std::convert::From<T>>, polarity:Positive), bound_vars: [] }
23+
= note: Binder { value: TraitPredicate(<Self as Trait<T>>, polarity:Positive), bound_vars: [] }
24+
= note: Binder { value: TraitPredicate(<P as std::marker::Sized>, polarity:Positive), bound_vars: [] }
25+
= note: Binder { value: TraitPredicate(<P as std::cmp::Eq>, polarity:Positive), bound_vars: [] }
26+
= note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<()> as std::marker::Copy>, polarity:Positive), bound_vars: [] }
27+
28+
error: rustc_dump_item_bounds
29+
--> $DIR/dump-preds.rs:13:5
30+
|
31+
LL | type Assoc<P: Eq>: std::ops::Deref<Target = ()>
32+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33+
|
34+
= note: Binder { value: ProjectionPredicate(AliasTerm { args: [Alias(Projection, AliasTy { args: [Self/#0, T/#1, P/#2], def_id: DefId(..) })], def_id: DefId(..) }, Term::Ty(())), bound_vars: [] }
35+
= note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::ops::Deref>, polarity:Positive), bound_vars: [] }
36+
= note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::marker::Sized>, polarity:Positive), bound_vars: [] }
37+
38+
error: aborting due to 3 previous errors
39+

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