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