Skip to content

Commit 9c9f439

Browse files
committed
Make attr template suggestions preserve attribute safety.
1 parent 835004a commit 9c9f439

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,23 @@ impl AttributeTemplate {
135135

136136
if self.word {
137137
debug_assert!(macro_call.is_empty(), "Macro suggestions use list style");
138-
suggestions.push(format!("{maybe_unsafe_start}{start}{name}{end}{maybe_unsafe_end}"));
138+
suggestions.push(format!("{start}{maybe_unsafe_start}{name}{maybe_unsafe_end}{end}"));
139139
}
140140
if let Some(descr) = self.list {
141141
for descr in descr {
142142
suggestions.push(format!(
143-
"{maybe_unsafe_start}{start}{name}{macro_call}({descr}){end}{maybe_unsafe_end}"
143+
"{start}{maybe_unsafe_start}{name}{macro_call}({descr}){maybe_unsafe_end}{end}"
144144
));
145145
}
146146
}
147147
suggestions.extend(self.one_of.iter().map(|&word| {
148-
format!("{maybe_unsafe_start}{start}{name}({word}){end}{maybe_unsafe_end}")
148+
format!("{start}{maybe_unsafe_start}{name}({word}){maybe_unsafe_end}{end}")
149149
}));
150150
if let Some(descr) = self.name_value_str {
151151
debug_assert!(macro_call.is_empty(), "Macro suggestions use list style");
152152
for descr in descr {
153153
suggestions.push(format!(
154-
"{maybe_unsafe_start}{start}{name} = \"{descr}\"{end}{maybe_unsafe_end}"
154+
"{start}{maybe_unsafe_start}{name} = \"{descr}\"{maybe_unsafe_end}{end}"
155155
));
156156
}
157157
}

tests/ui/attributes/malformed-attrs.stderr

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ LL | #[unsafe(export_name)]
159159
|
160160
help: must be of the form
161161
|
162-
LL - #[unsafe(export_name)]
163-
LL + #[export_name = "name"]
164-
|
162+
LL | #[unsafe(export_name = "name")]
163+
| ++++++++
165164

166165
error: `rustc_allow_const_fn_unstable` expects a list of feature names
167166
--> $DIR/malformed-attrs.rs:31:1
@@ -330,7 +329,7 @@ LL | #[unsafe(naked())]
330329
help: must be of the form
331330
|
332331
LL - #[unsafe(naked())]
333-
LL + #[naked]
332+
LL + #[unsafe(naked)]
334333
|
335334

336335
error[E0565]: malformed `track_caller` attribute input
@@ -651,7 +650,7 @@ LL | #[unsafe(ffi_pure = 1)]
651650
help: must be of the form
652651
|
653652
LL - #[unsafe(ffi_pure = 1)]
654-
LL + #[ffi_pure]
653+
LL + #[unsafe(ffi_pure)]
655654
|
656655

657656
error[E0539]: malformed `link_ordinal` attribute input
@@ -677,7 +676,7 @@ LL | #[unsafe(ffi_const = 1)]
677676
help: must be of the form
678677
|
679678
LL - #[unsafe(ffi_const = 1)]
680-
LL + #[ffi_const]
679+
LL + #[unsafe(ffi_const)]
681680
|
682681

683682
error[E0539]: malformed `linkage` attribute input

0 commit comments

Comments
 (0)