about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorleonardo.yvens <leoyvens@gmail.com>2018-01-18 10:38:33 -0200
committerleonardo.yvens <leoyvens@gmail.com>2018-01-27 15:42:55 -0200
commitcd4de4cece143e8dbaeeff93492afcbb356d3051 (patch)
tree84a7dded2acd2046eabaa197ff11687e8026c05c /src
parent4c0ff95e6ecd861741e868cc729afe0339a4b8c7 (diff)
downloadrust-cd4de4cece143e8dbaeeff93492afcbb356d3051.tar.gz
rust-cd4de4cece143e8dbaeeff93492afcbb356d3051.zip
Suppress unknown cast errors in the presence of other errors.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/check/cast.rs3
-rw-r--r--src/librustc_typeck/check/mod.rs8
-rw-r--r--src/test/compile-fail/derived-errors/issue-31997.rs4
-rw-r--r--src/test/ui/issue-45730.rs4
-rw-r--r--src/test/ui/issue-45730.stderr8
-rw-r--r--src/test/ui/mismatched_types/issue-26480-1.stderr11
-rw-r--r--src/test/ui/mismatched_types/issue-26480-2.rs18
-rw-r--r--src/test/ui/mismatched_types/issue-26480-2.stderr13
-rw-r--r--src/test/ui/mismatched_types/issue-26480.rs (renamed from src/test/ui/mismatched_types/issue-26480-1.rs)6
-rw-r--r--src/test/ui/mismatched_types/issue-26480.stderr13
10 files changed, 35 insertions, 53 deletions
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<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(())
 }
 
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.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 <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);
-}
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-1.rs b/src/test/ui/mismatched_types/issue-26480.rs
index 36a30ccb0fc..33c5e74fafa 100644
--- a/src/test/ui/mismatched_types/issue-26480-1.rs
+++ b/src/test/ui/mismatched_types/issue-26480.rs
@@ -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);
 }
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