Skip to content

Commit e280749

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 - Change to the NetBSD archive URL rather than the CDN rust-lang#127232 r? cuviper
2 parents 64a1fe6 + c822bf2 commit e280749

35 files changed

+268
-110
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

src/ci/docker/host-x86_64/dist-x86_64-netbsd/build-netbsd-toolchain.sh

+42-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
# ignore-tidy-linelength
33

4-
set -ex
4+
set -eux
55

66
hide_output() {
77
set +x
@@ -20,24 +20,54 @@ exit 1
2020
set -x
2121
}
2222

23+
# Download, verify SHA512, and remove the downloaded file
24+
# Usage: <file name> <url> <file sha> <full tar command using fname>
25+
download() {
26+
fname="$1"
27+
shift
28+
url="$1"
29+
shift
30+
sha="$1"
31+
shift
32+
33+
curl "$url" -o "$fname"
34+
echo "$sha $fname" | shasum -a 512 --check || exit 1
35+
"$@"
36+
rm "$fname"
37+
}
38+
2339
mkdir netbsd
2440
cd netbsd
2541

2642
mkdir -p /x-tools/x86_64-unknown-netbsd/sysroot
2743

2844
# URL=https://ci-mirrors.rust-lang.org/rustc
2945

30-
SOURCE_URL=https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/source/sets
31-
curl $SOURCE_URL/src.tgz | tar xzf -
32-
curl $SOURCE_URL/gnusrc.tgz | tar xzf -
33-
curl $SOURCE_URL/sharesrc.tgz | tar xzf -
34-
curl $SOURCE_URL/syssrc.tgz | tar xzf -
35-
36-
BINARY_URL=https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/amd64/binary/sets
37-
curl $BINARY_URL/base.tar.xz | \
38-
tar xJf - -C /x-tools/x86_64-unknown-netbsd/sysroot ./usr/include ./usr/lib ./lib
39-
curl $BINARY_URL/comp.tar.xz | \
40-
tar xJf - -C /x-tools/x86_64-unknown-netbsd/sysroot ./usr/include ./usr/lib
46+
# Hashes come from https://cdn.netbsd.org/pub/NetBSD/security/hashes/NetBSD-9.0_hashes.asc
47+
SRC_SHA=2c791ae009a6929c6fc893ec5df7e62910ee8207e0b2159d6937309c03efe175b6ae1e445829a13d041b6851334ad35c521f2fa03c97675d4a05f1fafe58ede0
48+
GNUSRC_SHA=3710085a73feecf6a843415271ec794c90146b03f6bbd30f07c9e0c79febf8995d557e40194f1e05db655e4f5ef2fae97563f8456fceaae65d4ea98857a83b1c
49+
SHARESRC_SHA=f080776ed82c3ac5d6272dee39746f87897d8e6984996caf5bf6d87bf11d9c9e0c1ad5c437c21258bd278bb6fd76974946e878f548517885f71c556096231369
50+
SYSSRC_SHA=60b9ddf4cc6402256473e2e1eefeabd9001aa4e205208715ecc6d6fc3f5b400e469944580077271b8e80562a4c2f601249e69e07a504f46744e0c50335f1cbf1
51+
BASE_SHA=b5926b107cebf40c3c19b4f6cd039b610987dd7f819e7cdde3bd1e5230a856906e7930b15ab242d52ced9f0bda01d574be59488b8dbb95fa5df2987d0a70995f
52+
COMP_SHA=38ea54f30d5fc2afea87e5096f06873e00182789e8ad9cec0cb3e9f7c538c1aa4779e63fd401a36ba02676158e83fa5c95e8e87898db59c1914fb206aecd82d2
53+
54+
# FIXME: the archive URL is being used temporarily while the CDN is down.
55+
# We should serve this from our own CDN
56+
# SOURCE_URL=https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/source/sets
57+
SOURCE_URL=http://archive.netbsd.org/pub/NetBSD-archive/NetBSD-9.0/source/sets
58+
download src.tgz "$SOURCE_URL/src.tgz" "$SRC_SHA" tar xzf src.tgz
59+
download gnusrc.tgz "$SOURCE_URL/gnusrc.tgz" "$GNUSRC_SHA" tar xzf gnusrc.tgz
60+
download sharesrc.tgz "$SOURCE_URL/sharesrc.tgz" "$SHARESRC_SHA" tar xzf sharesrc.tgz
61+
download syssrc.tgz "$SOURCE_URL/syssrc.tgz" "$SYSSRC_SHA" tar xzf syssrc.tgz
62+
63+
# FIXME: the archive URL is being used temporarily while the CDN is down.
64+
# We should serve this from our own CDN
65+
# BINARY_URL=https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/amd64/binary/sets
66+
BINARY_URL=http://archive.netbsd.org/pub/NetBSD-archive/NetBSD-9.0/amd64/binary/sets
67+
download base.tar.xz "$BINARY_URL/base.tar.xz" "$BASE_SHA" \
68+
tar xJf base.tar.xz -C /x-tools/x86_64-unknown-netbsd/sysroot ./usr/include ./usr/lib ./lib
69+
download comp.tar.xz "$BINARY_URL/comp.tar.xz" "$COMP_SHA" \
70+
tar xJf comp.tar.xz -C /x-tools/x86_64-unknown-netbsd/sysroot ./usr/include ./usr/lib
4171

4272
cd usr/src
4373

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() {

0 commit comments

Comments
 (0)