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
This commit is contained in:
bors 2016-04-25 08:13:22 -07:00
commit 90318b8c22
20 changed files with 348 additions and 99 deletions

View file

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

View file

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

View file

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

View file

@ -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() { }

View file

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

View file

@ -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() { }

View file

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

View file

@ -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() {

View file

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

View file

@ -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(),
}
}

View file

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