From cd4de4cece143e8dbaeeff93492afcbb356d3051 Mon Sep 17 00:00:00 2001 From: "leonardo.yvens" Date: Thu, 18 Jan 2018 10:38:33 -0200 Subject: Suppress unknown cast errors in the presence of other errors. --- src/librustc_typeck/check/cast.rs | 3 ++ src/librustc_typeck/check/mod.rs | 8 +++-- .../compile-fail/derived-errors/issue-31997.rs | 4 +-- src/test/ui/issue-45730.rs | 4 +++ src/test/ui/issue-45730.stderr | 8 ++--- src/test/ui/mismatched_types/issue-26480-1.rs | 35 ------------------- src/test/ui/mismatched_types/issue-26480-1.stderr | 11 ------ src/test/ui/mismatched_types/issue-26480-2.rs | 18 ---------- src/test/ui/mismatched_types/issue-26480-2.stderr | 13 -------- src/test/ui/mismatched_types/issue-26480.rs | 39 ++++++++++++++++++++++ src/test/ui/mismatched_types/issue-26480.stderr | 13 +++++++- 11 files changed, 69 insertions(+), 87 deletions(-) delete mode 100644 src/test/ui/mismatched_types/issue-26480-1.rs delete mode 100644 src/test/ui/mismatched_types/issue-26480-1.stderr delete mode 100644 src/test/ui/mismatched_types/issue-26480-2.rs delete mode 100644 src/test/ui/mismatched_types/issue-26480-2.stderr create mode 100644 src/test/ui/mismatched_types/issue-26480.rs (limited to 'src') diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 8dde3d7ab98..2978921fc62 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -290,6 +290,9 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { } CastError::UnknownCastPtrKind | CastError::UnknownExprPtrKind => { + if fcx.is_tainted_by_errors() { + return; + } let unknown_cast_to = match e { CastError::UnknownCastPtrKind => true, CastError::UnknownExprPtrKind => false, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index e97de581173..57e40ec19af 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2148,8 +2148,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { _ if self.is_tainted_by_errors() => self.tcx().types.err, UnconstrainedInt => self.tcx.types.i32, UnconstrainedFloat => self.tcx.types.f64, - Neither if self.type_var_diverges(ty) && fallback == Fallback::Full - => self.tcx.mk_diverging_default(), + Neither if self.type_var_diverges(ty) => { + match fallback { + Fallback::Full => self.tcx.mk_diverging_default(), + Fallback::Numeric => return, + } + } Neither => return }; debug!("default_type_parameters: defaulting `{:?}` to `{:?}`", ty, fallback); diff --git a/src/test/compile-fail/derived-errors/issue-31997.rs b/src/test/compile-fail/derived-errors/issue-31997.rs index 0385e3b8365..2e1d3c55a8f 100644 --- a/src/test/compile-fail/derived-errors/issue-31997.rs +++ b/src/test/compile-fail/derived-errors/issue-31997.rs @@ -20,9 +20,7 @@ fn closure(x: F) -> Result } fn foo() -> Result<(), ()> { - try!(closure(|| bar(0 as *mut _))); - //~^ ERROR cannot find function `bar` in this scope - //~^^ ERROR cannot cast to a pointer of an unknown kind + try!(closure(|| bar(0 as *mut _))); //~ ERROR cannot find function `bar` in this scope Ok(()) } diff --git a/src/test/ui/issue-45730.rs b/src/test/ui/issue-45730.rs index d733c8e6de2..1fe0b1ae2d2 100644 --- a/src/test/ui/issue-45730.rs +++ b/src/test/ui/issue-45730.rs @@ -11,9 +11,13 @@ use std::fmt; fn main() { let x: *const _ = 0 as _; //~ ERROR cannot cast +} +fn a() { let x: *const _ = 0 as *const _; //~ ERROR cannot cast let y: Option<*const fmt::Debug> = Some(x) as _; +} +fn c() { let x = 0 as *const i32 as *const _ as *mut _; //~ ERROR cannot cast } diff --git a/src/test/ui/issue-45730.stderr b/src/test/ui/issue-45730.stderr index 94d39239117..13205eead43 100644 --- a/src/test/ui/issue-45730.stderr +++ b/src/test/ui/issue-45730.stderr @@ -9,9 +9,9 @@ error[E0641]: cannot cast to a pointer of an unknown kind = note: The type information given here is insufficient to check whether the pointer cast is valid error[E0641]: cannot cast to a pointer of an unknown kind - --> $DIR/issue-45730.rs:15:23 + --> $DIR/issue-45730.rs:17:23 | -15 | let x: *const _ = 0 as *const _; //~ ERROR cannot cast +17 | let x: *const _ = 0 as *const _; //~ ERROR cannot cast | ^^^^^-------- | | | help: consider giving more type information @@ -19,9 +19,9 @@ error[E0641]: cannot cast to a pointer of an unknown kind = note: The type information given here is insufficient to check whether the pointer cast is valid error[E0641]: cannot cast to a pointer of an unknown kind - --> $DIR/issue-45730.rs:18:13 + --> $DIR/issue-45730.rs:22:13 | -18 | let x = 0 as *const i32 as *const _ as *mut _; //~ ERROR cannot cast +22 | let x = 0 as *const i32 as *const _ as *mut _; //~ ERROR cannot cast | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------ | | | help: consider giving more type information diff --git a/src/test/ui/mismatched_types/issue-26480-1.rs b/src/test/ui/mismatched_types/issue-26480-1.rs deleted file mode 100644 index 36a30ccb0fc..00000000000 --- a/src/test/ui/mismatched_types/issue-26480-1.rs +++ /dev/null @@ -1,35 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -// compile-flags: --error-format=human - -extern { - fn write(fildes: i32, buf: *const i8, nbyte: u64) -> i64; -} - -#[inline(always)] -fn size_of(_: T) -> usize { - ::std::mem::size_of::() -} - -macro_rules! write { - ($arr:expr) => {{ - #[allow(non_upper_case_globals)] - const stdout: i32 = 1; - unsafe { - write(stdout, $arr.as_ptr() as *const i8, - $arr.len() * size_of($arr[0])); //~ ERROR mismatched types - } - }} -} - -fn main() { - let hello = ['H', 'e', 'y']; - write!(hello); -} diff --git a/src/test/ui/mismatched_types/issue-26480-1.stderr b/src/test/ui/mismatched_types/issue-26480-1.stderr deleted file mode 100644 index 326b427b0fb..00000000000 --- a/src/test/ui/mismatched_types/issue-26480-1.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/issue-26480-1.rs:27:19 - | -27 | $arr.len() * size_of($arr[0])); //~ ERROR mismatched types - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u64, found usize -... -34 | write!(hello); - | -------------- in this macro invocation - -error: aborting due to previous error - diff --git a/src/test/ui/mismatched_types/issue-26480-2.rs b/src/test/ui/mismatched_types/issue-26480-2.rs deleted file mode 100644 index 7015e5909e9..00000000000 --- a/src/test/ui/mismatched_types/issue-26480-2.rs +++ /dev/null @@ -1,18 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -// compile-flags: --error-format=human - -macro_rules! cast { - ($x:expr) => ($x as ()) //~ ERROR non-primitive cast -} - -fn main() { - cast!(2); -} diff --git a/src/test/ui/mismatched_types/issue-26480-2.stderr b/src/test/ui/mismatched_types/issue-26480-2.stderr deleted file mode 100644 index 3f6dcccdedb..00000000000 --- a/src/test/ui/mismatched_types/issue-26480-2.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error[E0605]: non-primitive cast: `i32` as `()` - --> $DIR/issue-26480-2.rs:13:19 - | -13 | ($x:expr) => ($x as ()) //~ ERROR non-primitive cast - | ^^^^^^^^ -... -17 | cast!(2); - | --------- in this macro invocation - | - = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait - -error: aborting due to previous error - diff --git a/src/test/ui/mismatched_types/issue-26480.rs b/src/test/ui/mismatched_types/issue-26480.rs new file mode 100644 index 00000000000..33c5e74fafa --- /dev/null +++ b/src/test/ui/mismatched_types/issue-26480.rs @@ -0,0 +1,39 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern { + fn write(fildes: i32, buf: *const i8, nbyte: u64) -> i64; +} + +#[inline(always)] +fn size_of(_: T) -> usize { + ::std::mem::size_of::() +} + +macro_rules! write { + ($arr:expr) => {{ + #[allow(non_upper_case_globals)] + const stdout: i32 = 1; + unsafe { + write(stdout, $arr.as_ptr() as *const i8, + $arr.len() * size_of($arr[0])); //~ ERROR mismatched types + } + }} +} + +macro_rules! cast { + ($x:expr) => ($x as ()) //~ ERROR non-primitive cast +} + +fn main() { + let hello = ['H', 'e', 'y']; + write!(hello); + cast!(2); +} diff --git a/src/test/ui/mismatched_types/issue-26480.stderr b/src/test/ui/mismatched_types/issue-26480.stderr index 27698c864c3..5d25cb2f93c 100644 --- a/src/test/ui/mismatched_types/issue-26480.stderr +++ b/src/test/ui/mismatched_types/issue-26480.stderr @@ -7,5 +7,16 @@ error[E0308]: mismatched types 37 | write!(hello); | -------------- in this macro invocation -error: aborting due to previous error +error[E0605]: non-primitive cast: `{integer}` as `()` + --> $DIR/issue-26480.rs:32:19 + | +32 | ($x:expr) => ($x as ()) //~ ERROR non-primitive cast + | ^^^^^^^^ +... +38 | cast!(2); + | --------- in this macro invocation + | + = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait + +error: aborting due to 2 previous errors -- cgit 1.4.1-3-g733a5