Move safe intrinsic tests

This commit is contained in:
Francesco Zardi 2020-10-21 21:53:05 +02:00
parent f3aa44b01d
commit 0be21b05d6
2 changed files with 18 additions and 20 deletions

View file

@ -437,23 +437,3 @@ fn assoc_item_macros() {
"#]],
);
}
#[test]
fn safe_intrinsic() {
check(
r"
#![feature(core_intrinsics)]
fn reverse(input: u32) -> u32 {
std::intrinsics::bitreverse(input)
}
",
expect![[r#"
inner attrs: Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("feature"))] }, input: Some(TokenTree(SUBTREE () 0
IDENT core_intrinsics 1)) }]) }
top-level items:
Function { name: Name(Text("reverse")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, has_body: true, is_unsafe: false, params: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("u32"))] }, generic_args: [None] })], is_varargs: false, ret_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("u32"))] }, generic_args: [None] }), ast_id: FileAstId::<syntax::ast::generated::nodes::Fn>(0) }
"#]],
);
}

View file

@ -199,6 +199,24 @@ fn main() {
let x = STATIC_MUT.a;
}
}
"#,
);
}
#[test]
fn no_missing_unsafe_diagnostic_with_safe_intrinsic() {
check_diagnostics(
r#"
extern "rust-intrinsic" {
pub fn bitreverse(x: u32) -> u32; // Safe intrinsic
pub fn floorf32(x: f32) -> f32; // Unsafe intrinsic
}
fn main() {
let _ = bitreverse(12);
let _ = floorf32(12.0);
//^^^^^^^^^^^^^^ This operation is unsafe and requires an unsafe function or block
}
"#,
);
}