Merge pull request #2406 from nrc/str-fix

Make `is_mod_decl` more accommodating
This commit is contained in:
Nick Cameron 2018-02-04 14:18:34 +13:00 committed by GitHub
commit ca09746ce9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 8 deletions

2
Cargo.lock generated
View file

@ -294,7 +294,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustfmt-nightly"
version = "0.3.7"
version = "0.3.8"
dependencies = [
"cargo_metadata 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"derive-new 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -1,7 +1,7 @@
[package]
name = "rustfmt-nightly"
version = "0.3.7"
version = "0.3.8"
authors = ["Nicholas Cameron <ncameron@mozilla.com>", "The Rustfmt developers"]
description = "Tool to find and fix Rust formatting issues"
repository = "https://github.com/rust-lang-nursery/rustfmt"

View file

@ -48,8 +48,8 @@ pub trait LineRangeUtils {
impl SpanUtils for CodeMap {
fn span_after(&self, original: Span, needle: &str) -> BytePos {
let snippet = self.span_to_snippet(original).unwrap();
let offset = snippet.find_uncommented(needle).unwrap() + needle.len();
let snippet = self.span_to_snippet(original).expect("Bad snippet");
let offset = snippet.find_uncommented(needle).expect("Bad offset") + needle.len();
original.lo() + BytePos(offset as u32)
}

View file

@ -44,10 +44,7 @@ pub fn filter_inline_attrs(attrs: &[ast::Attribute], outer_span: Span) -> Vec<as
/// Returns true for `mod foo;`, false for `mod foo { .. }`.
fn is_mod_decl(item: &ast::Item) -> bool {
match item.node {
ast::ItemKind::Mod(ref m) => {
!(m.inner.lo() == BytePos(0) && m.inner.hi() == BytePos(0))
&& m.inner.hi() != item.span.hi()
}
ast::ItemKind::Mod(ref m) => m.inner.hi() != item.span.hi(),
_ => false,
}
}