Skip to content

Commit

Permalink
Merge branch 'rust-lang:master' into mips-sig
Browse files Browse the repository at this point in the history
  • Loading branch information
MinxuanZ committed Aug 9, 2024
2 parents 01fd2e5 + c7b0d4e commit 79fc1af
Show file tree
Hide file tree
Showing 27 changed files with 160 additions and 88 deletions.
19 changes: 12 additions & 7 deletions compiler/rustc_error_codes/src/error_codes/E0517.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
22 changes: 15 additions & 7 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2595,9 +2595,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.
Expand All @@ -2610,7 +2608,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}', "␍"),
Expand Down Expand Up @@ -2643,13 +2641,23 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
('\u{2067}', "�"),
('\u{2068}', "�"),
('\u{2069}', "�"),
// tidy-alphabetical-end
];

fn normalize_whitespace(s: &str) -> String {
// 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.
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 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),
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, .. } => {
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,9 +1129,6 @@ pub struct Resolver<'a, 'tcx> {
/// Also includes of list of each fields visibility
struct_constructors: LocalDefIdMap<(Res, ty::Visibility<DefId>, Vec<ty::Visibility<DefId>>)>,

/// Features declared for this crate.
declared_features: FxHashSet<Symbol>,

lint_buffer: LintBuffer,

next_node_id: NodeId,
Expand Down Expand Up @@ -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::<DefId>::Public;
let edition = tcx.sess.edition();

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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! {
Expand Down
3 changes: 3 additions & 0 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.;
Expand Down
13 changes: 10 additions & 3 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,16 +1169,23 @@ impl<T: ?Sized> NonNull<T> {
/// `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.
///
/// There are no guarantees whatsoever that offsetting the pointer will not overflow or go
/// 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.
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/crashes/121127.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/122909.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -Zpolymorphize=on -Zinline-mir=yes
//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes
//@ known-bug: #122909


Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/126896.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
27 changes: 0 additions & 27 deletions tests/run-make/thumb-none-qemu/Makefile

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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]
Expand Down
62 changes: 62 additions & 0 deletions tests/run-make/thumb-none-qemu/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//! 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.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, path_helpers, target};

const CRATE: &str = "example";

fn main() {
std::env::set_current_dir(CRATE).unwrap();

let bootstrap_cargo = env_var("BOOTSTRAP_CARGO");
let path = env_var("PATH");
let rustc = env_var("RUSTC");

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()])
.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()
};

debug.assert_stdout_contains("x = 42");

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()
};

release.assert_stdout_contains("x = 42");
}
20 changes: 0 additions & 20 deletions tests/run-make/thumb-none-qemu/script.sh

This file was deleted.

16 changes: 16 additions & 0 deletions tests/ui/inline-const/using-late-bound-from-closure.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Loading

0 comments on commit 79fc1af

Please sign in to comment.