From 397d0d3d72bf962fa37b1ed8457c5a42126c06b8 Mon Sep 17 00:00:00 2001 From: Marcus Klaas <mail@marcusklaas.nl> Date: Sat, 25 Jul 2015 23:10:48 +0200 Subject: [PATCH] Format simple imports --- src/imports.rs | 10 ++++++++-- tests/source/imports.rs | 5 +++++ tests/target/imports.rs | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/imports.rs b/src/imports.rs index 37b1d9e5d46..ec6a9f1e593 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -37,8 +37,14 @@ impl Rewrite for ast::ViewPath { // FIXME convert to list? None } - ast::ViewPath_::ViewPathSimple(_,_) => { - None + ast::ViewPath_::ViewPathSimple(ident, ref path) => { + let path_str = pprust::path_to_string(path); + + Some(if path.segments.last().unwrap().identifier == ident { + path_str + } else { + format!("{} as {}", path_str, ident) + }) } } } diff --git a/tests/source/imports.rs b/tests/source/imports.rs index 3590ecae61f..f759de3e7bb 100644 --- a/tests/source/imports.rs +++ b/tests/source/imports.rs @@ -39,3 +39,8 @@ fn test() { use Baz::*; use Qux; } + +// Simple imports +use foo::bar::baz as baz ; +use bar::quux as kaas; +use foo; diff --git a/tests/target/imports.rs b/tests/target/imports.rs index a799c096210..bbef3e85e16 100644 --- a/tests/target/imports.rs +++ b/tests/target/imports.rs @@ -32,3 +32,8 @@ fn test() { use Baz::*; use Qux; } + +// Simple imports +use foo::bar::baz; +use bar::quux as kaas; +use foo;