diff --git a/compiler/rustc_arena/src/lib.rs b/compiler/rustc_arena/src/lib.rs index 34736b820e963..1a85a46ed74f0 100644 --- a/compiler/rustc_arena/src/lib.rs +++ b/compiler/rustc_arena/src/lib.rs @@ -217,8 +217,12 @@ impl TypedArena { let mut chunks = self.chunks.borrow_mut(); let mut new_cap; if let Some(last_chunk) = chunks.last_mut() { - let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize; - last_chunk.entries = used_bytes / mem::size_of::(); + // If a type is `!needs_drop`, we don't need to keep track of how many elements + // the chunk stores - the field will be ignored anyway. + if mem::needs_drop::() { + let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize; + last_chunk.entries = used_bytes / mem::size_of::(); + } // If the previous chunk's len is less than HUGE_PAGE // bytes, then this chunk will be least double the previous diff --git a/compiler/rustc_ast_pretty/src/pp.rs b/compiler/rustc_ast_pretty/src/pp.rs index 95f969d7691e0..56e769ba6b710 100644 --- a/compiler/rustc_ast_pretty/src/pp.rs +++ b/compiler/rustc_ast_pretty/src/pp.rs @@ -390,7 +390,7 @@ impl Printer { self.scan_stack.pop_front().unwrap() } - fn scan_top(&mut self) -> usize { + fn scan_top(&self) -> usize { *self.scan_stack.front().unwrap() } @@ -484,7 +484,7 @@ impl Printer { self.pending_indentation += amount; } - fn get_top(&mut self) -> PrintStackElem { + fn get_top(&self) -> PrintStackElem { *self.print_stack.last().unwrap_or({ &PrintStackElem { offset: 0, pbreak: PrintStackBreak::Broken(Breaks::Inconsistent) } }) diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index af8f813278047..029a6cb664dc3 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -63,7 +63,7 @@ impl<'a> Comments<'a> { } pub fn trailing_comment( - &mut self, + &self, span: rustc_span::Span, next_pos: Option, ) -> Option { diff --git a/compiler/rustc_middle/src/mir/coverage/mod.rs b/compiler/rustc_middle/src/mir/coverage.rs similarity index 100% rename from compiler/rustc_middle/src/mir/coverage/mod.rs rename to compiler/rustc_middle/src/mir/coverage.rs diff --git a/compiler/rustc_middle/src/mir/terminator/mod.rs b/compiler/rustc_middle/src/mir/terminator.rs similarity index 100% rename from compiler/rustc_middle/src/mir/terminator/mod.rs rename to compiler/rustc_middle/src/mir/terminator.rs diff --git a/compiler/rustc_mir/src/interpret/intern.rs b/compiler/rustc_mir/src/interpret/intern.rs index dd5e9c9977437..945791eddc8f1 100644 --- a/compiler/rustc_mir/src/interpret/intern.rs +++ b/compiler/rustc_mir/src/interpret/intern.rs @@ -187,6 +187,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx>> ValueVisitor<'mir return walked; } } + + // ZSTs do not need validation unless they're uninhabited + if mplace.layout.is_zst() && !mplace.layout.abi.is_uninhabited() { + return Ok(()); + } + self.walk_aggregate(mplace, fields) } diff --git a/compiler/rustc_trait_selection/src/traits/codegen/mod.rs b/compiler/rustc_trait_selection/src/traits/codegen.rs similarity index 100% rename from compiler/rustc_trait_selection/src/traits/codegen/mod.rs rename to compiler/rustc_trait_selection/src/traits/codegen.rs diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 2a7c105e807f4..dbc7921a62a67 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1660,22 +1660,22 @@ extern "rust-intrinsic" { /// Returns (a + b) mod 2N, where N is the width of T in bits. /// /// The stabilized versions of this intrinsic are available on the integer - /// primitives via the `checked_add` method. For example, - /// [`u32::checked_add`] + /// primitives via the `wrapping_add` method. For example, + /// [`u32::wrapping_add`] #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")] pub fn wrapping_add(a: T, b: T) -> T; /// Returns (a - b) mod 2N, where N is the width of T in bits. /// /// The stabilized versions of this intrinsic are available on the integer - /// primitives via the `checked_sub` method. For example, - /// [`u32::checked_sub`] + /// primitives via the `wrapping_sub` method. For example, + /// [`u32::wrapping_sub`] #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")] pub fn wrapping_sub(a: T, b: T) -> T; /// Returns (a * b) mod 2N, where N is the width of T in bits. /// /// The stabilized versions of this intrinsic are available on the integer - /// primitives via the `checked_mul` method. For example, - /// [`u32::checked_mul`] + /// primitives via the `wrapping_mul` method. For example, + /// [`u32::wrapping_mul`] #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")] pub fn wrapping_mul(a: T, b: T) -> T; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 12726d2bd9a3e..3270cc4dda6d8 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -85,12 +85,6 @@ mod theme; mod visit_ast; mod visit_lib; -struct Output { - krate: clean::Crate, - renderinfo: config::RenderInfo, - renderopts: config::RenderOptions, -} - pub fn main() { rustc_driver::set_sigpipe_handler(); rustc_driver::install_ice_hook(); @@ -521,7 +515,6 @@ fn main_options(options: config::Options) -> MainResult { krate.version = crate_version; - let out = Output { krate, renderinfo, renderopts }; if show_coverage { // if we ran coverage, bail early, we don't need to also generate docs at this point @@ -529,7 +522,6 @@ fn main_options(options: config::Options) -> MainResult { return Ok(()); } - let Output { krate, renderinfo, renderopts } = out; info!("going to format"); let (error_format, edition, debugging_options) = diag_opts; let diag = core::new_handler(error_format, None, &debugging_options); diff --git a/src/test/codegen/issue-73827-bounds-check-index-in-subexpr.rs b/src/test/codegen/issue-73827-bounds-check-index-in-subexpr.rs new file mode 100644 index 0000000000000..d07eaa75b7a82 --- /dev/null +++ b/src/test/codegen/issue-73827-bounds-check-index-in-subexpr.rs @@ -0,0 +1,18 @@ +// This test checks that bounds checks are elided when +// index is part of a (x | y) < C style condition + +// min-llvm-version: 11.0.0 +// compile-flags: -O + +#![crate_type = "lib"] + +// CHECK-LABEL: @get +#[no_mangle] +pub fn get(array: &[u8; 8], x: usize, y: usize) -> u8 { + if x > 7 || y > 7 { + 0 + } else { + // CHECK-NOT: panic_bounds_check + array[y] + } +} diff --git a/src/test/ui/consts/const-eval/const_panic.rs b/src/test/ui/consts/const-eval/const_panic.rs index 3e5112b0b145f..ada9feec8971e 100644 --- a/src/test/ui/consts/const-eval/const_panic.rs +++ b/src/test/ui/consts/const-eval/const_panic.rs @@ -1,11 +1,26 @@ #![feature(const_panic)] #![crate_type = "lib"] -pub const Z: () = panic!("cheese"); +const Z: () = std::panic!("cheese"); //~^ ERROR any use of this value will cause an error -pub const Y: () = unreachable!(); +const Z2: () = std::panic!(); //~^ ERROR any use of this value will cause an error -pub const X: () = unimplemented!(); +const Y: () = std::unreachable!(); +//~^ ERROR any use of this value will cause an error + +const X: () = std::unimplemented!(); +//~^ ERROR any use of this value will cause an error + +const Z_CORE: () = core::panic!("cheese"); +//~^ ERROR any use of this value will cause an error + +const Z2_CORE: () = core::panic!(); +//~^ ERROR any use of this value will cause an error + +const Y_CORE: () = core::unreachable!(); +//~^ ERROR any use of this value will cause an error + +const X_CORE: () = core::unimplemented!(); //~^ ERROR any use of this value will cause an error diff --git a/src/test/ui/consts/const-eval/const_panic.stderr b/src/test/ui/consts/const-eval/const_panic.stderr index 679d8f280cc60..e4ca1f4fa26a2 100644 --- a/src/test/ui/consts/const-eval/const_panic.stderr +++ b/src/test/ui/consts/const-eval/const_panic.stderr @@ -1,33 +1,83 @@ error: any use of this value will cause an error - --> $DIR/const_panic.rs:4:19 + --> $DIR/const_panic.rs:4:15 | -LL | pub const Z: () = panic!("cheese"); - | ------------------^^^^^^^^^^^^^^^^- - | | - | the evaluated program panicked at 'cheese', $DIR/const_panic.rs:4:19 +LL | const Z: () = std::panic!("cheese"); + | --------------^^^^^^^^^^^^^^^^^^^^^- + | | + | the evaluated program panicked at 'cheese', $DIR/const_panic.rs:4:15 | = note: `#[deny(const_err)]` on by default = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: any use of this value will cause an error - --> $DIR/const_panic.rs:7:19 + --> $DIR/const_panic.rs:7:16 | -LL | pub const Y: () = unreachable!(); - | ------------------^^^^^^^^^^^^^^- - | | - | the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:7:19 +LL | const Z2: () = std::panic!(); + | ---------------^^^^^^^^^^^^^- + | | + | the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:7:16 | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: any use of this value will cause an error - --> $DIR/const_panic.rs:10:19 + --> $DIR/const_panic.rs:10:15 | -LL | pub const X: () = unimplemented!(); - | ------------------^^^^^^^^^^^^^^^^- - | | - | the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:10:19 +LL | const Y: () = std::unreachable!(); + | --------------^^^^^^^^^^^^^^^^^^^- + | | + | the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:10:15 | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 3 previous errors +error: any use of this value will cause an error + --> $DIR/const_panic.rs:13:15 + | +LL | const X: () = std::unimplemented!(); + | --------------^^^^^^^^^^^^^^^^^^^^^- + | | + | the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:13:15 + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: any use of this value will cause an error + --> $DIR/const_panic.rs:16:20 + | +LL | const Z_CORE: () = core::panic!("cheese"); + | -------------------^^^^^^^^^^^^^^^^^^^^^^- + | | + | the evaluated program panicked at 'cheese', $DIR/const_panic.rs:16:20 + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: any use of this value will cause an error + --> $DIR/const_panic.rs:19:21 + | +LL | const Z2_CORE: () = core::panic!(); + | --------------------^^^^^^^^^^^^^^- + | | + | the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:19:21 + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: any use of this value will cause an error + --> $DIR/const_panic.rs:22:20 + | +LL | const Y_CORE: () = core::unreachable!(); + | -------------------^^^^^^^^^^^^^^^^^^^^- + | | + | the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:22:20 + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: any use of this value will cause an error + --> $DIR/const_panic.rs:25:20 + | +LL | const X_CORE: () = core::unimplemented!(); + | -------------------^^^^^^^^^^^^^^^^^^^^^^- + | | + | the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:25:20 + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 8 previous errors diff --git a/src/test/ui/consts/const-eval/const_panic_libcore.rs b/src/test/ui/consts/const-eval/const_panic_libcore.rs deleted file mode 100644 index e42685e9c76b0..0000000000000 --- a/src/test/ui/consts/const-eval/const_panic_libcore.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![no_std] -#![crate_type = "lib"] -#![feature(const_panic)] - -const Z: () = panic!("cheese"); -//~^ ERROR any use of this value will cause an error - -const Y: () = unreachable!(); -//~^ ERROR any use of this value will cause an error - -const X: () = unimplemented!(); -//~^ ERROR any use of this value will cause an error diff --git a/src/test/ui/consts/const-eval/const_panic_libcore_main.rs b/src/test/ui/consts/const-eval/const_panic_libcore_bin.rs similarity index 100% rename from src/test/ui/consts/const-eval/const_panic_libcore_main.rs rename to src/test/ui/consts/const-eval/const_panic_libcore_bin.rs diff --git a/src/test/ui/consts/const-eval/const_panic_libcore.stderr b/src/test/ui/consts/const-eval/const_panic_libcore_bin.stderr similarity index 78% rename from src/test/ui/consts/const-eval/const_panic_libcore.stderr rename to src/test/ui/consts/const-eval/const_panic_libcore_bin.stderr index 2abf158aade54..9eeddc464f5ad 100644 --- a/src/test/ui/consts/const-eval/const_panic_libcore.stderr +++ b/src/test/ui/consts/const-eval/const_panic_libcore_bin.stderr @@ -1,31 +1,31 @@ error: any use of this value will cause an error - --> $DIR/const_panic_libcore.rs:5:15 + --> $DIR/const_panic_libcore_bin.rs:9:15 | LL | const Z: () = panic!("cheese"); | --------------^^^^^^^^^^^^^^^^- | | - | the evaluated program panicked at 'cheese', $DIR/const_panic_libcore.rs:5:15 + | the evaluated program panicked at 'cheese', $DIR/const_panic_libcore_bin.rs:9:15 | = note: `#[deny(const_err)]` on by default = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: any use of this value will cause an error - --> $DIR/const_panic_libcore.rs:8:15 + --> $DIR/const_panic_libcore_bin.rs:12:15 | LL | const Y: () = unreachable!(); | --------------^^^^^^^^^^^^^^- | | - | the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore.rs:8:15 + | the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore_bin.rs:12:15 | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: any use of this value will cause an error - --> $DIR/const_panic_libcore.rs:11:15 + --> $DIR/const_panic_libcore_bin.rs:15:15 | LL | const X: () = unimplemented!(); | --------------^^^^^^^^^^^^^^^^- | | - | the evaluated program panicked at 'not implemented', $DIR/const_panic_libcore.rs:11:15 + | the evaluated program panicked at 'not implemented', $DIR/const_panic_libcore_bin.rs:15:15 | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/consts/const-eval/const_panic_libcore_main.stderr b/src/test/ui/consts/const-eval/const_panic_libcore_main.stderr deleted file mode 100644 index c5887ff8c5697..0000000000000 --- a/src/test/ui/consts/const-eval/const_panic_libcore_main.stderr +++ /dev/null @@ -1,33 +0,0 @@ -error: any use of this value will cause an error - --> $DIR/const_panic_libcore_main.rs:9:15 - | -LL | const Z: () = panic!("cheese"); - | --------------^^^^^^^^^^^^^^^^- - | | - | the evaluated program panicked at 'cheese', $DIR/const_panic_libcore_main.rs:9:15 - | - = note: `#[deny(const_err)]` on by default - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: any use of this value will cause an error - --> $DIR/const_panic_libcore_main.rs:12:15 - | -LL | const Y: () = unreachable!(); - | --------------^^^^^^^^^^^^^^- - | | - | the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore_main.rs:12:15 - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: any use of this value will cause an error - --> $DIR/const_panic_libcore_main.rs:15:15 - | -LL | const X: () = unimplemented!(); - | --------------^^^^^^^^^^^^^^^^- - | | - | the evaluated program panicked at 'not implemented', $DIR/const_panic_libcore_main.rs:15:15 - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 3 previous errors - diff --git a/src/test/ui/issues/issue-68010-large-zst-consts.rs b/src/test/ui/issues/issue-68010-large-zst-consts.rs new file mode 100644 index 0000000000000..4f1bd45e90a19 --- /dev/null +++ b/src/test/ui/issues/issue-68010-large-zst-consts.rs @@ -0,0 +1,5 @@ +// build-pass + +fn main() { + println!("{}", [(); std::usize::MAX].len()); +} diff --git a/src/test/ui/mir/auxiliary/issue_76375_aux.rs b/src/test/ui/mir/auxiliary/issue_76375_aux.rs new file mode 100644 index 0000000000000..f8b318d58ba2a --- /dev/null +++ b/src/test/ui/mir/auxiliary/issue_76375_aux.rs @@ -0,0 +1,14 @@ +// edition:2018 +// compile-flags: -Z mir-opt-level=2 -Z unsound-mir-opts + +#[inline(always)] +pub fn f(s: bool) -> String { + let a = "Hello world!".to_string(); + let b = a; + let c = b; + if s { + c + } else { + String::new() + } +} diff --git a/src/test/ui/mir/issue-68841.rs b/src/test/ui/mir/issue-68841.rs new file mode 100644 index 0000000000000..14884a97fabcb --- /dev/null +++ b/src/test/ui/mir/issue-68841.rs @@ -0,0 +1,15 @@ +// compile-flags: -Z mir-opt-level=2 +// edition:2018 +// build-pass + +#![feature(async_closure)] + +use std::future::Future; + +fn async_closure() -> impl Future { + (async move || -> u8 { 42 })() +} + +fn main() { + let _fut = async_closure(); +} diff --git a/src/test/ui/mir/issue-75053.rs b/src/test/ui/mir/issue-75053.rs new file mode 100644 index 0000000000000..6e7211c2ee60e --- /dev/null +++ b/src/test/ui/mir/issue-75053.rs @@ -0,0 +1,48 @@ +// compile-flags: -Z mir-opt-level=2 +// build-pass + +#![feature(type_alias_impl_trait)] + +use std::marker::PhantomData; + +trait MyIndex { + type O; + fn my_index(self) -> Self::O; +} +trait MyFrom: Sized { + type Error; + fn my_from(value: T) -> Result; +} + +trait F {} +impl F for () {} +type DummyT = impl F; +fn _dummy_t() -> DummyT {} + +struct Phantom1(PhantomData); +struct Phantom2(PhantomData); +struct Scope(Phantom2>); + +impl Scope { + fn new() -> Self { + unimplemented!() + } +} + +impl MyFrom> for Phantom1 { + type Error = (); + fn my_from(_: Phantom2) -> Result { + unimplemented!() + } +} + +impl>>, U> MyIndex> for Scope { + type O = T; + fn my_index(self) -> Self::O { + MyFrom::my_from(self.0).ok().unwrap() + } +} + +fn main() { + let _pos: Phantom1> = Scope::new().my_index(); +} diff --git a/src/test/ui/mir/issue-76375.rs b/src/test/ui/mir/issue-76375.rs new file mode 100644 index 0000000000000..ef459f6a28ec8 --- /dev/null +++ b/src/test/ui/mir/issue-76375.rs @@ -0,0 +1,15 @@ +// edition:2018 +// build-pass +// compile-flags: -Z mir-opt-level=2 -L. +// aux-build:issue_76375_aux.rs + +#![crate_type = "lib"] + +extern crate issue_76375_aux; + +pub async fn g() { + issue_76375_aux::f(true); + h().await; +} + +pub async fn h() {} diff --git a/src/test/ui/mir/issue-77911.rs b/src/test/ui/mir/issue-77911.rs new file mode 100644 index 0000000000000..b24faa6f885c7 --- /dev/null +++ b/src/test/ui/mir/issue-77911.rs @@ -0,0 +1,16 @@ +// compile-flags: -Z mir-opt-level=2 +// ignore-cloudabi no std::fs +// build-pass + +use std::fs::File; +use std::io::{BufRead, BufReader}; + +fn file_lines() -> impl Iterator { + BufReader::new(File::open("").unwrap()) + .lines() + .map(Result::unwrap) +} + +fn main() { + for _ in file_lines() {} +}