File tree Expand file tree Collapse file tree 7 files changed +38
-46
lines changed
src/librustdoc/html/render Expand file tree Collapse file tree 7 files changed +38
-46
lines changed Original file line number Diff line number Diff line change @@ -2935,11 +2935,11 @@ fn render_attributes_in_code(
29352935 let hir:: Attribute :: Parsed ( kind) = attr else { continue } ;
29362936 let attr = match kind {
29372937 AttributeKind :: LinkSection { name, .. } => {
2938- Cow :: Owned ( format ! ( "#[unsafe(link_section = \" {name} \" )]" ) )
2938+ Cow :: Owned ( format ! ( "#[unsafe(link_section = {})]" , Escape ( & format! ( " {name:?}" ) ) ) )
29392939 }
29402940 AttributeKind :: NoMangle ( ..) => Cow :: Borrowed ( "#[unsafe(no_mangle)]" ) ,
29412941 AttributeKind :: ExportName { name, .. } => {
2942- Cow :: Owned ( format ! ( "#[unsafe(export_name = \" {name} \" )]" ) )
2942+ Cow :: Owned ( format ! ( "#[unsafe(export_name = {})]" , Escape ( & format! ( " {name:?}" ) ) ) )
29432943 }
29442944 AttributeKind :: NonExhaustive ( ..) => Cow :: Borrowed ( "#[non_exhaustive]" ) ,
29452945 _ => continue ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -9,6 +9,18 @@ pub extern "C" fn f() {}
99#[ unsafe( export_name = "bar" ) ]
1010pub extern "C" fn g ( ) { }
1111
12+ //@ has foo/fn.escape_special.html '//*[@class="code-attribute"]' \
13+ // '#[unsafe(export_name = "\n\"\n")]'
14+ #[ unsafe( export_name = "\n \"
15+ " ) ]
16+ pub extern "C" fn escape_special ( ) { }
17+
18+ // issue: <https://github.com/rust-lang/rust/issues/142835>
19+ //@ has foo/fn.escape_html.html '//*[@class="code-attribute"]' \
20+ // '#[unsafe(export_name = "<script>alert()</script>")]'
21+ #[ unsafe( export_name = "<script>alert()</script>" ) ]
22+ pub extern "C" fn escape_html ( ) { }
23+
1224//@ has foo/fn.example.html '//*[@class="code-attribute"]' '#[unsafe(link_section = ".text")]'
1325#[ unsafe( link_section = ".text" ) ]
1426pub extern "C" fn example ( ) { }
Original file line number Diff line number Diff line change 1+ // Ensure that we render attributes on inlined cross-crate re-exported items.
2+ // issue: <https://github.com/rust-lang/rust/issues/144004>
3+
14//@ aux-crate:attributes=attributes.rs
25//@ edition:2021
36#![ crate_name = "user" ]
47
5- //@ has 'user/struct.NonExhaustive.html'
6- //@ has - '//*[@class="rust item-decl"]//*[@class="code-attribute"]' '#[non_exhaustive]'
8+ //@ has 'user/fn.no_mangle.html' '//pre[@class="rust item-decl"]' '#[unsafe(no_mangle)]'
9+ pub use attributes:: no_mangle;
10+
11+ //@ has 'user/fn.link_section.html' '//pre[@class="rust item-decl"]' \
12+ // '#[unsafe(link_section = ".here")]'
13+ pub use attributes:: link_section;
14+
15+ //@ has 'user/fn.export_name.html' '//pre[@class="rust item-decl"]' \
16+ // '#[unsafe(export_name = "exonym")]'
17+ pub use attributes:: export_name;
18+
19+ //@ has 'user/struct.NonExhaustive.html' '//pre[@class="rust item-decl"]' '#[non_exhaustive]'
720pub use attributes:: NonExhaustive ;
Original file line number Diff line number Diff line change 1+ #[ unsafe( no_mangle) ]
2+ pub fn no_mangle ( ) { }
3+
4+ #[ unsafe( link_section = ".here" ) ]
5+ pub fn link_section ( ) { }
6+
7+ #[ unsafe( export_name = "exonym" ) ]
8+ pub fn export_name ( ) { }
9+
110#[ non_exhaustive]
211pub struct NonExhaustive ;
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments