Merge pull request #2971 from topecongiro/issue-2969

Use span_ends_with_comma to find a trailing comma in an attribute
This commit is contained in:
Nick Cameron 2018-08-27 23:01:27 +12:00 committed by GitHub
commit 4484609583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 5 deletions

View File

@ -217,11 +217,8 @@ impl Rewrite for ast::MetaItem {
ast::MetaItemKind::List(ref list) => {
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
let snippet = context.snippet(self.span);
// 2 = )] (this might go wrong if there is whitespace between the brackets, but
// it's close enough).
let snippet = snippet[..snippet.len() - 2].trim();
let trailing_comma = if snippet.ends_with(',') { "," } else { "" };
let has_comma = ::expr::span_ends_with_comma(context, self.span);
let trailing_comma = if has_comma { "," } else { "" };
let combine = list.len() == 1 && match list[0].node {
ast::NestedMetaItemKind::Literal(..) => false,
ast::NestedMetaItemKind::MetaItem(ref inner_meta_item) => {

View File

@ -190,3 +190,23 @@ pub struct Params {
job: Option<Job>
}
}
// #2969
#[cfg(not(all(feature="std",
any(target_os = "linux", target_os = "android",
target_os = "netbsd",
target_os = "dragonfly",
target_os = "haiku",
target_os = "emscripten",
target_os = "solaris",
target_os = "cloudabi",
target_os = "macos", target_os = "ios",
target_os = "freebsd",
target_os = "openbsd", target_os = "bitrig",
target_os = "redox",
target_os = "fuchsia",
windows,
all(target_arch = "wasm32", feature = "stdweb"),
all(target_arch = "wasm32", feature = "wasm-bindgen"),
))))]
type Os = NoSource;

View File

@ -219,3 +219,29 @@ mod issue_2620 {
job: Option<Job>,
}
}
// #2969
#[cfg(not(all(
feature = "std",
any(
target_os = "linux",
target_os = "android",
target_os = "netbsd",
target_os = "dragonfly",
target_os = "haiku",
target_os = "emscripten",
target_os = "solaris",
target_os = "cloudabi",
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "openbsd",
target_os = "bitrig",
target_os = "redox",
target_os = "fuchsia",
windows,
all(target_arch = "wasm32", feature = "stdweb"),
all(target_arch = "wasm32", feature = "wasm-bindgen"),
)
)))]
type Os = NoSource;