-
Notifications
You must be signed in to change notification settings - Fork 892
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
imports_granularity = "Module"
causes compile error when path contains self
#4681
Comments
Thanks for the report. We're aware of the differences between the two, which is why you'll notice these |
I am willing to try to fix this, but from the description of the expected behavior it is not clear whether the output should be Also, if this is a bug, why is the issue labeled |
Awesome, thank you!
It has to be the latter, because as noted in the issue description these are not equivalent and changing what the developer wrote has the potential to cause compilation issues in the emitted formatted code (rust-lang/rust#60941)
I've added a description to the label that hopefully clarifies, but it's used to indicate that the issue cannot occur with the default rustfmt behavior and requires the use of an overridden value for a configuration option.
I'm not sure I understand this. All options have default values, but this particular issue requires a non-default value in order to reproduce. The files used for the system/idempotence will need to have the corresponding config option self to I'd expect the input file to include: use crate::lexer::{self, tokens::TokenData}; and the target file to inculde: use crate::lexer::{self};
use crate::lexer::tokens::TokenData; |
No problem - my misunderstanding. I thought that the meaning of the label |
Cross linking #4991: required to be closed before |
@davidBar-On is this issue fixed by #4716? |
@Aloso this issue is still present in master - I just opened a fix in #5253 (there is a test added which reproduces the failure). The fix from #4716 appears to be present in the rc2 branch but not in master, I guess it got lost in a merge somewhere. There are more details in the description of #5253 |
Describe the bug
If a path contains
self
, this keyword must be enclosed in braces:rustfmt with
imports_granularity = "Module"
sometimes splitsuse
statements so that invalid code like above is emitted.To Reproduce
rustfmt formats it like this:
When formatting the file again, the
::self
is removed.Expected behavior
rustfmt should emit the following code without having to run it twice:
Note that
use crate::lexer;
anduse crate::lexer::{self};
are not actually equivalent: The latter only imports thelexer
module, while the former looks in all namespaces, so it can import up to 3 items at once, e.g. a function, a module and a macro of the same name.To make sure that the behaviour doesn't change, it needs to be formatted like so:
However, I would find this rather annoying, because of the way rust-analyzer handles auto-imports.
Meta
cargo fmt
The text was updated successfully, but these errors were encountered: