Skip to content

Commit 8b7c17d

Browse files
committed
Auto merge of #25524 - Manishearth:unsafe_derive, r=cmr
2 parents 9f3a7f0 + 5b63841 commit 8b7c17d

14 files changed

+25
-1
lines changed

src/libsyntax/ext/deriving/clone.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
3939
args: Vec::new(),
4040
ret_ty: Self_,
4141
attributes: attrs,
42+
is_unsafe: false,
4243
combine_substructure: combine_substructure(Box::new(|c, s, sub| {
4344
cs_clone("Clone", c, s, sub)
4445
})),

src/libsyntax/ext/deriving/cmp/eq.rs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
5959
args: vec!(),
6060
ret_ty: nil_ty(),
6161
attributes: attrs,
62+
is_unsafe: false,
6263
combine_substructure: combine_substructure(Box::new(|a, b, c| {
6364
cs_total_eq_assert(a, b, c)
6465
}))

src/libsyntax/ext/deriving/cmp/ord.rs

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
4040
args: vec!(borrowed_self()),
4141
ret_ty: Literal(path_std!(cx, core::cmp::Ordering)),
4242
attributes: attrs,
43+
is_unsafe: false,
4344
combine_substructure: combine_substructure(Box::new(|a, b, c| {
4445
cs_cmp(a, b, c)
4546
})),

src/libsyntax/ext/deriving/cmp/partial_eq.rs

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
7171
args: vec!(borrowed_self()),
7272
ret_ty: Literal(path_local!(bool)),
7373
attributes: attrs,
74+
is_unsafe: false,
7475
combine_substructure: combine_substructure(Box::new(|a, b, c| {
7576
$f(a, b, c)
7677
}))

src/libsyntax/ext/deriving/cmp/partial_ord.rs

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
3737
args: vec!(borrowed_self()),
3838
ret_ty: Literal(path_local!(bool)),
3939
attributes: attrs,
40+
is_unsafe: false,
4041
combine_substructure: combine_substructure(Box::new(|cx, span, substr| {
4142
cs_op($op, $equal, cx, span, substr)
4243
}))
@@ -60,6 +61,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
6061
args: vec![borrowed_self()],
6162
ret_ty: ret_ty,
6263
attributes: attrs,
64+
is_unsafe: false,
6365
combine_substructure: combine_substructure(Box::new(|cx, span, substr| {
6466
cs_partial_cmp(cx, span, substr)
6567
}))

src/libsyntax/ext/deriving/decodable.rs

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
7979
true
8080
)),
8181
attributes: Vec::new(),
82+
is_unsafe: false,
8283
combine_substructure: combine_substructure(Box::new(|a, b, c| {
8384
decodable_substructure(a, b, c, krate)
8485
})),

src/libsyntax/ext/deriving/default.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
3939
args: Vec::new(),
4040
ret_ty: Self_,
4141
attributes: attrs,
42+
is_unsafe: false,
4243
combine_substructure: combine_substructure(Box::new(|a, b, c| {
4344
default_substructure(a, b, c)
4445
}))

src/libsyntax/ext/deriving/encodable.rs

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
155155
true
156156
)),
157157
attributes: Vec::new(),
158+
is_unsafe: false,
158159
combine_substructure: combine_substructure(Box::new(|a, b, c| {
159160
encodable_substructure(a, b, c)
160161
})),

src/libsyntax/ext/deriving/generic/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ pub struct MethodDef<'a> {
253253

254254
pub attributes: Vec<ast::Attribute>,
255255

256+
// Is it an `unsafe fn`?
257+
pub is_unsafe: bool,
258+
256259
pub combine_substructure: RefCell<CombineSubstructureFunc<'a>>,
257260
}
258261

@@ -859,6 +862,12 @@ impl<'a> MethodDef<'a> {
859862
let fn_decl = cx.fn_decl(args, ret_type);
860863
let body_block = cx.block_expr(body);
861864

865+
let unsafety = if self.is_unsafe {
866+
ast::Unsafety::Unsafe
867+
} else {
868+
ast::Unsafety::Normal
869+
};
870+
862871
// Create the method.
863872
P(ast::ImplItem {
864873
id: ast::DUMMY_NODE_ID,
@@ -870,7 +879,7 @@ impl<'a> MethodDef<'a> {
870879
generics: fn_generics,
871880
abi: abi,
872881
explicit_self: explicit_self,
873-
unsafety: ast::Unsafety::Normal,
882+
unsafety: unsafety,
874883
decl: fn_decl
875884
}, body_block)
876885
})

src/libsyntax/ext/deriving/hash.rs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
4444
args: vec!(Ptr(Box::new(Literal(arg)), Borrowed(None, MutMutable))),
4545
ret_ty: nil_ty(),
4646
attributes: vec![],
47+
is_unsafe: false,
4748
combine_substructure: combine_substructure(Box::new(|a, b, c| {
4849
hash_substructure(a, b, c)
4950
}))

src/libsyntax/ext/deriving/primitive.rs

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
4444
true)),
4545
// #[inline] liable to cause code-bloat
4646
attributes: attrs.clone(),
47+
is_unsafe: false,
4748
combine_substructure: combine_substructure(Box::new(|c, s, sub| {
4849
cs_from("i64", c, s, sub)
4950
})),
@@ -59,6 +60,7 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
5960
true)),
6061
// #[inline] liable to cause code-bloat
6162
attributes: attrs,
63+
is_unsafe: false,
6264
combine_substructure: combine_substructure(Box::new(|c, s, sub| {
6365
cs_from("u64", c, s, sub)
6466
})),

src/libsyntax/ext/deriving/show.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt,
4242
args: vec!(fmtr),
4343
ret_ty: Literal(path_std!(cx, core::fmt::Result)),
4444
attributes: Vec::new(),
45+
is_unsafe: false,
4546
combine_substructure: combine_substructure(Box::new(|a, b, c| {
4647
show_substructure(a, b, c)
4748
}))

src/test/auxiliary/custom_derive_plugin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ fn expand(cx: &mut ExtCtxt,
5454
args: vec![],
5555
ret_ty: Literal(Path::new_local("isize")),
5656
attributes: vec![],
57+
is_unsafe: false,
5758
combine_substructure: combine_substructure(box |cx, span, substr| {
5859
let zero = cx.expr_isize(span, 0);
5960
cs_fold(false,

src/test/auxiliary/custom_derive_plugin_attr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ fn expand(cx: &mut ExtCtxt,
5656
args: vec![],
5757
ret_ty: Literal(Path::new_local("isize")),
5858
attributes: vec![],
59+
is_unsafe: false,
5960
combine_substructure: combine_substructure(Box::new(totalsum_substructure)),
6061
},
6162
],

0 commit comments

Comments
 (0)