Add additional ui tests for issue 26046
This tests the FnMut case.
This commit is contained in:
parent
94c808c1d3
commit
2c282b8e5d
21
src/test/ui/issue-26046-fn-mut.rs
Normal file
21
src/test/ui/issue-26046-fn-mut.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn foo() -> Box<Fn()> {
|
||||
let num = 5;
|
||||
|
||||
let closure = || {
|
||||
num += 1;
|
||||
};
|
||||
|
||||
Box::new(closure)
|
||||
}
|
||||
|
||||
fn main() {}
|
17
src/test/ui/issue-26046-fn-mut.stderr
Normal file
17
src/test/ui/issue-26046-fn-mut.stderr
Normal file
@ -0,0 +1,17 @@
|
||||
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnMut`
|
||||
--> $DIR/issue-26046-fn-mut.rs:14:19
|
||||
|
|
||||
14 | let closure = || {
|
||||
| ___________________^
|
||||
15 | | num += 1;
|
||||
16 | | };
|
||||
| |_____^
|
||||
|
|
||||
note: closure is `FnMut` because it mutates the variable `num` here
|
||||
--> $DIR/issue-26046-fn-mut.rs:15:9
|
||||
|
|
||||
15 | num += 1;
|
||||
| ^^^
|
||||
|
||||
error: aborting due to previous error(s)
|
||||
|
Loading…
Reference in New Issue
Block a user