Skip to content

Commit

Permalink
Impl only use (#2951)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored and topecongiro committed Aug 24, 2018
1 parent f009252 commit 10512a5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/config/file_lines.rs
Expand Up @@ -386,7 +386,7 @@ mod test {
);
}

use super::json::{self, json, json_internal};
use super::json::{self, json};
use super::{FileLines, FileName};
use std::{collections::HashMap, path::PathBuf};

Expand Down
28 changes: 13 additions & 15 deletions src/imports.rs
Expand Up @@ -149,12 +149,10 @@ impl UseSegment {
if name.is_empty() || name == "{{root}}" {
return None;
}
Some(if name == "self" {
UseSegment::Slf(None)
} else if name == "super" {
UseSegment::Super(None)
} else {
UseSegment::Ident((*name).to_owned(), None)
Some(match name {
"self" => UseSegment::Slf(None),
"super" => UseSegment::Super(None),
_ => UseSegment::Ident((*name).to_owned(), None),
})
}
}
Expand Down Expand Up @@ -350,19 +348,19 @@ impl UseTree {
UseTreeKind::Simple(ref rename, ..) => {
let name = rewrite_ident(context, path_to_imported_ident(&a.prefix)).to_owned();
let alias = rename.and_then(|ident| {
if ident == path_to_imported_ident(&a.prefix) {
if ident.name == "_" {
// for impl-only-use
Some("_".to_owned())
} else if ident == path_to_imported_ident(&a.prefix) {
None
} else {
Some(rewrite_ident(context, ident).to_owned())
}
});

let segment = if &name == "self" {
UseSegment::Slf(alias)
} else if &name == "super" {
UseSegment::Super(alias)
} else {
UseSegment::Ident(name, alias)
let segment = match name.as_ref() {
"self" => UseSegment::Slf(alias),
"super" => UseSegment::Super(alias),
_ => UseSegment::Ident(name, alias),
};

// `name` is already in result.
Expand Down Expand Up @@ -746,7 +744,7 @@ fn rewrite_nested_use_tree(

impl Rewrite for UseSegment {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
Some(match *self {
Some(match self {
UseSegment::Ident(ref ident, Some(ref rename)) => format!("{} as {}", ident, rename),
UseSegment::Ident(ref ident, None) => ident.clone(),
UseSegment::Slf(Some(ref rename)) => format!("self as {}", rename),
Expand Down
4 changes: 4 additions & 0 deletions tests/source/imports-impl-only-use.rs
@@ -0,0 +1,4 @@
#![feature(underscore_imports)]

use attr;
use std::iter::Iterator as _;
4 changes: 4 additions & 0 deletions tests/target/imports-impl-only-use.rs
@@ -0,0 +1,4 @@
#![feature(underscore_imports)]

use attr;
use std::iter::Iterator as _;

0 comments on commit 10512a5

Please sign in to comment.