Skip to content

Commit

Permalink
Auto merge of rust-lang#127377 - cuviper:beta-next, r=cuviper
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
bors committed Jul 6, 2024
2 parents 64a1fe6 + c822bf2 commit e280749
Show file tree
Hide file tree
Showing 35 changed files with 268 additions and 110 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# ignore-tidy-linelength

set -ex
set -eux

hide_output() {
set +x
Expand All @@ -20,24 +20,54 @@ exit 1
set -x
}

# Download, verify SHA512, and remove the downloaded file
# Usage: <file name> <url> <file sha> <full tar command using fname>
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

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

Expand Down
2 changes: 2 additions & 0 deletions tests/rustdoc-ui/doctest/non_local_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { () => {} }
Expand Down
8 changes: 6 additions & 2 deletions tests/rustdoc-ui/doctest/non_local_defs.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
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 { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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 <https://github.com/rust-lang/rust/issues/120363>
= 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

2 changes: 1 addition & 1 deletion tests/rustdoc-ui/doctest/non_local_defs.stdout
Original file line number Diff line number Diff line change
@@ -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

18 changes: 18 additions & 0 deletions tests/ui/const-generics/polymorphic-drop-shim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ compile-flags: -Zinline-mir=yes --crate-type=lib
//@ build-pass

use std::mem::ManuallyDrop;

pub struct Foo<T, const N: usize>([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<const M: usize>(x: *mut Foo<Dorp, M>) {
std::ptr::drop_in_place(x);
}
8 changes: 8 additions & 0 deletions tests/ui/feature-gates/feature-gate-unsafe-extern-blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
13 changes: 12 additions & 1 deletion tests/ui/feature-gates/feature-gate-unsafe-extern-blocks.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/rust-lang/rust/issues/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`.
2 changes: 2 additions & 0 deletions tests/ui/lint/non-local-defs/cargo-update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions tests/ui/lint/non-local-defs/cargo-update.stderr
Original file line number Diff line number Diff line change
@@ -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);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/120363>
= 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
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/lint/non-local-defs/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//@ edition:2021
//@ rustc-env:CARGO_CRATE_NAME=non_local_def

#![warn(non_local_definitions)]

struct Test;

trait Uto {}
Expand Down
22 changes: 13 additions & 9 deletions tests/ui/lint/non-local-defs/consts.stderr
Original file line number Diff line number Diff line change
@@ -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: () = {
| -----------
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/120363>
= 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`
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/120363>

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`
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/120363>

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`
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/120363>

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 {
| ___________-
Expand All @@ -84,7 +88,7 @@ LL | | };
= 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>

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
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/120363>

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 `<unnameable>` and up 2 bodies
Expand All @@ -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 <https://github.com/rust-lang/rust/issues/120363>

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; {
| ____________________-
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/lint/non-local-defs/exhaustive-trait.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//@ check-pass
//@ edition:2021

#![warn(non_local_definitions)]

struct Dog;

fn main() {
Expand Down
Loading

0 comments on commit e280749

Please sign in to comment.