Skip to content

Commit

Permalink
Make sure that const prop does not produce unsilenceable lints after …
Browse files Browse the repository at this point in the history
…inlining
  • Loading branch information
oli-obk committed Jan 23, 2021
1 parent b8727e2 commit 0491e74
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/rustc_mir/src/transform/const_prop.rs
Expand Up @@ -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,
}
Expand Down
15 changes: 15 additions & 0 deletions 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
}

0 comments on commit 0491e74

Please sign in to comment.