Skip to content

Commit 32ea361

Browse files
committed
Auto merge of #158159 - jhpratt:rollup-ceWlXSV, r=jhpratt
Rollup of 3 pull requests Successful merges: - #149267 (fix: clarify that fs::rename on unix accepts targets that don't exist) - #158106 (Expand diagnostic for attributes on macro calls) - #158125 (add a test for the `getrandom` fallback)
2 parents f428d12 + 82b925e commit 32ea361

9 files changed

Lines changed: 108 additions & 8 deletions

File tree

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ pub(crate) struct InvalidTarget {
344344
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
345345
)]
346346
pub previously_accepted: bool,
347+
#[note(
348+
"placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute"
349+
)]
350+
pub on_macro_call: bool,
347351
}
348352

349353
#[derive(Subdiagnostic)]

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ impl<'sess> AttributeParser<'sess> {
129129

130130
let allowed_targets = allowed_targets.allowed_targets();
131131
let (applied, only) = allowed_targets_applied(allowed_targets, cx.target, cx.features);
132+
132133
let diag = InvalidTarget {
133134
span: cx.attr_span.clone(),
134135
name: cx.attr_path.clone(),
@@ -138,6 +139,7 @@ impl<'sess> AttributeParser<'sess> {
138139
attribute_args,
139140
help: Self::target_checking_help(attribute_args, cx),
140141
previously_accepted: matches!(result, AllowedResult::Warn),
142+
on_macro_call: matches!(cx.target, Target::MacroCall),
141143
};
142144

143145
match result {

library/std/src/fs.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,19 +2751,21 @@ pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> io::Result<Metadata> {
27512751
///
27522752
/// # Platform-specific behavior
27532753
///
2754-
/// This function currently corresponds to the `rename` function on Unix
2755-
/// and the `MoveFileExW` or `SetFileInformationByHandle` function on Windows.
2754+
/// This function currently corresponds to the [rename] function on Unix, and
2755+
/// `MoveFileExW` with a fallback to `SetFileInformationByHandle` on Windows.
2756+
/// The exact behavior differs:
27562757
///
2757-
/// Because of this, the behavior when both `from` and `to` exist differs. On
2758-
/// Unix, if `from` is a directory, `to` must also be an (empty) directory. If
2759-
/// `from` is not a directory, `to` must also be not a directory. The behavior
2760-
/// on Windows is the same on Windows 10 1607 and higher if `FileRenameInfoEx`
2761-
/// is supported by the filesystem; otherwise, `from` can be anything, but
2762-
/// `to` must *not* be a directory.
2758+
/// - If `to` does not exist, `from` can be anything.
2759+
/// - On Unix, when `from` is a directory and `to` exists, `to` must be an empty directory.
2760+
/// - On Unix, when `from` is not a directory and `to` exists, `to` may not be a directory.
2761+
/// - On Windows 10 version 1607 and above, the behavior is the same as Unix if the
2762+
/// filesystem supports `FileRenameInfoEx`.
2763+
/// - Otherwise on Windows, `from` can be anything but `to` must not be a directory.
27632764
///
27642765
/// Note that, this [may change in the future][changes].
27652766
///
27662767
/// [changes]: io#platform-specific-behavior
2768+
/// [rename]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/rename.html
27672769
///
27682770
/// # Errors
27692771
///

tests/ui/attributes/attr-on-mac-call.stderr

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | #[sanitize(address = "off")]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics
8+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
89

910
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![register_tool]`
1011
--> $DIR/attr-on-mac-call.rs:110:5
@@ -26,6 +27,7 @@ LL | #[export_name = "x"]
2627
|
2728
= help: `#[export_name]` can be applied to functions and statics
2829
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
30+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
2931
note: the lint level is defined here
3032
--> $DIR/attr-on-mac-call.rs:3:9
3133
|
@@ -40,6 +42,7 @@ LL | #[unsafe(naked)]
4042
|
4143
= help: `#[naked]` can only be applied to functions
4244
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
45+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
4346

4447
warning: `#[track_caller]` attribute cannot be used on macro calls
4548
--> $DIR/attr-on-mac-call.rs:14:5
@@ -49,6 +52,7 @@ LL | #[track_caller]
4952
|
5053
= help: `#[track_caller]` can only be applied to functions
5154
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
55+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
5256

5357
warning: `#[used]` attribute cannot be used on macro calls
5458
--> $DIR/attr-on-mac-call.rs:17:5
@@ -58,6 +62,7 @@ LL | #[used]
5862
|
5963
= help: `#[used]` can only be applied to statics
6064
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
65+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
6166

6267
warning: `#[target_feature]` attribute cannot be used on macro calls
6368
--> $DIR/attr-on-mac-call.rs:20:5
@@ -67,6 +72,7 @@ LL | #[target_feature(enable = "x")]
6772
|
6873
= help: `#[target_feature]` can only be applied to functions
6974
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
75+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
7076

7177
warning: `#[deprecated]` attribute cannot be used on macro calls
7278
--> $DIR/attr-on-mac-call.rs:23:5
@@ -76,6 +82,7 @@ LL | #[deprecated]
7682
|
7783
= help: `#[deprecated]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, foreign statics, functions, inherent impl blocks, macro defs, modules, statics, struct fields, traits, type aliases, and use statements
7884
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
85+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
7986

8087
warning: `#[inline]` attribute cannot be used on macro calls
8188
--> $DIR/attr-on-mac-call.rs:26:5
@@ -85,6 +92,7 @@ LL | #[inline]
8592
|
8693
= help: `#[inline]` can only be applied to functions
8794
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
95+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
8896

8997
warning: `#[link_name]` attribute cannot be used on macro calls
9098
--> $DIR/attr-on-mac-call.rs:29:5
@@ -94,6 +102,7 @@ LL | #[link_name = "x"]
94102
|
95103
= help: `#[link_name]` can be applied to foreign functions and foreign statics
96104
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
105+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
97106

98107
warning: `#[link_section]` attribute cannot be used on macro calls
99108
--> $DIR/attr-on-mac-call.rs:32:5
@@ -103,6 +112,7 @@ LL | #[link_section = "__TEXT,__text"]
103112
|
104113
= help: `#[link_section]` can be applied to functions and statics
105114
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
115+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
106116

107117
warning: `#[link_ordinal]` attribute cannot be used on macro calls
108118
--> $DIR/attr-on-mac-call.rs:35:5
@@ -112,6 +122,7 @@ LL | #[link_ordinal(42)]
112122
|
113123
= help: `#[link_ordinal]` can be applied to foreign functions and foreign statics
114124
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
125+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
115126

116127
warning: `#[non_exhaustive]` attribute cannot be used on macro calls
117128
--> $DIR/attr-on-mac-call.rs:38:5
@@ -121,6 +132,7 @@ LL | #[non_exhaustive]
121132
|
122133
= help: `#[non_exhaustive]` can be applied to data types and enum variants
123134
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
135+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
124136

125137
warning: `#[proc_macro]` attribute cannot be used on macro calls
126138
--> $DIR/attr-on-mac-call.rs:41:5
@@ -130,6 +142,7 @@ LL | #[proc_macro]
130142
|
131143
= help: `#[proc_macro]` can only be applied to functions
132144
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
145+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
133146

134147
warning: `#[cold]` attribute cannot be used on macro calls
135148
--> $DIR/attr-on-mac-call.rs:44:5
@@ -139,6 +152,7 @@ LL | #[cold]
139152
|
140153
= help: `#[cold]` can only be applied to functions
141154
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
155+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
142156

143157
warning: `#[no_mangle]` attribute cannot be used on macro calls
144158
--> $DIR/attr-on-mac-call.rs:47:5
@@ -148,6 +162,7 @@ LL | #[no_mangle]
148162
|
149163
= help: `#[no_mangle]` can be applied to functions and statics
150164
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
165+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
151166

152167
warning: `#[deprecated]` attribute cannot be used on macro calls
153168
--> $DIR/attr-on-mac-call.rs:50:5
@@ -157,6 +172,7 @@ LL | #[deprecated]
157172
|
158173
= help: `#[deprecated]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, foreign statics, functions, inherent impl blocks, macro defs, modules, statics, struct fields, traits, type aliases, and use statements
159174
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
175+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
160176

161177
warning: `#[automatically_derived]` attribute cannot be used on macro calls
162178
--> $DIR/attr-on-mac-call.rs:53:5
@@ -166,6 +182,7 @@ LL | #[automatically_derived]
166182
|
167183
= help: `#[automatically_derived]` can only be applied to trait impl blocks
168184
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
185+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
169186

170187
warning: `#[macro_use]` attribute cannot be used on macro calls
171188
--> $DIR/attr-on-mac-call.rs:56:5
@@ -175,6 +192,7 @@ LL | #[macro_use]
175192
|
176193
= help: `#[macro_use]` can be applied to extern crates and modules
177194
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
195+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
178196

179197
warning: `#[must_use]` attribute cannot be used on macro calls
180198
--> $DIR/attr-on-mac-call.rs:59:5
@@ -184,6 +202,7 @@ LL | #[must_use]
184202
|
185203
= help: `#[must_use]` can be applied to data types, functions, and traits
186204
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
205+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
187206

188207
warning: `#[no_implicit_prelude]` attribute cannot be used on macro calls
189208
--> $DIR/attr-on-mac-call.rs:62:5
@@ -193,6 +212,7 @@ LL | #[no_implicit_prelude]
193212
|
194213
= help: `#[no_implicit_prelude]` can be applied to crates and modules
195214
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
215+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
196216

197217
warning: `#[path]` attribute cannot be used on macro calls
198218
--> $DIR/attr-on-mac-call.rs:65:5
@@ -202,6 +222,7 @@ LL | #[path = ""]
202222
|
203223
= help: `#[path]` can only be applied to modules
204224
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
225+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
205226

206227
warning: `#[ignore]` attribute cannot be used on macro calls
207228
--> $DIR/attr-on-mac-call.rs:68:5
@@ -211,6 +232,7 @@ LL | #[ignore]
211232
|
212233
= help: `#[ignore]` can only be applied to functions
213234
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
235+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
214236

215237
warning: `#[should_panic]` attribute cannot be used on macro calls
216238
--> $DIR/attr-on-mac-call.rs:71:5
@@ -220,6 +242,7 @@ LL | #[should_panic]
220242
|
221243
= help: `#[should_panic]` can only be applied to functions
222244
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
245+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
223246

224247
warning: `#[link_name]` attribute cannot be used on macro calls
225248
--> $DIR/attr-on-mac-call.rs:74:5
@@ -229,6 +252,7 @@ LL | #[link_name = "x"]
229252
|
230253
= help: `#[link_name]` can be applied to foreign functions and foreign statics
231254
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
255+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
232256

233257
warning: `#[repr()]` attribute cannot be used on macro calls
234258
--> $DIR/attr-on-mac-call.rs:81:5
@@ -238,6 +262,7 @@ LL | #[repr()]
238262
|
239263
= help: `#[repr()]` can only be applied to data types
240264
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
265+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
241266

242267
warning: unused attribute
243268
--> $DIR/attr-on-mac-call.rs:81:5
@@ -255,6 +280,7 @@ LL | #[repr(u8)]
255280
|
256281
= help: `#[repr(u8)]` can only be applied to enums
257282
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
283+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
258284

259285
warning: `#[repr(align(...))]` attribute cannot be used on macro calls
260286
--> $DIR/attr-on-mac-call.rs:90:5
@@ -264,6 +290,7 @@ LL | #[repr(align(8))]
264290
|
265291
= help: `#[repr(align(...))]` can only be applied to data types
266292
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
293+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
267294

268295
warning: `#[repr(packed)]` attribute cannot be used on macro calls
269296
--> $DIR/attr-on-mac-call.rs:94:5
@@ -273,6 +300,7 @@ LL | #[repr(packed)]
273300
|
274301
= help: `#[repr(packed)]` can only be applied to data types
275302
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
303+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
276304

277305
warning: `#[repr(C)]` attribute cannot be used on macro calls
278306
--> $DIR/attr-on-mac-call.rs:98:5
@@ -282,6 +310,7 @@ LL | #[repr(C)]
282310
|
283311
= help: `#[repr(C)]` can only be applied to data types
284312
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
313+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
285314

286315
warning: `#[repr(Rust)]` attribute cannot be used on macro calls
287316
--> $DIR/attr-on-mac-call.rs:102:5
@@ -291,6 +320,7 @@ LL | #[repr(Rust)]
291320
|
292321
= help: `#[repr(Rust)]` can only be applied to data types
293322
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
323+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
294324

295325
warning: `#[repr(simd)]` attribute cannot be used on macro calls
296326
--> $DIR/attr-on-mac-call.rs:106:5
@@ -300,6 +330,7 @@ LL | #[repr(simd)]
300330
|
301331
= help: `#[repr(simd)]` can only be applied to structs
302332
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
333+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
303334

304335
error: aborting due to 2 previous errors; 31 warnings emitted
305336

tests/ui/feature-gates/feature-gate-check-nested-macro-invocation.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ LL | foo!();
2121
| ------ in this macro invocation
2222
|
2323
= help: `#[allow_internal_unstable]` can be applied to functions and macro defs
24+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
2425
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
2526

2627
error: aborting due to 2 previous errors

tests/ui/lint/inert-attr-macro.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | #[inline] foo!();
66
|
77
= help: `#[inline]` can only be applied to functions
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
910
note: the lint level is defined here
1011
--> $DIR/inert-attr-macro.rs:3:9
1112
|
@@ -33,6 +34,7 @@ LL | #[allow(warnings)] #[inline] foo!();
3334
|
3435
= help: `#[inline]` can only be applied to functions
3536
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
37+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
3638

3739
warning: 3 warnings emitted
3840

tests/ui/lint/unused/unused_attributes-must_use.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | #[must_use]
66
|
77
= help: `#[must_use]` can be applied to data types, functions, and traits
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute
910
note: the lint level is defined here
1011
--> $DIR/unused_attributes-must_use.rs:4:9
1112
|

0 commit comments

Comments
 (0)