]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/defaulted-unit-warning.rs
New upstream version 1.17.0+dfsg1
[rustc.git] / src / test / compile-fail / defaulted-unit-warning.rs
1 // Copyright 2016 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 #![allow(unreachable_code)]
13 #![deny(resolve_trait_on_defaulted_unit)]
14
15 trait Deserialize: Sized {
16 fn deserialize() -> Result<Self, String>;
17 }
18
19 impl Deserialize for () {
20 fn deserialize() -> Result<(), String> {
21 Ok(())
22 }
23 }
24
25 fn doit() -> Result<(), String> {
26 let _ = match Deserialize::deserialize() {
27 //~^ ERROR code relies on type
28 //~| WARNING previously accepted
29 Ok(x) => x,
30 Err(e) => return Err(e),
31 };
32 Ok(())
33 }
34
35 trait ImplementedForUnitButNotNever {}
36
37 impl ImplementedForUnitButNotNever for () {}
38
39 fn foo<T: ImplementedForUnitButNotNever>(_t: T) {}
40
41 fn smeg() {
42 let _x = return;
43 foo(_x);
44 //~^ ERROR code relies on type
45 //~| WARNING previously accepted
46 }
47
48 fn main() {
49 let _ = doit();
50 }
51