Skip to content

Commit 415b6eb

Browse files
committed
Auto merge of rust-lang#127377 - cuviper:beta-next, r=cuviper
[beta] backports - Properly gate `safe` keyword in pre-expansion rust-lang#126757 - Switch back `non_local_definitions` lint to allow-by-default rust-lang#127015 - Stall computing instance for drop shim until it has no unsubstituted const params rust-lang#127068 - Update LLVM submodule rust-lang#127190 r? cuviper
2 parents 64a1fe6 + cd1d94b commit 415b6eb

34 files changed

+226
-98
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+4
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,10 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
562562
gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental");
563563
gate_all!(global_registration, "global registration is experimental");
564564
gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental");
565+
gate_all!(
566+
unsafe_extern_blocks,
567+
"`unsafe extern {}` blocks and `safe` keyword are experimental"
568+
);
565569

566570
if !visitor.features.never_patterns {
567571
if let Some(spans) = spans.get(&sym::never_patterns) {

compiler/rustc_lint/src/non_local_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ declare_lint! {
5050
/// All nested bodies (functions, enum discriminant, array length, consts) (expect for
5151
/// `const _: Ty = { ... }` in top-level module, which is still undecided) are checked.
5252
pub NON_LOCAL_DEFINITIONS,
53-
Warn,
53+
Allow,
5454
"checks for non-local definitions",
5555
report_in_external_macro
5656
}

compiler/rustc_mir_transform/src/inline.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}
1010
use rustc_middle::mir::visit::*;
1111
use rustc_middle::mir::*;
1212
use rustc_middle::ty::TypeVisitableExt;
13-
use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
13+
use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt, TypeFlags};
1414
use rustc_session::config::{DebugInfo, OptLevel};
1515
use rustc_span::source_map::Spanned;
1616
use rustc_span::sym;
@@ -320,6 +320,16 @@ impl<'tcx> Inliner<'tcx> {
320320
InstanceDef::Intrinsic(_) | InstanceDef::Virtual(..) => {
321321
return Err("instance without MIR (intrinsic / virtual)");
322322
}
323+
324+
// FIXME(#127030): `ConstParamHasTy` has bad interactions with
325+
// the drop shim builder, which does not evaluate predicates in
326+
// the correct param-env for types being dropped. Stall resolving
327+
// the MIR for this instance until all of its const params are
328+
// substituted.
329+
InstanceDef::DropGlue(_, Some(ty)) if ty.has_type_flags(TypeFlags::HAS_CT_PARAM) => {
330+
return Err("still needs substitution");
331+
}
332+
323333
// This cannot result in an immediate cycle since the callee MIR is a shim, which does
324334
// not get any optimizations run on it. Any subsequent inlining may cause cycles, but we
325335
// do not need to catch this here, we can wait until the inliner decides to continue

compiler/rustc_parse/src/parser/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,9 @@ impl<'a> Parser<'a> {
12211221
if self.eat_keyword_case(kw::Unsafe, case) {
12221222
Safety::Unsafe(self.prev_token.uninterpolated_span())
12231223
} else if self.eat_keyword_case(kw::Safe, case) {
1224+
self.psess
1225+
.gated_spans
1226+
.gate(sym::unsafe_extern_blocks, self.prev_token.uninterpolated_span());
12241227
Safety::Safe(self.prev_token.uninterpolated_span())
12251228
} else {
12261229
Safety::Default

tests/rustdoc-ui/doctest/non_local_defs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//@ normalize-stderr-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
55
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
66

7+
#![doc(test(attr(warn(non_local_definitions))))]
8+
79
//! ```
810
//! #[macro_export]
911
//! macro_rules! a_macro { () => {} }
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module
2-
--> $DIR/non_local_defs.rs:9:1
2+
--> $DIR/non_local_defs.rs:11:1
33
|
44
LL | macro_rules! a_macro { () => {} }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() { ... }`
88
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
99
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
10-
= note: `#[warn(non_local_definitions)]` on by default
10+
note: the lint level is defined here
11+
--> $DIR/non_local_defs.rs:8:9
12+
|
13+
LL | #![warn(non_local_definitions)]
14+
| ^^^^^^^^^^^^^^^^^^^^^
1115

1216
warning: 1 warning emitted
1317

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
running 1 test
3-
test $DIR/non_local_defs.rs - (line 7) ... ok
3+
test $DIR/non_local_defs.rs - (line 9) ... ok
44

55
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
66

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ compile-flags: -Zinline-mir=yes --crate-type=lib
2+
//@ build-pass
3+
4+
use std::mem::ManuallyDrop;
5+
6+
pub struct Foo<T, const N: usize>([T; N]);
7+
8+
pub struct Dorp {}
9+
10+
impl Drop for Dorp {
11+
fn drop(&mut self) {}
12+
}
13+
14+
#[inline]
15+
// SAFETY: call this with a valid allocation idk
16+
pub unsafe fn drop<const M: usize>(x: *mut Foo<Dorp, M>) {
17+
std::ptr::drop_in_place(x);
18+
}

tests/ui/feature-gates/feature-gate-unsafe-extern-blocks.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@ unsafe extern "C" {
22
//~^ ERROR extern block cannot be declared unsafe
33
}
44

5+
// We can't gate `unsafe extern` blocks themselves since they were previously
6+
// allowed, but we should gate the `safe` soft keyword.
7+
#[cfg(any())]
8+
unsafe extern "C" {
9+
safe fn foo();
10+
//~^ ERROR `unsafe extern {}` blocks and `safe` keyword are experimental
11+
}
12+
513
fn main() {}

tests/ui/feature-gates/feature-gate-unsafe-extern-blocks.stderr

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,16 @@ error: extern block cannot be declared unsafe
44
LL | unsafe extern "C" {
55
| ^^^^^^
66

7-
error: aborting due to 1 previous error
7+
error[E0658]: `unsafe extern {}` blocks and `safe` keyword are experimental
8+
--> $DIR/feature-gate-unsafe-extern-blocks.rs:9:5
9+
|
10+
LL | safe fn foo();
11+
| ^^^^
12+
|
13+
= note: see issue #123743 <https://github.com/rust-lang/rust/issues/123743> for more information
14+
= help: add `#![feature(unsafe_extern_blocks)]` to the crate attributes to enable
15+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
16+
17+
error: aborting due to 2 previous errors
818

19+
For more information about this error, try `rustc --explain E0658`.

tests/ui/lint/non-local-defs/cargo-update.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// of the `cargo update` suggestion we assert it here.
1111
//@ error-pattern: `cargo update -p non_local_macro`
1212

13+
#![warn(non_local_definitions)]
14+
1315
extern crate non_local_macro;
1416

1517
struct LocalStruct;

tests/ui/lint/non-local-defs/cargo-update.stderr

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
2-
--> $DIR/cargo-update.rs:17:1
2+
--> $DIR/cargo-update.rs:19:1
33
|
44
LL | non_local_macro::non_local_impl!(LocalStruct);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -13,7 +13,11 @@ LL | non_local_macro::non_local_impl!(LocalStruct);
1313
= 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`
1414
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
1515
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
16-
= note: `#[warn(non_local_definitions)]` on by default
16+
note: the lint level is defined here
17+
--> $DIR/cargo-update.rs:13:9
18+
|
19+
LL | #![warn(non_local_definitions)]
20+
| ^^^^^^^^^^^^^^^^^^^^^
1721
= note: this warning originates in the macro `non_local_macro::non_local_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
1822

1923
warning: 1 warning emitted

tests/ui/lint/non-local-defs/consts.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//@ edition:2021
33
//@ rustc-env:CARGO_CRATE_NAME=non_local_def
44

5+
#![warn(non_local_definitions)]
6+
57
struct Test;
68

79
trait Uto {}

tests/ui/lint/non-local-defs/consts.stderr

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
2-
--> $DIR/consts.rs:13:5
2+
--> $DIR/consts.rs:15:5
33
|
44
LL | const Z: () = {
55
| -----------
@@ -17,10 +17,14 @@ LL | impl Uto for &Test {}
1717
= 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`
1818
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration
1919
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
20-
= note: `#[warn(non_local_definitions)]` on by default
20+
note: the lint level is defined here
21+
--> $DIR/consts.rs:5:9
22+
|
23+
LL | #![warn(non_local_definitions)]
24+
| ^^^^^^^^^^^^^^^^^^^^^
2125

2226
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
23-
--> $DIR/consts.rs:24:5
27+
--> $DIR/consts.rs:26:5
2428
|
2529
LL | static A: u32 = {
2630
| ------------- move the `impl` block outside of this static `A`
@@ -36,7 +40,7 @@ LL | impl Uto2 for Test {}
3640
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
3741

3842
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
39-
--> $DIR/consts.rs:32:5
43+
--> $DIR/consts.rs:34:5
4044
|
4145
LL | const B: u32 = {
4246
| ------------ move the `impl` block outside of this constant `B`
@@ -52,7 +56,7 @@ LL | impl Uto3 for Test {}
5256
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
5357

5458
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
55-
--> $DIR/consts.rs:43:5
59+
--> $DIR/consts.rs:45:5
5660
|
5761
LL | fn main() {
5862
| --------- move the `impl` block outside of this function `main`
@@ -65,7 +69,7 @@ LL | impl Test {
6569
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
6670

6771
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
68-
--> $DIR/consts.rs:50:9
72+
--> $DIR/consts.rs:52:9
6973
|
7074
LL | const {
7175
| ___________-
@@ -84,7 +88,7 @@ LL | | };
8488
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
8589

8690
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
87-
--> $DIR/consts.rs:59:9
91+
--> $DIR/consts.rs:61:9
8892
|
8993
LL | const _: u32 = {
9094
| ------------ move the `impl` block outside of this constant `_` and up 2 bodies
@@ -98,7 +102,7 @@ LL | impl Test {
98102
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
99103

100104
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
101-
--> $DIR/consts.rs:72:9
105+
--> $DIR/consts.rs:74:9
102106
|
103107
LL | let _a = || {
104108
| -- move the `impl` block outside of this closure `<unnameable>` and up 2 bodies
@@ -113,7 +117,7 @@ LL | impl Uto9 for Test {}
113117
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
114118

115119
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
116-
--> $DIR/consts.rs:79:9
120+
--> $DIR/consts.rs:81:9
117121
|
118122
LL | type A = [u32; {
119123
| ____________________-

tests/ui/lint/non-local-defs/exhaustive-trait.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//@ check-pass
22
//@ edition:2021
33

4+
#![warn(non_local_definitions)]
5+
46
struct Dog;
57

68
fn main() {

tests/ui/lint/non-local-defs/exhaustive-trait.stderr

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
2-
--> $DIR/exhaustive-trait.rs:7:5
2+
--> $DIR/exhaustive-trait.rs:9:5
33
|
44
LL | fn main() {
55
| --------- move the `impl` block outside of this function `main`
@@ -12,10 +12,14 @@ LL | impl PartialEq<()> for Dog {
1212
= 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
1313
= 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`
1414
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
15-
= note: `#[warn(non_local_definitions)]` on by default
15+
note: the lint level is defined here
16+
--> $DIR/exhaustive-trait.rs:4:9
17+
|
18+
LL | #![warn(non_local_definitions)]
19+
| ^^^^^^^^^^^^^^^^^^^^^
1620

1721
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
18-
--> $DIR/exhaustive-trait.rs:14:5
22+
--> $DIR/exhaustive-trait.rs:16:5
1923
|
2024
LL | fn main() {
2125
| --------- move the `impl` block outside of this function `main`
@@ -31,7 +35,7 @@ LL | impl PartialEq<()> for &Dog {
3135
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
3236

3337
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
34-
--> $DIR/exhaustive-trait.rs:21:5
38+
--> $DIR/exhaustive-trait.rs:23:5
3539
|
3640
LL | fn main() {
3741
| --------- move the `impl` block outside of this function `main`
@@ -47,7 +51,7 @@ LL | impl PartialEq<Dog> for () {
4751
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
4852

4953
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
50-
--> $DIR/exhaustive-trait.rs:28:5
54+
--> $DIR/exhaustive-trait.rs:30:5
5155
|
5256
LL | fn main() {
5357
| --------- move the `impl` block outside of this function `main`
@@ -63,7 +67,7 @@ LL | impl PartialEq<&Dog> for () {
6367
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
6468

6569
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
66-
--> $DIR/exhaustive-trait.rs:35:5
70+
--> $DIR/exhaustive-trait.rs:37:5
6771
|
6872
LL | fn main() {
6973
| --------- move the `impl` block outside of this function `main`
@@ -79,7 +83,7 @@ LL | impl PartialEq<Dog> for &Dog {
7983
= note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
8084

8185
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
82-
--> $DIR/exhaustive-trait.rs:42:5
86+
--> $DIR/exhaustive-trait.rs:44:5
8387
|
8488
LL | fn main() {
8589
| --------- move the `impl` block outside of this function `main`

tests/ui/lint/non-local-defs/exhaustive.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//@ check-pass
22
//@ edition:2021
33

4+
#![warn(non_local_definitions)]
5+
46
use std::fmt::Display;
57

68
trait Trait {}

0 commit comments

Comments
 (0)