about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-04-25 08:13:22 -0700
committerbors <bors@rust-lang.org>2016-04-25 08:13:22 -0700
commit90318b8c225cde275cf2059330dc096f77301bce (patch)
tree6a5a5708d0fb4b45d09f90053cfbae877902e158 /src/test
parentcfae4dea875ddcc5f23481106a149ea15b6be1e5 (diff)
parentb3d54a2c0e793768cd9ce4a7887a75e3ec356cb5 (diff)
Auto merge of #32258 - nikomatsakis:fewer-errors, r=arielb1
Suppress fallback and ambiguity errors

If the infcx has observed other errors, then suppress both default type
parameter fallback (which can be unreliable, as the full constraint set
is not available) and errors related to unresovled
variables (annoyingly, integer type variables cannot currently be
unified with error, so that has to be a separate mechanism). Also add a
flag to `infcx` to allow us to independently indicate when we have
observed an error and hence should trigger this suppression mode.

Fixes #31997

cc @alexcrichton
r? @arielb1
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/cast-rfc0401-2.rs19
-rw-r--r--src/test/compile-fail/cast-rfc0401.rs2
-rw-r--r--src/test/compile-fail/derived-errors/issue-30580.rs (renamed from src/test/compile-fail/issue-30580.rs)0
-rw-r--r--src/test/compile-fail/derived-errors/issue-31997-1.rs66
-rw-r--r--src/test/compile-fail/derived-errors/issue-31997.rs27
-rw-r--r--src/test/compile-fail/issue-13853.rs2
-rw-r--r--src/test/compile-fail/issue-19692.rs2
-rw-r--r--src/test/compile-fail/issue-20261.rs1
-rw-r--r--src/test/compile-fail/issue-26480.rs3
-rw-r--r--src/test/compile-fail/issue-3973.rs2
-rw-r--r--src/test/compile-fail/issue-7092.rs2
-rw-r--r--src/test/run-pass/cast-to-infer-ty.rs17
12 files changed, 135 insertions, 8 deletions
diff --git a/src/test/compile-fail/cast-rfc0401-2.rs b/src/test/compile-fail/cast-rfc0401-2.rs
new file mode 100644
index 00000000000..1598a9aa1fc
--- /dev/null
+++ b/src/test/compile-fail/cast-rfc0401-2.rs
@@ -0,0 +1,19 @@
+// Copyright 2015 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.
+
+// RFC 401 test extracted into distinct file. This is because some the
+// change to suppress "derived" errors wound up suppressing this error
+// message, since the fallback for `3` doesn't occur.
+
+fn main() {
+    let _ = 3 as bool;
+    //~^ ERROR cannot cast as `bool`
+    //~| HELP compare with zero
+}
diff --git a/src/test/compile-fail/cast-rfc0401.rs b/src/test/compile-fail/cast-rfc0401.rs
index b81617abcf4..05c531e91f1 100644
--- a/src/test/compile-fail/cast-rfc0401.rs
+++ b/src/test/compile-fail/cast-rfc0401.rs
@@ -58,7 +58,7 @@ fn main()
     let _ = f as *const u8;
     //~^ ERROR casting
     //~^^ HELP through a usize first
-    let _ = 3 as bool;
+    let _ = 3_i32 as bool;
     //~^ ERROR cannot cast as `bool`
     //~| HELP compare with zero
     let _ = E::A as bool;
diff --git a/src/test/compile-fail/issue-30580.rs b/src/test/compile-fail/derived-errors/issue-30580.rs
index 88d4aef6d9d..88d4aef6d9d 100644
--- a/src/test/compile-fail/issue-30580.rs
+++ b/src/test/compile-fail/derived-errors/issue-30580.rs
diff --git a/src/test/compile-fail/derived-errors/issue-31997-1.rs b/src/test/compile-fail/derived-errors/issue-31997-1.rs
new file mode 100644
index 00000000000..7d79c48c06a
--- /dev/null
+++ b/src/test/compile-fail/derived-errors/issue-31997-1.rs
@@ -0,0 +1,66 @@
+// Copyright 2012 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.
+
+// Regression test for this example from #31997 -- main goal is to
+// emit as minimal and precise an error set as possible. Ideally, we'd
+// only emit the E0433 error below, but right now we emit two.
+
+use std::io::prelude::*;
+// use std::collections::HashMap;
+use std::io;
+
+#[derive(Debug)]
+struct Instance {
+    name: String,
+    start: Option<String>,
+    end: Option<String>,
+}
+
+fn main() {
+    let input = io::stdin();
+    let mut input = input.lock();
+
+    let mut map = HashMap::new();
+    //~^ ERROR E0433
+
+    for line in input.lines() {
+        let line = line.unwrap();
+        println!("process: {}", line);
+        let mut parts = line.splitn(2, ":");
+        let _logfile = parts.next().unwrap();
+        let rest = parts.next().unwrap();
+        let mut parts = line.split(" [-] ");
+
+        let stamp = parts.next().unwrap();
+
+        let rest = parts.next().unwrap();
+        let words = rest.split_whitespace().collect::<Vec<_>>();
+
+        let instance = words.iter().find(|a| a.starts_with("i-")).unwrap();
+        let name = words[1].to_owned();
+        let mut entry = map.entry(instance.to_owned()).or_insert(Instance {
+            name: name,
+            start: None,
+            end: None,
+        });
+
+        if rest.contains("terminating") {
+            assert!(entry.end.is_none());
+            entry.end = Some(stamp.to_string());
+        }
+        if rest.contains("waiting for") {
+            assert!(entry.start.is_none());
+            entry.start = Some(stamp.to_string());
+        }
+
+    }
+
+    println!("{:?}", map);
+}
diff --git a/src/test/compile-fail/derived-errors/issue-31997.rs b/src/test/compile-fail/derived-errors/issue-31997.rs
new file mode 100644
index 00000000000..cf283f6d3e4
--- /dev/null
+++ b/src/test/compile-fail/derived-errors/issue-31997.rs
@@ -0,0 +1,27 @@
+// Copyright 2012 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.
+
+// Test that the resolve failure does not lead to downstream type errors.
+// See issue #31997.
+
+trait TheTrait { }
+
+fn closure<F, T>(x: F) -> Result<T, ()>
+    where F: FnMut() -> T, T: TheTrait,
+{
+    unimplemented!()
+}
+
+fn foo() -> Result<(), ()> {
+    try!(closure(|| bar(0 as *mut _))); //~ ERROR unresolved name `bar`
+    Ok(())
+}
+
+fn main() { }
diff --git a/src/test/compile-fail/issue-13853.rs b/src/test/compile-fail/issue-13853.rs
index 7643310298d..86a6bdfd4dd 100644
--- a/src/test/compile-fail/issue-13853.rs
+++ b/src/test/compile-fail/issue-13853.rs
@@ -35,7 +35,7 @@ impl Node for Stuff {
 
 fn iterate<N: Node, G: Graph<N>>(graph: &G) {
     for node in graph.iter() { //~ ERROR no method named `iter` found
-        node.zomg();  //~ error: the type of this value must be known in this context
+        node.zomg();
     }
 }
 
diff --git a/src/test/compile-fail/issue-19692.rs b/src/test/compile-fail/issue-19692.rs
index 53ad2416878..ca1715445e5 100644
--- a/src/test/compile-fail/issue-19692.rs
+++ b/src/test/compile-fail/issue-19692.rs
@@ -12,7 +12,7 @@ struct Homura;
 
 fn akemi(homura: Homura) {
     let Some(ref madoka) = Some(homura.kaname()); //~ ERROR no method named `kaname` found
-    madoka.clone(); //~ ERROR the type of this value must be known
+    madoka.clone();
 }
 
 fn main() { }
diff --git a/src/test/compile-fail/issue-20261.rs b/src/test/compile-fail/issue-20261.rs
index 09044b5b505..2f1910b26bb 100644
--- a/src/test/compile-fail/issue-20261.rs
+++ b/src/test/compile-fail/issue-20261.rs
@@ -11,6 +11,5 @@
 fn main() {
     for (ref i,) in [].iter() { //~ ERROR mismatched types
         i.clone();
-        //~^ ERROR: the type of this value must be known in this context
     }
 }
diff --git a/src/test/compile-fail/issue-26480.rs b/src/test/compile-fail/issue-26480.rs
index 903df42291c..23e4ffb1f30 100644
--- a/src/test/compile-fail/issue-26480.rs
+++ b/src/test/compile-fail/issue-26480.rs
@@ -30,8 +30,7 @@ macro_rules! write {
 }
 
 macro_rules! cast {
-    ($x:expr) => ($x as ())
-    //~^ ERROR non-scalar cast: `i32` as `()`
+    ($x:expr) => ($x as ()) //~ ERROR non-scalar cast
 }
 
 fn main() {
diff --git a/src/test/compile-fail/issue-3973.rs b/src/test/compile-fail/issue-3973.rs
index 54eb2a90829..92456760b05 100644
--- a/src/test/compile-fail/issue-3973.rs
+++ b/src/test/compile-fail/issue-3973.rs
@@ -31,5 +31,5 @@ impl ToString_ for Point {
 fn main() {
     let p = Point::new(0.0, 0.0);
     //~^ ERROR no associated item named `new` found for type `Point` in the current scope
-    println!("{}", p.to_string()); //~ ERROR type of this value must be known
+    println!("{}", p.to_string());
 }
diff --git a/src/test/compile-fail/issue-7092.rs b/src/test/compile-fail/issue-7092.rs
index 4a278bbdeb0..4acbcb165ff 100644
--- a/src/test/compile-fail/issue-7092.rs
+++ b/src/test/compile-fail/issue-7092.rs
@@ -19,7 +19,7 @@ fn foo(x: Whatever) {
 //~| found `std::option::Option<_>`
 //~| expected enum `Whatever`
 //~| found enum `std::option::Option`
-            field.access(), //~ ERROR the type of this value must be known in this context
+            field.access(),
     }
 }
 
diff --git a/src/test/run-pass/cast-to-infer-ty.rs b/src/test/run-pass/cast-to-infer-ty.rs
new file mode 100644
index 00000000000..2aa0d9c62fb
--- /dev/null
+++ b/src/test/run-pass/cast-to-infer-ty.rs
@@ -0,0 +1,17 @@
+// Copyright 2012 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.
+
+// Check that we allow a cast to `_` so long as the target type can be
+// inferred elsewhere.
+
+pub fn main() {
+    let i: *const i32 = 0 as _;
+    assert!(i.is_null());
+}