Skip to content

Commit

Permalink
Suppress unknown cast errors in the presence of other errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
leoyvens committed Jan 27, 2018
1 parent 4c0ff95 commit cd4de4c
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 53 deletions.
3 changes: 3 additions & 0 deletions src/librustc_typeck/check/cast.rs
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/test/compile-fail/derived-errors/issue-31997.rs
Expand Up @@ -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(())
}

Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/issue-45730.rs
Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions src/test/ui/issue-45730.stderr
Expand Up @@ -9,19 +9,19 @@ 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
|
= 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
Expand Down
11 changes: 0 additions & 11 deletions src/test/ui/mismatched_types/issue-26480-1.stderr

This file was deleted.

18 changes: 0 additions & 18 deletions src/test/ui/mismatched_types/issue-26480-2.rs

This file was deleted.

13 changes: 0 additions & 13 deletions src/test/ui/mismatched_types/issue-26480-2.stderr

This file was deleted.

Expand Up @@ -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;
Expand All @@ -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);
}
13 changes: 12 additions & 1 deletion src/test/ui/mismatched_types/issue-26480.stderr
Expand Up @@ -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

0 comments on commit cd4de4c

Please sign in to comment.