Make sure that const prop does not produce unsilenceable lints after inlining

This commit is contained in:
oli 2020-12-30 02:04:52 +00:00
parent b8727e2d60
commit 0491e74dd9
2 changed files with 24 additions and 1 deletions

View file

@ -440,7 +440,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
}
fn lint_root(&self, source_info: SourceInfo) -> Option<HirId> {
match &self.source_scopes[source_info.scope].local_data {
let mut data = &self.source_scopes[source_info.scope];
// FIXME(oli-obk): we should be able to just walk the `inlined_parent_scope`, but it
// does not work as I thought it would. Needs more investigation and documentation.
while data.inlined.is_some() {
trace!(?data);
data = &self.source_scopes[data.parent_scope.unwrap()];
}
trace!(?data);
match &data.local_data {
ClearCrossCrate::Set(data) => Some(data.lint_root),
ClearCrossCrate::Clear => None,
}

View file

@ -0,0 +1,15 @@
// Must be build-pass, because check-pass will not run const prop and thus not emit the lint anyway.
// build-pass
// compile-flags: -Zmir-opt-level=2
#![deny(warnings)]
fn main() {
#[allow(arithmetic_overflow)]
let _ = add(u8::MAX, 1);
}
#[inline(always)]
fn add(x: u8, y: u8) -> u8 {
x + y
}