2022-05-25 11:08:41 -05:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
2022-05-30 07:17:36 -05:00
|
|
|
use crate::rustc_stderr::Level;
|
|
|
|
use crate::rustc_stderr::Message;
|
|
|
|
|
2022-05-30 05:56:34 -05:00
|
|
|
use super::*;
|
2022-05-25 11:08:41 -05:00
|
|
|
|
|
|
|
fn config() -> Config {
|
|
|
|
Config {
|
|
|
|
args: vec![],
|
|
|
|
target: None,
|
|
|
|
stderr_filters: vec![],
|
|
|
|
stdout_filters: vec![],
|
2022-05-30 05:56:34 -05:00
|
|
|
root_dir: PathBuf::from("$RUSTROOT"),
|
2022-05-25 11:08:41 -05:00
|
|
|
mode: Mode::Fail,
|
2022-05-30 03:27:41 -05:00
|
|
|
path_filter: vec![],
|
2022-05-25 11:08:41 -05:00
|
|
|
program: PathBuf::from("cake"),
|
|
|
|
output_conflict_handling: OutputConflictHandling::Error,
|
2022-07-14 05:03:08 -05:00
|
|
|
dependencies_crate_manifest_path: None,
|
|
|
|
dependency_builder: None,
|
2022-05-25 11:08:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-07-11 06:44:55 -05:00
|
|
|
fn issue_2156() {
|
2022-05-25 11:08:41 -05:00
|
|
|
let s = r"
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
fn main() {
|
2022-07-11 06:44:55 -05:00
|
|
|
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR: encountered a dangling reference (address $HEX is unallocated)
|
2022-05-25 11:08:41 -05:00
|
|
|
}
|
|
|
|
";
|
2022-05-30 05:56:34 -05:00
|
|
|
let path = Path::new("$DIR/<dummy>");
|
2022-07-11 06:44:55 -05:00
|
|
|
let comments = Comments::parse(path, s).unwrap();
|
2022-05-25 11:08:41 -05:00
|
|
|
let mut errors = vec![];
|
|
|
|
let config = config();
|
2022-05-30 07:17:36 -05:00
|
|
|
let messages = vec![
|
|
|
|
vec![], vec![], vec![], vec![], vec![],
|
|
|
|
vec![
|
|
|
|
Message {
|
|
|
|
message:"Undefined Behavior: type validation failed: encountered a dangling reference (address 0x10 is unallocated)".to_string(),
|
|
|
|
level: Level::Error,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
];
|
|
|
|
check_annotations(messages, vec![], Path::new("moobar"), &mut errors, &config, "", &comments);
|
|
|
|
match &errors[..] {
|
|
|
|
[
|
|
|
|
Error::PatternNotFound { definition_line: 5, .. },
|
|
|
|
Error::ErrorsWithoutPattern { path: Some((_, 5)), .. },
|
2022-07-11 06:44:55 -05:00
|
|
|
] => {}
|
2022-05-30 07:17:36 -05:00
|
|
|
_ => panic!("{:#?}", errors),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-07-11 06:44:55 -05:00
|
|
|
fn find_pattern() {
|
2022-05-30 07:17:36 -05:00
|
|
|
let s = r"
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
fn main() {
|
2022-07-11 06:44:55 -05:00
|
|
|
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR: encountered a dangling reference (address 0x10 is unallocated)
|
2022-05-30 07:17:36 -05:00
|
|
|
}
|
|
|
|
";
|
2022-07-11 06:44:55 -05:00
|
|
|
let comments = Comments::parse(Path::new("<dummy>"), s).unwrap();
|
2022-05-30 07:17:36 -05:00
|
|
|
let config = config();
|
|
|
|
{
|
|
|
|
let messages = vec![vec![], vec![], vec![], vec![], vec![], vec![
|
|
|
|
Message {
|
|
|
|
message: "Undefined Behavior: type validation failed: encountered a dangling reference (address 0x10 is unallocated)".to_string(),
|
|
|
|
level: Level::Error,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
];
|
|
|
|
let mut errors = vec![];
|
|
|
|
check_annotations(
|
|
|
|
messages,
|
|
|
|
vec![],
|
|
|
|
Path::new("moobar"),
|
|
|
|
&mut errors,
|
|
|
|
&config,
|
|
|
|
"",
|
|
|
|
&comments,
|
|
|
|
);
|
|
|
|
match &errors[..] {
|
|
|
|
[] => {}
|
|
|
|
_ => panic!("{:#?}", errors),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// only difference to above is a wrong line number
|
|
|
|
{
|
|
|
|
let messages = vec![vec![], vec![], vec![], vec![], vec![
|
|
|
|
Message {
|
|
|
|
message: "Undefined Behavior: type validation failed: encountered a dangling reference (address 0x10 is unallocated)".to_string(),
|
|
|
|
level: Level::Error,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
];
|
|
|
|
let mut errors = vec![];
|
|
|
|
check_annotations(
|
|
|
|
messages,
|
|
|
|
vec![],
|
|
|
|
Path::new("moobar"),
|
|
|
|
&mut errors,
|
|
|
|
&config,
|
|
|
|
"",
|
|
|
|
&comments,
|
|
|
|
);
|
|
|
|
match &errors[..] {
|
|
|
|
[
|
|
|
|
Error::PatternNotFound { definition_line: 5, .. },
|
|
|
|
Error::ErrorsWithoutPattern { path: Some((_, 4)), .. },
|
|
|
|
] => {}
|
|
|
|
_ => panic!("not the expected error: {:#?}", errors),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// only difference to first is a wrong level
|
|
|
|
{
|
|
|
|
let messages = vec![
|
|
|
|
vec![], vec![], vec![], vec![], vec![],
|
|
|
|
vec![
|
|
|
|
Message {
|
|
|
|
message: "Undefined Behavior: type validation failed: encountered a dangling reference (address 0x10 is unallocated)".to_string(),
|
|
|
|
level: Level::Note,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
];
|
|
|
|
let mut errors = vec![];
|
|
|
|
check_annotations(
|
|
|
|
messages,
|
|
|
|
vec![],
|
|
|
|
Path::new("moobar"),
|
|
|
|
&mut errors,
|
|
|
|
&config,
|
|
|
|
"",
|
|
|
|
&comments,
|
|
|
|
);
|
|
|
|
match &errors[..] {
|
|
|
|
// Note no `ErrorsWithoutPattern`, because there are no `//~NOTE` in the test file, so we ignore them
|
2022-07-11 06:44:55 -05:00
|
|
|
[Error::PatternNotFound { definition_line: 5, .. }] => {}
|
2022-05-30 07:17:36 -05:00
|
|
|
_ => panic!("not the expected error: {:#?}", errors),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-07-11 06:44:55 -05:00
|
|
|
fn duplicate_pattern() {
|
2022-05-30 07:17:36 -05:00
|
|
|
let s = r"
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
fn main() {
|
2022-07-11 06:44:55 -05:00
|
|
|
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR: encountered a dangling reference (address 0x10 is unallocated)
|
|
|
|
//~^ ERROR: encountered a dangling reference (address 0x10 is unallocated)
|
2022-05-30 07:17:36 -05:00
|
|
|
}
|
|
|
|
";
|
2022-07-11 06:44:55 -05:00
|
|
|
let comments = Comments::parse(Path::new("<dummy>"), s).unwrap();
|
2022-05-30 07:17:36 -05:00
|
|
|
let config = config();
|
|
|
|
let messages = vec![
|
|
|
|
vec![], vec![], vec![], vec![], vec![],
|
|
|
|
vec![
|
|
|
|
Message {
|
|
|
|
message: "Undefined Behavior: type validation failed: encountered a dangling reference (address 0x10 is unallocated)".to_string(),
|
|
|
|
level: Level::Error,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
];
|
|
|
|
let mut errors = vec![];
|
|
|
|
check_annotations(messages, vec![], Path::new("moobar"), &mut errors, &config, "", &comments);
|
|
|
|
match &errors[..] {
|
2022-07-11 06:44:55 -05:00
|
|
|
[Error::PatternNotFound { definition_line: 6, .. }] => {}
|
2022-05-30 07:17:36 -05:00
|
|
|
_ => panic!("{:#?}", errors),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-07-11 06:44:55 -05:00
|
|
|
fn missing_pattern() {
|
2022-05-30 07:17:36 -05:00
|
|
|
let s = r"
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
fn main() {
|
2022-07-11 06:44:55 -05:00
|
|
|
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR: encountered a dangling reference (address 0x10 is unallocated)
|
2022-05-30 07:17:36 -05:00
|
|
|
}
|
|
|
|
";
|
2022-07-11 06:44:55 -05:00
|
|
|
let comments = Comments::parse(Path::new("<dummy>"), s).unwrap();
|
2022-05-30 07:17:36 -05:00
|
|
|
let config = config();
|
|
|
|
let messages = vec![
|
|
|
|
vec![], vec![], vec![], vec![], vec![],
|
|
|
|
vec![
|
|
|
|
Message {
|
|
|
|
message: "Undefined Behavior: type validation failed: encountered a dangling reference (address 0x10 is unallocated)".to_string(),
|
|
|
|
level: Level::Error,
|
|
|
|
},
|
|
|
|
Message {
|
|
|
|
message: "Undefined Behavior: type validation failed: encountered a dangling reference (address 0x10 is unallocated)".to_string(),
|
|
|
|
level: Level::Error,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
];
|
|
|
|
let mut errors = vec![];
|
|
|
|
check_annotations(messages, vec![], Path::new("moobar"), &mut errors, &config, "", &comments);
|
|
|
|
match &errors[..] {
|
2022-07-11 06:44:55 -05:00
|
|
|
[Error::ErrorsWithoutPattern { path: Some((_, 5)), .. }] => {}
|
2022-05-30 07:17:36 -05:00
|
|
|
_ => panic!("{:#?}", errors),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-07-11 06:44:55 -05:00
|
|
|
fn missing_warn_pattern() {
|
2022-05-30 07:17:36 -05:00
|
|
|
let s = r"
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
fn main() {
|
2022-07-11 06:44:55 -05:00
|
|
|
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR: encountered a dangling reference (address 0x10 is unallocated)
|
|
|
|
//~^ WARN: cake
|
2022-05-30 07:17:36 -05:00
|
|
|
}
|
|
|
|
";
|
2022-07-11 06:44:55 -05:00
|
|
|
let comments = Comments::parse(Path::new("<dummy>"), s).unwrap();
|
2022-05-30 07:17:36 -05:00
|
|
|
let config = config();
|
|
|
|
let messages= vec![
|
|
|
|
vec![],
|
|
|
|
vec![],
|
|
|
|
vec![],
|
|
|
|
vec![],
|
|
|
|
vec![],
|
|
|
|
vec![
|
|
|
|
Message {
|
|
|
|
message: "Undefined Behavior: type validation failed: encountered a dangling reference (address 0x10 is unallocated)".to_string(),
|
|
|
|
level: Level::Error,
|
|
|
|
},
|
|
|
|
Message {
|
|
|
|
message: "kaboom".to_string(),
|
|
|
|
level: Level::Warn,
|
|
|
|
},
|
|
|
|
Message {
|
|
|
|
message: "cake".to_string(),
|
|
|
|
level: Level::Warn,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
];
|
|
|
|
let mut errors = vec![];
|
|
|
|
check_annotations(messages, vec![], Path::new("moobar"), &mut errors, &config, "", &comments);
|
|
|
|
match &errors[..] {
|
|
|
|
[Error::ErrorsWithoutPattern { path: Some((_, 5)), msgs, .. }] =>
|
|
|
|
match &msgs[..] {
|
2022-07-11 06:44:55 -05:00
|
|
|
[Message { message, level: Level::Warn }] if message == "kaboom" => {}
|
2022-05-30 07:17:36 -05:00
|
|
|
_ => panic!("{:#?}", msgs),
|
|
|
|
},
|
|
|
|
_ => panic!("{:#?}", errors),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-07-11 06:44:55 -05:00
|
|
|
fn missing_implicit_warn_pattern() {
|
2022-05-30 07:17:36 -05:00
|
|
|
let s = r"
|
|
|
|
use std::mem;
|
2022-07-11 06:44:55 -05:00
|
|
|
//@require-annotations-for-level: ERROR
|
2022-05-30 07:17:36 -05:00
|
|
|
fn main() {
|
2022-07-11 06:44:55 -05:00
|
|
|
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR: encountered a dangling reference (address 0x10 is unallocated)
|
|
|
|
//~^ WARN: cake
|
2022-05-30 07:17:36 -05:00
|
|
|
}
|
|
|
|
";
|
2022-07-11 06:44:55 -05:00
|
|
|
let comments = Comments::parse(Path::new("<dummy>"), s).unwrap();
|
2022-05-30 07:17:36 -05:00
|
|
|
let config = config();
|
|
|
|
let messages = vec![
|
|
|
|
vec![],
|
|
|
|
vec![],
|
|
|
|
vec![],
|
|
|
|
vec![],
|
|
|
|
vec![],
|
|
|
|
vec![
|
|
|
|
Message {
|
|
|
|
message: "Undefined Behavior: type validation failed: encountered a dangling reference (address 0x10 is unallocated)".to_string(),
|
|
|
|
level: Level::Error,
|
|
|
|
},
|
|
|
|
Message {
|
|
|
|
message: "kaboom".to_string(),
|
|
|
|
level: Level::Warn,
|
|
|
|
},
|
|
|
|
Message {
|
|
|
|
message: "cake".to_string(),
|
|
|
|
level: Level::Warn,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
];
|
|
|
|
let mut errors = vec![];
|
|
|
|
check_annotations(messages, vec![], Path::new("moobar"), &mut errors, &config, "", &comments);
|
|
|
|
match &errors[..] {
|
2022-07-11 06:44:55 -05:00
|
|
|
[] => {}
|
2022-05-30 07:17:36 -05:00
|
|
|
_ => panic!("{:#?}", errors),
|
|
|
|
}
|
|
|
|
}
|