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

librustc: hint close matches on accessing nonexisting fields #19267

Closed

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Nov 24, 2014

struct A {
    foo : int,
    car : int,
    barr : int
}
fn main() {
    let a = A { foo : 5, car : 9, bar : 42};
}

now shows

main.rs:7:39: 7:42 error: structure `A` has no field named `bar`
main.rs:7     let a = A { foo : 5, car : 9, bar : 42};
                                            ^~~
main.rs:7:39: 7:42 help: did you mean `car`?
main.rs:7     let a = A { foo : 5, car : 9, bar : 42};
                                            ^~~
main.rs:7:39: 7:42 help: did you mean `barr`?
main.rs:7     let a = A { foo : 5, car : 9, bar : 42};
                                            ^~~

same help message for accessing fields.

can't do it for functions, as they aren't iteratable. Only exact lookups are possible there.

}

fcx.write_error(expr.id);
}

fn suggest_field_names<'tcx>(t : ty::t,
Copy link
Member

Choose a reason for hiding this comment

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

Our style is to not add any whitespace for alignment.

@emberian
Copy link
Member

emberian commented Dec 4, 2014

Could you add some tests for this? Just a few cases in compile-fail that the messages get emitted.

@oli-obk oli-obk force-pushed the feature/hint_struct_field_access branch from d179dc0 to 5d1b223 Compare December 6, 2014 12:47
barosl added a commit to barosl/rust that referenced this pull request Dec 22, 2014
barosl added a commit to barosl/rust that referenced this pull request Dec 22, 2014
@Gankra
Copy link
Contributor

Gankra commented Jan 2, 2015

@oli-obk have you made all your changes? (github doesn't notify us when you just add commits, you need to ping someone when you're ready).

Regardless, needs a rebase.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 7, 2015

not yet, as i need to rewrite some of the error reporting code, to prevent hinting field names of fields that are actually set

@flaper87
Copy link
Contributor

closing for inactivity. @oli-obk let us know when you get back to this. It needs rebase so probably a new PR would be just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants