Skip to content

Commit 31530e5

Browse files
committed
Auto merge of rust-lang#78162 - GuillaumeGomez:rollup-6a4qiqu, r=GuillaumeGomez
Rollup of 9 pull requests Successful merges: - rust-lang#78046 (Add codegen test for issue rust-lang#73827) - rust-lang#78061 (Optimize const value interning for ZST types) - rust-lang#78070 (we can test std and core panic macros together) - rust-lang#78076 (Move orphan module-name/mod.rs files into module-name.rs files) - rust-lang#78129 (Wrapping intrinsics doc links update.) - rust-lang#78133 (Add some MIR-related regression tests) - rust-lang#78144 (Don't update `entries` in `TypedArena` if T does not need drop) - rust-lang#78145 (Drop unneeded `mut`) - rust-lang#78157 (Remove unused type from librustdoc) Failed merges: r? `@ghost`
2 parents 981346f + 1df5346 commit 31530e5

22 files changed

+242
-90
lines changed

compiler/rustc_arena/src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,12 @@ impl<T> TypedArena<T> {
217217
let mut chunks = self.chunks.borrow_mut();
218218
let mut new_cap;
219219
if let Some(last_chunk) = chunks.last_mut() {
220-
let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize;
221-
last_chunk.entries = used_bytes / mem::size_of::<T>();
220+
// If a type is `!needs_drop`, we don't need to keep track of how many elements
221+
// the chunk stores - the field will be ignored anyway.
222+
if mem::needs_drop::<T>() {
223+
let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize;
224+
last_chunk.entries = used_bytes / mem::size_of::<T>();
225+
}
222226

223227
// If the previous chunk's len is less than HUGE_PAGE
224228
// bytes, then this chunk will be least double the previous

compiler/rustc_ast_pretty/src/pp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl Printer {
390390
self.scan_stack.pop_front().unwrap()
391391
}
392392

393-
fn scan_top(&mut self) -> usize {
393+
fn scan_top(&self) -> usize {
394394
*self.scan_stack.front().unwrap()
395395
}
396396

@@ -484,7 +484,7 @@ impl Printer {
484484
self.pending_indentation += amount;
485485
}
486486

487-
fn get_top(&mut self) -> PrintStackElem {
487+
fn get_top(&self) -> PrintStackElem {
488488
*self.print_stack.last().unwrap_or({
489489
&PrintStackElem { offset: 0, pbreak: PrintStackBreak::Broken(Breaks::Inconsistent) }
490490
})

compiler/rustc_ast_pretty/src/pprust/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'a> Comments<'a> {
6363
}
6464

6565
pub fn trailing_comment(
66-
&mut self,
66+
&self,
6767
span: rustc_span::Span,
6868
next_pos: Option<BytePos>,
6969
) -> Option<Comment> {

compiler/rustc_mir/src/interpret/intern.rs

+6
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx>> ValueVisitor<'mir
187187
return walked;
188188
}
189189
}
190+
191+
// ZSTs do not need validation unless they're uninhabited
192+
if mplace.layout.is_zst() && !mplace.layout.abi.is_uninhabited() {
193+
return Ok(());
194+
}
195+
190196
self.walk_aggregate(mplace, fields)
191197
}
192198

library/core/src/intrinsics.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1660,22 +1660,22 @@ extern "rust-intrinsic" {
16601660
/// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
16611661
///
16621662
/// The stabilized versions of this intrinsic are available on the integer
1663-
/// primitives via the `checked_add` method. For example,
1664-
/// [`u32::checked_add`]
1663+
/// primitives via the `wrapping_add` method. For example,
1664+
/// [`u32::wrapping_add`]
16651665
#[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
16661666
pub fn wrapping_add<T: Copy>(a: T, b: T) -> T;
16671667
/// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
16681668
///
16691669
/// The stabilized versions of this intrinsic are available on the integer
1670-
/// primitives via the `checked_sub` method. For example,
1671-
/// [`u32::checked_sub`]
1670+
/// primitives via the `wrapping_sub` method. For example,
1671+
/// [`u32::wrapping_sub`]
16721672
#[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
16731673
pub fn wrapping_sub<T: Copy>(a: T, b: T) -> T;
16741674
/// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
16751675
///
16761676
/// The stabilized versions of this intrinsic are available on the integer
1677-
/// primitives via the `checked_mul` method. For example,
1678-
/// [`u32::checked_mul`]
1677+
/// primitives via the `wrapping_mul` method. For example,
1678+
/// [`u32::wrapping_mul`]
16791679
#[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
16801680
pub fn wrapping_mul<T: Copy>(a: T, b: T) -> T;
16811681

src/librustdoc/lib.rs

-9
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ mod theme;
8585
mod visit_ast;
8686
mod visit_lib;
8787

88-
struct Output {
89-
krate: clean::Crate,
90-
renderinfo: config::RenderInfo,
91-
renderopts: config::RenderOptions,
92-
}
93-
9488
pub fn main() {
9589
rustc_driver::set_sigpipe_handler();
9690
rustc_driver::install_ice_hook();
@@ -521,15 +515,12 @@ fn main_options(options: config::Options) -> MainResult {
521515

522516
krate.version = crate_version;
523517

524-
let out = Output { krate, renderinfo, renderopts };
525-
526518
if show_coverage {
527519
// if we ran coverage, bail early, we don't need to also generate docs at this point
528520
// (also we didn't load in any of the useful passes)
529521
return Ok(());
530522
}
531523

532-
let Output { krate, renderinfo, renderopts } = out;
533524
info!("going to format");
534525
let (error_format, edition, debugging_options) = diag_opts;
535526
let diag = core::new_handler(error_format, None, &debugging_options);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This test checks that bounds checks are elided when
2+
// index is part of a (x | y) < C style condition
3+
4+
// min-llvm-version: 11.0.0
5+
// compile-flags: -O
6+
7+
#![crate_type = "lib"]
8+
9+
// CHECK-LABEL: @get
10+
#[no_mangle]
11+
pub fn get(array: &[u8; 8], x: usize, y: usize) -> u8 {
12+
if x > 7 || y > 7 {
13+
0
14+
} else {
15+
// CHECK-NOT: panic_bounds_check
16+
array[y]
17+
}
18+
}
+18-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
#![feature(const_panic)]
22
#![crate_type = "lib"]
33

4-
pub const Z: () = panic!("cheese");
4+
const Z: () = std::panic!("cheese");
55
//~^ ERROR any use of this value will cause an error
66

7-
pub const Y: () = unreachable!();
7+
const Z2: () = std::panic!();
88
//~^ ERROR any use of this value will cause an error
99

10-
pub const X: () = unimplemented!();
10+
const Y: () = std::unreachable!();
11+
//~^ ERROR any use of this value will cause an error
12+
13+
const X: () = std::unimplemented!();
14+
//~^ ERROR any use of this value will cause an error
15+
16+
const Z_CORE: () = core::panic!("cheese");
17+
//~^ ERROR any use of this value will cause an error
18+
19+
const Z2_CORE: () = core::panic!();
20+
//~^ ERROR any use of this value will cause an error
21+
22+
const Y_CORE: () = core::unreachable!();
23+
//~^ ERROR any use of this value will cause an error
24+
25+
const X_CORE: () = core::unimplemented!();
1126
//~^ ERROR any use of this value will cause an error
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,83 @@
11
error: any use of this value will cause an error
2-
--> $DIR/const_panic.rs:4:19
2+
--> $DIR/const_panic.rs:4:15
33
|
4-
LL | pub const Z: () = panic!("cheese");
5-
| ------------------^^^^^^^^^^^^^^^^-
6-
| |
7-
| the evaluated program panicked at 'cheese', $DIR/const_panic.rs:4:19
4+
LL | const Z: () = std::panic!("cheese");
5+
| --------------^^^^^^^^^^^^^^^^^^^^^-
6+
| |
7+
| the evaluated program panicked at 'cheese', $DIR/const_panic.rs:4:15
88
|
99
= note: `#[deny(const_err)]` on by default
1010
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error: any use of this value will cause an error
13-
--> $DIR/const_panic.rs:7:19
13+
--> $DIR/const_panic.rs:7:16
1414
|
15-
LL | pub const Y: () = unreachable!();
16-
| ------------------^^^^^^^^^^^^^^-
17-
| |
18-
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:7:19
15+
LL | const Z2: () = std::panic!();
16+
| ---------------^^^^^^^^^^^^^-
17+
| |
18+
| the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:7:16
1919
|
2020
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2121

2222
error: any use of this value will cause an error
23-
--> $DIR/const_panic.rs:10:19
23+
--> $DIR/const_panic.rs:10:15
2424
|
25-
LL | pub const X: () = unimplemented!();
26-
| ------------------^^^^^^^^^^^^^^^^-
27-
| |
28-
| the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:10:19
25+
LL | const Y: () = std::unreachable!();
26+
| --------------^^^^^^^^^^^^^^^^^^^-
27+
| |
28+
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:10:15
2929
|
3030
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3131

32-
error: aborting due to 3 previous errors
32+
error: any use of this value will cause an error
33+
--> $DIR/const_panic.rs:13:15
34+
|
35+
LL | const X: () = std::unimplemented!();
36+
| --------------^^^^^^^^^^^^^^^^^^^^^-
37+
| |
38+
| the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:13:15
39+
|
40+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
41+
42+
error: any use of this value will cause an error
43+
--> $DIR/const_panic.rs:16:20
44+
|
45+
LL | const Z_CORE: () = core::panic!("cheese");
46+
| -------------------^^^^^^^^^^^^^^^^^^^^^^-
47+
| |
48+
| the evaluated program panicked at 'cheese', $DIR/const_panic.rs:16:20
49+
|
50+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
51+
52+
error: any use of this value will cause an error
53+
--> $DIR/const_panic.rs:19:21
54+
|
55+
LL | const Z2_CORE: () = core::panic!();
56+
| --------------------^^^^^^^^^^^^^^-
57+
| |
58+
| the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:19:21
59+
|
60+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
61+
62+
error: any use of this value will cause an error
63+
--> $DIR/const_panic.rs:22:20
64+
|
65+
LL | const Y_CORE: () = core::unreachable!();
66+
| -------------------^^^^^^^^^^^^^^^^^^^^-
67+
| |
68+
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:22:20
69+
|
70+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
71+
72+
error: any use of this value will cause an error
73+
--> $DIR/const_panic.rs:25:20
74+
|
75+
LL | const X_CORE: () = core::unimplemented!();
76+
| -------------------^^^^^^^^^^^^^^^^^^^^^^-
77+
| |
78+
| the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:25:20
79+
|
80+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
81+
82+
error: aborting due to 8 previous errors
3383

src/test/ui/consts/const-eval/const_panic_libcore.rs

-12
This file was deleted.

src/test/ui/consts/const-eval/const_panic_libcore.stderr src/test/ui/consts/const-eval/const_panic_libcore_bin.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
error: any use of this value will cause an error
2-
--> $DIR/const_panic_libcore.rs:5:15
2+
--> $DIR/const_panic_libcore_bin.rs:9:15
33
|
44
LL | const Z: () = panic!("cheese");
55
| --------------^^^^^^^^^^^^^^^^-
66
| |
7-
| the evaluated program panicked at 'cheese', $DIR/const_panic_libcore.rs:5:15
7+
| the evaluated program panicked at 'cheese', $DIR/const_panic_libcore_bin.rs:9:15
88
|
99
= note: `#[deny(const_err)]` on by default
1010
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error: any use of this value will cause an error
13-
--> $DIR/const_panic_libcore.rs:8:15
13+
--> $DIR/const_panic_libcore_bin.rs:12:15
1414
|
1515
LL | const Y: () = unreachable!();
1616
| --------------^^^^^^^^^^^^^^-
1717
| |
18-
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore.rs:8:15
18+
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore_bin.rs:12:15
1919
|
2020
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2121

2222
error: any use of this value will cause an error
23-
--> $DIR/const_panic_libcore.rs:11:15
23+
--> $DIR/const_panic_libcore_bin.rs:15:15
2424
|
2525
LL | const X: () = unimplemented!();
2626
| --------------^^^^^^^^^^^^^^^^-
2727
| |
28-
| the evaluated program panicked at 'not implemented', $DIR/const_panic_libcore.rs:11:15
28+
| the evaluated program panicked at 'not implemented', $DIR/const_panic_libcore_bin.rs:15:15
2929
|
3030
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3131

src/test/ui/consts/const-eval/const_panic_libcore_main.stderr

-33
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// build-pass
2+
3+
fn main() {
4+
println!("{}", [(); std::usize::MAX].len());
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// edition:2018
2+
// compile-flags: -Z mir-opt-level=2 -Z unsound-mir-opts
3+
4+
#[inline(always)]
5+
pub fn f(s: bool) -> String {
6+
let a = "Hello world!".to_string();
7+
let b = a;
8+
let c = b;
9+
if s {
10+
c
11+
} else {
12+
String::new()
13+
}
14+
}

src/test/ui/mir/issue-68841.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-flags: -Z mir-opt-level=2
2+
// edition:2018
3+
// build-pass
4+
5+
#![feature(async_closure)]
6+
7+
use std::future::Future;
8+
9+
fn async_closure() -> impl Future<Output = u8> {
10+
(async move || -> u8 { 42 })()
11+
}
12+
13+
fn main() {
14+
let _fut = async_closure();
15+
}

0 commit comments

Comments
 (0)