Skip to content

Commit bd47189

Browse files
committed
qualify_min_const_fn: ignore cleanup bbs
1 parent 763e334 commit bd47189

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv)
4040
)?;
4141

4242
for bb in &*body.basic_blocks {
43-
check_terminator(tcx, body, bb.terminator(), msrv)?;
44-
for stmt in &bb.statements {
45-
check_statement(tcx, body, def_id, stmt, msrv)?;
43+
// Cleanup blocks are ignored entirely by const eval, so we can too:
44+
// https://github.com/rust-lang/rust/blob/1dea922ea6e74f99a0e97de5cdb8174e4dea0444/compiler/rustc_const_eval/src/transform/check_consts/check.rs#L382
45+
if !bb.is_cleanup {
46+
check_terminator(tcx, body, bb.terminator(), msrv)?;
47+
for stmt in &bb.statements {
48+
check_statement(tcx, body, def_id, stmt, msrv)?;
49+
}
4650
}
4751
}
4852
Ok(())

tests/ui/missing_const_for_fn/could_be_const.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,16 @@ mod issue12677 {
158158
Self { strings: Vec::new() }
159159
}
160160
}
161+
162+
pub struct Other {
163+
pub text: String,
164+
pub vec: Vec<String>,
165+
}
166+
167+
impl Other {
168+
pub fn new(text: String) -> Self {
169+
let vec = Vec::new();
170+
Self { text, vec }
171+
}
172+
}
161173
}

tests/ui/missing_const_for_fn/could_be_const.stderr

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,14 @@ LL | | Self { strings: Vec::new() }
146146
LL | | }
147147
| |_________^
148148

149-
error: aborting due to 16 previous errors
149+
error: this could be a `const fn`
150+
--> tests/ui/missing_const_for_fn/could_be_const.rs:168:9
151+
|
152+
LL | / pub fn new(text: String) -> Self {
153+
LL | | let vec = Vec::new();
154+
LL | | Self { text, vec }
155+
LL | | }
156+
| |_________^
157+
158+
error: aborting due to 17 previous errors
150159

0 commit comments

Comments
 (0)