tuple struct expressions with non-visible (private) fields should bias towards suggesting methods #103215
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Uh oh!
There was an error while loading. Please reload this page.
Given the following code (play):
The current output is:
Ideally the output should look like:
In other words: If a type from an external crate has non-public fields, we should not be suggesting the user attempt to use them for constructing an instance of the type. Especially in the case of tuple struct expressions, which can be a sign of an omitted constructor method name. (I'm thinking specifically of people who are coming from Java, and thus may be used to writing something like
new BufReader(f)
where we would writeBufReader::new(f)
.)A simple heuristic here could be to look for methods on the type that 1. do not take
self
parameter, and 2. (optional) have a matching number of argumentsThis issue is similar to #66067 and #52144, except worse, because (if I understand them correctly) those two are both talking about improving the UX for incorrect tuple struct expressions that at least are also referring to tuple struct definitions.
In the scenario described here, we have a record struct definition being used as a tuple struct, which, in the presence of private fields, we should interpret as a strong hint that someone probably meant to use a method.
The text was updated successfully, but these errors were encountered: