From 20075306f7f18050744b851b82a72e2bd12fc9d1 Mon Sep 17 00:00:00 2001 From: crw5996 Date: Mon, 27 Aug 2018 14:31:43 -0400 Subject: [PATCH] Fixed Issues brought up in PR --- src/imports.rs | 20 +++++++++++++++++--- tests/source/issue-2927-2.rs | 7 +++++++ tests/source/issue-2927.rs | 7 +++++++ tests/target/issue-2927-2.rs | 7 +++++++ tests/target/issue-2927.rs | 7 +++++++ 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tests/source/issue-2927-2.rs create mode 100644 tests/source/issue-2927.rs create mode 100644 tests/target/issue-2927-2.rs create mode 100644 tests/target/issue-2927.rs diff --git a/src/imports.rs b/src/imports.rs index b3408bf7bf2..4aee67759c1 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -15,7 +15,7 @@ use syntax::ast::{self, UseTreeKind}; use syntax::source_map::{self, BytePos, Span, DUMMY_SP}; use comment::combine_strs_with_missing_comments; -use config::IndentStyle; +use config::{Edition, IndentStyle}; use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator}; use rewrite::{Rewrite, RewriteContext}; use shape::Shape; @@ -144,6 +144,7 @@ impl UseSegment { fn from_path_segment( context: &RewriteContext, path_seg: &ast::PathSegment, + modsep: bool, ) -> Option { let name = rewrite_ident(context, path_seg.ident); if name.is_empty() || name == "{{root}}" { @@ -152,7 +153,10 @@ impl UseSegment { Some(match name { "self" => UseSegment::Slf(None), "super" => UseSegment::Super(None), - _ => UseSegment::Ident((*name).to_owned(), None), + _ => { + let mod_sep = if modsep { "::" } else { "" }; + UseSegment::Ident(format!("{}{}", mod_sep, name), None) + } }) } } @@ -313,8 +317,18 @@ impl UseTree { visibility, attrs, }; + + let leading_modsep = if context.config.edition() == Edition::Edition2018 { + if a.prefix.to_string().len() > 2 && a.prefix.to_string().starts_with("::") { + true + } else { + false + } + } else { + false + }; for p in &a.prefix.segments { - if let Some(use_segment) = UseSegment::from_path_segment(context, p) { + if let Some(use_segment) = UseSegment::from_path_segment(context, p, leading_modsep) { result.path.push(use_segment); } } diff --git a/tests/source/issue-2927-2.rs b/tests/source/issue-2927-2.rs new file mode 100644 index 00000000000..0a8969c4837 --- /dev/null +++ b/tests/source/issue-2927-2.rs @@ -0,0 +1,7 @@ +// rustfmt-edition: Edition2015 +#![feature(rust_2018_preview, uniform_paths)] +use futures::prelude::*; +use http_03::cli::Cli; +use hyper::{service::service_fn_ok, Body, Response, Server}; +use ::log::{error, info, log}; +use structopt::StructOpt; diff --git a/tests/source/issue-2927.rs b/tests/source/issue-2927.rs new file mode 100644 index 00000000000..69871b48496 --- /dev/null +++ b/tests/source/issue-2927.rs @@ -0,0 +1,7 @@ +// rustfmt-edition: Edition2018 +#![feature(rust_2018_preview, uniform_paths)] +use futures::prelude::*; +use http_03::cli::Cli; +use hyper::{service::service_fn_ok, Body, Response, Server}; +use ::log::{error, info, log}; +use structopt::StructOpt; diff --git a/tests/target/issue-2927-2.rs b/tests/target/issue-2927-2.rs new file mode 100644 index 00000000000..c9fdcdea239 --- /dev/null +++ b/tests/target/issue-2927-2.rs @@ -0,0 +1,7 @@ +// rustfmt-edition: Edition2015 +#![feature(rust_2018_preview, uniform_paths)] +use futures::prelude::*; +use http_03::cli::Cli; +use hyper::{service::service_fn_ok, Body, Response, Server}; +use log::{error, info, log}; +use structopt::StructOpt; diff --git a/tests/target/issue-2927.rs b/tests/target/issue-2927.rs new file mode 100644 index 00000000000..1aa34f01741 --- /dev/null +++ b/tests/target/issue-2927.rs @@ -0,0 +1,7 @@ +// rustfmt-edition: Edition2018 +#![feature(rust_2018_preview, uniform_paths)] +use ::log::{error, info, log}; +use futures::prelude::*; +use http_03::cli::Cli; +use hyper::{service::service_fn_ok, Body, Response, Server}; +use structopt::StructOpt;