Skip to content

rustfmt should be able to simplify use path::to::module::{self} #5510

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

Closed
RuijieYu opened this issue Aug 18, 2022 · 1 comment
Closed

rustfmt should be able to simplify use path::to::module::{self} #5510

RuijieYu opened this issue Aug 18, 2022 · 1 comment

Comments

@RuijieYu
Copy link

Currently rustfmt is able to simplify use path::to::module::self (which happens to be invalid syntax) into use path::to::module, and also to simplify use path::to::sub::{module} into use path::to::sub::module.

I want to suggest, based on these observations, that use path::to::module::{self} should simplify into use path::to::module.


A bigger example, using rustfmt 1.4.38-stable (e092d0b 2022-07-16):

Before:

#![allow(unused_imports)]
use std::fs::{self}; // warn(unused_import_braces)
use std::io::self; // invalid syntax
use std::path::{PathBuf}; // warn(unused_import_braces)

After:

#![allow(unused_imports)]
use std::fs::{self}; // warn(unused_import_braces)
use std::io; // no warnings
use std::path::PathBuf; // no warnings

Proposed:

#![allow(unused_imports)]
use std::fs; // no warnings
use std::io; // no warnings
use std::path::PathBuf; // no warnings
@calebcartwright
Copy link
Member

Thanks for reaching out but I am going to close as non-actionable and a duplicate (e.g. #5398).

The type of conversion you're suggesting is not valid/semantics preserving and can in some cases introduce compilation failures.

See also #3568, #4681, and rust-lang/rust#60941

use path::to::module::self (which happens to be invalid syntax)

rustfmt works at the AST level, so the code only needs to be parseable in order for rustfmt to be able to operate, even if that parsed code will be failed by later stages of the compiler.

@calebcartwright calebcartwright closed this as not planned Won't fix, can't repro, duplicate, stale Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants