Skip to content

Commit 9382ba4

Browse files
committed
Auto merge of rust-lang#124617 - GuillaumeGomez:rollup-eihxh6v, r=GuillaumeGomez
Rollup of 3 pull requests Successful merges: - rust-lang#124568 (Adjust `#[macro_export]`/doctest help suggestion for non_local_defs lint) - rust-lang#124582 (always print nice 'std not found' error when std is not found) - rust-lang#124597 (Use an explicit x86-64 cpu in tests that are sensitive to it) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 80451a4 + 1b0972c commit 9382ba4

17 files changed

+84
-33
lines changed

compiler/rustc_lint/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ lint_non_local_definitions_macro_rules = non-local `macro_rules!` definition, th
456456
[one] `{$body_name}`
457457
*[other] `{$body_name}` and up {$depth} bodies
458458
}
459+
.help_doctest =
460+
remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() {"{"} ... {"}"}`
459461
.non_local = a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
460462
.exception = one exception to the rule are anon-const (`const _: () = {"{"} ... {"}"}`) at top-level module
461463

compiler/rustc_lint/src/lints.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1350,14 +1350,18 @@ pub enum NonLocalDefinitionsDiag {
13501350
const_anon: Option<Span>,
13511351
},
13521352
#[diag(lint_non_local_definitions_macro_rules)]
1353-
#[help]
1354-
#[note(lint_non_local)]
1355-
#[note(lint_exception)]
1356-
#[note(lint_non_local_definitions_deprecation)]
13571353
MacroRules {
13581354
depth: u32,
13591355
body_kind_descr: &'static str,
13601356
body_name: String,
1357+
#[help]
1358+
help: Option<()>,
1359+
#[help(lint_help_doctest)]
1360+
doctest_help: Option<()>,
1361+
#[note(lint_non_local)]
1362+
#[note(lint_exception)]
1363+
#[note(lint_non_local_definitions_deprecation)]
1364+
notes: (),
13611365
#[subdiagnostic]
13621366
cargo_update: Option<NonLocalDefinitionsCargoUpdateNote>,
13631367
},

compiler/rustc_lint/src/non_local_def.rs

+9
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
233233
ItemKind::Macro(_macro, MacroKind::Bang)
234234
if cx.tcx.has_attr(item.owner_id.def_id, sym::macro_export) =>
235235
{
236+
// determining we if are in a doctest context can't currently be determined
237+
// by the code it-self (no specific attrs), but fortunatly rustdoc sets a
238+
// perma-unstable env for libtest so we just re-use that env for now
239+
let is_at_toplevel_doctest =
240+
self.body_depth == 2 && std::env::var("UNSTABLE_RUSTDOC_TEST_PATH").is_ok();
241+
236242
cx.emit_span_lint(
237243
NON_LOCAL_DEFINITIONS,
238244
item.span,
@@ -243,6 +249,9 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
243249
.map(|s| s.to_ident_string())
244250
.unwrap_or_else(|| "<unnameable>".to_string()),
245251
cargo_update: cargo_update(),
252+
help: (!is_at_toplevel_doctest).then_some(()),
253+
doctest_help: is_at_toplevel_doctest.then_some(()),
254+
notes: (),
246255
},
247256
)
248257
}

compiler/rustc_metadata/src/errors.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::{
55

66
use rustc_errors::{codes::*, Diag, DiagCtxt, Diagnostic, EmissionGuarantee, Level};
77
use rustc_macros::{Diagnostic, Subdiagnostic};
8-
use rustc_session::config;
98
use rustc_span::{sym, Span, Symbol};
109
use rustc_target::spec::{PanicStrategy, TargetTriple};
1110

@@ -640,9 +639,7 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for CannotFindCrate {
640639
diag.arg("locator_triple", self.locator_triple.triple());
641640
diag.code(E0463);
642641
diag.span(self.span);
643-
if (self.crate_name == sym::std || self.crate_name == sym::core)
644-
&& self.locator_triple != TargetTriple::from_triple(config::host_triple())
645-
{
642+
if self.crate_name == sym::std || self.crate_name == sym::core {
646643
if self.missing_core {
647644
diag.note(fluent::metadata_target_not_installed);
648645
} else {

tests/assembly/simd-intrinsic-mask-reduce.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// verify that simd mask reductions do not introduce additional bit shift operations
22
//@ revisions: x86 aarch64
33
//@ [x86] compile-flags: --target=x86_64-unknown-linux-gnu -C llvm-args=-x86-asm-syntax=intel
4+
// Set the base cpu explicitly, in case the default has been changed.
5+
//@ [x86] compile-flags: -C target-cpu=x86-64
46
//@ [x86] needs-llvm-components: x86
57
//@ [aarch64] compile-flags: --target=aarch64-unknown-linux-gnu
68
//@ [aarch64] needs-llvm-components: aarch64

tests/assembly/x86_64-floating-point-clamp.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// so check to make sure that's what it's actually emitting.
33

44
//@ assembly-output: emit-asm
5-
//@ compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel
5+
// Set the base cpu explicitly, in case the default has been changed.
6+
//@ compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel -C target-cpu=x86-64
67
//@ only-x86_64
78
//@ ignore-sgx
89

tests/codegen/target-feature-inline-closure.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ only-x86_64
2-
//@ compile-flags: -Copt-level=3
2+
// Set the base cpu explicitly, in case the default has been changed.
3+
//@ compile-flags: -Copt-level=3 -Ctarget-cpu=x86-64
34

45
#![crate_type = "lib"]
56
#![feature(target_feature_11)]
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ check-pass
2+
//@ compile-flags:--test --test-args --test-threads=1 --nocapture -Zunstable-options
3+
//@ normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
4+
//@ normalize-stderr-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
5+
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
6+
7+
//! ```
8+
//! #[macro_export]
9+
//! macro_rules! a_macro { () => {} }
10+
//! ```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: non-local `macro_rules!` definition, they should be avoided as they go against expectation
2+
--> $DIR/non_local_defs.rs:9:1
3+
|
4+
LL | macro_rules! a_macro { () => {} }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() { ... }`
8+
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
9+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module
10+
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
11+
= note: `#[warn(non_local_definitions)]` on by default
12+
13+
warning: 1 warning emitted
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
running 1 test
3+
test $DIR/non_local_defs.rs - (line 7) ... ok
4+
5+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
6+

tests/ui/asm/x86_64/target-feature-attr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//@ only-x86_64
2+
// Set the base cpu explicitly, in case the default has been changed.
3+
//@ compile-flags: -C target-cpu=x86-64
24

35
#![feature(avx512_target_feature)]
46

tests/ui/asm/x86_64/target-feature-attr.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: register class `ymm_reg` requires the `avx` target feature
2-
--> $DIR/target-feature-attr.rs:18:40
2+
--> $DIR/target-feature-attr.rs:20:40
33
|
44
LL | asm!("vaddps {2:y}, {0:y}, {1:y}", in(ymm_reg) x, in(ymm_reg) y, lateout(ymm_reg) x);
55
| ^^^^^^^^^^^^^
66

77
error: register class `ymm_reg` requires the `avx` target feature
8-
--> $DIR/target-feature-attr.rs:18:55
8+
--> $DIR/target-feature-attr.rs:20:55
99
|
1010
LL | asm!("vaddps {2:y}, {0:y}, {1:y}", in(ymm_reg) x, in(ymm_reg) y, lateout(ymm_reg) x);
1111
| ^^^^^^^^^^^^^
1212

1313
error: register class `ymm_reg` requires the `avx` target feature
14-
--> $DIR/target-feature-attr.rs:18:70
14+
--> $DIR/target-feature-attr.rs:20:70
1515
|
1616
LL | asm!("vaddps {2:y}, {0:y}, {1:y}", in(ymm_reg) x, in(ymm_reg) y, lateout(ymm_reg) x);
1717
| ^^^^^^^^^^^^^^^^^^
1818

1919
error: register class `kreg` requires at least one of the following target features: avx512bw, avx512f
20-
--> $DIR/target-feature-attr.rs:33:23
20+
--> $DIR/target-feature-attr.rs:35:23
2121
|
2222
LL | asm!("/* {0} */", in(kreg) x);
2323
| ^^^^^^^^^^

tests/ui/consts/const-eval/const_fn_target_feature.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ only-x86_64
2-
//@ compile-flags:-C target-feature=+ssse3
2+
// Set the base cpu explicitly, in case the default has been changed.
3+
//@ compile-flags: -C target-cpu=x86-64 -C target-feature=+ssse3
34

45
#![crate_type = "lib"]
56

tests/ui/consts/const-eval/const_fn_target_feature.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/const_fn_target_feature.rs:10:24
2+
--> $DIR/const_fn_target_feature.rs:11:24
33
|
44
LL | const B: () = unsafe { avx2_fn() };
55
| ^^^^^^^^^ calling a function that requires unavailable target features: avx2

tests/ui/rfcs/rfc-2396-target_feature-11/safe-calls.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//@ only-x86_64
2+
// Set the base cpu explicitly, in case the default has been changed.
3+
//@ compile-flags: -C target-cpu=x86-64
24

35
#![feature(target_feature_11)]
46

tests/ui/rfcs/rfc-2396-target_feature-11/safe-calls.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0133]: call to function `sse2` with `#[target_feature]` is unsafe and requires unsafe function or block
2-
--> $DIR/safe-calls.rs:25:5
2+
--> $DIR/safe-calls.rs:27:5
33
|
44
LL | sse2();
55
| ^^^^^^ call to function with `#[target_feature]`
@@ -8,39 +8,39 @@ LL | sse2();
88
= note: the sse2 target feature being enabled in the build configuration does not remove the requirement to list it in `#[target_feature]`
99

1010
error[E0133]: call to function `avx_bmi2` with `#[target_feature]` is unsafe and requires unsafe function or block
11-
--> $DIR/safe-calls.rs:27:5
11+
--> $DIR/safe-calls.rs:29:5
1212
|
1313
LL | avx_bmi2();
1414
| ^^^^^^^^^^ call to function with `#[target_feature]`
1515
|
1616
= help: in order for the call to be safe, the context requires the following additional target features: avx and bmi2
1717

1818
error[E0133]: call to function `Quux::avx_bmi2` with `#[target_feature]` is unsafe and requires unsafe function or block
19-
--> $DIR/safe-calls.rs:29:5
19+
--> $DIR/safe-calls.rs:31:5
2020
|
2121
LL | Quux.avx_bmi2();
2222
| ^^^^^^^^^^^^^^^ call to function with `#[target_feature]`
2323
|
2424
= help: in order for the call to be safe, the context requires the following additional target features: avx and bmi2
2525

2626
error[E0133]: call to function `avx_bmi2` with `#[target_feature]` is unsafe and requires unsafe function or block
27-
--> $DIR/safe-calls.rs:35:5
27+
--> $DIR/safe-calls.rs:37:5
2828
|
2929
LL | avx_bmi2();
3030
| ^^^^^^^^^^ call to function with `#[target_feature]`
3131
|
3232
= help: in order for the call to be safe, the context requires the following additional target features: avx and bmi2
3333

3434
error[E0133]: call to function `Quux::avx_bmi2` with `#[target_feature]` is unsafe and requires unsafe function or block
35-
--> $DIR/safe-calls.rs:37:5
35+
--> $DIR/safe-calls.rs:39:5
3636
|
3737
LL | Quux.avx_bmi2();
3838
| ^^^^^^^^^^^^^^^ call to function with `#[target_feature]`
3939
|
4040
= help: in order for the call to be safe, the context requires the following additional target features: avx and bmi2
4141

4242
error[E0133]: call to function `sse2` with `#[target_feature]` is unsafe and requires unsafe function or block
43-
--> $DIR/safe-calls.rs:43:5
43+
--> $DIR/safe-calls.rs:45:5
4444
|
4545
LL | sse2();
4646
| ^^^^^^ call to function with `#[target_feature]`
@@ -49,23 +49,23 @@ LL | sse2();
4949
= note: the sse2 target feature being enabled in the build configuration does not remove the requirement to list it in `#[target_feature]`
5050

5151
error[E0133]: call to function `avx_bmi2` with `#[target_feature]` is unsafe and requires unsafe function or block
52-
--> $DIR/safe-calls.rs:45:5
52+
--> $DIR/safe-calls.rs:47:5
5353
|
5454
LL | avx_bmi2();
5555
| ^^^^^^^^^^ call to function with `#[target_feature]`
5656
|
5757
= help: in order for the call to be safe, the context requires the following additional target feature: bmi2
5858

5959
error[E0133]: call to function `Quux::avx_bmi2` with `#[target_feature]` is unsafe and requires unsafe function or block
60-
--> $DIR/safe-calls.rs:47:5
60+
--> $DIR/safe-calls.rs:49:5
6161
|
6262
LL | Quux.avx_bmi2();
6363
| ^^^^^^^^^^^^^^^ call to function with `#[target_feature]`
6464
|
6565
= help: in order for the call to be safe, the context requires the following additional target feature: bmi2
6666

6767
error[E0133]: call to function `sse2` with `#[target_feature]` is unsafe and requires unsafe function or block
68-
--> $DIR/safe-calls.rs:54:5
68+
--> $DIR/safe-calls.rs:56:5
6969
|
7070
LL | sse2();
7171
| ^^^^^^ call to function with `#[target_feature]`
@@ -74,7 +74,7 @@ LL | sse2();
7474
= note: the sse2 target feature being enabled in the build configuration does not remove the requirement to list it in `#[target_feature]`
7575

7676
error[E0133]: call to function `sse2` with `#[target_feature]` is unsafe and requires unsafe function or block
77-
--> $DIR/safe-calls.rs:58:15
77+
--> $DIR/safe-calls.rs:60:15
7878
|
7979
LL | const _: () = sse2();
8080
| ^^^^^^ call to function with `#[target_feature]`
@@ -83,7 +83,7 @@ LL | const _: () = sse2();
8383
= note: the sse2 target feature being enabled in the build configuration does not remove the requirement to list it in `#[target_feature]`
8484

8585
error[E0133]: call to function `sse2_and_fxsr` with `#[target_feature]` is unsafe and requires unsafe function or block
86-
--> $DIR/safe-calls.rs:61:15
86+
--> $DIR/safe-calls.rs:63:15
8787
|
8888
LL | const _: () = sse2_and_fxsr();
8989
| ^^^^^^^^^^^^^^^ call to function with `#[target_feature]`
@@ -92,7 +92,7 @@ LL | const _: () = sse2_and_fxsr();
9292
= note: the fxsr and sse2 target features being enabled in the build configuration does not remove the requirement to list them in `#[target_feature]`
9393

9494
error: call to function `sse2` with `#[target_feature]` is unsafe and requires unsafe block (error E0133)
95-
--> $DIR/safe-calls.rs:68:5
95+
--> $DIR/safe-calls.rs:70:5
9696
|
9797
LL | sse2();
9898
| ^^^^^^ call to function with `#[target_feature]`
@@ -101,12 +101,12 @@ LL | sse2();
101101
= help: in order for the call to be safe, the context requires the following additional target feature: sse2
102102
= note: the sse2 target feature being enabled in the build configuration does not remove the requirement to list it in `#[target_feature]`
103103
note: an unsafe function restricts its caller, but its body is safe by default
104-
--> $DIR/safe-calls.rs:67:1
104+
--> $DIR/safe-calls.rs:69:1
105105
|
106106
LL | unsafe fn needs_unsafe_block() {
107107
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
108108
note: the lint level is defined here
109-
--> $DIR/safe-calls.rs:64:8
109+
--> $DIR/safe-calls.rs:66:8
110110
|
111111
LL | #[deny(unsafe_op_in_unsafe_fn)]
112112
| ^^^^^^^^^^^^^^^^^^^^^^

tests/ui/sse2.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
assert!(cfg!(target_feature = "sse2"),
2020
"SSE2 was not detected as available on an x86 platform");
2121
}
22-
// check a negative case too -- allowed on x86, but not enabled by default
23-
assert!(cfg!(not(target_feature = "avx2")),
24-
"AVX2 shouldn't be detected as available by default on any platform");
22+
// check a negative case too -- certainly not enabled by default
23+
assert!(cfg!(not(target_feature = "ferris_wheel")),
24+
"🎡 shouldn't be detected as available by default on any platform");
2525
}

0 commit comments

Comments
 (0)