Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass struct field HirId when check_expr_struct_fields #138460

Merged
merged 1 commit into from
Mar 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
@@ -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(|| {
12 changes: 12 additions & 0 deletions tests/ui/pattern/check-struct-pat-fields-stability-issue-138319.rs
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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

39 changes: 39 additions & 0 deletions tests/ui/stability-attribute/check-stability-issue-138319.rs
Original file line number Diff line number Diff line change
@@ -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() {}
10 changes: 10 additions & 0 deletions tests/ui/stability-attribute/check-stability-issue-138319.stderr
Original file line number Diff line number Diff line change
@@ -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

Loading