Rollup merge of #140762 - aDotInTheVoid:popnl, r=GuillaumeGomez

rustdoc-json: Remove newlines from attributes

Fixes #140689

Not sure if this needs to bump `FORMAT_VERSION` or not.

r? ``@GuillaumeGomez``

cc ``@obi1kenobi``
This commit is contained in:
Matthias Krüger 2025-05-08 08:14:19 +02:00 committed by GitHub
commit cd235bdec8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 17 additions and 13 deletions

View file

@ -786,7 +786,11 @@ impl Item {
// because it isn't public API.
None
}
_ => Some(rustc_hir_pretty::attribute_to_string(&tcx, attr)),
_ => Some({
let mut s = rustc_hir_pretty::attribute_to_string(&tcx, attr);
assert_eq!(s.pop(), Some('\n'));
s
}),
}
} else if attr.has_any_name(ALLOWED_ATTRIBUTES) {
Some(

View file

@ -9,5 +9,5 @@ impl Default for Manual {
}
}
//@ is '$.index[?(@.inner.impl.for.resolved_path.path == "Derive" && @.inner.impl.trait.path == "Default")].attrs' '["#[automatically_derived]\n"]'
//@ is '$.index[?(@.inner.impl.for.resolved_path.path == "Derive" && @.inner.impl.trait.path == "Default")].attrs' '["#[automatically_derived]"]'
//@ is '$.index[?(@.inner.impl.for.resolved_path.path == "Manual" && @.inner.impl.trait.path == "Default")].attrs' '[]'

View file

@ -1,6 +1,6 @@
//@ edition: 2021
#![no_std]
//@ is "$.index[?(@.name=='example')].attrs" '["#[export_name = \"altered\"]\n"]'
//@ is "$.index[?(@.name=='example')].attrs" '["#[export_name = \"altered\"]"]'
#[export_name = "altered"]
pub extern "C" fn example() {}

View file

@ -4,6 +4,6 @@
// The representation of `#[unsafe(export_name = ..)]` in rustdoc in edition 2024
// is still `#[export_name = ..]` without the `unsafe` attribute wrapper.
//@ is "$.index[?(@.name=='example')].attrs" '["#[export_name = \"altered\"]\n"]'
//@ is "$.index[?(@.name=='example')].attrs" '["#[export_name = \"altered\"]"]'
#[unsafe(export_name = "altered")]
pub extern "C" fn example() {}

View file

@ -1,9 +1,9 @@
#![no_std]
//@ is "$.index[?(@.name=='example')].attrs" '["#[must_use]\n"]'
//@ is "$.index[?(@.name=='example')].attrs" '["#[must_use]"]'
#[must_use]
pub fn example() -> impl Iterator<Item = i64> {}
//@ is "$.index[?(@.name=='explicit_message')].attrs" '["#[must_use = \"does nothing if you do not use it\"]\n"]'
//@ is "$.index[?(@.name=='explicit_message')].attrs" '["#[must_use = \"does nothing if you do not use it\"]"]'
#[must_use = "does nothing if you do not use it"]
pub fn explicit_message() -> impl Iterator<Item = i64> {}

View file

@ -1,6 +1,6 @@
//@ edition: 2021
#![no_std]
//@ is "$.index[?(@.name=='example')].attrs" '["#[no_mangle]\n"]'
//@ is "$.index[?(@.name=='example')].attrs" '["#[no_mangle]"]'
#[no_mangle]
pub extern "C" fn example() {}

View file

@ -4,6 +4,6 @@
// The representation of `#[unsafe(no_mangle)]` in rustdoc in edition 2024
// is still `#[no_mangle]` without the `unsafe` attribute wrapper.
//@ is "$.index[?(@.name=='example')].attrs" '["#[no_mangle]\n"]'
//@ is "$.index[?(@.name=='example')].attrs" '["#[no_mangle]"]'
#[unsafe(no_mangle)]
pub extern "C" fn example() {}

View file

@ -1,18 +1,18 @@
#![no_std]
//@ is "$.index[?(@.name=='MyEnum')].attrs" '["#[non_exhaustive]\n"]'
//@ is "$.index[?(@.name=='MyEnum')].attrs" '["#[non_exhaustive]"]'
#[non_exhaustive]
pub enum MyEnum {
First,
}
pub enum NonExhaustiveVariant {
//@ is "$.index[?(@.name=='Variant')].attrs" '["#[non_exhaustive]\n"]'
//@ is "$.index[?(@.name=='Variant')].attrs" '["#[non_exhaustive]"]'
#[non_exhaustive]
Variant(i64),
}
//@ is "$.index[?(@.name=='MyStruct')].attrs" '["#[non_exhaustive]\n"]'
//@ is "$.index[?(@.name=='MyStruct')].attrs" '["#[non_exhaustive]"]'
#[non_exhaustive]
pub struct MyStruct {
pub x: i64,

View file

@ -5,7 +5,7 @@
//@ !has "$.index[?(@.name=='match')]"
//@ has "$.index[?(@.name=='foo')]"
//@ is "$.index[?(@.name=='foo')].attrs" '["#[doc(keyword = \"match\")]\n"]'
//@ is "$.index[?(@.name=='foo')].attrs" '["#[doc(keyword = \"match\")]"]'
//@ is "$.index[?(@.name=='foo')].docs" '"this is a test!"'
#[doc(keyword = "match")]
/// this is a test!
@ -13,7 +13,7 @@ pub mod foo {}
//@ !has "$.index[?(@.name=='break')]"
//@ has "$.index[?(@.name=='bar')]"
//@ is "$.index[?(@.name=='bar')].attrs" '["#[doc(keyword = \"break\")]\n"]'
//@ is "$.index[?(@.name=='bar')].attrs" '["#[doc(keyword = \"break\")]"]'
//@ is "$.index[?(@.name=='bar')].docs" '"hello"'
#[doc(keyword = "break")]
/// hello