-
Notifications
You must be signed in to change notification settings - Fork 889
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
rustfmt eats _ in underscore_imports (a.k.a. impl-only-use) #2887
Comments
cc @max-sixty the universe provides! This would be a great issue to start on. Look in imports.rs and look for the code dealing with aliasing. You'll want to look at libsyntax/ast.rs in the rust repo to find out how the underscore is represented, and then take that into account in the rustfmt code. |
(FYI I had a look at this over the weekend. It was a steeper learning curve than I had thought, but I'll give it another try) |
What's the easiest way for me to discover how |
@max-sixty I would run rustfmt on a very simple program using |
For the sake of progress - and feedback if I'm doing something bad, I ran this file: // #![allow(unused_variables)]
// #![allow(unused_imports)]
extern crate syntax;
use std::path::PathBuf;
use syntax::with_globals;
use syntax::codemap::FilePathMapping;
use syntax::parse::{filemap_to_stream, ParseSess};
fn main() {
let parse_session = ParseSess::new(FilePathMapping::empty());
// let p = Path::new(file!());
// let string = "use std::iter::Iterator as _;".to_string();
with_globals(|| {
let stream = filemap_to_stream(
&parse_session,
parse_session
.codemap()
.new_filemap(PathBuf::from("").into(), "use a::b as _".to_string()),
None,
);
println!("{:?}", stream)
});
} ...which generated this output:
...suggesting that |
Reading through the code, my hypothesis is this section is passing an empty https://github.com/rust-lang-nursery/rustfmt/blob/master/src/imports.rs#L352-L357 I'm not sure how to debug this though. Let me know if you have any guidance from here! |
I would look at |
With an input file like
running
rustfmt
on it producesVersion:
Tracking issue for the unstable feature: rust-lang/rust#48216
The text was updated successfully, but these errors were encountered: