Skip to content
/ rust Public
forked from rust-lang/rust

Commit d115322

Browse files
authored
Rollup merge of rust-lang#138060 - jdonszelmann:revert-138019, r=compiler-errors
Revert rust-lang#138019 after further discussion about how hir-pretty printing should work After some more discussion, rust-lang#138019 was probably merged a little fast. Though there probably is a real bug in pretty printing, it is not feasible to add similar pretty printing routines for all attributes, and making this specific exception is likely not desired either. For more context, see post-merge comments on rust-lang#138019 I kept the tests around, but reverted the hir-pretty change. r? `@compiler-errors`
2 parents 3a2325c + 8391c08 commit d115322

File tree

3 files changed

+14
-79
lines changed

3 files changed

+14
-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

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

8-
#[deprecated]
8+
// FIXME(jdonszelmann): the pretty printing output for deprecated (and possibly more attrs) is
9+
// slightly broken.
10+
#[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote:
11+
suggestion: }span: }")]
912
struct PlainDeprecated;
1013

11-
#[deprecated = "here's why this is deprecated"]
14+
#[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote:
15+
here's why this is deprecatedsuggestion: }span: }")]
1216
struct DirectNote;
1317

14-
#[deprecated = "here's why this is deprecated"]
18+
#[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote:
19+
here's why this is deprecatedsuggestion: }span: }")]
1520
struct ExplicitNote;
1621

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

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

0 commit comments

Comments
 (0)