From 3d7aa163d656389b6e7c41ed0b38b23c2bac2a77 Mon Sep 17 00:00:00 2001 From: Wiktor Przetacznik <85874198+WiktorPrzetacznik@users.noreply.github.com> Date: Sun, 28 Jul 2024 16:08:08 +0200 Subject: [PATCH 01/12] Update NonNull::align_offset quarantees Update NonNull::align_offset quarantees, keeping it in sync with ptr::align_offset --- library/core/src/ptr/non_null.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 796c85d0cacc7..7c87f462c5793 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1171,9 +1171,7 @@ impl NonNull { /// `align`. /// /// If it is not possible to align the pointer, the implementation returns - /// `usize::MAX`. It is permissible for the implementation to *always* - /// return `usize::MAX`. Only your algorithm's performance can depend - /// on getting a usable offset here, not its correctness. + /// `usize::MAX`. /// /// The offset is expressed in number of `T` elements, and not bytes. /// @@ -1181,6 +1179,15 @@ impl NonNull { /// beyond the allocation that the pointer points into. It is up to the caller to ensure that /// the returned offset is correct in all terms other than alignment. /// + /// When this is called during compile-time evaluation (which is unstable), the implementation + /// may return `usize::MAX` in cases where that can never happen at runtime. This is because the + /// actual alignment of pointers is not known yet during compile-time, so an offset with + /// guaranteed alignment can sometimes not be computed. For example, a buffer declared as `[u8; + /// N]` might be allocated at an odd or an even address, but at compile-time this is not yet + /// known, so the execution has to be correct for either choice. It is therefore impossible to + /// find an offset that is guaranteed to be 2-aligned. (This behavior is subject to change, as usual + /// for unstable APIs.) + /// /// # Panics /// /// The function panics if `align` is not a power-of-two. From 470ada2de0ec507191ad8da35b0712986646d01c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 3 Aug 2024 14:11:31 -0400 Subject: [PATCH 02/12] Make validate_mir pull optimized/ctfe MIR for all bodies --- compiler/rustc_interface/src/passes.rs | 7 +++++++ tests/crashes/121127.rs | 2 +- tests/crashes/122909.rs | 2 +- tests/crashes/126896.rs | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 8c99b1f444766..023352156eb45 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -818,6 +818,13 @@ fn run_required_analyses(tcx: TyCtxt<'_>) { }); sess.time("layout_testing", || layout_test::test_layout(tcx)); sess.time("abi_testing", || abi_test::test_abi(tcx)); + if tcx.sess.opts.unstable_opts.validate_mir { + sess.time("ensuring_optimized_MIR_is_computable", || { + tcx.hir().par_body_owners(|def_id| { + tcx.instance_mir(ty::InstanceKind::Item(def_id.into())); + }); + }); + } } /// Runs the type-checking, region checking and other miscellaneous analysis diff --git a/tests/crashes/121127.rs b/tests/crashes/121127.rs index 2e64bf68b82fb..e50dc7763fc65 100644 --- a/tests/crashes/121127.rs +++ b/tests/crashes/121127.rs @@ -1,5 +1,5 @@ //@ known-bug: #121127 -//@ compile-flags: -Zpolymorphize=on -Zinline-mir=yes -C debuginfo=2 +//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes -C debuginfo=2 // Note that as of PR#123949 this only crashes with debuginfo enabled #![feature(specialization)] diff --git a/tests/crashes/122909.rs b/tests/crashes/122909.rs index 90bba772b915e..9d17ed83ea99b 100644 --- a/tests/crashes/122909.rs +++ b/tests/crashes/122909.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -Zpolymorphize=on -Zinline-mir=yes +//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes //@ known-bug: #122909 diff --git a/tests/crashes/126896.rs b/tests/crashes/126896.rs index 35bf9d5207ac1..49c539d7acc8a 100644 --- a/tests/crashes/126896.rs +++ b/tests/crashes/126896.rs @@ -1,5 +1,5 @@ //@ known-bug: rust-lang/rust#126896 -//@ compile-flags: -Zpolymorphize=on -Zinline-mir=yes +//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes #![feature(type_alias_impl_trait)] type Two<'a, 'b> = impl std::fmt::Debug; From b0a89441208e56f85b5c51eccde89275f667f787 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Thu, 1 Aug 2024 00:57:38 +0300 Subject: [PATCH 03/12] rustc_errors: enforce OUTPUT_REPLACEMENTS is sorted with a compile-time assertion --- compiler/rustc_errors/src/emitter.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index d673646ace450..0e9c7ef5fb3c4 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2564,9 +2564,7 @@ fn num_decimal_digits(num: usize) -> usize { // We replace some characters so the CLI output is always consistent and underlines aligned. // Keep the following list in sync with `rustc_span::char_width`. -// ATTENTION: keep lexicografically sorted so that the binary search will work const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[ - // tidy-alphabetical-start // In terminals without Unicode support the following will be garbled, but in *all* terminals // the underlying codepoint will be as well. We could gate this replacement behind a "unicode // support" gate. @@ -2579,7 +2577,7 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[ ('\u{0006}', "␆"), ('\u{0007}', "␇"), ('\u{0008}', "␈"), - ('\u{0009}', " "), // We do our own tab replacement + ('\t', " "), // We do our own tab replacement ('\u{000b}', "␋"), ('\u{000c}', "␌"), ('\u{000d}', "␍"), @@ -2612,10 +2610,20 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[ ('\u{2067}', "�"), ('\u{2068}', "�"), ('\u{2069}', "�"), - // tidy-alphabetical-end ]; fn normalize_whitespace(s: &str) -> String { + const { + let mut i = 1; + while i < OUTPUT_REPLACEMENTS.len() { + assert!( + OUTPUT_REPLACEMENTS[i - 1].0 < OUTPUT_REPLACEMENTS[i].0, + "The OUTPUT_REPLACEMENTS array must be sorted (for binary search to work) \ + and must contain no duplicate entries" + ); + i += 1; + } + } // Scan the input string for a character in the ordered table above. If it's present, replace // it with it's alternative string (it can be more than 1 char!). Otherwise, retain the input // char. At the end, allocate all chars into a string in one operation. From 15982b2fcae0fba61816dbd31617bc6604e36af5 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Thu, 1 Aug 2024 01:02:25 +0300 Subject: [PATCH 04/12] rustc_errors: fix inaccurate comment --- compiler/rustc_errors/src/emitter.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 0e9c7ef5fb3c4..ef9194022b529 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2624,9 +2624,9 @@ fn normalize_whitespace(s: &str) -> String { i += 1; } } - // Scan the input string for a character in the ordered table above. If it's present, replace - // it with it's alternative string (it can be more than 1 char!). Otherwise, retain the input - // char. At the end, allocate all chars into a string in one operation. + // Scan the input string for a character in the ordered table above. + // If it's present, replace it with its alternative string (it can be more than 1 char!). + // Otherwise, retain the input char. s.chars().fold(String::with_capacity(s.len()), |mut s, c| { match OUTPUT_REPLACEMENTS.binary_search_by_key(&c, |(k, _)| *k) { Ok(i) => s.push_str(OUTPUT_REPLACEMENTS[i].1), From 6b3feb49c603096dd904a4689f2b57ba3ed6b27d Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 6 Aug 2024 14:16:53 -0400 Subject: [PATCH 05/12] Mark `{f32,f64}::{next_up,next_down,midpoint}` inline Most float functions are marked `#[inline]` so any float symbols used by these functions only need to be provided if the function itself is used. RFL recently noticed that `next_up`, `next_down`, and `midpoint` for `f32` and `f64` are not inline, which causes linker errors when building with certain configurations [1]. Add the missing attributes so the symbols should no longer be required. Cc: Gary Guo Reported-by: Alice Ryhl Link: https://lore.kernel.org/all/20240806150619.192882-1-ojeda@kernel.org/ [1] --- library/core/src/num/f32.rs | 3 +++ library/core/src/num/f64.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index 08d863f17caf7..eca75e1b6c394 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -797,6 +797,7 @@ impl f32 { /// [`INFINITY`]: Self::INFINITY /// [`MIN`]: Self::MIN /// [`MAX`]: Self::MAX + #[inline] #[unstable(feature = "float_next_up_down", issue = "91399")] #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_up(self) -> Self { @@ -845,6 +846,7 @@ impl f32 { /// [`INFINITY`]: Self::INFINITY /// [`MIN`]: Self::MIN /// [`MAX`]: Self::MAX + #[inline] #[unstable(feature = "float_next_up_down", issue = "91399")] #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_down(self) -> Self { @@ -1042,6 +1044,7 @@ impl f32 { /// assert_eq!(1f32.midpoint(4.0), 2.5); /// assert_eq!((-5.5f32).midpoint(8.0), 1.25); /// ``` + #[inline] #[unstable(feature = "num_midpoint", issue = "110840")] pub fn midpoint(self, other: f32) -> f32 { cfg_if! { diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index 5d33eea6d011f..533861381f922 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -805,6 +805,7 @@ impl f64 { /// [`INFINITY`]: Self::INFINITY /// [`MIN`]: Self::MIN /// [`MAX`]: Self::MAX + #[inline] #[unstable(feature = "float_next_up_down", issue = "91399")] #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_up(self) -> Self { @@ -853,6 +854,7 @@ impl f64 { /// [`INFINITY`]: Self::INFINITY /// [`MIN`]: Self::MIN /// [`MAX`]: Self::MAX + #[inline] #[unstable(feature = "float_next_up_down", issue = "91399")] #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_down(self) -> Self { @@ -1051,6 +1053,7 @@ impl f64 { /// assert_eq!(1f64.midpoint(4.0), 2.5); /// assert_eq!((-5.5f64).midpoint(8.0), 1.25); /// ``` + #[inline] #[unstable(feature = "num_midpoint", issue = "110840")] pub fn midpoint(self, other: f64) -> f64 { const LO: f64 = f64::MIN_POSITIVE * 2.; From 8eaef3eca04793eeb380870f8b9701c0e6727cd9 Mon Sep 17 00:00:00 2001 From: tiif Date: Sun, 4 Aug 2024 22:11:43 +0800 Subject: [PATCH 06/12] Add test --- .../using-late-bound-from-closure.rs | 16 ++++++++++++++++ .../using-late-bound-from-closure.stderr | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/ui/inline-const/using-late-bound-from-closure.rs create mode 100644 tests/ui/inline-const/using-late-bound-from-closure.stderr diff --git a/tests/ui/inline-const/using-late-bound-from-closure.rs b/tests/ui/inline-const/using-late-bound-from-closure.rs new file mode 100644 index 0000000000000..2b12b2e26a226 --- /dev/null +++ b/tests/ui/inline-const/using-late-bound-from-closure.rs @@ -0,0 +1,16 @@ +// Test for ICE: cannot convert ReLateParam to a region vid +// https://github.com/rust-lang/rust/issues/125873 + +#![feature(closure_lifetime_binder)] +fn foo() { + let a = for<'a> |b: &'a ()| -> &'a () { + const { + let awd = (); + let _: &'a () = &awd; + //~^ `awd` does not live long enough + }; + b + }; +} + +fn main() {} diff --git a/tests/ui/inline-const/using-late-bound-from-closure.stderr b/tests/ui/inline-const/using-late-bound-from-closure.stderr new file mode 100644 index 0000000000000..d6e1579aa343d --- /dev/null +++ b/tests/ui/inline-const/using-late-bound-from-closure.stderr @@ -0,0 +1,19 @@ +error[E0597]: `awd` does not live long enough + --> $DIR/using-late-bound-from-closure.rs:9:29 + | +LL | let a = for<'a> |b: &'a ()| -> &'a () { + | -- lifetime `'a` defined here +LL | const { +LL | let awd = (); + | --- binding `awd` declared here +LL | let _: &'a () = &awd; + | ------ ^^^^ borrowed value does not live long enough + | | + | type annotation requires that `awd` is borrowed for `'a` +LL | +LL | }; + | - `awd` dropped here while still borrowed + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0597`. From 7869400e589ca4e88cebb1da80a420f8e9042cdf Mon Sep 17 00:00:00 2001 From: Zachary S Date: Wed, 7 Aug 2024 13:04:43 -0500 Subject: [PATCH 07/12] Update E0517 message to reflect RFC 2195. --- .../src/error_codes/E0517.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0517.md b/compiler/rustc_error_codes/src/error_codes/E0517.md index ae802245bd1d7..5354a08bf31a7 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0517.md +++ b/compiler/rustc_error_codes/src/error_codes/E0517.md @@ -25,14 +25,17 @@ impl Foo { These attributes do not work on typedefs, since typedefs are just aliases. Representations like `#[repr(u8)]`, `#[repr(i64)]` are for selecting the -discriminant size for enums with no data fields on any of the variants, e.g. -`enum Color {Red, Blue, Green}`, effectively setting the size of the enum to -the size of the provided type. Such an enum can be cast to a value of the same -type as well. In short, `#[repr(u8)]` makes the enum behave like an integer -with a constrained set of allowed values. +discriminant size for enums. For enums with no data fields on any of the +variants, e.g. `enum Color {Red, Blue, Green}`, this effectively sets the size +of the enum to the size of the provided type. Such an enum can be cast to a +value of the same type as well. In short, `#[repr(u8)]` makes a field-less enum +behave like an integer with a constrained set of allowed values. -Only field-less enums can be cast to numerical primitives, so this attribute -will not apply to structs. +For a description of how `#[repr(C)]` and representations like `#[repr(u8)]` +affect the layout of enums with data fields, see [RFC 2195][rfc2195]. + +Only field-less enums can be cast to numerical primitives. Representations like +`#[repr(u8)]` will not apply to structs. `#[repr(packed)]` reduces padding to make the struct size smaller. The representation of enums isn't strictly defined in Rust, and this attribute @@ -42,3 +45,5 @@ won't work on enums. types (i.e., `u8`, `i32`, etc) a representation that permits vectorization via SIMD. This doesn't make much sense for enums since they don't consist of a single list of data. + +[rfc2195]: https://github.com/rust-lang/rfcs/blob/master/text/2195-really-tagged-unions.md From ae68b2fc56dd46b18ed12114d01015dcb73c7015 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 4 Aug 2024 13:59:11 +0200 Subject: [PATCH 08/12] migrate `thumb-none-qemu` to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/thumb-none-qemu/Makefile | 27 ---------- tests/run-make/thumb-none-qemu/rmake.rs | 51 +++++++++++++++++++ tests/run-make/thumb-none-qemu/script.sh | 20 -------- 4 files changed, 51 insertions(+), 48 deletions(-) delete mode 100644 tests/run-make/thumb-none-qemu/Makefile create mode 100644 tests/run-make/thumb-none-qemu/rmake.rs delete mode 100644 tests/run-make/thumb-none-qemu/script.sh diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 5ad688b55287a..14f0a9cd23d21 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -22,6 +22,5 @@ run-make/rlib-format-packed-bundled-libs/Makefile run-make/split-debuginfo/Makefile run-make/symbol-mangling-hashed/Makefile run-make/sysroot-crates-are-unstable/Makefile -run-make/thumb-none-qemu/Makefile run-make/translation/Makefile run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile diff --git a/tests/run-make/thumb-none-qemu/Makefile b/tests/run-make/thumb-none-qemu/Makefile deleted file mode 100644 index eea6ca3499289..0000000000000 --- a/tests/run-make/thumb-none-qemu/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -include ../tools.mk - -# only-thumb - -# How to run this -# $ ./x.py clean -# $ ./x.py test --target thumbv7m-none-eabi tests/run-make - -# For cargo setting -export RUSTC := $(RUSTC_ORIGINAL) -export LD_LIBRARY_PATH := $(HOST_RPATH_DIR) -# We need to be outside of 'src' dir in order to run cargo -export WORK_DIR := $(TMPDIR) -export HERE := $(shell pwd) - -## clean up unused env variables which might cause harm. -unexport RUSTC_LINKER -unexport RUSTC_BOOTSTRAP -unexport RUST_BUILD_STAGE -unexport RUST_TEST_THREADS -unexport RUST_TEST_TMPDIR -unexport AR -unexport CC -unexport CXX - -all: - bash script.sh diff --git a/tests/run-make/thumb-none-qemu/rmake.rs b/tests/run-make/thumb-none-qemu/rmake.rs new file mode 100644 index 0000000000000..e280f5fafa5c0 --- /dev/null +++ b/tests/run-make/thumb-none-qemu/rmake.rs @@ -0,0 +1,51 @@ +//! How to run this +//! $ ./x.py clean +//! $ ./x.py test --target thumbv6m-none-eabi,thumbv7m-none-eabi tests/run-make +//! +//! For supported targets, see `example/.cargo/config` + +//@ only-thumb + +use std::path::PathBuf; + +use run_make_support::{cmd, env_var}; + +const CRATE: &str = "example"; + +fn main() { + std::env::set_current_dir(CRATE).unwrap(); + + let target = env_var("TARGET"); + let bootstrap_cargo = env_var("BOOTSTRAP_CARGO"); + let path = env_var("PATH"); + let rustc = env_var("RUSTC"); + + let target_dir = PathBuf::from("target"); + let manifest_path = PathBuf::from("Cargo.toml"); + + let debug = { + let mut cmd = cmd(&bootstrap_cargo); + cmd.args(&["run", "--target", &target]) + .env("RUSTFLAGS", "-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x") + .env("CARGO_TARGET_DIR", &target_dir) + .env("PATH", &path) + .env("RUSTC", &rustc); + cmd.run() + }; + + let stdout = debug.stdout_utf8(); + assert!(stdout.contains("x = 42"), "stdout: {:?}", stdout); + + let release = { + let mut cmd = cmd(&bootstrap_cargo); + cmd.args(&["run", "--release", "--target", &target]) + .env("RUSTFLAGS", "-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x") + .env("CARGO_TARGET_DIR", &target_dir) + .env("PATH", &path) + .env("RUSTC", &rustc); + cmd.run() + }; + + let stdout = release.stdout_utf8(); + assert!(stdout.contains("x = 42"), "stdout: {:?}", stdout); +} diff --git a/tests/run-make/thumb-none-qemu/script.sh b/tests/run-make/thumb-none-qemu/script.sh deleted file mode 100644 index a8aa72af1845b..0000000000000 --- a/tests/run-make/thumb-none-qemu/script.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh -set -exuo pipefail - -CRATE=example - -env | sort -mkdir -p $WORK_DIR -pushd $WORK_DIR - rm -rf $CRATE || echo OK - cp -a $HERE/example . - pushd $CRATE - # HACK(eddyb) sets `RUSTC_BOOTSTRAP=1` so Cargo can accept nightly features. - # These come from the top-level Rust workspace, that this crate is not a - # member of, but Cargo tries to load the workspace `Cargo.toml` anyway. - env RUSTC_BOOTSTRAP=1 RUSTFLAGS="-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x" \ - $BOOTSTRAP_CARGO run --target $TARGET | grep "x = 42" - env RUSTC_BOOTSTRAP=1 RUSTFLAGS="-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x" \ - $BOOTSTRAP_CARGO run --target $TARGET --release | grep "x = 42" - popd -popd From 3e5885f7d2ad5c22a39b23e4b37b3b8483470e1e Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 4 Aug 2024 22:24:20 +0200 Subject: [PATCH 09/12] changes after review --- .../example/.cargo/{config => config.toml} | 5 ++- tests/run-make/thumb-none-qemu/rmake.rs | 33 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) rename tests/run-make/thumb-none-qemu/example/.cargo/{config => config.toml} (90%) diff --git a/tests/run-make/thumb-none-qemu/example/.cargo/config b/tests/run-make/thumb-none-qemu/example/.cargo/config.toml similarity index 90% rename from tests/run-make/thumb-none-qemu/example/.cargo/config rename to tests/run-make/thumb-none-qemu/example/.cargo/config.toml index 8b30310e7d432..7152e81b50221 100644 --- a/tests/run-make/thumb-none-qemu/example/.cargo/config +++ b/tests/run-make/thumb-none-qemu/example/.cargo/config.toml @@ -1,6 +1,5 @@ [target.thumbv6m-none-eabi] -# FIXME: Should be Cortex-M0, but Qemu used by CI is too old -runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" +runner = "qemu-system-arm -cpu cortex-m0 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" [target.thumbv7m-none-eabi] runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" @@ -12,7 +11,7 @@ runner = "qemu-system-arm -cpu cortex-m4 -machine lm3s6965evb -nographic -semiho runner = "qemu-system-arm -cpu cortex-m4 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" [target.thumbv8m.base-none-eabi] -# FIXME: Should be the Cortex-M23, bt Qemu does not currently support it +# FIXME: Should be the Cortex-M23, but Qemu does not currently support it runner = "qemu-system-arm -cpu cortex-m33 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel" [target.thumbv8m.main-none-eabi] diff --git a/tests/run-make/thumb-none-qemu/rmake.rs b/tests/run-make/thumb-none-qemu/rmake.rs index e280f5fafa5c0..d0f42bc880897 100644 --- a/tests/run-make/thumb-none-qemu/rmake.rs +++ b/tests/run-make/thumb-none-qemu/rmake.rs @@ -1,31 +1,44 @@ +//! This test runs a basic application for thumb targets, using the cortex-m crate. +//! +//! These targets are very bare-metal: the first instruction the core runs on +//! power-on is already user code. The cortex-m-rt has to initialize the stack, .data, +//! .bss, enable the FPU if present, etc. +//! +//! This test builds and runs the applications for various thumb targets using qemu. +//! //! How to run this //! $ ./x.py clean //! $ ./x.py test --target thumbv6m-none-eabi,thumbv7m-none-eabi tests/run-make //! -//! For supported targets, see `example/.cargo/config` +//! For supported targets, see `example/.cargo/config.toml` +//! +//! FIXME: https://github.com/rust-lang/rust/issues/128733 this test uses external +//! dependencies, and needs an active internet connection +//! +//! FIXME: https://github.com/rust-lang/rust/issues/128734 extract bootstrap cargo +//! to a proper command //@ only-thumb use std::path::PathBuf; -use run_make_support::{cmd, env_var}; +use run_make_support::{cmd, env_var, path_helpers, target}; const CRATE: &str = "example"; fn main() { std::env::set_current_dir(CRATE).unwrap(); - let target = env_var("TARGET"); let bootstrap_cargo = env_var("BOOTSTRAP_CARGO"); let path = env_var("PATH"); let rustc = env_var("RUSTC"); - let target_dir = PathBuf::from("target"); - let manifest_path = PathBuf::from("Cargo.toml"); + let target_dir = path_helpers::path("target"); + let manifest_path = path_helpers::path("Cargo.toml"); let debug = { let mut cmd = cmd(&bootstrap_cargo); - cmd.args(&["run", "--target", &target]) + cmd.args(&["run", "--target", &target()]) .env("RUSTFLAGS", "-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x") .env("CARGO_TARGET_DIR", &target_dir) .env("PATH", &path) @@ -33,12 +46,11 @@ fn main() { cmd.run() }; - let stdout = debug.stdout_utf8(); - assert!(stdout.contains("x = 42"), "stdout: {:?}", stdout); + debug.assert_stdout_contains("x = 42"); let release = { let mut cmd = cmd(&bootstrap_cargo); - cmd.args(&["run", "--release", "--target", &target]) + cmd.args(&["run", "--release", "--target", &target()]) .env("RUSTFLAGS", "-C linker=arm-none-eabi-ld -C link-arg=-Tlink.x") .env("CARGO_TARGET_DIR", &target_dir) .env("PATH", &path) @@ -46,6 +58,5 @@ fn main() { cmd.run() }; - let stdout = release.stdout_utf8(); - assert!(stdout.contains("x = 42"), "stdout: {:?}", stdout); + release.assert_stdout_contains("x = 42"); } From 9c29e0b818a157023025da233f0c411dfebb5080 Mon Sep 17 00:00:00 2001 From: bohan Date: Thu, 8 Aug 2024 20:30:20 +0800 Subject: [PATCH 10/12] rm `declared_features` field in resolver --- compiler/rustc_resolve/src/lib.rs | 5 ----- compiler/rustc_resolve/src/macros.rs | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 023e428dc1ba7..89ac839651fb1 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1129,9 +1129,6 @@ pub struct Resolver<'a, 'tcx> { /// Also includes of list of each fields visibility struct_constructors: LocalDefIdMap<(Res, ty::Visibility, Vec>)>, - /// Features declared for this crate. - declared_features: FxHashSet, - lint_buffer: LintBuffer, next_node_id: NodeId, @@ -1402,7 +1399,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let registered_tools = tcx.registered_tools(()); - let features = tcx.features(); let pub_vis = ty::Visibility::::Public; let edition = tcx.sess.edition(); @@ -1506,7 +1502,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { multi_segment_macro_resolutions: Default::default(), builtin_attrs: Default::default(), containers_deriving_copy: Default::default(), - declared_features: features.declared_features.clone(), lint_buffer: LintBuffer::default(), next_node_id: CRATE_NODE_ID, node_id_to_def_id, diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index a6301a367a4b3..da7278175e93a 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -1001,7 +1001,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let feature = stability.feature; let is_allowed = |feature| { - self.declared_features.contains(&feature) || span.allows_unstable(feature) + self.tcx.features().declared_features.contains(&feature) + || span.allows_unstable(feature) }; let allowed_by_implication = implied_by.is_some_and(|feature| is_allowed(feature)); if !is_allowed(feature) && !allowed_by_implication { From 9289f5691b29aa54a2c7fb596e4cf26d9ebcd53f Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Thu, 8 Aug 2024 13:09:58 +0000 Subject: [PATCH 11/12] Only suggest `#[allow]` for `--warn` and `--deny` lint level flags --- compiler/rustc_middle/src/lint.rs | 8 +++++--- tests/ui/lint/command-line-lint-group-forbid.stderr | 1 - .../cap-lints-warn-allowed-warn-by-default-lint.stderr | 1 - tests/ui/lint/force-warn/lint-group-allow-warnings.stderr | 1 - .../lint-group-allowed-cli-warn-by-default-lint.stderr | 1 - .../lint/force-warn/lint-group-allowed-lint-group.stderr | 1 - .../lint-group-allowed-warn-by-default-lint.stderr | 1 - tests/ui/lint/group-forbid-always-trumps-cli.stderr | 1 - 8 files changed, 5 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 6a9e67f74dac7..8c27cac1ea858 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -228,9 +228,11 @@ pub fn explain_lint_level_source( err.note_once(format!( "`{flag} {hyphen_case_lint_name}` implied by `{flag} {hyphen_case_flag_val}`" )); - err.help_once(format!( - "to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`" - )); + if matches!(orig_level, Level::Warn | Level::Deny) { + err.help_once(format!( + "to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`" + )); + } } } LintLevelSource::Node { name: lint_attr_name, span, reason, .. } => { diff --git a/tests/ui/lint/command-line-lint-group-forbid.stderr b/tests/ui/lint/command-line-lint-group-forbid.stderr index 7b527e7b8b461..ec9b6ca9664ca 100644 --- a/tests/ui/lint/command-line-lint-group-forbid.stderr +++ b/tests/ui/lint/command-line-lint-group-forbid.stderr @@ -5,7 +5,6 @@ LL | let _InappropriateCamelCasing = true; | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `_inappropriate_camel_casing` | = note: `-F non-snake-case` implied by `-F bad-style` - = help: to override `-F bad-style` add `#[allow(non_snake_case)]` error: aborting due to 1 previous error diff --git a/tests/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr b/tests/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr index 01c2ed84c635a..d1b764b341435 100644 --- a/tests/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr +++ b/tests/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr @@ -7,7 +7,6 @@ LL | 0...100 => true, = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see = note: `--force-warn ellipsis-inclusive-range-patterns` implied by `--force-warn rust-2021-compatibility` - = help: to override `--force-warn rust-2021-compatibility` add `#[allow(ellipsis_inclusive_range_patterns)]` warning: 1 warning emitted diff --git a/tests/ui/lint/force-warn/lint-group-allow-warnings.stderr b/tests/ui/lint/force-warn/lint-group-allow-warnings.stderr index e925a195fb1c4..dc7b1b7b98d0c 100644 --- a/tests/ui/lint/force-warn/lint-group-allow-warnings.stderr +++ b/tests/ui/lint/force-warn/lint-group-allow-warnings.stderr @@ -5,7 +5,6 @@ LL | pub fn FUNCTION() {} | ^^^^^^^^ help: convert the identifier to snake case: `function` | = note: `--force-warn non-snake-case` implied by `--force-warn nonstandard-style` - = help: to override `--force-warn nonstandard-style` add `#[allow(non_snake_case)]` warning: 1 warning emitted diff --git a/tests/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr b/tests/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr index a74cda2239f50..dc85e8cf96179 100644 --- a/tests/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr +++ b/tests/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr @@ -7,7 +7,6 @@ LL | pub fn function(_x: Box) {} = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see = note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms` - = help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]` help: if this is an object-safe trait, use `dyn` | LL | pub fn function(_x: Box) {} diff --git a/tests/ui/lint/force-warn/lint-group-allowed-lint-group.stderr b/tests/ui/lint/force-warn/lint-group-allowed-lint-group.stderr index c9472a3b9b9d3..55cfad838f84f 100644 --- a/tests/ui/lint/force-warn/lint-group-allowed-lint-group.stderr +++ b/tests/ui/lint/force-warn/lint-group-allowed-lint-group.stderr @@ -7,7 +7,6 @@ LL | pub fn function(_x: Box) {} = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see = note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms` - = help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]` help: if this is an object-safe trait, use `dyn` | LL | pub fn function(_x: Box) {} diff --git a/tests/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr b/tests/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr index 558d5cbb53156..b7bf0c4ee212f 100644 --- a/tests/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr +++ b/tests/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr @@ -7,7 +7,6 @@ LL | pub fn function(_x: Box) {} = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see = note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms` - = help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]` help: if this is an object-safe trait, use `dyn` | LL | pub fn function(_x: Box) {} diff --git a/tests/ui/lint/group-forbid-always-trumps-cli.stderr b/tests/ui/lint/group-forbid-always-trumps-cli.stderr index 21674ebae9cec..ed1242eacfce7 100644 --- a/tests/ui/lint/group-forbid-always-trumps-cli.stderr +++ b/tests/ui/lint/group-forbid-always-trumps-cli.stderr @@ -5,7 +5,6 @@ LL | let x = 1; | ^ help: if this is intentional, prefix it with an underscore: `_x` | = note: `-F unused-variables` implied by `-F unused` - = help: to override `-F unused` add `#[allow(unused_variables)]` error: aborting due to 1 previous error From 40a63d4f6e81c9083b56ac82f3fb489f7df644fb Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 8 Aug 2024 10:26:47 -0400 Subject: [PATCH 12/12] Update cargo --- src/tools/cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cargo b/src/tools/cargo index 94977cb1fab00..0d8d22f83b066 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 94977cb1fab003d45eb5bb108cb5e2fa0149672a +Subproject commit 0d8d22f83b066503f6b2b755925197e959e58b4f