]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/unused-result.rs
New upstream version 1.27.1+dfsg1
[rustc.git] / src / test / compile-fail / unused-result.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(dead_code)]
12 #![deny(unused_results, unused_must_use)]
13 //~^ NOTE: lint level defined here
14 //~| NOTE: lint level defined here
15
16 #[must_use]
17 enum MustUse { Test }
18
19 #[must_use = "some message"]
20 enum MustUseMsg { Test2 }
21
22 fn foo<T>() -> T { panic!() }
23
24 fn bar() -> isize { return foo::<isize>(); }
25 fn baz() -> MustUse { return foo::<MustUse>(); }
26 fn qux() -> MustUseMsg { return foo::<MustUseMsg>(); }
27
28 #[allow(unused_results)]
29 fn test() {
30 foo::<isize>();
31 foo::<MustUse>(); //~ ERROR: unused `MustUse` which must be used
32 foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used
33 //~^ NOTE: some message
34 }
35
36 #[allow(unused_results, unused_must_use)]
37 fn test2() {
38 foo::<isize>();
39 foo::<MustUse>();
40 foo::<MustUseMsg>();
41 }
42
43 fn main() {
44 foo::<isize>(); //~ ERROR: unused result
45 foo::<MustUse>(); //~ ERROR: unused `MustUse` which must be used
46 foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used
47 //~^ NOTE: some message
48
49 let _ = foo::<isize>();
50 let _ = foo::<MustUse>();
51 let _ = foo::<MustUseMsg>();
52 }