about summary refs log tree commit diff
diff options
context:
space:
mode:
authorxizheyin <xizheyin@smail.nju.edu.cn>2025-03-14 00:39:18 +0800
committerxizheyin <xizheyin@smail.nju.edu.cn>2025-03-14 14:51:58 +0800
commitaad1db737347b93b51a7dc45dcb6bec9e367bc02 (patch)
treedb9450212195aabd75df9316735790529edc96f3
parenta2aba0578ba440130d2ee213fc9dfdaa7095bdb5 (diff)
downloadrust-aad1db737347b93b51a7dc45dcb6bec9e367bc02.tar.gz
rust-aad1db737347b93b51a7dc45dcb6bec9e367bc02.zip
Pass precise HirId when calling check_stability
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
-rw-r--r--compiler/rustc_hir_typeck/src/expr.rs2
-rw-r--r--compiler/rustc_hir_typeck/src/pat.rs4
-rw-r--r--tests/ui/pattern/check-struct-pat-fields-stability-issue-138319.rs12
-rw-r--r--tests/ui/pattern/check-struct-pat-fields-stability-issue-138319.stderr10
-rw-r--r--tests/ui/stability-attribute/check-stability-issue-138319.rs39
-rw-r--r--tests/ui/stability-attribute/check-stability-issue-138319.stderr10
6 files changed, 74 insertions, 3 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index 7c6bb495be3..7e8e4e3a561 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -2060,7 +2060,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 // struct-like enums (yet...), but it's definitely not
                 // a bug to have constructed one.
                 if adt_kind != AdtKind::Enum {
-                    tcx.check_stability(v_field.did, Some(expr.hir_id), field.span, None);
+                    tcx.check_stability(v_field.did, Some(field.hir_id), field.span, None);
                 }
 
                 self.field_ty(field.span, v_field, args)
diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs
index 7e6973259fe..3d1c61a9c34 100644
--- a/compiler/rustc_hir_typeck/src/pat.rs
+++ b/compiler/rustc_hir_typeck/src/pat.rs
@@ -1422,7 +1422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
 
                 self.tcx.check_stability(
                     variant.fields[FieldIdx::from_usize(i)].did,
-                    Some(pat.hir_id),
+                    Some(subpat.hir_id),
                     subpat.span,
                     None,
                 );
@@ -1686,7 +1686,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                         .get(&ident)
                         .map(|(i, f)| {
                             self.write_field_index(field.hir_id, *i);
-                            self.tcx.check_stability(f.did, Some(pat.hir_id), span, None);
+                            self.tcx.check_stability(f.did, Some(field.hir_id), span, None);
                             self.field_ty(span, f, args)
                         })
                         .unwrap_or_else(|| {
diff --git a/tests/ui/pattern/check-struct-pat-fields-stability-issue-138319.rs b/tests/ui/pattern/check-struct-pat-fields-stability-issue-138319.rs
new file mode 100644
index 00000000000..b951c6d92ee
--- /dev/null
+++ b/tests/ui/pattern/check-struct-pat-fields-stability-issue-138319.rs
@@ -0,0 +1,12 @@
+//@ check-pass
+struct Point {
+    #[deprecated = "x is deprecated"]
+    _x: i32,
+    _y: i32,
+}
+
+fn main() {
+    let p = Point { _x: 1, _y: 2 }; //~ WARNING use of deprecated field `Point::_x`
+    // Before fix, it report an warning
+    let Point { #[expect(deprecated)]_x, .. } = p;
+}
diff --git a/tests/ui/pattern/check-struct-pat-fields-stability-issue-138319.stderr b/tests/ui/pattern/check-struct-pat-fields-stability-issue-138319.stderr
new file mode 100644
index 00000000000..707eb58e547
--- /dev/null
+++ b/tests/ui/pattern/check-struct-pat-fields-stability-issue-138319.stderr
@@ -0,0 +1,10 @@
+warning: use of deprecated field `Point::_x`: x is deprecated
+  --> $DIR/check-struct-pat-fields-stability-issue-138319.rs:9:21
+   |
+LL |     let p = Point { _x: 1, _y: 2 };
+   |                     ^^^^^
+   |
+   = note: `#[warn(deprecated)]` on by default
+
+warning: 1 warning emitted
+
diff --git a/tests/ui/stability-attribute/check-stability-issue-138319.rs b/tests/ui/stability-attribute/check-stability-issue-138319.rs
new file mode 100644
index 00000000000..5440e0cad94
--- /dev/null
+++ b/tests/ui/stability-attribute/check-stability-issue-138319.rs
@@ -0,0 +1,39 @@
+//@ check-pass
+fn _foo() {
+    _Bar { //~ WARNING use of deprecated struct `_Bar`: reason
+        #[expect(deprecated)]
+        foo: 0,
+    };
+}
+
+#[deprecated = "reason"]
+struct _Bar {
+    foo: u32,
+}
+
+fn _foo2() {
+    #[expect(deprecated)]
+    _Bar2 {
+        foo2: 0,
+    };
+}
+
+#[deprecated = "reason"]
+struct _Bar2 {
+    foo2: u32,
+}
+
+fn _foo3() {
+    _Bar3 {
+        #[expect(deprecated)]
+        foo3: 0,
+    };
+}
+
+struct _Bar3 {
+    #[deprecated = "reason"]
+    foo3: u32,
+}
+
+
+fn main() {}
diff --git a/tests/ui/stability-attribute/check-stability-issue-138319.stderr b/tests/ui/stability-attribute/check-stability-issue-138319.stderr
new file mode 100644
index 00000000000..4a2c3554a1e
--- /dev/null
+++ b/tests/ui/stability-attribute/check-stability-issue-138319.stderr
@@ -0,0 +1,10 @@
+warning: use of deprecated struct `_Bar`: reason
+  --> $DIR/check-stability-issue-138319.rs:3:5
+   |
+LL |     _Bar {
+   |     ^^^^
+   |
+   = note: `#[warn(deprecated)]` on by default
+
+warning: 1 warning emitted
+