diff options
| author | Andrew Cann <shum@canndrew.org> | 2016-08-11 19:28:52 +0800 |
|---|---|---|
| committer | Andrew Cann <shum@canndrew.org> | 2016-08-13 21:37:09 +0800 |
| commit | bcff5a78b3ae8b3803928386755ee56e72eafa81 (patch) | |
| tree | f049b5fa9e9913d89df4a2b6f358fa867aa4e00e | |
| parent | 06747c669f3e6fb53270b76975d4382e52d567e2 (diff) | |
| download | rust-bcff5a78b3ae8b3803928386755ee56e72eafa81.tar.gz rust-bcff5a78b3ae8b3803928386755ee56e72eafa81.zip | |
Permit `! as T` with test
| -rw-r--r-- | src/librustc_typeck/check/coercion.rs | 5 | ||||
| -rw-r--r-- | src/test/run-fail/cast-never.rs | 18 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index b9a7cf76d92..4a0d5298128 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -642,7 +642,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { apply(&mut coerce, &|| Some(expr), source, target)?; if !adjustment.is_identity() { debug!("Success, coerced with {:?}", adjustment); - assert!(!self.tables.borrow().adjustments.contains_key(&expr.id)); + match self.tables.borrow().adjustments.get(&expr.id) { + None | Some(&AdjustNeverToAny(..)) => (), + _ => bug!("expr already has an adjustment on it!"), + }; self.write_adjustment(expr.id, adjustment); } Ok(ty) diff --git a/src/test/run-fail/cast-never.rs b/src/test/run-fail/cast-never.rs new file mode 100644 index 00000000000..02ef0ad29b2 --- /dev/null +++ b/src/test/run-fail/cast-never.rs @@ -0,0 +1,18 @@ +// Copyright 2012 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. + +#![feature(never_type)] + +// error-pattern:explicit +fn main() { + let x: ! = panic!(); + let y: u32 = x as u32; +} + |
