mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
qualify_min_const_fn: ignore cleanup bbs
This commit is contained in:
parent
6fdf295664
commit
973f318514
3 changed files with 29 additions and 4 deletions
|
@ -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(())
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue