]> git.lizzy.rs Git - rust.git/blobdiff - src/imports.rs
set of clippy changes
[rust.git] / src / imports.rs
index 2007d05bc548973132fb0289c09aeb7a4d607f2f..b3408bf7bf26a4103c876ccd953d5f0c7e04ad98 100644 (file)
 
 use config::lists::*;
 use syntax::ast::{self, UseTreeKind};
-use syntax::codemap::{self, BytePos, Span, DUMMY_SP};
+use syntax::source_map::{self, BytePos, Span, DUMMY_SP};
 
-use codemap::SpanUtils;
 use comment::combine_strs_with_missing_comments;
 use config::IndentStyle;
 use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator};
 use rewrite::{Rewrite, RewriteContext};
 use shape::Shape;
+use source_map::SpanUtils;
 use spanned::Spanned;
 use utils::{is_same_visibility, mk_sp, rewrite_ident};
 use visitor::FmtVisitor;
@@ -149,12 +149,10 @@ fn from_path_segment(
         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),
         })
     }
 }
@@ -350,19 +348,19 @@ fn from_ast(
             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.
@@ -470,7 +468,7 @@ fn has_comment(&self) -> bool {
     fn same_visibility(&self, other: &UseTree) -> bool {
         match (&self.visibility, &other.visibility) {
             (
-                Some(codemap::Spanned {
+                Some(source_map::Spanned {
                     node: ast::VisibilityKind::Inherited,
                     ..
                 }),
@@ -478,7 +476,7 @@ fn same_visibility(&self, other: &UseTree) -> bool {
             )
             | (
                 None,
-                Some(codemap::Spanned {
+                Some(source_map::Spanned {
                     node: ast::VisibilityKind::Inherited,
                     ..
                 }),
@@ -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),
@@ -785,7 +783,7 @@ fn rewrite(&self, context: &RewriteContext, mut shape: Shape) -> Option<String>
 #[cfg(test)]
 mod test {
     use super::*;
-    use syntax::codemap::DUMMY_SP;
+    use syntax::source_map::DUMMY_SP;
 
     // Parse the path part of an import. This parser is not robust and is only
     // suitable for use in a test harness.