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(
2935
2935
let hir:: Attribute :: Parsed ( kind) = attr else { continue } ;
2936
2936
let attr = match kind {
2937
2937
AttributeKind :: LinkSection { name, .. } => {
2938
- Cow :: Owned ( format ! ( "#[unsafe(link_section = \" {name} \" )]" ) )
2938
+ Cow :: Owned ( format ! ( "#[unsafe(link_section = {})]" , Escape ( & format! ( " {name:?}" ) ) ) )
2939
2939
}
2940
2940
AttributeKind :: NoMangle ( ..) => Cow :: Borrowed ( "#[unsafe(no_mangle)]" ) ,
2941
2941
AttributeKind :: ExportName { name, .. } => {
2942
- Cow :: Owned ( format ! ( "#[unsafe(export_name = \" {name} \" )]" ) )
2942
+ Cow :: Owned ( format ! ( "#[unsafe(export_name = {})]" , Escape ( & format! ( " {name:?}" ) ) ) )
2943
2943
}
2944
2944
AttributeKind :: NonExhaustive ( ..) => Cow :: Borrowed ( "#[non_exhaustive]" ) ,
2945
2945
_ => 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() {}
9
9
#[ unsafe( export_name = "bar" ) ]
10
10
pub extern "C" fn g ( ) { }
11
11
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
+
12
24
//@ has foo/fn.example.html '//*[@class="code-attribute"]' '#[unsafe(link_section = ".text")]'
13
25
#[ unsafe( link_section = ".text" ) ]
14
26
pub 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
+
1
4
//@ aux-crate:attributes=attributes.rs
2
5
//@ edition:2021
3
6
#![ crate_name = "user" ]
4
7
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]'
7
20
pub 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
+
1
10
#[ non_exhaustive]
2
11
pub 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