]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_passes/liveness.rs
Run RustFmt
[rust.git] / src / librustc_passes / liveness.rs
index 7718139f6e9246af2b0eb2ef03781ee4c3de31e6..709068d2189378f9d27ac9683ded814fb9bde14e 100644 (file)
@@ -822,8 +822,15 @@ fn merge_from_succ(&mut self, ln: LiveNode, succ_ln: LiveNode, first_merge: bool
             return false;
         }
 
-        let mut changed = false;
+        let mut any_changed = false;
         self.indices2(ln, succ_ln, |this, idx, succ_idx| {
+            // This is a special case, pulled out from the code below, where we
+            // don't have to do anything. It occurs about 60-70% of the time.
+            if this.rwu_table.packed_rwus[succ_idx] == INV_INV_FALSE {
+                return;
+            }
+
+            let mut changed = false;
             let mut rwu = this.rwu_table.get(idx);
             let succ_rwu = this.rwu_table.get(succ_idx);
             if succ_rwu.reader.is_valid() && !rwu.reader.is_valid() {
@@ -843,6 +850,7 @@ fn merge_from_succ(&mut self, ln: LiveNode, succ_ln: LiveNode, first_merge: bool
 
             if changed {
                 this.rwu_table.assign_unpacked(idx, rwu);
+                any_changed = true;
             }
         });
 
@@ -851,9 +859,9 @@ fn merge_from_succ(&mut self, ln: LiveNode, succ_ln: LiveNode, first_merge: bool
             ln,
             self.ln_str(succ_ln),
             first_merge,
-            changed
+            any_changed
         );
-        return changed;
+        return any_changed;
     }
 
     // Indicates that a local variable was *defined*; we know that no
@@ -1513,45 +1521,47 @@ fn report_unused(&self, spans: Vec<Span>, hir_id: HirId, ln: LiveNode, var: Vari
                 if ln == self.s.exit_ln { false } else { self.assigned_on_exit(ln, var).is_some() };
 
             if is_assigned {
-                self.ir
-                    .tcx
-                    .struct_span_lint_hir(
-                        lint::builtin::UNUSED_VARIABLES,
-                        hir_id,
-                        spans,
-                        &format!("variable `{}` is assigned to, but never used", name),
-                    )
-                    .note(&format!("consider using `_{}` instead", name))
-                    .emit();
+                self.ir.tcx.struct_span_lint_hir(
+                    lint::builtin::UNUSED_VARIABLES,
+                    hir_id,
+                    spans,
+                    |lint| {
+                        lint.build(&format!("variable `{}` is assigned to, but never used", name))
+                            .note(&format!("consider using `_{}` instead", name))
+                            .emit();
+                    },
+                )
             } else {
-                let mut err = self.ir.tcx.struct_span_lint_hir(
+                self.ir.tcx.struct_span_lint_hir(
                     lint::builtin::UNUSED_VARIABLES,
                     hir_id,
                     spans.clone(),
-                    &format!("unused variable: `{}`", name),
+                    |lint| {
+                        let mut err = lint.build(&format!("unused variable: `{}`", name));
+                        if self.ir.variable_is_shorthand(var) {
+                            if let Node::Binding(pat) = self.ir.tcx.hir().get(hir_id) {
+                                // Handle `ref` and `ref mut`.
+                                let spans = spans
+                                    .iter()
+                                    .map(|_span| (pat.span, format!("{}: _", name)))
+                                    .collect();
+
+                                err.multipart_suggestion(
+                                    "try ignoring the field",
+                                    spans,
+                                    Applicability::MachineApplicable,
+                                );
+                            }
+                        } else {
+                            err.multipart_suggestion(
+                                "consider prefixing with an underscore",
+                                spans.iter().map(|span| (*span, format!("_{}", name))).collect(),
+                                Applicability::MachineApplicable,
+                            );
+                        }
+                        err.emit()
+                    },
                 );
-
-                if self.ir.variable_is_shorthand(var) {
-                    if let Node::Binding(pat) = self.ir.tcx.hir().get(hir_id) {
-                        // Handle `ref` and `ref mut`.
-                        let spans =
-                            spans.iter().map(|_span| (pat.span, format!("{}: _", name))).collect();
-
-                        err.multipart_suggestion(
-                            "try ignoring the field",
-                            spans,
-                            Applicability::MachineApplicable,
-                        );
-                    }
-                } else {
-                    err.multipart_suggestion(
-                        "consider prefixing with an underscore",
-                        spans.iter().map(|span| (*span, format!("_{}", name))).collect(),
-                        Applicability::MachineApplicable,
-                    );
-                }
-
-                err.emit()
             }
         }
     }
@@ -1565,27 +1575,27 @@ fn warn_about_dead_assign(&self, spans: Vec<Span>, hir_id: HirId, ln: LiveNode,
     fn report_dead_assign(&self, hir_id: HirId, spans: Vec<Span>, var: Variable, is_param: bool) {
         if let Some(name) = self.should_warn(var) {
             if is_param {
-                self.ir
-                    .tcx
-                    .struct_span_lint_hir(
-                        lint::builtin::UNUSED_ASSIGNMENTS,
-                        hir_id,
-                        spans,
-                        &format!("value passed to `{}` is never read", name),
-                    )
-                    .help("maybe it is overwritten before being read?")
-                    .emit();
+                self.ir.tcx.struct_span_lint_hir(
+                    lint::builtin::UNUSED_ASSIGNMENTS,
+                    hir_id,
+                    spans,
+                    |lint| {
+                        lint.build(&format!("value passed to `{}` is never read", name))
+                            .help("maybe it is overwritten before being read?")
+                            .emit();
+                    },
+                )
             } else {
-                self.ir
-                    .tcx
-                    .struct_span_lint_hir(
-                        lint::builtin::UNUSED_ASSIGNMENTS,
-                        hir_id,
-                        spans,
-                        &format!("value assigned to `{}` is never read", name),
-                    )
-                    .help("maybe it is overwritten before being read?")
-                    .emit();
+                self.ir.tcx.struct_span_lint_hir(
+                    lint::builtin::UNUSED_ASSIGNMENTS,
+                    hir_id,
+                    spans,
+                    |lint| {
+                        lint.build(&format!("value assigned to `{}` is never read", name))
+                            .help("maybe it is overwritten before being read?")
+                            .emit();
+                    },
+                )
             }
         }
     }