rust/tests/ui/panic_unimplemented.rs

82 lines
1.6 KiB
Rust
Raw Normal View History

2018-10-06 11:18:06 -05:00
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// 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.
2018-07-28 10:34:52 -05:00
#![feature(tool_lints)]
2017-09-18 05:47:33 -05:00
2018-07-28 10:34:52 -05:00
#![warn(clippy::panic_params, clippy::unimplemented)]
2015-12-23 15:37:52 -06:00
fn missing() {
if true {
2017-02-08 07:58:07 -06:00
panic!("{}");
} else if false {
2017-02-08 07:58:07 -06:00
panic!("{:?}");
} else {
2017-02-08 07:58:07 -06:00
assert!(true, "here be missing values: {}");
}
panic!("{{{this}}}");
2015-12-23 15:37:52 -06:00
}
fn ok_single() {
2015-12-23 15:37:52 -06:00
panic!("foo bar");
}
fn ok_inner() {
// Test for #768
assert!("foo bar".contains(&format!("foo {}", "bar")));
}
2015-12-23 15:37:52 -06:00
fn ok_multiple() {
panic!("{}", "This is {ok}");
}
fn ok_bracket() {
match 42 {
1337 => panic!("{so is this"),
666 => panic!("so is this}"),
_ => panic!("}so is that{"),
}
}
const ONE : u32= 1;
fn ok_nomsg() {
assert!({ 1 == ONE });
assert!(if 1 == ONE { ONE == 1 } else { false });
}
fn ok_escaped() {
panic!("{{ why should this not be ok? }}");
panic!(" or {{ that ?");
panic!(" or }} this ?");
panic!(" {or {{ that ?");
panic!(" }or }} this ?");
panic!("{{ test }");
panic!("{case }}");
}
2018-05-23 09:43:05 -05:00
fn unimplemented() {
let a = 2;
2018-05-23 09:43:05 -05:00
unimplemented!();
let b = a + 2;
2018-05-23 09:43:05 -05:00
}
2015-12-23 15:37:52 -06:00
fn main() {
missing();
ok_single();
2015-12-23 15:37:52 -06:00
ok_multiple();
ok_bracket();
ok_inner();
ok_nomsg();
ok_escaped();
2018-05-23 09:43:05 -05:00
unimplemented();
2015-12-23 15:37:52 -06:00
}