about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2024-06-19 14:24:25 +0200
committerLeón Orell Valerian Liehr <me@fmease.dev>2024-06-22 06:34:09 +0200
commit38bd7a0fcbfeb206d7d38791c884e036dfbb04ff (patch)
tree2334a71fb38520a74fdd2e70c2fc70313e31e370
parentbc12972bcd7fb93e515c14b9e1f514bc3d2683d8 (diff)
downloadrust-38bd7a0fcbfeb206d7d38791c884e036dfbb04ff.tar.gz
rust-38bd7a0fcbfeb206d7d38791c884e036dfbb04ff.zip
Add `#[rustc_dump_{predicates,item_bounds}]`
-rw-r--r--compiler/rustc_feature/src/builtin_attrs.rs8
-rw-r--r--compiler/rustc_hir_analysis/src/collect/dump.rs25
-rw-r--r--compiler/rustc_hir_analysis/src/lib.rs1
-rw-r--r--compiler/rustc_span/src/symbol.rs2
-rw-r--r--tests/ui/attributes/dump-preds.rs20
-rw-r--r--tests/ui/attributes/dump-preds.stderr39
6 files changed, 95 insertions, 0 deletions
diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs
index c165620f657..9e2756f07ed 100644
--- a/compiler/rustc_feature/src/builtin_attrs.rs
+++ b/compiler/rustc_feature/src/builtin_attrs.rs
@@ -1089,6 +1089,14 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
         "the `#[custom_mir]` attribute is just used for the Rust test suite",
     ),
     rustc_attr!(
+        TEST, rustc_dump_item_bounds, Normal, template!(Word),
+        WarnFollowing, EncodeCrossCrate::No
+    ),
+    rustc_attr!(
+        TEST, rustc_dump_predicates, Normal, template!(Word),
+        WarnFollowing, EncodeCrossCrate::No
+    ),
+    rustc_attr!(
         TEST, rustc_object_lifetime_default, Normal, template!(Word),
         WarnFollowing, EncodeCrossCrate::No
     ),
diff --git a/compiler/rustc_hir_analysis/src/collect/dump.rs b/compiler/rustc_hir_analysis/src/collect/dump.rs
index f7323edfe4d..85e1c600d6d 100644
--- a/compiler/rustc_hir_analysis/src/collect/dump.rs
+++ b/compiler/rustc_hir_analysis/src/collect/dump.rs
@@ -16,3 +16,28 @@ pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) {
         tcx.dcx().emit_err(crate::errors::TypeOf { span: tcx.def_span(id.owner_id), ty });
     }
 }
+
+pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) {
+    for id in tcx.hir_crate_items(()).owners() {
+        if tcx.has_attr(id, sym::rustc_dump_predicates) {
+            let preds = tcx.predicates_of(id).instantiate_identity(tcx).predicates;
+            let span = tcx.def_span(id);
+
+            let mut diag = tcx.dcx().struct_span_err(span, sym::rustc_dump_predicates.as_str());
+            for pred in preds {
+                diag.note(format!("{pred:?}"));
+            }
+            diag.emit();
+        }
+        if tcx.has_attr(id, sym::rustc_dump_item_bounds) {
+            let bounds = tcx.item_bounds(id).instantiate_identity();
+            let span = tcx.def_span(id);
+
+            let mut diag = tcx.dcx().struct_span_err(span, sym::rustc_dump_item_bounds.as_str());
+            for bound in bounds {
+                diag.note(format!("{bound:?}"));
+            }
+            diag.emit();
+        }
+    }
+}
diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs
index 6af4fdaea21..0428abcdf24 100644
--- a/compiler/rustc_hir_analysis/src/lib.rs
+++ b/compiler/rustc_hir_analysis/src/lib.rs
@@ -168,6 +168,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
         tcx.sess.time("outlives_dumping", || outlives::dump::inferred_outlives(tcx));
         tcx.sess.time("variance_dumping", || variance::dump::variances(tcx));
         collect::dump::opaque_hidden_types(tcx);
+        collect::dump::predicates_and_item_bounds(tcx);
     }
 
     // Make sure we evaluate all static and (non-associated) const items, even if unused.
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 55eba257ca2..fc31eae13ee 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -1592,6 +1592,8 @@ symbols! {
         rustc_do_not_const_check,
         rustc_doc_primitive,
         rustc_dummy,
+        rustc_dump_item_bounds,
+        rustc_dump_predicates,
         rustc_dump_user_args,
         rustc_dump_vtable,
         rustc_effective_visibility,
diff --git a/tests/ui/attributes/dump-preds.rs b/tests/ui/attributes/dump-preds.rs
new file mode 100644
index 00000000000..1e15ff2f9bd
--- /dev/null
+++ b/tests/ui/attributes/dump-preds.rs
@@ -0,0 +1,20 @@
+//@ normalize-stderr-test "DefId\(.+?\)" -> "DefId(..)"
+
+#![feature(rustc_attrs)]
+
+#[rustc_dump_predicates]
+trait Trait<T>: Iterator<Item: Copy>
+//~^ ERROR rustc_dump_predicates
+where
+    String: From<T>
+{
+    #[rustc_dump_predicates]
+    #[rustc_dump_item_bounds]
+    type Assoc<P: Eq>: std::ops::Deref<Target = ()>
+    //~^ ERROR rustc_dump_predicates
+    //~| ERROR rustc_dump_item_bounds
+    where
+        Self::Assoc<()>: Copy;
+}
+
+fn main() {}
diff --git a/tests/ui/attributes/dump-preds.stderr b/tests/ui/attributes/dump-preds.stderr
new file mode 100644
index 00000000000..26834376e76
--- /dev/null
+++ b/tests/ui/attributes/dump-preds.stderr
@@ -0,0 +1,39 @@
+error: rustc_dump_predicates
+  --> $DIR/dump-preds.rs:6:1
+   |
+LL | trait Trait<T>: Iterator<Item: Copy>
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: Binder { value: TraitPredicate(<Self as std::iter::Iterator>, polarity:Positive), bound_vars: [] }
+   = note: Binder { value: TraitPredicate(<<Self as std::iter::Iterator>::Item as std::marker::Copy>, polarity:Positive), bound_vars: [] }
+   = note: Binder { value: TraitPredicate(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] }
+   = note: Binder { value: TraitPredicate(<std::string::String as std::convert::From<T>>, polarity:Positive), bound_vars: [] }
+   = note: Binder { value: TraitPredicate(<Self as Trait<T>>, polarity:Positive), bound_vars: [] }
+
+error: rustc_dump_predicates
+  --> $DIR/dump-preds.rs:13:5
+   |
+LL |     type Assoc<P: Eq>: std::ops::Deref<Target = ()>
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: Binder { value: TraitPredicate(<Self as std::iter::Iterator>, polarity:Positive), bound_vars: [] }
+   = note: Binder { value: TraitPredicate(<<Self as std::iter::Iterator>::Item as std::marker::Copy>, polarity:Positive), bound_vars: [] }
+   = note: Binder { value: TraitPredicate(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] }
+   = note: Binder { value: TraitPredicate(<std::string::String as std::convert::From<T>>, polarity:Positive), bound_vars: [] }
+   = note: Binder { value: TraitPredicate(<Self as Trait<T>>, polarity:Positive), bound_vars: [] }
+   = note: Binder { value: TraitPredicate(<P as std::marker::Sized>, polarity:Positive), bound_vars: [] }
+   = note: Binder { value: TraitPredicate(<P as std::cmp::Eq>, polarity:Positive), bound_vars: [] }
+   = note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<()> as std::marker::Copy>, polarity:Positive), bound_vars: [] }
+
+error: rustc_dump_item_bounds
+  --> $DIR/dump-preds.rs:13:5
+   |
+LL |     type Assoc<P: Eq>: std::ops::Deref<Target = ()>
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = 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: [] }
+   = note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::ops::Deref>, polarity:Positive), bound_vars: [] }
+   = note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::marker::Sized>, polarity:Positive), bound_vars: [] }
+
+error: aborting due to 3 previous errors
+