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

File tree

17 files changed

+84
-33
lines changed

17 files changed

+84
-33
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 2 additions & 0 deletions
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

Lines changed: 8 additions & 4 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 1 addition & 4 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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)]
Lines changed: 10 additions & 0 deletions
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+
//! ```
Lines changed: 14 additions & 0 deletions
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+
Lines changed: 6 additions & 0 deletions
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+

0 commit comments

Comments
 (0)