Remove unnecessary unsafe block around calls to discriminant_value
Since 63793 the discriminant_value intrinsic is safe to call. Remove unnecessary unsafe block around calls to this intrinsic in built-in derive macros.
This commit is contained in:
parent
c38f001db5
commit
50da126557
2 changed files with 16 additions and 15 deletions
|
@ -1137,12 +1137,9 @@ impl<'a> MethodDef<'a> {
|
||||||
/// for each of the self-args, carried in precomputed variables.
|
/// for each of the self-args, carried in precomputed variables.
|
||||||
|
|
||||||
/// ```{.text}
|
/// ```{.text}
|
||||||
/// let __self0_vi = unsafe {
|
/// let __self0_vi = std::intrinsics::discriminant_value(&self);
|
||||||
/// std::intrinsics::discriminant_value(&self) };
|
/// let __self1_vi = std::intrinsics::discriminant_value(&arg1);
|
||||||
/// let __self1_vi = unsafe {
|
/// let __self2_vi = std::intrinsics::discriminant_value(&arg2);
|
||||||
/// std::intrinsics::discriminant_value(&arg1) };
|
|
||||||
/// let __self2_vi = unsafe {
|
|
||||||
/// std::intrinsics::discriminant_value(&arg2) };
|
|
||||||
///
|
///
|
||||||
/// if __self0_vi == __self1_vi && __self0_vi == __self2_vi && ... {
|
/// if __self0_vi == __self1_vi && __self0_vi == __self2_vi && ... {
|
||||||
/// match (...) {
|
/// match (...) {
|
||||||
|
@ -1325,7 +1322,7 @@ impl<'a> MethodDef<'a> {
|
||||||
// Since we know that all the arguments will match if we reach
|
// Since we know that all the arguments will match if we reach
|
||||||
// the match expression we add the unreachable intrinsics as the
|
// the match expression we add the unreachable intrinsics as the
|
||||||
// result of the catch all which should help llvm in optimizing it
|
// result of the catch all which should help llvm in optimizing it
|
||||||
Some(deriving::call_intrinsic(cx, sp, sym::unreachable, vec![]))
|
Some(deriving::call_unreachable(cx, sp))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
@ -1356,12 +1353,9 @@ impl<'a> MethodDef<'a> {
|
||||||
// with three Self args, builds three statements:
|
// with three Self args, builds three statements:
|
||||||
//
|
//
|
||||||
// ```
|
// ```
|
||||||
// let __self0_vi = unsafe {
|
// let __self0_vi = std::intrinsics::discriminant_value(&self);
|
||||||
// std::intrinsics::discriminant_value(&self) };
|
// let __self1_vi = std::intrinsics::discriminant_value(&arg1);
|
||||||
// let __self1_vi = unsafe {
|
// let __self2_vi = std::intrinsics::discriminant_value(&arg2);
|
||||||
// std::intrinsics::discriminant_value(&arg1) };
|
|
||||||
// let __self2_vi = unsafe {
|
|
||||||
// std::intrinsics::discriminant_value(&arg2) };
|
|
||||||
// ```
|
// ```
|
||||||
let mut index_let_stmts: Vec<ast::Stmt> = Vec::with_capacity(vi_idents.len() + 1);
|
let mut index_let_stmts: Vec<ast::Stmt> = Vec::with_capacity(vi_idents.len() + 1);
|
||||||
|
|
||||||
|
@ -1474,7 +1468,7 @@ impl<'a> MethodDef<'a> {
|
||||||
// derive Debug on such a type could here generate code
|
// derive Debug on such a type could here generate code
|
||||||
// that needs the feature gate enabled.)
|
// that needs the feature gate enabled.)
|
||||||
|
|
||||||
deriving::call_intrinsic(cx, sp, sym::unreachable, vec![])
|
deriving::call_unreachable(cx, sp)
|
||||||
} else {
|
} else {
|
||||||
// Final wrinkle: the self_args are expressions that deref
|
// Final wrinkle: the self_args are expressions that deref
|
||||||
// down to desired places, but we cannot actually deref
|
// down to desired places, but we cannot actually deref
|
||||||
|
|
|
@ -68,7 +68,14 @@ fn call_intrinsic(
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let span = cx.with_def_site_ctxt(span);
|
let span = cx.with_def_site_ctxt(span);
|
||||||
let path = cx.std_path(&[sym::intrinsics, intrinsic]);
|
let path = cx.std_path(&[sym::intrinsics, intrinsic]);
|
||||||
let call = cx.expr_call_global(span, path, args);
|
cx.expr_call_global(span, path, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Constructs an expression that calls the `unreachable` intrinsic.
|
||||||
|
fn call_unreachable(cx: &ExtCtxt<'_>, span: Span) -> P<ast::Expr> {
|
||||||
|
let span = cx.with_def_site_ctxt(span);
|
||||||
|
let path = cx.std_path(&[sym::intrinsics, sym::unreachable]);
|
||||||
|
let call = cx.expr_call_global(span, path, vec![]);
|
||||||
|
|
||||||
cx.expr_block(P(ast::Block {
|
cx.expr_block(P(ast::Block {
|
||||||
stmts: vec![cx.stmt_expr(call)],
|
stmts: vec![cx.stmt_expr(call)],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue