Skip to content

Commit 0491e74

Browse files
committed
Make sure that const prop does not produce unsilenceable lints after inlining
1 parent b8727e2 commit 0491e74

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

compiler/rustc_mir/src/transform/const_prop.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
440440
}
441441

442442
fn lint_root(&self, source_info: SourceInfo) -> Option<HirId> {
443-
match &self.source_scopes[source_info.scope].local_data {
443+
let mut data = &self.source_scopes[source_info.scope];
444+
// FIXME(oli-obk): we should be able to just walk the `inlined_parent_scope`, but it
445+
// does not work as I thought it would. Needs more investigation and documentation.
446+
while data.inlined.is_some() {
447+
trace!(?data);
448+
data = &self.source_scopes[data.parent_scope.unwrap()];
449+
}
450+
trace!(?data);
451+
match &data.local_data {
444452
ClearCrossCrate::Set(data) => Some(data.lint_root),
445453
ClearCrossCrate::Clear => None,
446454
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Must be build-pass, because check-pass will not run const prop and thus not emit the lint anyway.
2+
// build-pass
3+
// compile-flags: -Zmir-opt-level=2
4+
5+
#![deny(warnings)]
6+
7+
fn main() {
8+
#[allow(arithmetic_overflow)]
9+
let _ = add(u8::MAX, 1);
10+
}
11+
12+
#[inline(always)]
13+
fn add(x: u8, y: u8) -> u8 {
14+
x + y
15+
}

0 commit comments

Comments
 (0)