Skip to content

Commit

Permalink
Rollup merge of rust-lang#138060 - jdonszelmann:revert-138019, r=comp…
Browse files Browse the repository at this point in the history
…iler-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``
  • Loading branch information
matthiaskrgr authored Mar 7, 2025
2 parents caf03fd + 8391c08 commit e928a26
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 79 deletions.
74 changes: 0 additions & 74 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,80 +117,6 @@ impl<'a> State<'a> {
));
self.hardbreak()
}
hir::Attribute::Parsed(AttributeKind::Deprecation { deprecation, .. }) => {
self.word("#[deprecated");

// There are three possible forms here:
// 1. a form with explicit components like
// `#[deprecated(since = "1.2.3", note = "some note", suggestion = "something")]`
// where each component may be present or absent.
// 2. `#[deprecated = "message"]`
// 3. `#[deprecated]`
//
// Let's figure out which we need.
// If there's a `since` or `suggestion` value, we're definitely in form 1.
if matches!(
deprecation.since,
rustc_attr_parsing::DeprecatedSince::RustcVersion(..)
| rustc_attr_parsing::DeprecatedSince::Future
| rustc_attr_parsing::DeprecatedSince::NonStandard(..)
) || deprecation.suggestion.is_some()
{
self.word("(");
let mut use_comma = false;

match &deprecation.since {
rustc_attr_parsing::DeprecatedSince::RustcVersion(rustc_version) => {
self.word("since = \"");
self.word(format!(
"{}.{}.{}",
rustc_version.major, rustc_version.minor, rustc_version.patch
));
self.word("\"");
use_comma = true;
}
rustc_attr_parsing::DeprecatedSince::Future => {
self.word("since = \"future\"");
use_comma = true;
}
rustc_attr_parsing::DeprecatedSince::NonStandard(symbol) => {
self.word("since = \"");
self.word(symbol.to_ident_string());
self.word("\"");
use_comma = true;
}
_ => {}
}

if let Some(note) = &deprecation.note {
if use_comma {
self.word(", ");
}
self.word("note = \"");
self.word(note.to_ident_string());
self.word("\"");
use_comma = true;
}

if let Some(suggestion) = &deprecation.suggestion {
if use_comma {
self.word(", ");
}
self.word("suggestion = \"");
self.word(suggestion.to_ident_string());
self.word("\"");
}
} else if let Some(note) = &deprecation.note {
// We're in form 2: `#[deprecated = "message"]`.
self.word(" = \"");
self.word(note.to_ident_string());
self.word("\"");
} else {
// We're in form 3: `#[deprecated]`. Nothing to do here.
}

self.word("]");
}
hir::Attribute::Parsed(pa) => {
self.word("#[attr=\"");
pa.print_attribute(self);
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/unpretty/deprecated-attr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//@ compile-flags: -Zunpretty=hir
//@ check-pass

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

Expand Down
17 changes: 12 additions & 5 deletions tests/ui/unpretty/deprecated-attr.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ extern crate std;
//@ compile-flags: -Zunpretty=hir
//@ check-pass

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

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

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

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

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

0 comments on commit e928a26

Please sign in to comment.