Skip to content

Commit cd4de4c

Browse files
committed
Suppress unknown cast errors in the presence of other errors.
1 parent 4c0ff95 commit cd4de4c

File tree

10 files changed

+35
-53
lines changed

10 files changed

+35
-53
lines changed

src/librustc_typeck/check/cast.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
290290
}
291291
CastError::UnknownCastPtrKind |
292292
CastError::UnknownExprPtrKind => {
293+
if fcx.is_tainted_by_errors() {
294+
return;
295+
}
293296
let unknown_cast_to = match e {
294297
CastError::UnknownCastPtrKind => true,
295298
CastError::UnknownExprPtrKind => false,

src/librustc_typeck/check/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,8 +2148,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
21482148
_ if self.is_tainted_by_errors() => self.tcx().types.err,
21492149
UnconstrainedInt => self.tcx.types.i32,
21502150
UnconstrainedFloat => self.tcx.types.f64,
2151-
Neither if self.type_var_diverges(ty) && fallback == Fallback::Full
2152-
=> self.tcx.mk_diverging_default(),
2151+
Neither if self.type_var_diverges(ty) => {
2152+
match fallback {
2153+
Fallback::Full => self.tcx.mk_diverging_default(),
2154+
Fallback::Numeric => return,
2155+
}
2156+
}
21532157
Neither => return
21542158
};
21552159
debug!("default_type_parameters: defaulting `{:?}` to `{:?}`", ty, fallback);

src/test/compile-fail/derived-errors/issue-31997.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ fn closure<F, T>(x: F) -> Result<T, ()>
2020
}
2121

2222
fn foo() -> Result<(), ()> {
23-
try!(closure(|| bar(0 as *mut _)));
24-
//~^ ERROR cannot find function `bar` in this scope
25-
//~^^ ERROR cannot cast to a pointer of an unknown kind
23+
try!(closure(|| bar(0 as *mut _))); //~ ERROR cannot find function `bar` in this scope
2624
Ok(())
2725
}
2826

src/test/ui/issue-45730.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
use std::fmt;
1212
fn main() {
1313
let x: *const _ = 0 as _; //~ ERROR cannot cast
14+
}
1415

16+
fn a() {
1517
let x: *const _ = 0 as *const _; //~ ERROR cannot cast
1618
let y: Option<*const fmt::Debug> = Some(x) as _;
19+
}
1720

21+
fn c() {
1822
let x = 0 as *const i32 as *const _ as *mut _; //~ ERROR cannot cast
1923
}

src/test/ui/issue-45730.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ error[E0641]: cannot cast to a pointer of an unknown kind
99
= note: The type information given here is insufficient to check whether the pointer cast is valid
1010

1111
error[E0641]: cannot cast to a pointer of an unknown kind
12-
--> $DIR/issue-45730.rs:15:23
12+
--> $DIR/issue-45730.rs:17:23
1313
|
14-
15 | let x: *const _ = 0 as *const _; //~ ERROR cannot cast
14+
17 | let x: *const _ = 0 as *const _; //~ ERROR cannot cast
1515
| ^^^^^--------
1616
| |
1717
| help: consider giving more type information
1818
|
1919
= note: The type information given here is insufficient to check whether the pointer cast is valid
2020

2121
error[E0641]: cannot cast to a pointer of an unknown kind
22-
--> $DIR/issue-45730.rs:18:13
22+
--> $DIR/issue-45730.rs:22:13
2323
|
24-
18 | let x = 0 as *const i32 as *const _ as *mut _; //~ ERROR cannot cast
24+
22 | let x = 0 as *const i32 as *const _ as *mut _; //~ ERROR cannot cast
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------
2626
| |
2727
| help: consider giving more type information

src/test/ui/mismatched_types/issue-26480-1.stderr

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

src/test/ui/mismatched_types/issue-26480-2.rs

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

src/test/ui/mismatched_types/issue-26480-2.stderr

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

src/test/ui/mismatched_types/issue-26480-1.rs renamed to src/test/ui/mismatched_types/issue-26480.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10-
// compile-flags: --error-format=human
1110

1211
extern {
1312
fn write(fildes: i32, buf: *const i8, nbyte: u64) -> i64;
@@ -29,7 +28,12 @@ macro_rules! write {
2928
}}
3029
}
3130

31+
macro_rules! cast {
32+
($x:expr) => ($x as ()) //~ ERROR non-primitive cast
33+
}
34+
3235
fn main() {
3336
let hello = ['H', 'e', 'y'];
3437
write!(hello);
38+
cast!(2);
3539
}

src/test/ui/mismatched_types/issue-26480.stderr

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,16 @@ error[E0308]: mismatched types
77
37 | write!(hello);
88
| -------------- in this macro invocation
99

10-
error: aborting due to previous error
10+
error[E0605]: non-primitive cast: `{integer}` as `()`
11+
--> $DIR/issue-26480.rs:32:19
12+
|
13+
32 | ($x:expr) => ($x as ()) //~ ERROR non-primitive cast
14+
| ^^^^^^^^
15+
...
16+
38 | cast!(2);
17+
| --------- in this macro invocation
18+
|
19+
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
20+
21+
error: aborting due to 2 previous errors
1122

0 commit comments

Comments
 (0)