Skip to content

Commit e172351

Browse files
committed
Auto merge of #115825 - cjgillot:expr-field-lint, r=compiler-errors
Visit ExprField for lint levels. Fixes #115823
2 parents 2394959 + 01d7bf0 commit e172351

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

compiler/rustc_lint/src/late.rs

+4
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
159159
hir_visit::walk_pat(self, p);
160160
}
161161

162+
fn visit_expr_field(&mut self, field: &'tcx hir::ExprField<'tcx>) {
163+
self.with_lint_attrs(field.hir_id, |cx| hir_visit::walk_expr_field(cx, field))
164+
}
165+
162166
fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
163167
ensure_sufficient_stack(|| {
164168
self.with_lint_attrs(e.hir_id, |cx| {

compiler/rustc_lint/src/levels.rs

+5
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
338338
intravisit::walk_expr(self, e);
339339
}
340340

341+
fn visit_expr_field(&mut self, f: &'tcx hir::ExprField<'tcx>) {
342+
self.add_id(f.hir_id);
343+
intravisit::walk_expr_field(self, f);
344+
}
345+
341346
fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) {
342347
self.add_id(s.hir_id);
343348
intravisit::walk_field_def(self, s);

tests/ui/lint/expr-field.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// check-pass
2+
3+
pub struct A {
4+
pub x: u32,
5+
}
6+
7+
#[deny(unused_comparisons)]
8+
pub fn foo(y: u32) -> A {
9+
A {
10+
#[allow(unused_comparisons)]
11+
x: if y < 0 { 1 } else { 2 },
12+
}
13+
}
14+
15+
fn main() {}

0 commit comments

Comments
 (0)