Skip to content

Commit 4617418

Browse files
authored
Rollup merge of #81716 - m-ou-se:fix-ice, r=eddyb
Fix non-existent-field ICE for generic fields. I mentioned this ICE in a chat and it took about 3 milliseconds before `@eddyb` found the problem and said this change would fix it. :) This also changes one the field types in the related test to one that triggered the ICE. Fixes #81627. Fixes #81672. Fixes #81709. Cc #81480 `@b-naber` `@estebank.`
2 parents 65b3c0c + 68cc12a commit 4617418

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

compiler/rustc_typeck/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19741974

19751975
field_path.push(candidate_field.ident.normalize_to_macros_2_0());
19761976
let field_ty = candidate_field.ty(self.tcx, subst);
1977-
if let Some((nested_fields, _)) = self.get_field_candidates(span, &field_ty) {
1977+
if let Some((nested_fields, subst)) = self.get_field_candidates(span, &field_ty) {
19781978
for field in nested_fields.iter() {
19791979
let ident = field.ident.normalize_to_macros_2_0();
19801980
if ident == target_field {

src/test/ui/suggestions/non-existent-field-present-in-subfield.fixed

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
struct Foo {
44
first: Bar,
55
_second: u32,
6-
_third: u32,
6+
_third: Vec<String>,
77
}
88

99
struct Bar {
@@ -32,7 +32,7 @@ fn main() {
3232
let d = D { test: e };
3333
let c = C { c: d };
3434
let bar = Bar { bar: c };
35-
let fooer = Foo { first: bar, _second: 4, _third: 5 };
35+
let fooer = Foo { first: bar, _second: 4, _third: Vec::new() };
3636

3737
let _test = &fooer.first.bar.c;
3838
//~^ ERROR no field

src/test/ui/suggestions/non-existent-field-present-in-subfield.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
struct Foo {
44
first: Bar,
55
_second: u32,
6-
_third: u32,
6+
_third: Vec<String>,
77
}
88

99
struct Bar {
@@ -32,7 +32,7 @@ fn main() {
3232
let d = D { test: e };
3333
let c = C { c: d };
3434
let bar = Bar { bar: c };
35-
let fooer = Foo { first: bar, _second: 4, _third: 5 };
35+
let fooer = Foo { first: bar, _second: 4, _third: Vec::new() };
3636

3737
let _test = &fooer.c;
3838
//~^ ERROR no field

0 commit comments

Comments
 (0)