Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure mir_drops_elaborated_and_const_checked when requiring codegen. #110107

Merged
merged 3 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,14 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
}
tcx.ensure().has_ffi_unwind_calls(def_id);

if tcx.hir().body_const_context(def_id).is_some() {
// If we need to codegen, ensure that we emit all errors from
// `mir_drops_elaborated_and_const_checked` now, to avoid discovering
// them later during codegen.
if tcx.sess.opts.output_types.should_codegen()
|| tcx.hir().body_const_context(def_id).is_some()
{
tcx.ensure().mir_drops_elaborated_and_const_checked(def_id);
tcx.ensure().unused_generic_params(ty::InstanceDef::Item(def_id.to_def_id()));
}
}
});
Expand Down
6 changes: 6 additions & 0 deletions src/tools/miri/tests/fail/const-ub-checks.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ error[E0080]: evaluation of constant value failed
LL | ptr.read();
| ^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required

note: erroneous constant used
--> $DIR/const-ub-checks.rs:LL:CC
|
LL | let _x = UNALIGNED_READ;
| ^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
14 changes: 14 additions & 0 deletions src/tools/miri/tests/fail/erroneous_const2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ error[E0080]: evaluation of constant value failed
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
| ^^^^^ attempt to compute `5_u32 - 6_u32`, which would overflow

note: erroneous constant used
--> $DIR/erroneous_const2.rs:LL:CC
|
LL | println!("{}", FOO);
| ^^^

note: erroneous constant used
--> $DIR/erroneous_const2.rs:LL:CC
|
LL | println!("{}", FOO);
| ^^^
|
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
6 changes: 0 additions & 6 deletions src/tools/miri/tests/pass/track-alloc-1.rs

This file was deleted.

5 changes: 0 additions & 5 deletions src/tools/miri/tests/pass/track-alloc-1.stderr

This file was deleted.

9 changes: 9 additions & 0 deletions tests/run-make/const-prop-lint/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include ../tools.mk

# Test that emitting an error because of arithmetic
# overflow lint does not leave .o files around
# because of interrupted codegen.

all:
$(RUSTC) input.rs; test $$? -eq 1
ls *.o; test $$? -ne 0
5 changes: 5 additions & 0 deletions tests/run-make/const-prop-lint/input.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![deny(arithmetic_overflow)]

fn main() {
let x = 255u8 + 1;
}
2 changes: 2 additions & 0 deletions tests/ui/consts/const-eval/issue-100878.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This checks that the const-eval ICE in issue #100878 does not recur.
//
// build-pass

#[allow(arithmetic_overflow)]
pub fn bitshift_data(data: [u8; 1]) -> u8 {
data[0] << 8
}
Expand Down
1 change: 1 addition & 0 deletions tests/ui/issues/issue-33287.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// build-pass
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unconditional_panic)]
const A: [u32; 1] = [0];

fn test() {
Expand Down
12 changes: 0 additions & 12 deletions tests/ui/polymorphization/generators.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ LL | pub fn unused_type<T>() -> impl Generator<(), Yield = u32, Return = u32> +
LL | || {
| ^^

note: the above error was encountered while instantiating `fn finish::<[generator@$DIR/generators.rs:35:5: 35:7], u32, u32>`
--> $DIR/generators.rs:86:5
|
LL | finish(unused_type::<u32>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: item has unused generic parameters
--> $DIR/generators.rs:60:5
|
Expand All @@ -29,11 +23,5 @@ LL | pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Retu
LL | || {
| ^^

note: the above error was encountered while instantiating `fn finish::<[generator@$DIR/generators.rs:60:5: 60:7], u32, u32>`
--> $DIR/generators.rs:89:5
|
LL | finish(unused_const::<1u32>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors; 1 warning emitted

18 changes: 6 additions & 12 deletions tests/ui/polymorphization/predicates.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
error: item has unused generic parameters
--> $DIR/predicates.rs:10:4
|
LL | fn bar<I>() {
| ^^^ - generic parameter `I` is unused

error: item has unused generic parameters
--> $DIR/predicates.rs:15:4
|
Expand Down Expand Up @@ -35,17 +41,5 @@ error: item has unused generic parameters
LL | fn foobar<F, G>() -> usize
| ^^^^^^ - generic parameter `F` is unused

error: item has unused generic parameters
--> $DIR/predicates.rs:10:4
|
LL | fn bar<I>() {
| ^^^ - generic parameter `I` is unused

note: the above error was encountered while instantiating `fn foo::<std::slice::Iter<'_, u32>, T>`
--> $DIR/predicates.rs:86:5
|
LL | foo(x.iter());
| ^^^^^^^^^^^^^

error: aborting due to 6 previous errors

30 changes: 15 additions & 15 deletions tests/ui/polymorphization/type_parameters/closures.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,6 @@ LL | impl<F: Default> Foo<F> {
LL | pub fn unused_all<G: Default>() -> u32 {
| ^^^^^^^^^^ - generic parameter `G` is unused

error: item has unused generic parameters
--> $DIR/closures.rs:128:23
|
LL | pub fn used_impl<G: Default>() -> u32 {
| - generic parameter `G` is unused
LL |
LL | let add_one = |x: u32| {
| ^^^^^^^^

error: item has unused generic parameters
--> $DIR/closures.rs:126:12
|
LL | pub fn used_impl<G: Default>() -> u32 {
| ^^^^^^^^^ - generic parameter `G` is unused

error: item has unused generic parameters
--> $DIR/closures.rs:115:23
|
Expand All @@ -76,5 +61,20 @@ LL | impl<F: Default> Foo<F> {
LL | pub fn used_fn<G: Default>() -> u32 {
| ^^^^^^^

error: item has unused generic parameters
--> $DIR/closures.rs:128:23
|
LL | pub fn used_impl<G: Default>() -> u32 {
| - generic parameter `G` is unused
LL |
LL | let add_one = |x: u32| {
| ^^^^^^^^

error: item has unused generic parameters
--> $DIR/closures.rs:126:12
|
LL | pub fn used_impl<G: Default>() -> u32 {
| ^^^^^^^^^ - generic parameter `G` is unused

error: aborting due to 9 previous errors