Skip to content

Commit 59688e1

Browse files
committed
Make coerce_never lint an error
Remove the coerce_never lint and make the behaviour an error.
1 parent 32ddb30 commit 59688e1

File tree

12 files changed

+21
-102
lines changed

12 files changed

+21
-102
lines changed

src/librustc/lint/builtin.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,6 @@ declare_lint! {
230230
"detect mut variables which don't need to be mutable"
231231
}
232232

233-
declare_lint! {
234-
pub COERCE_NEVER,
235-
Deny,
236-
"detect coercion to !"
237-
}
238-
239233
declare_lint! {
240234
pub SINGLE_USE_LIFETIME,
241235
Allow,
@@ -310,7 +304,6 @@ impl LintPass for HardwiredLints {
310304
DEPRECATED,
311305
UNUSED_UNSAFE,
312306
UNUSED_MUT,
313-
COERCE_NEVER,
314307
SINGLE_USE_LIFETIME,
315308
TYVAR_BEHIND_RAW_POINTER,
316309
ELIDED_LIFETIME_IN_PATH,

src/librustc_lint/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
270270
reference: "issue #46205 <https://github.com/rust-lang/rust/issues/46205>",
271271
epoch: None,
272272
},
273-
FutureIncompatibleInfo {
274-
id: LintId::of(COERCE_NEVER),
275-
reference: "issue #46325 <https://github.com/rust-lang/rust/issues/46325>",
276-
epoch: None,
277-
},
278273
FutureIncompatibleInfo {
279274
id: LintId::of(TYVAR_BEHIND_RAW_POINTER),
280275
reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>",

src/librustc_typeck/check/cast.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
//! expression, `e as U2` is not necessarily so (in fact it will only be valid if
3939
//! `U1` coerces to `U2`).
4040
41-
use super::{Diverges, FnCtxt};
41+
use super::FnCtxt;
4242

4343
use errors::DiagnosticBuilder;
4444
use hir::def_id::DefId;
@@ -59,7 +59,6 @@ use util::common::ErrorReported;
5959
pub struct CastCheck<'tcx> {
6060
expr: &'tcx hir::Expr,
6161
expr_ty: Ty<'tcx>,
62-
expr_diverges: Diverges,
6362
cast_ty: Ty<'tcx>,
6463
cast_span: Span,
6564
span: Span,
@@ -183,15 +182,13 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
183182
pub fn new(fcx: &FnCtxt<'a, 'gcx, 'tcx>,
184183
expr: &'tcx hir::Expr,
185184
expr_ty: Ty<'tcx>,
186-
expr_diverges: Diverges,
187185
cast_ty: Ty<'tcx>,
188186
cast_span: Span,
189187
span: Span)
190188
-> Result<CastCheck<'tcx>, ErrorReported> {
191189
let check = CastCheck {
192190
expr,
193191
expr_ty,
194-
expr_diverges,
195192
cast_ty,
196193
cast_span,
197194
span,
@@ -437,7 +434,6 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
437434
let f = self.expr_ty.fn_sig(fcx.tcx);
438435
let res = fcx.try_coerce(self.expr,
439436
self.expr_ty,
440-
self.expr_diverges,
441437
fcx.tcx.mk_fn_ptr(f));
442438
if !res.is_ok() {
443439
return Err(CastError::NonScalar);
@@ -620,7 +616,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
620616
}
621617

622618
fn try_coercion_cast(&self, fcx: &FnCtxt<'a, 'gcx, 'tcx>) -> bool {
623-
fcx.try_coerce(self.expr, self.expr_ty, self.expr_diverges, self.cast_ty).is_ok()
619+
fcx.try_coerce(self.expr, self.expr_ty, self.cast_ty).is_ok()
624620
}
625621
}
626622

src/librustc_typeck/check/coercion.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ use rustc::hir;
6666
use rustc::hir::def_id::DefId;
6767
use rustc::infer::{Coercion, InferResult, InferOk};
6868
use rustc::infer::type_variable::TypeVariableOrigin;
69-
use rustc::lint;
7069
use rustc::traits::{self, ObligationCause, ObligationCauseCode};
7170
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability};
7271
use rustc::ty::{self, TypeAndMut, Ty, ClosureSubsts};
@@ -752,27 +751,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
752751
pub fn try_coerce(&self,
753752
expr: &hir::Expr,
754753
expr_ty: Ty<'tcx>,
755-
expr_diverges: Diverges,
756754
target: Ty<'tcx>)
757755
-> RelateResult<'tcx, Ty<'tcx>> {
758756
let source = self.resolve_type_vars_with_obligations(expr_ty);
759757
debug!("coercion::try({:?}: {:?} -> {:?})", expr, source, target);
760758

761-
// Special-ish case: we can coerce any type `T` into the `!`
762-
// type, but only if the source expression diverges.
763-
if target.is_never() && expr_diverges.always() {
764-
debug!("permit coercion to `!` because expr diverges");
765-
if self.can_eq(self.param_env, source, target).is_err() {
766-
self.tcx.lint_node(
767-
lint::builtin::COERCE_NEVER,
768-
expr.id,
769-
expr.span,
770-
&format!("cannot coerce `{}` to !", source)
771-
);
772-
return Ok(target);
773-
}
774-
}
775-
776759
let cause = self.cause(expr.span, ObligationCauseCode::ExprAssignable);
777760
let coerce = Coerce::new(self, cause);
778761
let ok = self.commit_if_ok(|_| coerce.coerce(source, target))?;
@@ -1123,7 +1106,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
11231106
if self.pushed == 0 {
11241107
// Special-case the first expression we are coercing.
11251108
// To be honest, I'm not entirely sure why we do this.
1126-
fcx.try_coerce(expression, expression_ty, expression_diverges, self.expected_ty)
1109+
fcx.try_coerce(expression, expression_ty, self.expected_ty)
11271110
} else {
11281111
match self.expressions {
11291112
Expressions::Dynamic(ref exprs) =>

src/librustc_typeck/check/demand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
100100
-> (Ty<'tcx>, Option<DiagnosticBuilder<'tcx>>) {
101101
let expected = self.resolve_type_vars_with_obligations(expected);
102102

103-
let e = match self.try_coerce(expr, checked_ty, self.diverges.get(), expected) {
103+
let e = match self.try_coerce(expr, checked_ty, expected) {
104104
Ok(ty) => return (ty, None),
105105
Err(e) => e
106106
};

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3944,15 +3944,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
39443944
let t_cast = self.resolve_type_vars_if_possible(&t_cast);
39453945
let t_expr = self.check_expr_with_expectation(e, ExpectCastableToType(t_cast));
39463946
let t_cast = self.resolve_type_vars_if_possible(&t_cast);
3947-
let diverges = self.diverges.get();
39483947

39493948
// Eagerly check for some obvious errors.
39503949
if t_expr.references_error() || t_cast.references_error() {
39513950
tcx.types.err
39523951
} else {
39533952
// Defer other checks until we're done type checking.
39543953
let mut deferred_cast_checks = self.deferred_cast_checks.borrow_mut();
3955-
match cast::CastCheck::new(self, e, t_expr, diverges, t_cast, t.span, expr.span) {
3954+
match cast::CastCheck::new(self, e, t_expr, t_cast, t.span, expr.span) {
39563955
Ok(cast_check) => {
39573956
deferred_cast_checks.push(cast_check);
39583957
t_cast

src/test/compile-fail/coerce-to-bang-cast.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010

1111
fn foo(x: usize, y: !, z: usize) { }
1212

13-
#[deny(coerce_never)]
1413
fn cast_a() {
1514
let y = {return; 22} as !;
16-
//~^ ERROR cannot coerce `i32` to !
17-
//~| hard error
15+
//~^ ERROR non-primitive cast
1816
}
1917

2018
fn cast_b() {

src/test/compile-fail/coerce-to-bang.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![deny(coerce_never)]
12-
1311
fn foo(x: usize, y: !, z: usize) { }
1412

1513
fn call_foo_a() {
16-
// FIXME(#40800) -- accepted because divergence happens **before**
17-
// the coercion to `!`, but within same expression. Not clear that
18-
// these are the rules we want.
1914
foo(return, 22, 44);
20-
//~^ ERROR cannot coerce `{integer}` to !
21-
//~| hard error
15+
//~^ ERROR mismatched types
2216
}
2317

2418
fn call_foo_b() {
@@ -38,8 +32,7 @@ fn call_foo_d() {
3832
let b = 22;
3933
let c = 44;
4034
foo(a, b, c); // ... and hence a reference to `a` is expected to diverge.
41-
//~^ ERROR cannot coerce `{integer}` to !
42-
//~| hard error
35+
//~^ ERROR mismatched types
4336
}
4437

4538
fn call_foo_e() {
@@ -79,8 +72,7 @@ fn tuple_a() {
7972
fn tuple_b() {
8073
// Divergence happens before coercion: OK
8174
let x: (usize, !, usize) = (return, 44, 66);
82-
//~^ ERROR cannot coerce `{integer}` to !
83-
//~| hard error
75+
//~^ ERROR mismatched types
8476
}
8577

8678
fn tuple_c() {

src/test/compile-fail/diverging-fn-tail-35849.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[deny(coerce_never)]
1211
fn assert_sizeof() -> ! {
1312
unsafe {
1413
::std::mem::transmute::<f64, [u8; 8]>(panic!())
15-
//~^ ERROR cannot coerce `[u8; 8]` to !
16-
//~| hard error
14+
//~^ ERROR mismatched types
1715
}
1816
}
1917

src/test/run-pass/diverging-fn-tail-35849.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)