about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorJubilee <workingjubilee@gmail.com>2025-03-04 19:37:07 -0800
committerGitHub <noreply@github.com>2025-03-04 19:37:07 -0800
commita69982e00a6bff2f1ca168f52bf3bb3058b891a0 (patch)
tree58d86670daf385c19e9a52465fa451368e789f19 /tests
parentf32ba6b6cabd95a7cfa56f077a7ae87796232619 (diff)
parent55f8d3f628e674d6874c96c9da425db406f15d09 (diff)
downloadrust-a69982e00a6bff2f1ca168f52bf3bb3058b891a0.tar.gz
rust-a69982e00a6bff2f1ca168f52bf3bb3058b891a0.zip
Rollup merge of #138019 - obi1kenobi:pg/pretty-print-more-attrs, r=compiler-errors
Pretty-print `#[deprecated]` attribute in HIR.

Pretty-print `#[deprecated]` attribute in a form closer to how it might appear in Rust source code, rather than using a `Debug`-like representation.

Consider the following Rust code:
```rust
#[deprecated]
pub struct PlainDeprecated;

#[deprecated = "here's why this is deprecated"]
pub struct DirectNote;

#[deprecated(since = "1.2.3", note = "here's why this is deprecated")]
pub struct SinceAndNote;
```

Here's the previous output:
```
#[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote:
suggestion: }span: }")]
struct PlainDeprecated;

#[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote:
here's why this is deprecatedsuggestion: }span: }")]
struct DirectNote;

#[attr="Deprecation{deprecation: Deprecation{since: NonStandard(1.2.3)note:
here's why this is deprecatedsuggestion: }span: }")]
struct SinceAndNote;
```

Here's the new output:
```rust
#[deprecated]
struct PlainDeprecated;

#[deprecated = "here's why this is deprecated"]
struct DirectNote;

#[deprecated(since = "1.2.3", note = "here's why this is deprecated"]
struct SinceAndNote;
```

Also includes a test for `#[diagnostic::(..)]` attributes, though their behavior is not changed here. I already wrote the test, so I figured it probably won't hurt to have it.

Related to discussion in #137645.

r? `@jdonszelmann`
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/unpretty/deprecated-attr.rs17
-rw-r--r--tests/ui/unpretty/deprecated-attr.stdout21
-rw-r--r--tests/ui/unpretty/diagnostic-attr.rs13
-rw-r--r--tests/ui/unpretty/diagnostic-attr.stdout16
4 files changed, 67 insertions, 0 deletions
diff --git a/tests/ui/unpretty/deprecated-attr.rs b/tests/ui/unpretty/deprecated-attr.rs
new file mode 100644
index 00000000000..dda362a595e
--- /dev/null
+++ b/tests/ui/unpretty/deprecated-attr.rs
@@ -0,0 +1,17 @@
+//@ compile-flags: -Zunpretty=hir
+//@ check-pass
+
+#[deprecated]
+pub struct PlainDeprecated;
+
+#[deprecated = "here's why this is deprecated"]
+pub struct DirectNote;
+
+#[deprecated(note = "here's why this is deprecated")]
+pub struct ExplicitNote;
+
+#[deprecated(since = "1.2.3", note = "here's why this is deprecated")]
+pub struct SinceAndNote;
+
+#[deprecated(note = "here's why this is deprecated", since = "1.2.3")]
+pub struct FlippedOrder;
diff --git a/tests/ui/unpretty/deprecated-attr.stdout b/tests/ui/unpretty/deprecated-attr.stdout
new file mode 100644
index 00000000000..60dbac1072b
--- /dev/null
+++ b/tests/ui/unpretty/deprecated-attr.stdout
@@ -0,0 +1,21 @@
+#[prelude_import]
+use ::std::prelude::rust_2015::*;
+#[macro_use]
+extern crate std;
+//@ compile-flags: -Zunpretty=hir
+//@ check-pass
+
+#[deprecated]
+struct PlainDeprecated;
+
+#[deprecated = "here's why this is deprecated"]
+struct DirectNote;
+
+#[deprecated = "here's why this is deprecated"]
+struct ExplicitNote;
+
+#[deprecated(since = "1.2.3", note = "here's why this is deprecated"]
+struct SinceAndNote;
+
+#[deprecated(since = "1.2.3", note = "here's why this is deprecated"]
+struct FlippedOrder;
diff --git a/tests/ui/unpretty/diagnostic-attr.rs b/tests/ui/unpretty/diagnostic-attr.rs
new file mode 100644
index 00000000000..27f5b693e69
--- /dev/null
+++ b/tests/ui/unpretty/diagnostic-attr.rs
@@ -0,0 +1,13 @@
+//@ compile-flags: -Zunpretty=hir
+//@ check-pass
+
+#[diagnostic::on_unimplemented(
+    message = "My Message for `ImportantTrait<{A}>` implemented for `{Self}`",
+    label = "My Label",
+    note = "Note 1",
+    note = "Note 2"
+)]
+pub trait ImportantTrait<A> {}
+
+#[diagnostic::do_not_recommend]
+impl<T> ImportantTrait<T> for T where T: Clone {}
diff --git a/tests/ui/unpretty/diagnostic-attr.stdout b/tests/ui/unpretty/diagnostic-attr.stdout
new file mode 100644
index 00000000000..e8696d04d38
--- /dev/null
+++ b/tests/ui/unpretty/diagnostic-attr.stdout
@@ -0,0 +1,16 @@
+#[prelude_import]
+use ::std::prelude::rust_2015::*;
+#[macro_use]
+extern crate std;
+//@ compile-flags: -Zunpretty=hir
+//@ check-pass
+
+#[diagnostic::on_unimplemented(message =
+"My Message for `ImportantTrait<{A}>` implemented for `{Self}`", label =
+"My Label", note = "Note 1", note = "Note 2")]
+trait ImportantTrait<A> { }
+
+#[diagnostic::do_not_recommend]
+impl <T> ImportantTrait<T> for T where T: Clone
+    {#![diagnostic::do_not_recommend]
+}