Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4484609

Browse files
authored
Merge pull request rust-lang#2971 from topecongiro/issue-2969
Use span_ends_with_comma to find a trailing comma in an attribute
2 parents 1c40881 + 0d60f67 commit 4484609

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

src/attr.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,8 @@ impl Rewrite for ast::MetaItem {
217217
ast::MetaItemKind::List(ref list) => {
218218
let path = rewrite_path(context, PathContext::Type, None, &self.ident, shape)?;
219219

220-
let snippet = context.snippet(self.span);
221-
// 2 = )] (this might go wrong if there is whitespace between the brackets, but
222-
// it's close enough).
223-
let snippet = snippet[..snippet.len() - 2].trim();
224-
let trailing_comma = if snippet.ends_with(',') { "," } else { "" };
220+
let has_comma = ::expr::span_ends_with_comma(context, self.span);
221+
let trailing_comma = if has_comma { "," } else { "" };
225222
let combine = list.len() == 1 && match list[0].node {
226223
ast::NestedMetaItemKind::Literal(..) => false,
227224
ast::NestedMetaItemKind::MetaItem(ref inner_meta_item) => {

tests/source/attrib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,23 @@ pub struct Params {
190190
job: Option<Job>
191191
}
192192
}
193+
194+
// #2969
195+
#[cfg(not(all(feature="std",
196+
any(target_os = "linux", target_os = "android",
197+
target_os = "netbsd",
198+
target_os = "dragonfly",
199+
target_os = "haiku",
200+
target_os = "emscripten",
201+
target_os = "solaris",
202+
target_os = "cloudabi",
203+
target_os = "macos", target_os = "ios",
204+
target_os = "freebsd",
205+
target_os = "openbsd", target_os = "bitrig",
206+
target_os = "redox",
207+
target_os = "fuchsia",
208+
windows,
209+
all(target_arch = "wasm32", feature = "stdweb"),
210+
all(target_arch = "wasm32", feature = "wasm-bindgen"),
211+
))))]
212+
type Os = NoSource;

tests/target/attrib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,29 @@ mod issue_2620 {
219219
job: Option<Job>,
220220
}
221221
}
222+
223+
// #2969
224+
#[cfg(not(all(
225+
feature = "std",
226+
any(
227+
target_os = "linux",
228+
target_os = "android",
229+
target_os = "netbsd",
230+
target_os = "dragonfly",
231+
target_os = "haiku",
232+
target_os = "emscripten",
233+
target_os = "solaris",
234+
target_os = "cloudabi",
235+
target_os = "macos",
236+
target_os = "ios",
237+
target_os = "freebsd",
238+
target_os = "openbsd",
239+
target_os = "bitrig",
240+
target_os = "redox",
241+
target_os = "fuchsia",
242+
windows,
243+
all(target_arch = "wasm32", feature = "stdweb"),
244+
all(target_arch = "wasm32", feature = "wasm-bindgen"),
245+
)
246+
)))]
247+
type Os = NoSource;

0 commit comments

Comments
 (0)