mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 22:12:15 +00:00
Auto merge of #115825 - cjgillot:expr-field-lint, r=compiler-errors
Visit ExprField for lint levels. Fixes https://github.com/rust-lang/rust/issues/115823
This commit is contained in:
commit
e17235105c
@ -159,6 +159,10 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
||||
hir_visit::walk_pat(self, p);
|
||||
}
|
||||
|
||||
fn visit_expr_field(&mut self, field: &'tcx hir::ExprField<'tcx>) {
|
||||
self.with_lint_attrs(field.hir_id, |cx| hir_visit::walk_expr_field(cx, field))
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
|
||||
ensure_sufficient_stack(|| {
|
||||
self.with_lint_attrs(e.hir_id, |cx| {
|
||||
|
@ -338,6 +338,11 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
|
||||
intravisit::walk_expr(self, e);
|
||||
}
|
||||
|
||||
fn visit_expr_field(&mut self, f: &'tcx hir::ExprField<'tcx>) {
|
||||
self.add_id(f.hir_id);
|
||||
intravisit::walk_expr_field(self, f);
|
||||
}
|
||||
|
||||
fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) {
|
||||
self.add_id(s.hir_id);
|
||||
intravisit::walk_field_def(self, s);
|
||||
|
15
tests/ui/lint/expr-field.rs
Normal file
15
tests/ui/lint/expr-field.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// check-pass
|
||||
|
||||
pub struct A {
|
||||
pub x: u32,
|
||||
}
|
||||
|
||||
#[deny(unused_comparisons)]
|
||||
pub fn foo(y: u32) -> A {
|
||||
A {
|
||||
#[allow(unused_comparisons)]
|
||||
x: if y < 0 { 1 } else { 2 },
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user