Merge pull request #2952 from crw5996/fix-use-bug

Fixed modsep operator for various rustlang editions
This commit is contained in:
Nick Cameron 2018-08-30 11:18:04 +12:00 committed by GitHub
commit b784f23484
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 3 deletions

View File

@ -15,7 +15,7 @@
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 @@ fn remove_alias(&self) -> UseSegment {
fn from_path_segment(
context: &RewriteContext,
path_seg: &ast::PathSegment,
modsep: bool,
) -> Option<UseSegment> {
let name = rewrite_ident(context, path_seg.ident);
if name.is_empty() || name == "{{root}}" {
@ -152,7 +153,10 @@ fn from_path_segment(
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,13 @@ fn from_ast(
visibility,
attrs,
};
let leading_modsep = context.config.edition() == Edition::Edition2018
&& a.prefix.to_string().len() > 2
&& a.prefix.to_string().starts_with("::");
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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;