From 00583a64ee03bb38ac91095285916d8b997c4711 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 20 Jun 2024 14:14:36 -0400 Subject: [PATCH 1/6] Properly gate `safe` keyword in pre-expansion (cherry picked from commit 108b3f214a7e160ecb7ac2ec05bbb41aedd05a95) --- compiler/rustc_ast_passes/src/feature_gate.rs | 4 ++++ compiler/rustc_parse/src/parser/mod.rs | 3 +++ .../feature-gate-unsafe-extern-blocks.rs | 8 ++++++++ .../feature-gate-unsafe-extern-blocks.stderr | 13 ++++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 764d942836c20..e1c1a027a30a7 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -562,6 +562,10 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) { gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental"); gate_all!(global_registration, "global registration is experimental"); gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental"); + gate_all!( + unsafe_extern_blocks, + "`unsafe extern {}` blocks and `safe` keyword are experimental" + ); if !visitor.features.never_patterns { if let Some(spans) = spans.get(&sym::never_patterns) { diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index adf04fcf2241d..7ac6c143f1714 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1221,6 +1221,9 @@ impl<'a> Parser<'a> { if self.eat_keyword_case(kw::Unsafe, case) { Safety::Unsafe(self.prev_token.uninterpolated_span()) } else if self.eat_keyword_case(kw::Safe, case) { + self.psess + .gated_spans + .gate(sym::unsafe_extern_blocks, self.prev_token.uninterpolated_span()); Safety::Safe(self.prev_token.uninterpolated_span()) } else { Safety::Default diff --git a/tests/ui/feature-gates/feature-gate-unsafe-extern-blocks.rs b/tests/ui/feature-gates/feature-gate-unsafe-extern-blocks.rs index eab134a4a4de4..3ea62e875b8e3 100644 --- a/tests/ui/feature-gates/feature-gate-unsafe-extern-blocks.rs +++ b/tests/ui/feature-gates/feature-gate-unsafe-extern-blocks.rs @@ -2,4 +2,12 @@ unsafe extern "C" { //~^ ERROR extern block cannot be declared unsafe } +// We can't gate `unsafe extern` blocks themselves since they were previously +// allowed, but we should gate the `safe` soft keyword. +#[cfg(any())] +unsafe extern "C" { + safe fn foo(); + //~^ ERROR `unsafe extern {}` blocks and `safe` keyword are experimental +} + fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-unsafe-extern-blocks.stderr b/tests/ui/feature-gates/feature-gate-unsafe-extern-blocks.stderr index 7e9b199a2db55..84f00827c6010 100644 --- a/tests/ui/feature-gates/feature-gate-unsafe-extern-blocks.stderr +++ b/tests/ui/feature-gates/feature-gate-unsafe-extern-blocks.stderr @@ -4,5 +4,16 @@ error: extern block cannot be declared unsafe LL | unsafe extern "C" { | ^^^^^^ -error: aborting due to 1 previous error +error[E0658]: `unsafe extern {}` blocks and `safe` keyword are experimental + --> $DIR/feature-gate-unsafe-extern-blocks.rs:9:5 + | +LL | safe fn foo(); + | ^^^^ + | + = note: see issue #123743 for more information + = help: add `#![feature(unsafe_extern_blocks)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0658`. From aa82d2e49246ee4ca2baa6f4989dea1267af39fd Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 27 Jun 2024 08:05:07 +0200 Subject: [PATCH 2/6] Switch back `non_local_definitions` lint to allow-by-default as request T-lang is requesting some major changes in the lint inner workings in #126768#issuecomment-2192634762 (cherry picked from commit 0c0dfb88eeefbbaa4c10cfa4a7f0e16541e086eb) --- compiler/rustc_lint/src/non_local_def.rs | 2 +- tests/rustdoc-ui/doctest/non_local_defs.rs | 2 + .../rustdoc-ui/doctest/non_local_defs.stderr | 8 ++- .../rustdoc-ui/doctest/non_local_defs.stdout | 2 +- tests/ui/lint/non-local-defs/cargo-update.rs | 2 + .../lint/non-local-defs/cargo-update.stderr | 8 ++- tests/ui/lint/non-local-defs/consts.rs | 2 + tests/ui/lint/non-local-defs/consts.stderr | 22 ++++--- .../lint/non-local-defs/exhaustive-trait.rs | 2 + .../non-local-defs/exhaustive-trait.stderr | 18 +++--- tests/ui/lint/non-local-defs/exhaustive.rs | 2 + .../ui/lint/non-local-defs/exhaustive.stderr | 58 ++++++++++--------- .../non-local-defs/from-local-for-global.rs | 2 + .../from-local-for-global.stderr | 24 ++++---- tests/ui/lint/non-local-defs/generics.rs | 2 + tests/ui/lint/non-local-defs/generics.stderr | 36 +++++++----- .../lint/non-local-defs/inside-macro_rules.rs | 2 + .../non-local-defs/inside-macro_rules.stderr | 8 ++- tests/ui/lint/non-local-defs/local.rs | 2 + tests/ui/lint/non-local-defs/macro_rules.rs | 2 + .../ui/lint/non-local-defs/macro_rules.stderr | 14 +++-- .../non-local-defs/suggest-moving-inner.rs | 2 + .../suggest-moving-inner.stderr | 10 +++- .../trait-solver-overflow-123573.rs | 2 + .../trait-solver-overflow-123573.stderr | 10 +++- tests/ui/lint/non-local-defs/weird-exprs.rs | 2 + .../ui/lint/non-local-defs/weird-exprs.stderr | 18 +++--- 27 files changed, 169 insertions(+), 95 deletions(-) diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index d7ffc34d824fd..c8965801b94db 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -50,7 +50,7 @@ declare_lint! { /// All nested bodies (functions, enum discriminant, array length, consts) (expect for /// `const _: Ty = { ... }` in top-level module, which is still undecided) are checked. pub NON_LOCAL_DEFINITIONS, - Warn, + Allow, "checks for non-local definitions", report_in_external_macro } diff --git a/tests/rustdoc-ui/doctest/non_local_defs.rs b/tests/rustdoc-ui/doctest/non_local_defs.rs index aa166c343b2b0..d8cfe5637ae02 100644 --- a/tests/rustdoc-ui/doctest/non_local_defs.rs +++ b/tests/rustdoc-ui/doctest/non_local_defs.rs @@ -4,6 +4,8 @@ //@ normalize-stderr-test: "tests/rustdoc-ui/doctest" -> "$$DIR" //@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME" +#![doc(test(attr(warn(non_local_definitions))))] + //! ``` //! #[macro_export] //! macro_rules! a_macro { () => {} } diff --git a/tests/rustdoc-ui/doctest/non_local_defs.stderr b/tests/rustdoc-ui/doctest/non_local_defs.stderr index 2b47e6b5bc4d5..13cd2558793f8 100644 --- a/tests/rustdoc-ui/doctest/non_local_defs.stderr +++ b/tests/rustdoc-ui/doctest/non_local_defs.stderr @@ -1,5 +1,5 @@ warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module - --> $DIR/non_local_defs.rs:9:1 + --> $DIR/non_local_defs.rs:11:1 | LL | macro_rules! a_macro { () => {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,7 +7,11 @@ LL | macro_rules! a_macro { () => {} } = help: remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() { ... }` = note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue - = note: `#[warn(non_local_definitions)]` on by default +note: the lint level is defined here + --> $DIR/non_local_defs.rs:8:9 + | +LL | #![warn(non_local_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^ warning: 1 warning emitted diff --git a/tests/rustdoc-ui/doctest/non_local_defs.stdout b/tests/rustdoc-ui/doctest/non_local_defs.stdout index bee195fcdd772..61b4074886e4b 100644 --- a/tests/rustdoc-ui/doctest/non_local_defs.stdout +++ b/tests/rustdoc-ui/doctest/non_local_defs.stdout @@ -1,6 +1,6 @@ running 1 test -test $DIR/non_local_defs.rs - (line 7) ... ok +test $DIR/non_local_defs.rs - (line 9) ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME diff --git a/tests/ui/lint/non-local-defs/cargo-update.rs b/tests/ui/lint/non-local-defs/cargo-update.rs index 8b8c15795d376..3c62a655a9f61 100644 --- a/tests/ui/lint/non-local-defs/cargo-update.rs +++ b/tests/ui/lint/non-local-defs/cargo-update.rs @@ -10,6 +10,8 @@ // of the `cargo update` suggestion we assert it here. //@ error-pattern: `cargo update -p non_local_macro` +#![warn(non_local_definitions)] + extern crate non_local_macro; struct LocalStruct; diff --git a/tests/ui/lint/non-local-defs/cargo-update.stderr b/tests/ui/lint/non-local-defs/cargo-update.stderr index 888fd2e61837f..f9e55d4ad7f55 100644 --- a/tests/ui/lint/non-local-defs/cargo-update.stderr +++ b/tests/ui/lint/non-local-defs/cargo-update.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/cargo-update.rs:17:1 + --> $DIR/cargo-update.rs:19:1 | LL | non_local_macro::non_local_impl!(LocalStruct); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,11 @@ LL | non_local_macro::non_local_impl!(LocalStruct); = note: the macro `non_local_macro::non_local_impl` may come from an old version of the `non_local_macro` crate, try updating your dependency with `cargo update -p non_local_macro` = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue - = note: `#[warn(non_local_definitions)]` on by default +note: the lint level is defined here + --> $DIR/cargo-update.rs:13:9 + | +LL | #![warn(non_local_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^ = note: this warning originates in the macro `non_local_macro::non_local_impl` (in Nightly builds, run with -Z macro-backtrace for more info) warning: 1 warning emitted diff --git a/tests/ui/lint/non-local-defs/consts.rs b/tests/ui/lint/non-local-defs/consts.rs index d8a497e43e502..e7ee611529b96 100644 --- a/tests/ui/lint/non-local-defs/consts.rs +++ b/tests/ui/lint/non-local-defs/consts.rs @@ -2,6 +2,8 @@ //@ edition:2021 //@ rustc-env:CARGO_CRATE_NAME=non_local_def +#![warn(non_local_definitions)] + struct Test; trait Uto {} diff --git a/tests/ui/lint/non-local-defs/consts.stderr b/tests/ui/lint/non-local-defs/consts.stderr index 2756ea4013877..ae46cc23fc977 100644 --- a/tests/ui/lint/non-local-defs/consts.stderr +++ b/tests/ui/lint/non-local-defs/consts.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:13:5 + --> $DIR/consts.rs:15:5 | LL | const Z: () = { | ----------- @@ -17,10 +17,14 @@ LL | impl Uto for &Test {} = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue - = note: `#[warn(non_local_definitions)]` on by default +note: the lint level is defined here + --> $DIR/consts.rs:5:9 + | +LL | #![warn(non_local_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:24:5 + --> $DIR/consts.rs:26:5 | LL | static A: u32 = { | ------------- move the `impl` block outside of this static `A` @@ -36,7 +40,7 @@ LL | impl Uto2 for Test {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:32:5 + --> $DIR/consts.rs:34:5 | LL | const B: u32 = { | ------------ move the `impl` block outside of this constant `B` @@ -52,7 +56,7 @@ LL | impl Uto3 for Test {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:43:5 + --> $DIR/consts.rs:45:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -65,7 +69,7 @@ LL | impl Test { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:50:9 + --> $DIR/consts.rs:52:9 | LL | const { | ___________- @@ -84,7 +88,7 @@ LL | | }; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:59:9 + --> $DIR/consts.rs:61:9 | LL | const _: u32 = { | ------------ move the `impl` block outside of this constant `_` and up 2 bodies @@ -98,7 +102,7 @@ LL | impl Test { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:72:9 + --> $DIR/consts.rs:74:9 | LL | let _a = || { | -- move the `impl` block outside of this closure `` and up 2 bodies @@ -113,7 +117,7 @@ LL | impl Uto9 for Test {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/consts.rs:79:9 + --> $DIR/consts.rs:81:9 | LL | type A = [u32; { | ____________________- diff --git a/tests/ui/lint/non-local-defs/exhaustive-trait.rs b/tests/ui/lint/non-local-defs/exhaustive-trait.rs index 40d2314460f86..79f8cc4620b97 100644 --- a/tests/ui/lint/non-local-defs/exhaustive-trait.rs +++ b/tests/ui/lint/non-local-defs/exhaustive-trait.rs @@ -1,6 +1,8 @@ //@ check-pass //@ edition:2021 +#![warn(non_local_definitions)] + struct Dog; fn main() { diff --git a/tests/ui/lint/non-local-defs/exhaustive-trait.stderr b/tests/ui/lint/non-local-defs/exhaustive-trait.stderr index 67df0e31d5bdf..24c9a6b4f01e2 100644 --- a/tests/ui/lint/non-local-defs/exhaustive-trait.stderr +++ b/tests/ui/lint/non-local-defs/exhaustive-trait.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive-trait.rs:7:5 + --> $DIR/exhaustive-trait.rs:9:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -12,10 +12,14 @@ LL | impl PartialEq<()> for Dog { = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue - = note: `#[warn(non_local_definitions)]` on by default +note: the lint level is defined here + --> $DIR/exhaustive-trait.rs:4:9 + | +LL | #![warn(non_local_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive-trait.rs:14:5 + --> $DIR/exhaustive-trait.rs:16:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -31,7 +35,7 @@ LL | impl PartialEq<()> for &Dog { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive-trait.rs:21:5 + --> $DIR/exhaustive-trait.rs:23:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -47,7 +51,7 @@ LL | impl PartialEq for () { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive-trait.rs:28:5 + --> $DIR/exhaustive-trait.rs:30:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -63,7 +67,7 @@ LL | impl PartialEq<&Dog> for () { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive-trait.rs:35:5 + --> $DIR/exhaustive-trait.rs:37:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -79,7 +83,7 @@ LL | impl PartialEq for &Dog { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive-trait.rs:42:5 + --> $DIR/exhaustive-trait.rs:44:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` diff --git a/tests/ui/lint/non-local-defs/exhaustive.rs b/tests/ui/lint/non-local-defs/exhaustive.rs index 2fb30f4344abb..f59a85c7ed94f 100644 --- a/tests/ui/lint/non-local-defs/exhaustive.rs +++ b/tests/ui/lint/non-local-defs/exhaustive.rs @@ -1,6 +1,8 @@ //@ check-pass //@ edition:2021 +#![warn(non_local_definitions)] + use std::fmt::Display; trait Trait {} diff --git a/tests/ui/lint/non-local-defs/exhaustive.stderr b/tests/ui/lint/non-local-defs/exhaustive.stderr index 1e0d5caec3830..6d8c2ec0bc7cf 100644 --- a/tests/ui/lint/non-local-defs/exhaustive.stderr +++ b/tests/ui/lint/non-local-defs/exhaustive.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:10:5 + --> $DIR/exhaustive.rs:12:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -10,10 +10,14 @@ LL | impl Test { | = note: methods and associated constants are still usable outside the current expression, only `impl Local` and `impl dyn Local` can ever be private, and only if the type is nested in the same item as the `impl` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue - = note: `#[warn(non_local_definitions)]` on by default +note: the lint level is defined here + --> $DIR/exhaustive.rs:4:9 + | +LL | #![warn(non_local_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:15:5 + --> $DIR/exhaustive.rs:17:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -29,7 +33,7 @@ LL | impl Display for Test { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:22:5 + --> $DIR/exhaustive.rs:24:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -43,7 +47,7 @@ LL | impl dyn Trait {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:25:5 + --> $DIR/exhaustive.rs:27:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -59,7 +63,7 @@ LL | impl Trait for Vec { } = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:28:5 + --> $DIR/exhaustive.rs:30:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -75,7 +79,7 @@ LL | impl Trait for &dyn Trait {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:31:5 + --> $DIR/exhaustive.rs:33:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -91,7 +95,7 @@ LL | impl Trait for *mut Test {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:34:5 + --> $DIR/exhaustive.rs:36:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -107,7 +111,7 @@ LL | impl Trait for *mut [Test] {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:37:5 + --> $DIR/exhaustive.rs:39:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -123,7 +127,7 @@ LL | impl Trait for [Test; 8] {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:40:5 + --> $DIR/exhaustive.rs:42:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -139,7 +143,7 @@ LL | impl Trait for (Test,) {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:43:5 + --> $DIR/exhaustive.rs:45:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -155,7 +159,7 @@ LL | impl Trait for fn(Test) -> () {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:46:5 + --> $DIR/exhaustive.rs:48:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -171,7 +175,7 @@ LL | impl Trait for fn() -> Test {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:50:9 + --> $DIR/exhaustive.rs:52:9 | LL | let _a = || { | -- move the `impl` block outside of this closure `` and up 2 bodies @@ -186,7 +190,7 @@ LL | impl Trait for Test {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:58:5 + --> $DIR/exhaustive.rs:60:5 | LL | impl Trait for *mut InsideMain {} | ^^^^^-----^^^^^--------------- @@ -198,7 +202,7 @@ LL | impl Trait for *mut InsideMain {} = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:9:1 + --> $DIR/exhaustive.rs:11:1 | LL | fn main() { | ^^^^^^^^^ @@ -208,7 +212,7 @@ LL | struct InsideMain; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:60:5 + --> $DIR/exhaustive.rs:62:5 | LL | impl Trait for *mut [InsideMain] {} | ^^^^^-----^^^^^----------------- @@ -219,7 +223,7 @@ LL | impl Trait for *mut [InsideMain] {} = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:9:1 + --> $DIR/exhaustive.rs:11:1 | LL | fn main() { | ^^^^^^^^^ @@ -229,7 +233,7 @@ LL | struct InsideMain; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:62:5 + --> $DIR/exhaustive.rs:64:5 | LL | impl Trait for [InsideMain; 8] {} | ^^^^^-----^^^^^--------------- @@ -240,7 +244,7 @@ LL | impl Trait for [InsideMain; 8] {} = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:9:1 + --> $DIR/exhaustive.rs:11:1 | LL | fn main() { | ^^^^^^^^^ @@ -250,7 +254,7 @@ LL | struct InsideMain; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:64:5 + --> $DIR/exhaustive.rs:66:5 | LL | impl Trait for (InsideMain,) {} | ^^^^^-----^^^^^------------- @@ -261,7 +265,7 @@ LL | impl Trait for (InsideMain,) {} = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:9:1 + --> $DIR/exhaustive.rs:11:1 | LL | fn main() { | ^^^^^^^^^ @@ -271,7 +275,7 @@ LL | struct InsideMain; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:66:5 + --> $DIR/exhaustive.rs:68:5 | LL | impl Trait for fn(InsideMain) -> () {} | ^^^^^-----^^^^^-------------------- @@ -282,7 +286,7 @@ LL | impl Trait for fn(InsideMain) -> () {} = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:9:1 + --> $DIR/exhaustive.rs:11:1 | LL | fn main() { | ^^^^^^^^^ @@ -292,7 +296,7 @@ LL | struct InsideMain; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:68:5 + --> $DIR/exhaustive.rs:70:5 | LL | impl Trait for fn() -> InsideMain {} | ^^^^^-----^^^^^------------------ @@ -303,7 +307,7 @@ LL | impl Trait for fn() -> InsideMain {} = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `main` - --> $DIR/exhaustive.rs:9:1 + --> $DIR/exhaustive.rs:11:1 | LL | fn main() { | ^^^^^^^^^ @@ -313,7 +317,7 @@ LL | struct InsideMain; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:72:9 + --> $DIR/exhaustive.rs:74:9 | LL | fn inside_inside() { | ------------------ move the `impl` block outside of this function `inside_inside` and up 2 bodies @@ -328,7 +332,7 @@ LL | impl Display for InsideMain { = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/exhaustive.rs:79:9 + --> $DIR/exhaustive.rs:81:9 | LL | fn inside_inside() { | ------------------ move the `impl` block outside of this function `inside_inside` and up 2 bodies diff --git a/tests/ui/lint/non-local-defs/from-local-for-global.rs b/tests/ui/lint/non-local-defs/from-local-for-global.rs index fea9679d7375d..1d8f4845c2860 100644 --- a/tests/ui/lint/non-local-defs/from-local-for-global.rs +++ b/tests/ui/lint/non-local-defs/from-local-for-global.rs @@ -1,6 +1,8 @@ //@ check-pass //@ edition:2021 +#![warn(non_local_definitions)] + struct Cat; struct Wrap(T); diff --git a/tests/ui/lint/non-local-defs/from-local-for-global.stderr b/tests/ui/lint/non-local-defs/from-local-for-global.stderr index 67fd937d134cc..04eba8435fc04 100644 --- a/tests/ui/lint/non-local-defs/from-local-for-global.stderr +++ b/tests/ui/lint/non-local-defs/from-local-for-global.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/from-local-for-global.rs:8:5 + --> $DIR/from-local-for-global.rs:10:5 | LL | fn main() { | --------- move the `impl` block outside of this function `main` @@ -12,10 +12,14 @@ LL | impl From for () { = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue - = note: `#[warn(non_local_definitions)]` on by default +note: the lint level is defined here + --> $DIR/from-local-for-global.rs:4:9 + | +LL | #![warn(non_local_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/from-local-for-global.rs:18:5 + --> $DIR/from-local-for-global.rs:20:5 | LL | impl From>> for () { | ^^^^^----^^^^^^^^^^^^^^^^^^^^^^^^^^^-- @@ -25,7 +29,7 @@ LL | impl From>> for () { = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `main` - --> $DIR/from-local-for-global.rs:7:1 + --> $DIR/from-local-for-global.rs:9:1 | LL | fn main() { | ^^^^^^^^^ @@ -35,7 +39,7 @@ LL | struct Elephant; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/from-local-for-global.rs:32:5 + --> $DIR/from-local-for-global.rs:34:5 | LL | impl StillNonLocal for &Foo {} | ^^^^^-------------^^^^^---- @@ -47,7 +51,7 @@ LL | impl StillNonLocal for &Foo {} = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `only_global` - --> $DIR/from-local-for-global.rs:30:1 + --> $DIR/from-local-for-global.rs:32:1 | LL | fn only_global() { | ^^^^^^^^^^^^^^^^ @@ -56,7 +60,7 @@ LL | struct Foo; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/from-local-for-global.rs:40:5 + --> $DIR/from-local-for-global.rs:42:5 | LL | impl From for GlobalSameFunction { | ^^^^^----^^^^^^^^^^^^^------------------ @@ -67,7 +71,7 @@ LL | impl From for GlobalSameFunction { = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `same_function` - --> $DIR/from-local-for-global.rs:38:1 + --> $DIR/from-local-for-global.rs:40:1 | LL | fn same_function() { | ^^^^^^^^^^^^^^^^^^ @@ -76,7 +80,7 @@ LL | struct Local1(GlobalSameFunction); = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/from-local-for-global.rs:48:5 + --> $DIR/from-local-for-global.rs:50:5 | LL | impl From for GlobalSameFunction { | ^^^^^----^^^^^^^^^^^^^------------------ @@ -87,7 +91,7 @@ LL | impl From for GlobalSameFunction { = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `same_function` - --> $DIR/from-local-for-global.rs:38:1 + --> $DIR/from-local-for-global.rs:40:1 | LL | fn same_function() { | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/non-local-defs/generics.rs b/tests/ui/lint/non-local-defs/generics.rs index 0f526526dba21..13e392c510c64 100644 --- a/tests/ui/lint/non-local-defs/generics.rs +++ b/tests/ui/lint/non-local-defs/generics.rs @@ -1,6 +1,8 @@ //@ check-pass //@ edition:2021 +#![warn(non_local_definitions)] + trait Global {} fn main() { diff --git a/tests/ui/lint/non-local-defs/generics.stderr b/tests/ui/lint/non-local-defs/generics.stderr index ed2f87a4ed2d2..35366ed8ecf94 100644 --- a/tests/ui/lint/non-local-defs/generics.stderr +++ b/tests/ui/lint/non-local-defs/generics.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:9:5 + --> $DIR/generics.rs:11:5 | LL | impl Global for Vec { } | ^^^^^^^^^^^^^^^------^^^^^---^^^ @@ -10,17 +10,21 @@ LL | impl Global for Vec { } = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `main` - --> $DIR/generics.rs:6:1 + --> $DIR/generics.rs:8:1 | LL | fn main() { | ^^^^^^^^^ LL | trait Local {}; | ----------- may need to be moved as well = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue - = note: `#[warn(non_local_definitions)]` on by default +note: the lint level is defined here + --> $DIR/generics.rs:4:9 + | +LL | #![warn(non_local_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:20:5 + --> $DIR/generics.rs:22:5 | LL | impl Uto7 for Test where Local: std::any::Any {} | ^^^^^----^^^^^---- @@ -31,7 +35,7 @@ LL | impl Uto7 for Test where Local: std::any::Any {} = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `bad` - --> $DIR/generics.rs:18:1 + --> $DIR/generics.rs:20:1 | LL | fn bad() { | ^^^^^^^^ @@ -40,7 +44,7 @@ LL | struct Local; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:23:5 + --> $DIR/generics.rs:25:5 | LL | fn bad() { | -------- move the `impl` block outside of this function `bad` @@ -56,7 +60,7 @@ LL | impl Uto8 for T {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:32:5 + --> $DIR/generics.rs:34:5 | LL | impl Default for UwU { | ^^^^^-------^^^^^---^^^^^ @@ -67,7 +71,7 @@ LL | impl Default for UwU { = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `fun` - --> $DIR/generics.rs:29:1 + --> $DIR/generics.rs:31:1 | LL | fn fun() { | ^^^^^^^^ @@ -77,7 +81,7 @@ LL | struct OwO; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:43:5 + --> $DIR/generics.rs:45:5 | LL | impl AsRef for () { | ^^^^^-----^^^^^^^^^^-- @@ -88,7 +92,7 @@ LL | impl AsRef for () { = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `meow` - --> $DIR/generics.rs:40:1 + --> $DIR/generics.rs:42:1 | LL | fn meow() { | ^^^^^^^^^ @@ -98,7 +102,7 @@ LL | struct Cat; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:54:5 + --> $DIR/generics.rs:56:5 | LL | impl PartialEq for G { | ^^^^^---------^^^^^^^^- @@ -109,7 +113,7 @@ LL | impl PartialEq for G { = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `fun2` - --> $DIR/generics.rs:51:1 + --> $DIR/generics.rs:53:1 | LL | fn fun2() { | ^^^^^^^^^ @@ -119,7 +123,7 @@ LL | struct B; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:69:5 + --> $DIR/generics.rs:71:5 | LL | impl From>> for () { | ^^^^^----^^^^^^^^^^^^^^^^^^^^^^^-- @@ -129,7 +133,7 @@ LL | impl From>> for () { = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `rawr` - --> $DIR/generics.rs:66:1 + --> $DIR/generics.rs:68:1 | LL | fn rawr() { | ^^^^^^^^^ @@ -138,7 +142,7 @@ LL | struct Lion; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/generics.rs:76:5 + --> $DIR/generics.rs:78:5 | LL | impl From<()> for Wrap { | ^^^^^----^^^^^^^^^----^^^^^^ @@ -149,7 +153,7 @@ LL | impl From<()> for Wrap { = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `rawr` - --> $DIR/generics.rs:66:1 + --> $DIR/generics.rs:68:1 | LL | fn rawr() { | ^^^^^^^^^ diff --git a/tests/ui/lint/non-local-defs/inside-macro_rules.rs b/tests/ui/lint/non-local-defs/inside-macro_rules.rs index 9f21cc89852e2..744a1f7a6f1ab 100644 --- a/tests/ui/lint/non-local-defs/inside-macro_rules.rs +++ b/tests/ui/lint/non-local-defs/inside-macro_rules.rs @@ -1,6 +1,8 @@ //@ check-pass //@ edition:2021 +#![warn(non_local_definitions)] + macro_rules! m { () => { trait MacroTrait {} diff --git a/tests/ui/lint/non-local-defs/inside-macro_rules.stderr b/tests/ui/lint/non-local-defs/inside-macro_rules.stderr index b52301d1aa086..fc6c0c8e57a2e 100644 --- a/tests/ui/lint/non-local-defs/inside-macro_rules.stderr +++ b/tests/ui/lint/non-local-defs/inside-macro_rules.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/inside-macro_rules.rs:9:13 + --> $DIR/inside-macro_rules.rs:11:13 | LL | fn my_func() { | ------------ move the `impl` block outside of this function `my_func` @@ -15,7 +15,11 @@ LL | m!(); = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue - = note: `#[warn(non_local_definitions)]` on by default +note: the lint level is defined here + --> $DIR/inside-macro_rules.rs:4:9 + | +LL | #![warn(non_local_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^ = note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) warning: 1 warning emitted diff --git a/tests/ui/lint/non-local-defs/local.rs b/tests/ui/lint/non-local-defs/local.rs index 166ee88c0210c..e9dbff1300f28 100644 --- a/tests/ui/lint/non-local-defs/local.rs +++ b/tests/ui/lint/non-local-defs/local.rs @@ -1,6 +1,8 @@ //@ check-pass //@ edition:2021 +#![warn(non_local_definitions)] + use std::fmt::Debug; trait GlobalTrait {} diff --git a/tests/ui/lint/non-local-defs/macro_rules.rs b/tests/ui/lint/non-local-defs/macro_rules.rs index ed30a24903d01..20672cf0a3225 100644 --- a/tests/ui/lint/non-local-defs/macro_rules.rs +++ b/tests/ui/lint/non-local-defs/macro_rules.rs @@ -3,6 +3,8 @@ //@ aux-build:non_local_macro.rs //@ rustc-env:CARGO_CRATE_NAME=non_local_def +#![warn(non_local_definitions)] + extern crate non_local_macro; const B: u32 = { diff --git a/tests/ui/lint/non-local-defs/macro_rules.stderr b/tests/ui/lint/non-local-defs/macro_rules.stderr index 4e86fc7b987e6..f9995bf82183c 100644 --- a/tests/ui/lint/non-local-defs/macro_rules.stderr +++ b/tests/ui/lint/non-local-defs/macro_rules.stderr @@ -1,5 +1,5 @@ warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module - --> $DIR/macro_rules.rs:10:5 + --> $DIR/macro_rules.rs:12:5 | LL | macro_rules! m0 { () => { } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,10 +7,14 @@ LL | macro_rules! m0 { () => { } }; = help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current constant `B` = note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue - = note: `#[warn(non_local_definitions)]` on by default +note: the lint level is defined here + --> $DIR/macro_rules.rs:6:9 + | +LL | #![warn(non_local_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^ warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module - --> $DIR/macro_rules.rs:16:1 + --> $DIR/macro_rules.rs:18:1 | LL | non_local_macro::non_local_macro_rules!(my_macro); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -22,7 +26,7 @@ LL | non_local_macro::non_local_macro_rules!(my_macro); = note: this warning originates in the macro `non_local_macro::non_local_macro_rules` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module - --> $DIR/macro_rules.rs:21:5 + --> $DIR/macro_rules.rs:23:5 | LL | macro_rules! m { () => { } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -32,7 +36,7 @@ LL | macro_rules! m { () => { } }; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module - --> $DIR/macro_rules.rs:29:13 + --> $DIR/macro_rules.rs:31:13 | LL | macro_rules! m2 { () => { } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/non-local-defs/suggest-moving-inner.rs b/tests/ui/lint/non-local-defs/suggest-moving-inner.rs index 61b32e5bad9fe..9360ace4d805b 100644 --- a/tests/ui/lint/non-local-defs/suggest-moving-inner.rs +++ b/tests/ui/lint/non-local-defs/suggest-moving-inner.rs @@ -1,5 +1,7 @@ //@ check-pass +#![warn(non_local_definitions)] + trait Trait {} fn main() { diff --git a/tests/ui/lint/non-local-defs/suggest-moving-inner.stderr b/tests/ui/lint/non-local-defs/suggest-moving-inner.stderr index f0de0f72e74f6..a214415316f84 100644 --- a/tests/ui/lint/non-local-defs/suggest-moving-inner.stderr +++ b/tests/ui/lint/non-local-defs/suggest-moving-inner.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/suggest-moving-inner.rs:12:5 + --> $DIR/suggest-moving-inner.rs:14:5 | LL | impl Trait for &Vec> | ^^^^^^^^-----^^^^^^^^^^^^^^^^^---------------------------------- @@ -10,7 +10,7 @@ LL | impl Trait for &Vec> = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `main` - --> $DIR/suggest-moving-inner.rs:5:1 + --> $DIR/suggest-moving-inner.rs:7:1 | LL | fn main() { | ^^^^^^^^^ @@ -23,7 +23,11 @@ LL | struct InsideMain; LL | trait HasFoo {} | ------------ may need to be moved as well = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue - = note: `#[warn(non_local_definitions)]` on by default +note: the lint level is defined here + --> $DIR/suggest-moving-inner.rs:3:9 + | +LL | #![warn(non_local_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^ warning: 1 warning emitted diff --git a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs index 4291426e046a8..b726398bf9c9a 100644 --- a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs +++ b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs @@ -3,6 +3,8 @@ // https://github.com/rust-lang/rust/issues/123573#issue-2229428739 +#![warn(non_local_definitions)] + pub trait Test {} impl<'a, T: 'a> Test for &[T] where &'a T: Test {} diff --git a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr index 80930ce1bcdf3..2eb71cecacaaf 100644 --- a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr +++ b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/trait-solver-overflow-123573.rs:12:5 + --> $DIR/trait-solver-overflow-123573.rs:14:5 | LL | impl Test for &Local {} | ^^^^^----^^^^^------ @@ -11,14 +11,18 @@ LL | impl Test for &Local {} = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` help: move the `impl` block outside of this function `main` - --> $DIR/trait-solver-overflow-123573.rs:10:1 + --> $DIR/trait-solver-overflow-123573.rs:12:1 | LL | fn main() { | ^^^^^^^^^ LL | struct Local {} | ------------ may need to be moved as well = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue - = note: `#[warn(non_local_definitions)]` on by default +note: the lint level is defined here + --> $DIR/trait-solver-overflow-123573.rs:6:9 + | +LL | #![warn(non_local_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^ warning: 1 warning emitted diff --git a/tests/ui/lint/non-local-defs/weird-exprs.rs b/tests/ui/lint/non-local-defs/weird-exprs.rs index 1d9cecea0c971..fbf1fd941eecb 100644 --- a/tests/ui/lint/non-local-defs/weird-exprs.rs +++ b/tests/ui/lint/non-local-defs/weird-exprs.rs @@ -1,6 +1,8 @@ //@ check-pass //@ edition:2021 +#![warn(non_local_definitions)] + trait Uto {} struct Test; diff --git a/tests/ui/lint/non-local-defs/weird-exprs.stderr b/tests/ui/lint/non-local-defs/weird-exprs.stderr index cd414d636d34b..49aba904ebb0e 100644 --- a/tests/ui/lint/non-local-defs/weird-exprs.stderr +++ b/tests/ui/lint/non-local-defs/weird-exprs.stderr @@ -1,5 +1,5 @@ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/weird-exprs.rs:8:5 + --> $DIR/weird-exprs.rs:10:5 | LL | type A = [u32; { | ________________- @@ -16,10 +16,14 @@ LL | | }]; = note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue - = note: `#[warn(non_local_definitions)]` on by default +note: the lint level is defined here + --> $DIR/weird-exprs.rs:4:9 + | +LL | #![warn(non_local_definitions)] + | ^^^^^^^^^^^^^^^^^^^^^ warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/weird-exprs.rs:16:9 + --> $DIR/weird-exprs.rs:18:9 | LL | Discr = { | _____________- @@ -38,7 +42,7 @@ LL | | } = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/weird-exprs.rs:25:9 + --> $DIR/weird-exprs.rs:27:9 | LL | let _array = [0i32; { | _________________________- @@ -57,7 +61,7 @@ LL | | }]; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/weird-exprs.rs:34:9 + --> $DIR/weird-exprs.rs:36:9 | LL | type A = [u32; { | ____________________- @@ -76,7 +80,7 @@ LL | | }]; = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/weird-exprs.rs:41:9 + --> $DIR/weird-exprs.rs:43:9 | LL | fn a(_: [u32; { | ___________________- @@ -95,7 +99,7 @@ LL | | }]) {} = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item - --> $DIR/weird-exprs.rs:48:9 + --> $DIR/weird-exprs.rs:50:9 | LL | fn b() -> [u32; { | _____________________- From e1f26a62602e27f5c9f5e0005f286523a16b0ce3 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 27 Jun 2024 19:54:28 -0400 Subject: [PATCH 3/6] Failing test for computing drop shim that has const param (cherry picked from commit 90c2b238e6a38e3309a7ffc1162e6361db14ffdd) --- .../const-generics/polymorphic-drop-shim.rs | 21 ++ .../polymorphic-drop-shim.stderr | 257 ++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100644 tests/ui/const-generics/polymorphic-drop-shim.rs create mode 100644 tests/ui/const-generics/polymorphic-drop-shim.stderr diff --git a/tests/ui/const-generics/polymorphic-drop-shim.rs b/tests/ui/const-generics/polymorphic-drop-shim.rs new file mode 100644 index 0000000000000..97ade9fe69a30 --- /dev/null +++ b/tests/ui/const-generics/polymorphic-drop-shim.rs @@ -0,0 +1,21 @@ +//@ compile-flags: -Zinline-mir=yes --crate-type=lib + +//@ known-bug: unknown +//@ build-fail +//@ failure-status: 101 + +use std::mem::ManuallyDrop; + +pub struct Foo([T; N]); + +pub struct Dorp {} + +impl Drop for Dorp { + fn drop(&mut self) {} +} + +#[inline] +// SAFETY: call this with a valid allocation idk +pub unsafe fn drop(x: *mut Foo) { + std::ptr::drop_in_place(x); +} diff --git a/tests/ui/const-generics/polymorphic-drop-shim.stderr b/tests/ui/const-generics/polymorphic-drop-shim.stderr new file mode 100644 index 0000000000000..3a445a524097d --- /dev/null +++ b/tests/ui/const-generics/polymorphic-drop-shim.stderr @@ -0,0 +1,257 @@ +thread 'rustc' panicked at compiler/rustc_middle/src/ty/sty.rs:360:36: +called `Option::unwrap()` on a `None` value +stack backtrace: + 0: begin_panic_handler + at ./library/std/src/panicking.rs:661:5 + 1: panic_fmt + at ./library/core/src/panicking.rs:74:14 + 2: panic + at ./library/core/src/panicking.rs:148:5 + 3: core::option::unwrap_failed + at ./library/core/src/option.rs:2013:5 + 4: unwrap + at ./library/core/src/option.rs:963:21 + 5: find_ty_from_env + at ./compiler/rustc_middle/src/ty/sty.rs:360:18 + 6: {closure#0} + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1016:29 + 7: maybe_grow, rustc_trait_selection::traits::select::{impl#1}::evaluate_predicate_recursively::{closure#0}::{closure_env#0}> + at /home/michael/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stacker-0.1.15/src/lib.rs:55:9 + 8: ensure_sufficient_stack, rustc_trait_selection::traits::select::{impl#1}::evaluate_predicate_recursively::{closure#0}::{closure_env#0}> + at ./compiler/rustc_data_structures/src/stack.rs:17:5 + 9: {closure#0} + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:664:9 + 10: evaluate_predicate_recursively + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:643:5 + 11: evaluate_predicates_recursively, alloc::alloc::Global>> + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:631:24 + 12: {closure#0} + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1317:21 + 13: {closure#0} + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:596:26 + 14: probe, rustc_trait_selection::traits::select::{impl#1}::evaluation_probe::{closure_env#0}> + at ./compiler/rustc_infer/src/infer/snapshot/mod.rs:85:17 + 15: ::evaluation_probe::<::evaluate_candidate::{closure#0}::{closure#0}> + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:594:9 + 16: {closure#0} + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1298:26 + 17: evaluate_candidate + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1286:5 + 18: evaluate_stack + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1257:28 + 19: {closure#1} + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1083:30 + 20: {closure#0}> + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1445:88 + 21: with_anon_task>, core::result::Result> + at ./compiler/rustc_query_system/src/dep_graph/graph.rs:306:22 + 22: in_task> + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1445:13 + 23: {closure#0} + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1082:34 + 24: evaluate_trait_predicate_recursively + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1037:5 + 25: {closure#0} + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:671:21 + 26: maybe_grow, rustc_trait_selection::traits::select::{impl#1}::evaluate_predicate_recursively::{closure#0}::{closure_env#0}> + at /home/michael/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stacker-0.1.15/src/lib.rs:55:9 + 27: ensure_sufficient_stack, rustc_trait_selection::traits::select::{impl#1}::evaluate_predicate_recursively::{closure#0}::{closure_env#0}> + at ./compiler/rustc_data_structures/src/stack.rs:17:5 + 28: {closure#0} + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:664:9 + 29: evaluate_predicate_recursively + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:643:5 + 30: {closure#0} + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:572:30 + 31: {closure#0} + at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:596:26 + 32: probe, rustc_trait_selection::traits::select::{impl#1}::evaluation_probe::{closure_env#0}> + at ./compiler/rustc_infer/src/infer/snapshot/mod.rs:85:17 + 33: evaluate_obligation + at ./compiler/rustc_traits/src/evaluate_obligation.rs:29:5 + 34: {closure#0} + at ./compiler/rustc_query_impl/src/plumbing.rs:281:9 + [... omitted 22 frames ...] + 35: query_get_at>, rustc_middle::query::erase::Erased<[u8; 2]>>> + at ./compiler/rustc_middle/src/query/plumbing.rs:145:17 + 36: evaluate_obligation + at ./compiler/rustc_middle/src/query/plumbing.rs:423:31 + 37: evaluate_obligation + at ./compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs:93:13 + 38: evaluate_obligation_no_overflow + at ./compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs:107:15 + 39: {closure#0}> + at ./compiler/rustc_trait_selection/src/traits/mod.rs:221:18 + 40: pred_known_to_hold_modulo_regions> + at ./compiler/rustc_trait_selection/src/traits/mod.rs:213:1 + 41: rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions + at ./compiler/rustc_trait_selection/src/traits/mod.rs:206:5 + 42: rustc_ty_utils::common_traits::is_item_raw + at ./compiler/rustc_ty_utils/src/common_traits.rs:33:5 + 43: {closure#0} + at ./compiler/rustc_query_impl/src/plumbing.rs:281:9 + [... omitted 22 frames ...] + 44: query_get_at, rustc_middle::query::erase::Erased<[u8; 1]>>> + at ./compiler/rustc_middle/src/query/plumbing.rs:145:17 + 45: is_copy_raw + at ./compiler/rustc_middle/src/query/plumbing.rs:423:31 + 46: is_copy_raw + at ./compiler/rustc_middle/src/query/plumbing.rs:414:17 + 47: is_copy_modulo_regions + at ./compiler/rustc_middle/src/ty/util.rs:1243:48 + 48: next, alloc::vec::into_iter::IntoIter> + at ./compiler/rustc_ty_utils/src/needs_drop.rs:184:26 + 49: try_fold>, (), core::iter::traits::iterator::Iterator::find::check::{closure_env#0}, &mut rustc_ty_utils::needs_drop::filter_array_elements::{closure_env#0}>, core::ops::control_flow::ControlFlow, ()>> + at ./library/core/src/iter/traits/iterator.rs:2409:29 + 50: find>, &mut rustc_ty_utils::needs_drop::filter_array_elements::{closure_env#0}> + at ./library/core/src/iter/traits/iterator.rs:2880:9 + 51: next>, rustc_ty_utils::needs_drop::filter_array_elements::{closure_env#0}> + at ./library/core/src/iter/adapters/filter.rs:96:9 + 52: needs_drop_raw + at ./compiler/rustc_ty_utils/src/needs_drop.rs:24:15 + 53: {closure#0} + at ./compiler/rustc_query_impl/src/plumbing.rs:281:9 + [... omitted 22 frames ...] + 54: query_get_at, rustc_middle::query::erase::Erased<[u8; 1]>>> + at ./compiler/rustc_middle/src/query/plumbing.rs:145:17 + 55: needs_drop_raw + at ./compiler/rustc_middle/src/query/plumbing.rs:423:31 + 56: needs_drop_raw + at ./compiler/rustc_middle/src/query/plumbing.rs:414:17 + 57: needs_drop + at ./compiler/rustc_middle/src/ty/util.rs:1433:17 + 58: {closure#0} + at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:378:13 + 59: {closure#0}<(rustc_middle::mir::syntax::Place, core::option::Option<()>), alloc::alloc::Global, rustc_mir_dataflow::elaborate_drops::{impl#2}::drop_ladder::{closure_env#0}> + at ./library/alloc/src/vec/mod.rs:1683:32 + 60: process_loop), alloc::alloc::Global, rustc_mir_dataflow::elaborate_drops::{impl#2}::drop_ladder::{closure_env#0}>, (rustc_middle::mir::syntax::Place, core::option::Option<()>), alloc::alloc::Global, false> + at ./library/alloc/src/vec/mod.rs:1763:21 + 61: retain_mut<(rustc_middle::mir::syntax::Place, core::option::Option<()>), alloc::alloc::Global, alloc::vec::{impl#1}::retain::{closure_env#0}<(rustc_middle::mir::syntax::Place, core::option::Option<()>), alloc::alloc::Global, rustc_mir_dataflow::elaborate_drops::{impl#2}::drop_ladder::{closure_env#0}>> + at ./library/alloc/src/vec/mod.rs:1789:9 + 62: retain<(rustc_middle::mir::syntax::Place, core::option::Option<()>), alloc::alloc::Global, rustc_mir_dataflow::elaborate_drops::{impl#2}::drop_ladder::{closure_env#0}> + at ./library/alloc/src/vec/mod.rs:1683:9 + 63: drop_ladder + at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:377:9 + 64: open_drop_for_adt_contents + at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:488:13 + 65: {closure#0} + at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:461:13 + 66: open_drop_for_adt + at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:440:5 + 67: open_drop + at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:869:35 + 68: elaborate_drop + at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:253:31 + 69: rustc_mir_dataflow::elaborate_drops::elaborate_drop:: + at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:192:5 + 70: build_drop_shim + at ./compiler/rustc_mir_transform/src/shim.rs:283:13 + 71: make_shim + at ./compiler/rustc_mir_transform/src/shim.rs:128:13 + 72: {closure#0} + at ./compiler/rustc_query_impl/src/plumbing.rs:281:9 + [... omitted 22 frames ...] + 73: query_get_at>> + at ./compiler/rustc_middle/src/query/plumbing.rs:145:17 + 74: mir_shims + at ./compiler/rustc_middle/src/query/plumbing.rs:423:31 + 75: mir_shims + at ./compiler/rustc_middle/src/query/plumbing.rs:414:17 + 76: instance_mir + at ./compiler/rustc_middle/src/ty/mod.rs:1738:62 + 77: try_instance_mir + at ./compiler/rustc_mir_transform/src/inline.rs:1082:8 + 78: try_inlining + at ./compiler/rustc_mir_transform/src/inline.rs:194:27 + 79: process_blocks + at ./compiler/rustc_mir_transform/src/inline.rs:139:19 + 80: inline + at ./compiler/rustc_mir_transform/src/inline.rs:97:5 + 81: run_pass + at ./compiler/rustc_mir_transform/src/inline.rs:62:12 + 82: run_passes_inner + at ./compiler/rustc_mir_transform/src/pass_manager.rs:144:17 + 83: rustc_mir_transform::pass_manager::run_passes + at ./compiler/rustc_mir_transform/src/pass_manager.rs:87:5 + 84: run_optimization_passes + at ./compiler/rustc_mir_transform/src/lib.rs:561:5 + 85: inner_optimized_mir + at ./compiler/rustc_mir_transform/src/lib.rs:667:5 + 86: optimized_mir + at ./compiler/rustc_mir_transform/src/lib.rs:630:21 + 87: {closure#0} + at ./compiler/rustc_query_impl/src/plumbing.rs:285:13 + [... omitted 22 frames ...] + 88: query_get_at>> + at ./compiler/rustc_middle/src/query/plumbing.rs:145:17 + 89: optimized_mir + at ./compiler/rustc_middle/src/query/plumbing.rs:423:31 + 90: optimized_mir + at ./compiler/rustc_middle/src/query/plumbing.rs:414:17 + 91: encode_mir + at ./compiler/rustc_metadata/src/rmeta/encoder.rs:1656:74 + 92: {closure#15} + at ./compiler/rustc_metadata/src/rmeta/encoder.rs:639:29 + 93: encode_crate_root + at ./compiler/rustc_metadata/src/rmeta/encoder.rs:600:27 + 94: encode_metadata + at ./compiler/rustc_metadata/src/rmeta/encoder.rs:2269:16 + 95: encode_and_write_metadata + at ./compiler/rustc_metadata/src/fs.rs:65:13 + 96: start_codegen + at ./compiler/rustc_interface/src/passes.rs:1024:44 + 97: {closure#0} + at ./compiler/rustc_interface/src/queries.rs:122:35 + 98: {closure#1}> + at ./compiler/rustc_middle/src/ty/context.rs:1288:37 + 99: {closure#0}>, core::result::Result> + at ./compiler/rustc_middle/src/ty/context/tls.rs:82:9 + 100: try_with, rustc_middle::ty::context::tls::enter_context::{closure_env#0}>, core::result::Result>, core::result::Result> + at ./library/std/src/thread/local.rs:283:12 + 101: with, rustc_middle::ty::context::tls::enter_context::{closure_env#0}>, core::result::Result>, core::result::Result> + at ./library/std/src/thread/local.rs:260:9 + 102: enter_context>, core::result::Result> + at ./compiler/rustc_middle/src/ty/context/tls.rs:79:5 + 103: enter> + at ./compiler/rustc_middle/src/ty/context.rs:1288:9 + 104: >::enter::, ::codegen_and_build_linker::{closure#0}> + at ./compiler/rustc_interface/src/queries.rs:64:9 + 105: codegen_and_build_linker + at ./compiler/rustc_interface/src/queries.rs:121:9 + 106: {closure#1} + at ./compiler/rustc_driver_impl/src/lib.rs:451:26 + 107: enter, rustc_span::ErrorGuaranteed>> + at ./compiler/rustc_interface/src/queries.rs:202:19 + 108: {closure#0} + at ./compiler/rustc_driver_impl/src/lib.rs:389:22 + 109: {closure#1}, rustc_driver_impl::run_compiler::{closure_env#0}> + at ./compiler/rustc_interface/src/interface.rs:502:27 + 110: {closure#0}, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>> + at ./compiler/rustc_interface/src/util.rs:154:13 + 111: {closure#0}, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>> + at ./compiler/rustc_interface/src/util.rs:106:21 + 112: set, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>> + at /home/michael/.cargo/registry/src/index.crates.io-6f17d22bba15001f/scoped-tls-1.0.1/src/lib.rs:137:9 + 113: create_session_globals_then, rustc_interface::util::run_in_thread_with_globals::{closure#0}::{closure#0}::{closure_env#0}, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>>> + at ./compiler/rustc_span/src/lib.rs:134:5 + 114: {closure#0}, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>> + at ./compiler/rustc_interface/src/util.rs:105:17 +note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. + +error: the compiler unexpectedly panicked. this is a bug. + +note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md + +note: please make sure that you have updated to the latest nightly + +note: rustc 1.81.0-dev running on x86_64-unknown-linux-gnu + +note: compiler flags: -Z threads=1 -Z simulate-remapped-rust-src-base=/rustc/FAKE_PREFIX -Z translate-remapped-path-to-local-path=no -Z ignore-directory-in-diagnostics-source-blocks=/home/michael/.cargo -Z ignore-directory-in-diagnostics-source-blocks=/home/michael/programming/rust2/vendor -C codegen-units=1 -Z ui-testing -Z deduplicate-diagnostics=no -Z write-long-types-to-disk=no -C strip=debuginfo -C prefer-dynamic -C rpath -C debuginfo=0 -Z inline-mir=yes --crate-type lib + +query stack during panic: +#0 [evaluate_obligation] evaluating trait selection obligation `[Dorp; M]: core::marker::Copy` +#1 [is_copy_raw] computing whether `[Dorp; M]` is `Copy` +#2 [needs_drop_raw] computing whether `[Dorp; M]` needs drop +#3 [mir_shims] generating MIR shim for `core::ptr::drop_in_place` +#4 [optimized_mir] optimizing MIR for `drop` +end of query stack From bb458674f0510e29fe9bf7de67c0c5769031393b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 28 Jun 2024 10:18:13 -0400 Subject: [PATCH 4/6] Don't inline drop shims with unsubstituted generic consts in MIR inliner (cherry picked from commit f17b27b3014adea0c40df55b31bd2fbbd72e76c4) --- compiler/rustc_mir_transform/src/inline.rs | 12 +- .../const-generics/polymorphic-drop-shim.rs | 5 +- .../polymorphic-drop-shim.stderr | 257 ------------------ 3 files changed, 12 insertions(+), 262 deletions(-) delete mode 100644 tests/ui/const-generics/polymorphic-drop-shim.stderr diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index fe2237dd2e97a..05411e662bf90 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -10,7 +10,7 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs} use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::TypeVisitableExt; -use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt}; +use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt, TypeFlags}; use rustc_session::config::{DebugInfo, OptLevel}; use rustc_span::source_map::Spanned; use rustc_span::sym; @@ -320,6 +320,16 @@ impl<'tcx> Inliner<'tcx> { InstanceDef::Intrinsic(_) | InstanceDef::Virtual(..) => { return Err("instance without MIR (intrinsic / virtual)"); } + + // FIXME(#127030): `ConstParamHasTy` has bad interactions with + // the drop shim builder, which does not evaluate predicates in + // the correct param-env for types being dropped. Stall resolving + // the MIR for this instance until all of its const params are + // substituted. + InstanceDef::DropGlue(_, Some(ty)) if ty.has_type_flags(TypeFlags::HAS_CT_PARAM) => { + return Err("still needs substitution"); + } + // This cannot result in an immediate cycle since the callee MIR is a shim, which does // not get any optimizations run on it. Any subsequent inlining may cause cycles, but we // do not need to catch this here, we can wait until the inliner decides to continue diff --git a/tests/ui/const-generics/polymorphic-drop-shim.rs b/tests/ui/const-generics/polymorphic-drop-shim.rs index 97ade9fe69a30..4ca2e86cff915 100644 --- a/tests/ui/const-generics/polymorphic-drop-shim.rs +++ b/tests/ui/const-generics/polymorphic-drop-shim.rs @@ -1,8 +1,5 @@ //@ compile-flags: -Zinline-mir=yes --crate-type=lib - -//@ known-bug: unknown -//@ build-fail -//@ failure-status: 101 +//@ build-pass use std::mem::ManuallyDrop; diff --git a/tests/ui/const-generics/polymorphic-drop-shim.stderr b/tests/ui/const-generics/polymorphic-drop-shim.stderr deleted file mode 100644 index 3a445a524097d..0000000000000 --- a/tests/ui/const-generics/polymorphic-drop-shim.stderr +++ /dev/null @@ -1,257 +0,0 @@ -thread 'rustc' panicked at compiler/rustc_middle/src/ty/sty.rs:360:36: -called `Option::unwrap()` on a `None` value -stack backtrace: - 0: begin_panic_handler - at ./library/std/src/panicking.rs:661:5 - 1: panic_fmt - at ./library/core/src/panicking.rs:74:14 - 2: panic - at ./library/core/src/panicking.rs:148:5 - 3: core::option::unwrap_failed - at ./library/core/src/option.rs:2013:5 - 4: unwrap - at ./library/core/src/option.rs:963:21 - 5: find_ty_from_env - at ./compiler/rustc_middle/src/ty/sty.rs:360:18 - 6: {closure#0} - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1016:29 - 7: maybe_grow, rustc_trait_selection::traits::select::{impl#1}::evaluate_predicate_recursively::{closure#0}::{closure_env#0}> - at /home/michael/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stacker-0.1.15/src/lib.rs:55:9 - 8: ensure_sufficient_stack, rustc_trait_selection::traits::select::{impl#1}::evaluate_predicate_recursively::{closure#0}::{closure_env#0}> - at ./compiler/rustc_data_structures/src/stack.rs:17:5 - 9: {closure#0} - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:664:9 - 10: evaluate_predicate_recursively - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:643:5 - 11: evaluate_predicates_recursively, alloc::alloc::Global>> - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:631:24 - 12: {closure#0} - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1317:21 - 13: {closure#0} - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:596:26 - 14: probe, rustc_trait_selection::traits::select::{impl#1}::evaluation_probe::{closure_env#0}> - at ./compiler/rustc_infer/src/infer/snapshot/mod.rs:85:17 - 15: ::evaluation_probe::<::evaluate_candidate::{closure#0}::{closure#0}> - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:594:9 - 16: {closure#0} - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1298:26 - 17: evaluate_candidate - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1286:5 - 18: evaluate_stack - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1257:28 - 19: {closure#1} - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1083:30 - 20: {closure#0}> - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1445:88 - 21: with_anon_task>, core::result::Result> - at ./compiler/rustc_query_system/src/dep_graph/graph.rs:306:22 - 22: in_task> - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1445:13 - 23: {closure#0} - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1082:34 - 24: evaluate_trait_predicate_recursively - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:1037:5 - 25: {closure#0} - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:671:21 - 26: maybe_grow, rustc_trait_selection::traits::select::{impl#1}::evaluate_predicate_recursively::{closure#0}::{closure_env#0}> - at /home/michael/.cargo/registry/src/index.crates.io-6f17d22bba15001f/stacker-0.1.15/src/lib.rs:55:9 - 27: ensure_sufficient_stack, rustc_trait_selection::traits::select::{impl#1}::evaluate_predicate_recursively::{closure#0}::{closure_env#0}> - at ./compiler/rustc_data_structures/src/stack.rs:17:5 - 28: {closure#0} - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:664:9 - 29: evaluate_predicate_recursively - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:643:5 - 30: {closure#0} - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:572:30 - 31: {closure#0} - at ./compiler/rustc_trait_selection/src/traits/select/mod.rs:596:26 - 32: probe, rustc_trait_selection::traits::select::{impl#1}::evaluation_probe::{closure_env#0}> - at ./compiler/rustc_infer/src/infer/snapshot/mod.rs:85:17 - 33: evaluate_obligation - at ./compiler/rustc_traits/src/evaluate_obligation.rs:29:5 - 34: {closure#0} - at ./compiler/rustc_query_impl/src/plumbing.rs:281:9 - [... omitted 22 frames ...] - 35: query_get_at>, rustc_middle::query::erase::Erased<[u8; 2]>>> - at ./compiler/rustc_middle/src/query/plumbing.rs:145:17 - 36: evaluate_obligation - at ./compiler/rustc_middle/src/query/plumbing.rs:423:31 - 37: evaluate_obligation - at ./compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs:93:13 - 38: evaluate_obligation_no_overflow - at ./compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs:107:15 - 39: {closure#0}> - at ./compiler/rustc_trait_selection/src/traits/mod.rs:221:18 - 40: pred_known_to_hold_modulo_regions> - at ./compiler/rustc_trait_selection/src/traits/mod.rs:213:1 - 41: rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions - at ./compiler/rustc_trait_selection/src/traits/mod.rs:206:5 - 42: rustc_ty_utils::common_traits::is_item_raw - at ./compiler/rustc_ty_utils/src/common_traits.rs:33:5 - 43: {closure#0} - at ./compiler/rustc_query_impl/src/plumbing.rs:281:9 - [... omitted 22 frames ...] - 44: query_get_at, rustc_middle::query::erase::Erased<[u8; 1]>>> - at ./compiler/rustc_middle/src/query/plumbing.rs:145:17 - 45: is_copy_raw - at ./compiler/rustc_middle/src/query/plumbing.rs:423:31 - 46: is_copy_raw - at ./compiler/rustc_middle/src/query/plumbing.rs:414:17 - 47: is_copy_modulo_regions - at ./compiler/rustc_middle/src/ty/util.rs:1243:48 - 48: next, alloc::vec::into_iter::IntoIter> - at ./compiler/rustc_ty_utils/src/needs_drop.rs:184:26 - 49: try_fold>, (), core::iter::traits::iterator::Iterator::find::check::{closure_env#0}, &mut rustc_ty_utils::needs_drop::filter_array_elements::{closure_env#0}>, core::ops::control_flow::ControlFlow, ()>> - at ./library/core/src/iter/traits/iterator.rs:2409:29 - 50: find>, &mut rustc_ty_utils::needs_drop::filter_array_elements::{closure_env#0}> - at ./library/core/src/iter/traits/iterator.rs:2880:9 - 51: next>, rustc_ty_utils::needs_drop::filter_array_elements::{closure_env#0}> - at ./library/core/src/iter/adapters/filter.rs:96:9 - 52: needs_drop_raw - at ./compiler/rustc_ty_utils/src/needs_drop.rs:24:15 - 53: {closure#0} - at ./compiler/rustc_query_impl/src/plumbing.rs:281:9 - [... omitted 22 frames ...] - 54: query_get_at, rustc_middle::query::erase::Erased<[u8; 1]>>> - at ./compiler/rustc_middle/src/query/plumbing.rs:145:17 - 55: needs_drop_raw - at ./compiler/rustc_middle/src/query/plumbing.rs:423:31 - 56: needs_drop_raw - at ./compiler/rustc_middle/src/query/plumbing.rs:414:17 - 57: needs_drop - at ./compiler/rustc_middle/src/ty/util.rs:1433:17 - 58: {closure#0} - at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:378:13 - 59: {closure#0}<(rustc_middle::mir::syntax::Place, core::option::Option<()>), alloc::alloc::Global, rustc_mir_dataflow::elaborate_drops::{impl#2}::drop_ladder::{closure_env#0}> - at ./library/alloc/src/vec/mod.rs:1683:32 - 60: process_loop), alloc::alloc::Global, rustc_mir_dataflow::elaborate_drops::{impl#2}::drop_ladder::{closure_env#0}>, (rustc_middle::mir::syntax::Place, core::option::Option<()>), alloc::alloc::Global, false> - at ./library/alloc/src/vec/mod.rs:1763:21 - 61: retain_mut<(rustc_middle::mir::syntax::Place, core::option::Option<()>), alloc::alloc::Global, alloc::vec::{impl#1}::retain::{closure_env#0}<(rustc_middle::mir::syntax::Place, core::option::Option<()>), alloc::alloc::Global, rustc_mir_dataflow::elaborate_drops::{impl#2}::drop_ladder::{closure_env#0}>> - at ./library/alloc/src/vec/mod.rs:1789:9 - 62: retain<(rustc_middle::mir::syntax::Place, core::option::Option<()>), alloc::alloc::Global, rustc_mir_dataflow::elaborate_drops::{impl#2}::drop_ladder::{closure_env#0}> - at ./library/alloc/src/vec/mod.rs:1683:9 - 63: drop_ladder - at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:377:9 - 64: open_drop_for_adt_contents - at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:488:13 - 65: {closure#0} - at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:461:13 - 66: open_drop_for_adt - at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:440:5 - 67: open_drop - at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:869:35 - 68: elaborate_drop - at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:253:31 - 69: rustc_mir_dataflow::elaborate_drops::elaborate_drop:: - at ./compiler/rustc_mir_dataflow/src/elaborate_drops.rs:192:5 - 70: build_drop_shim - at ./compiler/rustc_mir_transform/src/shim.rs:283:13 - 71: make_shim - at ./compiler/rustc_mir_transform/src/shim.rs:128:13 - 72: {closure#0} - at ./compiler/rustc_query_impl/src/plumbing.rs:281:9 - [... omitted 22 frames ...] - 73: query_get_at>> - at ./compiler/rustc_middle/src/query/plumbing.rs:145:17 - 74: mir_shims - at ./compiler/rustc_middle/src/query/plumbing.rs:423:31 - 75: mir_shims - at ./compiler/rustc_middle/src/query/plumbing.rs:414:17 - 76: instance_mir - at ./compiler/rustc_middle/src/ty/mod.rs:1738:62 - 77: try_instance_mir - at ./compiler/rustc_mir_transform/src/inline.rs:1082:8 - 78: try_inlining - at ./compiler/rustc_mir_transform/src/inline.rs:194:27 - 79: process_blocks - at ./compiler/rustc_mir_transform/src/inline.rs:139:19 - 80: inline - at ./compiler/rustc_mir_transform/src/inline.rs:97:5 - 81: run_pass - at ./compiler/rustc_mir_transform/src/inline.rs:62:12 - 82: run_passes_inner - at ./compiler/rustc_mir_transform/src/pass_manager.rs:144:17 - 83: rustc_mir_transform::pass_manager::run_passes - at ./compiler/rustc_mir_transform/src/pass_manager.rs:87:5 - 84: run_optimization_passes - at ./compiler/rustc_mir_transform/src/lib.rs:561:5 - 85: inner_optimized_mir - at ./compiler/rustc_mir_transform/src/lib.rs:667:5 - 86: optimized_mir - at ./compiler/rustc_mir_transform/src/lib.rs:630:21 - 87: {closure#0} - at ./compiler/rustc_query_impl/src/plumbing.rs:285:13 - [... omitted 22 frames ...] - 88: query_get_at>> - at ./compiler/rustc_middle/src/query/plumbing.rs:145:17 - 89: optimized_mir - at ./compiler/rustc_middle/src/query/plumbing.rs:423:31 - 90: optimized_mir - at ./compiler/rustc_middle/src/query/plumbing.rs:414:17 - 91: encode_mir - at ./compiler/rustc_metadata/src/rmeta/encoder.rs:1656:74 - 92: {closure#15} - at ./compiler/rustc_metadata/src/rmeta/encoder.rs:639:29 - 93: encode_crate_root - at ./compiler/rustc_metadata/src/rmeta/encoder.rs:600:27 - 94: encode_metadata - at ./compiler/rustc_metadata/src/rmeta/encoder.rs:2269:16 - 95: encode_and_write_metadata - at ./compiler/rustc_metadata/src/fs.rs:65:13 - 96: start_codegen - at ./compiler/rustc_interface/src/passes.rs:1024:44 - 97: {closure#0} - at ./compiler/rustc_interface/src/queries.rs:122:35 - 98: {closure#1}> - at ./compiler/rustc_middle/src/ty/context.rs:1288:37 - 99: {closure#0}>, core::result::Result> - at ./compiler/rustc_middle/src/ty/context/tls.rs:82:9 - 100: try_with, rustc_middle::ty::context::tls::enter_context::{closure_env#0}>, core::result::Result>, core::result::Result> - at ./library/std/src/thread/local.rs:283:12 - 101: with, rustc_middle::ty::context::tls::enter_context::{closure_env#0}>, core::result::Result>, core::result::Result> - at ./library/std/src/thread/local.rs:260:9 - 102: enter_context>, core::result::Result> - at ./compiler/rustc_middle/src/ty/context/tls.rs:79:5 - 103: enter> - at ./compiler/rustc_middle/src/ty/context.rs:1288:9 - 104: >::enter::, ::codegen_and_build_linker::{closure#0}> - at ./compiler/rustc_interface/src/queries.rs:64:9 - 105: codegen_and_build_linker - at ./compiler/rustc_interface/src/queries.rs:121:9 - 106: {closure#1} - at ./compiler/rustc_driver_impl/src/lib.rs:451:26 - 107: enter, rustc_span::ErrorGuaranteed>> - at ./compiler/rustc_interface/src/queries.rs:202:19 - 108: {closure#0} - at ./compiler/rustc_driver_impl/src/lib.rs:389:22 - 109: {closure#1}, rustc_driver_impl::run_compiler::{closure_env#0}> - at ./compiler/rustc_interface/src/interface.rs:502:27 - 110: {closure#0}, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>> - at ./compiler/rustc_interface/src/util.rs:154:13 - 111: {closure#0}, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>> - at ./compiler/rustc_interface/src/util.rs:106:21 - 112: set, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>> - at /home/michael/.cargo/registry/src/index.crates.io-6f17d22bba15001f/scoped-tls-1.0.1/src/lib.rs:137:9 - 113: create_session_globals_then, rustc_interface::util::run_in_thread_with_globals::{closure#0}::{closure#0}::{closure_env#0}, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>>> - at ./compiler/rustc_span/src/lib.rs:134:5 - 114: {closure#0}, rustc_driver_impl::run_compiler::{closure_env#0}>, core::result::Result<(), rustc_span::ErrorGuaranteed>>, core::result::Result<(), rustc_span::ErrorGuaranteed>> - at ./compiler/rustc_interface/src/util.rs:105:17 -note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. - -error: the compiler unexpectedly panicked. this is a bug. - -note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md - -note: please make sure that you have updated to the latest nightly - -note: rustc 1.81.0-dev running on x86_64-unknown-linux-gnu - -note: compiler flags: -Z threads=1 -Z simulate-remapped-rust-src-base=/rustc/FAKE_PREFIX -Z translate-remapped-path-to-local-path=no -Z ignore-directory-in-diagnostics-source-blocks=/home/michael/.cargo -Z ignore-directory-in-diagnostics-source-blocks=/home/michael/programming/rust2/vendor -C codegen-units=1 -Z ui-testing -Z deduplicate-diagnostics=no -Z write-long-types-to-disk=no -C strip=debuginfo -C prefer-dynamic -C rpath -C debuginfo=0 -Z inline-mir=yes --crate-type lib - -query stack during panic: -#0 [evaluate_obligation] evaluating trait selection obligation `[Dorp; M]: core::marker::Copy` -#1 [is_copy_raw] computing whether `[Dorp; M]` is `Copy` -#2 [needs_drop_raw] computing whether `[Dorp; M]` needs drop -#3 [mir_shims] generating MIR shim for `core::ptr::drop_in_place` -#4 [optimized_mir] optimizing MIR for `drop` -end of query stack From cd1d94b574399df3d39db8c4308373842b2c21e6 Mon Sep 17 00:00:00 2001 From: DianQK Date: Mon, 1 Jul 2024 06:03:08 +0800 Subject: [PATCH 5/6] Update LLVM submodule (cherry picked from commit da81d0d940481827fb2bdd164ea0038832e3779e) --- src/llvm-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llvm-project b/src/llvm-project index 5a5152f653959..e6a6470d1eb4c 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 5a5152f653959d14d68613a3a8a033fb65eec021 +Subproject commit e6a6470d1eb4c88fee4b1ea98cd8e0ac4a181c16 From c822bf2486496b410b828f8c68778af8839074f3 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 2 Jul 2024 01:51:55 -0400 Subject: [PATCH 6/6] Change to the NetBSD archive URL rather than the CDN The CDN has been down for a few hours. Switch to an alternative for the time being so we can unblock CI. It appears that the CDN is quite a bit faster, so we will likely want to switch back when available. (cherry picked from commit 42ac903f4fe4e9894f8c6e97538696bdbae848dc) --- .../build-netbsd-toolchain.sh | 54 ++++++++++++++----- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/src/ci/docker/host-x86_64/dist-x86_64-netbsd/build-netbsd-toolchain.sh b/src/ci/docker/host-x86_64/dist-x86_64-netbsd/build-netbsd-toolchain.sh index e0c008b76fa8b..4a42f5da29fcc 100755 --- a/src/ci/docker/host-x86_64/dist-x86_64-netbsd/build-netbsd-toolchain.sh +++ b/src/ci/docker/host-x86_64/dist-x86_64-netbsd/build-netbsd-toolchain.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # ignore-tidy-linelength -set -ex +set -eux hide_output() { set +x @@ -20,6 +20,22 @@ exit 1 set -x } +# Download, verify SHA512, and remove the downloaded file +# Usage: +download() { + fname="$1" + shift + url="$1" + shift + sha="$1" + shift + + curl "$url" -o "$fname" + echo "$sha $fname" | shasum -a 512 --check || exit 1 + "$@" + rm "$fname" +} + mkdir netbsd cd netbsd @@ -27,17 +43,31 @@ mkdir -p /x-tools/x86_64-unknown-netbsd/sysroot # URL=https://ci-mirrors.rust-lang.org/rustc -SOURCE_URL=https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/source/sets -curl $SOURCE_URL/src.tgz | tar xzf - -curl $SOURCE_URL/gnusrc.tgz | tar xzf - -curl $SOURCE_URL/sharesrc.tgz | tar xzf - -curl $SOURCE_URL/syssrc.tgz | tar xzf - - -BINARY_URL=https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/amd64/binary/sets -curl $BINARY_URL/base.tar.xz | \ - tar xJf - -C /x-tools/x86_64-unknown-netbsd/sysroot ./usr/include ./usr/lib ./lib -curl $BINARY_URL/comp.tar.xz | \ - tar xJf - -C /x-tools/x86_64-unknown-netbsd/sysroot ./usr/include ./usr/lib +# Hashes come from https://cdn.netbsd.org/pub/NetBSD/security/hashes/NetBSD-9.0_hashes.asc +SRC_SHA=2c791ae009a6929c6fc893ec5df7e62910ee8207e0b2159d6937309c03efe175b6ae1e445829a13d041b6851334ad35c521f2fa03c97675d4a05f1fafe58ede0 +GNUSRC_SHA=3710085a73feecf6a843415271ec794c90146b03f6bbd30f07c9e0c79febf8995d557e40194f1e05db655e4f5ef2fae97563f8456fceaae65d4ea98857a83b1c +SHARESRC_SHA=f080776ed82c3ac5d6272dee39746f87897d8e6984996caf5bf6d87bf11d9c9e0c1ad5c437c21258bd278bb6fd76974946e878f548517885f71c556096231369 +SYSSRC_SHA=60b9ddf4cc6402256473e2e1eefeabd9001aa4e205208715ecc6d6fc3f5b400e469944580077271b8e80562a4c2f601249e69e07a504f46744e0c50335f1cbf1 +BASE_SHA=b5926b107cebf40c3c19b4f6cd039b610987dd7f819e7cdde3bd1e5230a856906e7930b15ab242d52ced9f0bda01d574be59488b8dbb95fa5df2987d0a70995f +COMP_SHA=38ea54f30d5fc2afea87e5096f06873e00182789e8ad9cec0cb3e9f7c538c1aa4779e63fd401a36ba02676158e83fa5c95e8e87898db59c1914fb206aecd82d2 + +# FIXME: the archive URL is being used temporarily while the CDN is down. +# We should serve this from our own CDN +# SOURCE_URL=https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/source/sets +SOURCE_URL=http://archive.netbsd.org/pub/NetBSD-archive/NetBSD-9.0/source/sets +download src.tgz "$SOURCE_URL/src.tgz" "$SRC_SHA" tar xzf src.tgz +download gnusrc.tgz "$SOURCE_URL/gnusrc.tgz" "$GNUSRC_SHA" tar xzf gnusrc.tgz +download sharesrc.tgz "$SOURCE_URL/sharesrc.tgz" "$SHARESRC_SHA" tar xzf sharesrc.tgz +download syssrc.tgz "$SOURCE_URL/syssrc.tgz" "$SYSSRC_SHA" tar xzf syssrc.tgz + +# FIXME: the archive URL is being used temporarily while the CDN is down. +# We should serve this from our own CDN +# BINARY_URL=https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/amd64/binary/sets +BINARY_URL=http://archive.netbsd.org/pub/NetBSD-archive/NetBSD-9.0/amd64/binary/sets +download base.tar.xz "$BINARY_URL/base.tar.xz" "$BASE_SHA" \ + tar xJf base.tar.xz -C /x-tools/x86_64-unknown-netbsd/sysroot ./usr/include ./usr/lib ./lib +download comp.tar.xz "$BINARY_URL/comp.tar.xz" "$COMP_SHA" \ + tar xJf comp.tar.xz -C /x-tools/x86_64-unknown-netbsd/sysroot ./usr/include ./usr/lib cd usr/src