Skip to content

Commit f1f96a5

Browse files
committed
Pass struct field HirId when check_expr_struct_fields
Signed-off-by: xizheyin <[email protected]>
1 parent a2aba05 commit f1f96a5

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20602060
// struct-like enums (yet...), but it's definitely not
20612061
// a bug to have constructed one.
20622062
if adt_kind != AdtKind::Enum {
2063-
tcx.check_stability(v_field.did, Some(expr.hir_id), field.span, None);
2063+
let field_hir_id = match expr.kind {
2064+
hir::ExprKind::Struct(_qpath, fields, _tail) if idx < fields.len() => {
2065+
Some(fields[idx].expr.hir_id)
2066+
}
2067+
_ => None,
2068+
};
2069+
tcx.check_stability(v_field.did, field_hir_id, field.span, None);
20642070
}
20652071

20662072
self.field_ty(field.span, v_field, args)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ run-pass
2+
fn _foo() {
3+
_Bar {
4+
#[expect(deprecated)]
5+
foo: 0,
6+
};
7+
}
8+
9+
10+
struct _Bar {
11+
#[deprecated = "reason"]
12+
foo: u32,
13+
}
14+
15+
fn main() {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//@ run-pass
2+
fn _foo() {
3+
_Bar { //~ WARNING use of deprecated struct `_Bar`: reason
4+
#[expect(deprecated)]
5+
foo: 0,
6+
};
7+
}
8+
9+
#[deprecated = "reason"]
10+
struct _Bar {
11+
foo: u32,
12+
}
13+
14+
fn _foo2() {
15+
#[expect(deprecated)]
16+
_Bar2 {
17+
foo2: 0,
18+
};
19+
}
20+
21+
#[deprecated = "reason"]
22+
struct _Bar2 {
23+
foo2: u32,
24+
}
25+
26+
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: use of deprecated struct `_Bar`: reason
2+
--> $DIR/check-stability-issue-138319-2.rs:3:5
3+
|
4+
LL | _Bar {
5+
| ^^^^
6+
|
7+
= note: `#[warn(deprecated)]` on by default
8+
9+
warning: 1 warning emitted
10+

0 commit comments

Comments
 (0)