Suggest use "{}", self.x instead of {self.x} when resolve x as field of self#141213
Suggest use "{}", self.x instead of {self.x} when resolve x as field of self#141213bors merged 4 commits intorust-lang:masterfrom
self#141213Conversation
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
…field of `self` Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
|
Thanks for your fix! |
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
|
|
|
Would you mind squashing the commits into one? It helps keep the history cleaner. Also, while reviewing this, I noticed a small inconsistency in how similar errors are reported for other macros. For example: Current Meanwhile, The This isn’t a blocker for this PR at all, but it got me thinking—maybe in the future we could consider applying similar diagnostics to other macros like Thanks again for the work on this! |
|
Committing test in the first commit and seeing the commit changes in the second commit will make reviewing easier. Maybe we can wait for @nnethercote to review before squash. Additionally, for |
|
Oh, I see now, but I still wonder if this possible to make suggestion like this by any chance |
6 | let _ = format!("{x}");
| ^
|
help: you might have meant to use the available field
|
6 | let _ = format!("{}", self.x);
| |
|
Thank you for your observations. It's not easy because once the parameters become more numerous, we have to deal with the multi-parameter case, which will be much more complicated. For the inline case, I observe that it is almost always changed in-place because it is easy to show the diff. if it is not changed in-place, the diff will be more confusing. I think the current situation is sufficient. |
tests/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr
Show resolved
Hide resolved
|
This is looking good to me, I will r+ once the suggestions are made. But I definitely want to keep the commits separate; it's helpful for review and also for anyone who might be looking at the commit history in the future. |
…ng` and optimize expression Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
|
Maybe it is Ok. @rustbot ready |
|
@bors r+ |
There was a problem hiding this comment.
What happens on
struct Foo { x: i32 }
impl Foo {
fn foo(&self) { _ = {x}; }
}Does it essentially suggest fn foo(&self) { _ = "{}", self.x } (sic!)?
There was a problem hiding this comment.
It will give this message.
error[E0425]: cannot find value `x` in this scope
--> src/main.rs:4:26
|
4 | fn foo(&self) { _ = {x}; }
| ^
|
= help: you might have meant to use the available field in a format string: `"{}", self.x`
For further improvement, below two suggestions may be better?
The first suggestion is
help: you might have meant to use the available field if in a format string: `"{}", self.x`
and keep the origin suggestion
help: you might have meant to use the available field
|
4 | fn foo(&self) { _ = {self.x}; }
| +++++
There was a problem hiding this comment.
Yeah, the message as emitted right now (on master) is not correct. It should indeed suggest you might have meant to use the available field as we do on beta/stable.
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#137759 (Add `std::os::unix::process::CommandExt::chroot` to safely chroot a child process) - rust-lang#140994 (replace `cc_detect::cc2ar` with `cc::try_get_archiver`) - rust-lang#141213 (Suggest use "{}", self.x instead of {self.x} when resolve x as field of `self`) - rust-lang#141283 (Allow `x perf` to find rustc.exe on Windows) - rust-lang#141284 (Allow trailing comma after argument in query definition) - rust-lang#141317 (typeck: catch `continue`s pointing to blocks) - rust-lang#141318 (Avoid creating an empty identifer in `Symbol::to_ident_string`.) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#141213 - xizheyin:issue-141136, r=nnethercote Suggest use "{}", self.x instead of {self.x} when resolve x as field of `self` Fixes rust-lang#141136 Changes can be seen in the second commit: rust-lang@9de7fff r? compiler
Fixes #141136
Changes can be seen in the second commit: 9de7fff
r? compiler