Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4200f8e

Browse files
committedMar 5, 2025
Revert #138019 after further discussion about adding this exception in hir-pretty
1 parent 4559163 commit 4200f8e

File tree

3 files changed

+12
-79
lines changed

3 files changed

+12
-79
lines changed
 

‎compiler/rustc_hir_pretty/src/lib.rs

-74
Original file line numberDiff line numberDiff line change
@@ -117,80 +117,6 @@ impl<'a> State<'a> {
117117
));
118118
self.hardbreak()
119119
}
120-
hir::Attribute::Parsed(AttributeKind::Deprecation { deprecation, .. }) => {
121-
self.word("#[deprecated");
122-
123-
// There are three possible forms here:
124-
// 1. a form with explicit components like
125-
// `#[deprecated(since = "1.2.3", note = "some note", suggestion = "something")]`
126-
// where each component may be present or absent.
127-
// 2. `#[deprecated = "message"]`
128-
// 3. `#[deprecated]`
129-
//
130-
// Let's figure out which we need.
131-
// If there's a `since` or `suggestion` value, we're definitely in form 1.
132-
if matches!(
133-
deprecation.since,
134-
rustc_attr_parsing::DeprecatedSince::RustcVersion(..)
135-
| rustc_attr_parsing::DeprecatedSince::Future
136-
| rustc_attr_parsing::DeprecatedSince::NonStandard(..)
137-
) || deprecation.suggestion.is_some()
138-
{
139-
self.word("(");
140-
let mut use_comma = false;
141-
142-
match &deprecation.since {
143-
rustc_attr_parsing::DeprecatedSince::RustcVersion(rustc_version) => {
144-
self.word("since = \"");
145-
self.word(format!(
146-
"{}.{}.{}",
147-
rustc_version.major, rustc_version.minor, rustc_version.patch
148-
));
149-
self.word("\"");
150-
use_comma = true;
151-
}
152-
rustc_attr_parsing::DeprecatedSince::Future => {
153-
self.word("since = \"future\"");
154-
use_comma = true;
155-
}
156-
rustc_attr_parsing::DeprecatedSince::NonStandard(symbol) => {
157-
self.word("since = \"");
158-
self.word(symbol.to_ident_string());
159-
self.word("\"");
160-
use_comma = true;
161-
}
162-
_ => {}
163-
}
164-
165-
if let Some(note) = &deprecation.note {
166-
if use_comma {
167-
self.word(", ");
168-
}
169-
self.word("note = \"");
170-
self.word(note.to_ident_string());
171-
self.word("\"");
172-
use_comma = true;
173-
}
174-
175-
if let Some(suggestion) = &deprecation.suggestion {
176-
if use_comma {
177-
self.word(", ");
178-
}
179-
self.word("suggestion = \"");
180-
self.word(suggestion.to_ident_string());
181-
self.word("\"");
182-
}
183-
} else if let Some(note) = &deprecation.note {
184-
// We're in form 2: `#[deprecated = "message"]`.
185-
self.word(" = \"");
186-
self.word(note.to_ident_string());
187-
self.word("\"");
188-
} else {
189-
// We're in form 3: `#[deprecated]`. Nothing to do here.
190-
}
191-
192-
self.word("]");
193-
}
194120
hir::Attribute::Parsed(pa) => {
195121
self.word("#[attr=\"");
196122
pa.print_attribute(self);

‎tests/ui/unpretty/deprecated-attr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//@ compile-flags: -Zunpretty=hir
22
//@ check-pass
33

4+
// FIXME(jdonszelmann): the pretty printing output for deprecated (and possibly more attrs) is
5+
// slightly broken.
46
#[deprecated]
57
pub struct PlainDeprecated;
68

‎tests/ui/unpretty/deprecated-attr.stdout

+10-5
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@ extern crate std;
55
//@ compile-flags: -Zunpretty=hir
66
//@ check-pass
77

8-
#[deprecated]
8+
#[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote:
9+
suggestion: }span: }")]
910
struct PlainDeprecated;
1011

11-
#[deprecated = "here's why this is deprecated"]
12+
#[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote:
13+
here's why this is deprecatedsuggestion: }span: }")]
1214
struct DirectNote;
1315

14-
#[deprecated = "here's why this is deprecated"]
16+
#[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote:
17+
here's why this is deprecatedsuggestion: }span: }")]
1518
struct ExplicitNote;
1619

17-
#[deprecated(since = "1.2.3", note = "here's why this is deprecated"]
20+
#[attr="Deprecation{deprecation: Deprecation{since: NonStandard(1.2.3)note:
21+
here's why this is deprecatedsuggestion: }span: }")]
1822
struct SinceAndNote;
1923

20-
#[deprecated(since = "1.2.3", note = "here's why this is deprecated"]
24+
#[attr="Deprecation{deprecation: Deprecation{since: NonStandard(1.2.3)note:
25+
here's why this is deprecatedsuggestion: }span: }")]
2126
struct FlippedOrder;

0 commit comments

Comments
 (0)
Failed to load comments.