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

Fix non-existent-field ICE for generic fields. #81716

Merged
merged 1 commit into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
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_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

field_path.push(candidate_field.ident.normalize_to_macros_2_0());
let field_ty = candidate_field.ty(self.tcx, subst);
if let Some((nested_fields, _)) = self.get_field_candidates(span, &field_ty) {
if let Some((nested_fields, subst)) = self.get_field_candidates(span, &field_ty) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random note about something I noticed, that I don't think is worth touching in this PR: this function used subst instead of substs, and while we do use the name subst, it's for the method (where it means "substitute") - the variables of type Substs ("substitutions") should be called substs.

for field in nested_fields.iter() {
let ident = field.ident.normalize_to_macros_2_0();
if ident == target_field {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
struct Foo {
first: Bar,
_second: u32,
_third: u32,
_third: Vec<String>,
}

struct Bar {
Expand Down Expand Up @@ -32,7 +32,7 @@ fn main() {
let d = D { test: e };
let c = C { c: d };
let bar = Bar { bar: c };
let fooer = Foo { first: bar, _second: 4, _third: 5 };
let fooer = Foo { first: bar, _second: 4, _third: Vec::new() };

let _test = &fooer.first.bar.c;
//~^ ERROR no field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
struct Foo {
first: Bar,
_second: u32,
_third: u32,
_third: Vec<String>,
}

struct Bar {
Expand Down Expand Up @@ -32,7 +32,7 @@ fn main() {
let d = D { test: e };
let c = C { c: d };
let bar = Bar { bar: c };
let fooer = Foo { first: bar, _second: 4, _third: 5 };
let fooer = Foo { first: bar, _second: 4, _third: Vec::new() };

let _test = &fooer.c;
//~^ ERROR no field
Expand Down