]> git.lizzy.rs Git - rust.git/commitdiff
Avoid running lookup_line_range when file_lines are not specified
authortopecongiro <seuchida@gmail.com>
Mon, 19 Feb 2018 03:36:36 +0000 (12:36 +0900)
committertopecongiro <seuchida@gmail.com>
Mon, 19 Feb 2018 03:52:40 +0000 (12:52 +0900)
rustfmt-config/src/file_lines.rs
rustfmt-core/src/utils.rs

index 87e201345deefdb587e31eb44d11b27c165e6378..714f33c03dc0933c802098bad627ac2ef10adc25 100644 (file)
@@ -132,6 +132,11 @@ pub fn all() -> FileLines {
         FileLines(None)
     }
 
+    /// Returns true if this `FileLines` contains all lines in all files.
+    pub fn is_all(&self) -> bool {
+        self.0.is_none()
+    }
+
     pub fn from_ranges(mut ranges: HashMap<FileName, Vec<Range>>) -> FileLines {
         normalize_ranges(&mut ranges);
         FileLines(Some(ranges))
index d1bb7e26f5ee89e732e7f5483e2a8cbccdb8338b..20b30089d70eda65a552db7d42b18a19b55f29f3 100644 (file)
@@ -278,10 +278,11 @@ pub fn mk_sp(lo: BytePos, hi: BytePos) -> Span {
 // Return true if the given span does not intersect with file lines.
 macro_rules! out_of_file_lines_range {
     ($self: ident, $span: expr) => {
-        !$self
-            .config
-            .file_lines()
-            .intersects(&$self.codemap.lookup_line_range($span))
+        !$self.config.file_lines().is_all()
+            && !$self
+                .config
+                .file_lines()
+                .intersects(&$self.codemap.lookup_line_range($span))
     };
 }