Skip to content

Commit a4e0e6b

Browse files
committed
avoid "type must be known here" errors if tainted
1 parent ccaa2f8 commit a4e0e6b

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4800,9 +4800,11 @@ fn structurally_resolve_type_or_else<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
48004800

48014801
// If not, error.
48024802
if alternative.is_ty_var() || alternative.references_error() {
4803-
fcx.type_error_message(sp, |_actual| {
4804-
"the type of this value must be known in this context".to_string()
4805-
}, ty, None);
4803+
if !fcx.infcx().is_tainted_by_errors() {
4804+
fcx.type_error_message(sp, |_actual| {
4805+
"the type of this value must be known in this context".to_string()
4806+
}, ty, None);
4807+
}
48064808
demand::suptype(fcx, sp, fcx.tcx().types.err, ty);
48074809
ty = fcx.tcx().types.err;
48084810
} else {

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for this example from #31997 -- main goal is to
12+
// emit as minimal and precise an error set as possible. Ideally, we'd
13+
// only emit the E0433 error below, but right now we emit two.
14+
15+
use std::io::prelude::*;
16+
// use std::collections::HashMap;
17+
use std::io;
18+
19+
#[derive(Debug)]
20+
struct Instance {
21+
name: String,
22+
start: Option<String>,
23+
end: Option<String>,
24+
}
25+
26+
fn main() {
27+
let input = io::stdin();
28+
let mut input = input.lock();
29+
30+
let mut map = HashMap::new();
31+
//~^ ERROR E0433
32+
//~| ERROR E0425
33+
34+
for line in input.lines() {
35+
let line = line.unwrap();
36+
println!("process: {}", line);
37+
let mut parts = line.splitn(2, ":");
38+
let _logfile = parts.next().unwrap();
39+
let rest = parts.next().unwrap();
40+
let mut parts = line.split(" [-] ");
41+
42+
let stamp = parts.next().unwrap();
43+
44+
let rest = parts.next().unwrap();
45+
let words = rest.split_whitespace().collect::<Vec<_>>();
46+
47+
let instance = words.iter().find(|a| a.starts_with("i-")).unwrap();
48+
let name = words[1].to_owned();
49+
let mut entry = map.entry(instance.to_owned()).or_insert(Instance {
50+
name: name,
51+
start: None,
52+
end: None,
53+
});
54+
55+
if rest.contains("terminating") {
56+
assert!(entry.end.is_none());
57+
entry.end = Some(stamp.to_string());
58+
}
59+
if rest.contains("waiting for") {
60+
assert!(entry.start.is_none());
61+
entry.start = Some(stamp.to_string());
62+
}
63+
64+
}
65+
66+
println!("{:?}", map);
67+
}

0 commit comments

Comments
 (0)