diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-02-05 09:14:39 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-02-05 09:14:39 -0500 |
| commit | 4f8ce9efb9ff27af430d398ca472049e3595aaa6 (patch) | |
| tree | 63e137a34f2935f1fc91eb796962a7a7fa5642a6 /src/test/compile-fail | |
| parent | ca202fe181ec52998fe8843e87528bbd920605d5 (diff) | |
| parent | 42f3ac5ea610b351e404dd30199d13ffc91617d5 (diff) | |
| download | rust-4f8ce9efb9ff27af430d398ca472049e3595aaa6.tar.gz rust-4f8ce9efb9ff27af430d398ca472049e3595aaa6.zip | |
Rollup merge of #39009 - canndrew:default-unit-warnings, r=nikomatsakis
Add warning for () to ! switch With feature(never_type) enabled diverging type variables will default to `!` instead of `()`. This can cause breakages where a trait is resolved on such a type. This PR emits a future-compatibility warning when it sees this happen.
Diffstat (limited to 'src/test/compile-fail')
| -rw-r--r-- | src/test/compile-fail/defaulted-unit-warning.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/test/compile-fail/defaulted-unit-warning.rs b/src/test/compile-fail/defaulted-unit-warning.rs new file mode 100644 index 00000000000..5213a189714 --- /dev/null +++ b/src/test/compile-fail/defaulted-unit-warning.rs @@ -0,0 +1,51 @@ +// Copyright 2016 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. + +#![allow(dead_code)] +#![allow(unreachable_code)] +#![deny(resolve_trait_on_defaulted_unit)] + +trait Deserialize: Sized { + fn deserialize() -> Result<Self, String>; +} + +impl Deserialize for () { + fn deserialize() -> Result<(), String> { + Ok(()) + } +} + +fn doit() -> Result<(), String> { + let _ = match Deserialize::deserialize() { + //~^ ERROR code relies on type + //~| WARNING previously accepted + Ok(x) => x, + Err(e) => return Err(e), + }; + Ok(()) +} + +trait ImplementedForUnitButNotNever {} + +impl ImplementedForUnitButNotNever for () {} + +fn foo<T: ImplementedForUnitButNotNever>(_t: T) {} + +fn smeg() { + let _x = return; + foo(_x); + //~^ ERROR code relies on type + //~| WARNING previously accepted +} + +fn main() { + let _ = doit(); +} + |
