qualify_min_const_fn: ignore cleanup bbs

This commit is contained in:
y21 2024-04-16 21:27:34 +02:00
parent 6fdf295664
commit 973f318514
3 changed files with 29 additions and 4 deletions

View file

@ -40,9 +40,13 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv)
)?;
for bb in &*body.basic_blocks {
check_terminator(tcx, body, bb.terminator(), msrv)?;
for stmt in &bb.statements {
check_statement(tcx, body, def_id, stmt, msrv)?;
// Cleanup blocks are ignored entirely by const eval, so we can too:
// https://github.com/rust-lang/rust/blob/1dea922ea6e74f99a0e97de5cdb8174e4dea0444/compiler/rustc_const_eval/src/transform/check_consts/check.rs#L382
if !bb.is_cleanup {
check_terminator(tcx, body, bb.terminator(), msrv)?;
for stmt in &bb.statements {
check_statement(tcx, body, def_id, stmt, msrv)?;
}
}
}
Ok(())

View file

@ -158,4 +158,16 @@ mod issue12677 {
Self { strings: Vec::new() }
}
}
pub struct Other {
pub text: String,
pub vec: Vec<String>,
}
impl Other {
pub fn new(text: String) -> Self {
let vec = Vec::new();
Self { text, vec }
}
}
}

View file

@ -146,5 +146,14 @@ LL | | Self { strings: Vec::new() }
LL | | }
| |_________^
error: aborting due to 16 previous errors
error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:168:9
|
LL | / pub fn new(text: String) -> Self {
LL | | let vec = Vec::new();
LL | | Self { text, vec }
LL | | }
| |_________^
error: aborting due to 17 previous errors