Skip to content

Commit aad1db7

Browse files
committed
Pass precise HirId when calling check_stability
Signed-off-by: xizheyin <[email protected]>
1 parent a2aba05 commit aad1db7

6 files changed

+74
-3
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ 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+
tcx.check_stability(v_field.did, Some(field.hir_id), field.span, None);
20642064
}
20652065

20662066
self.field_ty(field.span, v_field, args)

compiler/rustc_hir_typeck/src/pat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14221422

14231423
self.tcx.check_stability(
14241424
variant.fields[FieldIdx::from_usize(i)].did,
1425-
Some(pat.hir_id),
1425+
Some(subpat.hir_id),
14261426
subpat.span,
14271427
None,
14281428
);
@@ -1686,7 +1686,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16861686
.get(&ident)
16871687
.map(|(i, f)| {
16881688
self.write_field_index(field.hir_id, *i);
1689-
self.tcx.check_stability(f.did, Some(pat.hir_id), span, None);
1689+
self.tcx.check_stability(f.did, Some(field.hir_id), span, None);
16901690
self.field_ty(span, f, args)
16911691
})
16921692
.unwrap_or_else(|| {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ check-pass
2+
struct Point {
3+
#[deprecated = "x is deprecated"]
4+
_x: i32,
5+
_y: i32,
6+
}
7+
8+
fn main() {
9+
let p = Point { _x: 1, _y: 2 }; //~ WARNING use of deprecated field `Point::_x`
10+
// Before fix, it report an warning
11+
let Point { #[expect(deprecated)]_x, .. } = p;
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: use of deprecated field `Point::_x`: x is deprecated
2+
--> $DIR/check-struct-pat-fields-stability-issue-138319.rs:9:21
3+
|
4+
LL | let p = Point { _x: 1, _y: 2 };
5+
| ^^^^^
6+
|
7+
= note: `#[warn(deprecated)]` on by default
8+
9+
warning: 1 warning emitted
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//@ check-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 _foo3() {
27+
_Bar3 {
28+
#[expect(deprecated)]
29+
foo3: 0,
30+
};
31+
}
32+
33+
struct _Bar3 {
34+
#[deprecated = "reason"]
35+
foo3: u32,
36+
}
37+
38+
39+
fn main() {}
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.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)