diff options
| author | Tommy Ip <hkmp7tommy@gmail.com> | 2017-06-07 21:26:28 +0100 |
|---|---|---|
| committer | Tommy Ip <hkmp7tommy@gmail.com> | 2017-06-07 21:26:28 +0100 |
| commit | 345b8332bde78dca7664b1b1b4f4a7284bd70a6d (patch) | |
| tree | 3635a0e0a7e5d6e86a460ca5165ec6f3c593dc09 | |
| parent | b1b6490c5d60b0c5d0166407db9b57e39fc3e3a4 (diff) | |
| download | rust-345b8332bde78dca7664b1b1b4f4a7284bd70a6d.tar.gz rust-345b8332bde78dca7664b1b1b4f4a7284bd70a6d.zip | |
Cover all cases in closure errors
| -rw-r--r-- | src/librustc/traits/error_reporting.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/closure_context/issue-26046-fn-mut.stderr | 3 | ||||
| -rw-r--r-- | src/test/ui/closure_context/issue-26046-fn-once.stderr | 3 |
3 files changed, 12 insertions, 5 deletions
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 73753382a7c..c8e99c0354a 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -648,6 +648,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { kind, found_kind); + err.span_label( + obligation.cause.span, + format!("the requirement to implement `{}` derives from here", kind)); + let infer_tables = match self.tables { InferTables::Interned(tables) => Some(InferTablesRef::Interned(tables)), @@ -656,6 +660,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { InferTables::Missing => None, }; + // Additional context information explaining why the closure only implements + // a particular trait. if let Some(tables) = infer_tables { match tables.closure_kinds.get(&node_id) { Some(&(ty::ClosureKind::FnOnce, Some((span, name)))) => { @@ -670,11 +676,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { }, _ => {} } - } else { - err.span_note( - obligation.cause.span, - &format!("the requirement to implement `{}` \ - derives from here", kind)); } err.emit(); diff --git a/src/test/ui/closure_context/issue-26046-fn-mut.stderr b/src/test/ui/closure_context/issue-26046-fn-mut.stderr index 4dd33ef8a0e..dbf702e4503 100644 --- a/src/test/ui/closure_context/issue-26046-fn-mut.stderr +++ b/src/test/ui/closure_context/issue-26046-fn-mut.stderr @@ -6,6 +6,9 @@ error[E0525]: expected a closure that implements the `Fn` trait, but this closur 15 | | num += 1; 16 | | }; | |_____^ +17 | +18 | Box::new(closure) + | ----------------- the requirement to implement `Fn` derives from here | note: closure is `FnMut` because it mutates the variable `num` here --> $DIR/issue-26046-fn-mut.rs:15:9 diff --git a/src/test/ui/closure_context/issue-26046-fn-once.stderr b/src/test/ui/closure_context/issue-26046-fn-once.stderr index 4a7aae87439..3ec3f0cc9aa 100644 --- a/src/test/ui/closure_context/issue-26046-fn-once.stderr +++ b/src/test/ui/closure_context/issue-26046-fn-once.stderr @@ -6,6 +6,9 @@ error[E0525]: expected a closure that implements the `Fn` trait, but this closur 15 | | vec 16 | | }; | |_____^ +17 | +18 | Box::new(closure) + | ----------------- the requirement to implement `Fn` derives from here | note: closure is `FnOnce` because it moves the variable `vec` out of its environment --> $DIR/issue-26046-fn-once.rs:15:9 |
