Ensure mir_drops_elaborated_and_const_checked when requiring codegen.

This commit is contained in:
Camille GILLOT 2023-04-09 09:42:57 +00:00
parent 409661936f
commit ed7e50e08b
8 changed files with 45 additions and 40 deletions

View File

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

View File

@ -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 $$? -eq 2

View File

@ -0,0 +1,5 @@
#![deny(arithmetic_overflow)]
fn main() {
let x = 255u8 + 1;
}

View File

@ -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
}

View File

@ -1,6 +1,7 @@
// build-pass
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unconditional_panic)]
const A: [u32; 1] = [0];
fn test() {

View File

@ -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
|
@ -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

View File

@ -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
|
@ -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

View File

@ -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
|
@ -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