Suppress unknown cast errors in the presence of other errors.

This commit is contained in:
leonardo.yvens 2018-01-18 10:38:33 -02:00
parent 4c0ff95e6e
commit cd4de4cece
10 changed files with 35 additions and 53 deletions

View file

@ -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,

View file

@ -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);

View file

@ -20,9 +20,7 @@ fn closure<F, T>(x: F) -> Result<T, ()>
}
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(())
}

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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 <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.
// compile-flags: --error-format=human
macro_rules! cast {
($x:expr) => ($x as ()) //~ ERROR non-primitive cast
}
fn main() {
cast!(2);
}

View file

@ -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

View file

@ -7,7 +7,6 @@
// <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.
// compile-flags: --error-format=human
extern {
fn write(fildes: i32, buf: *const i8, nbyte: u64) -> i64;
@ -29,7 +28,12 @@ macro_rules! write {
}}
}
macro_rules! cast {
($x:expr) => ($x as ()) //~ ERROR non-primitive cast
}
fn main() {
let hello = ['H', 'e', 'y'];
write!(hello);
cast!(2);
}

View file

@ -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