From bcff5a78b3ae8b3803928386755ee56e72eafa81 Mon Sep 17 00:00:00 2001 From: Andrew Cann Date: Thu, 11 Aug 2016 19:28:52 +0800 Subject: [PATCH] Permit `! as T` with test --- src/librustc_typeck/check/coercion.rs | 5 ++++- src/test/run-fail/cast-never.rs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/test/run-fail/cast-never.rs diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index b9a7cf76d92e..4a0d52981289 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 000000000000..02ef0ad29b28 --- /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 or the MIT license +// , 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; +} +