diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index 354d213689e..fd5c2236902 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -440,7 +440,15 @@ fn remove_const(ecx: &mut InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>, lo } fn lint_root(&self, source_info: SourceInfo) -> Option { - 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, } diff --git a/src/test/ui/const_prop/inline_spans_lint_attribute.rs b/src/test/ui/const_prop/inline_spans_lint_attribute.rs new file mode 100644 index 00000000000..656ff02dc67 --- /dev/null +++ b/src/test/ui/const_prop/inline_spans_lint_attribute.rs @@ -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 +}