Skip to content

Commit 09dd65c

Browse files
committed
Auto merge of #28090 - mystor:derive-unsafe-trait, r=Manishearth
2 parents 3f002a4 + 38d450f commit 09dd65c

File tree

15 files changed

+25
-1
lines changed

15 files changed

+25
-1
lines changed

src/libsyntax/ext/deriving/bounds.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub fn expand_deriving_copy(cx: &mut ExtCtxt,
4040
path: path,
4141
additional_bounds: Vec::new(),
4242
generics: LifetimeBounds::empty(),
43+
is_unsafe: false,
4344
methods: Vec::new(),
4445
associated_types: Vec::new(),
4546
};

src/libsyntax/ext/deriving/clone.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
3131
path: path_std!(cx, core::clone::Clone),
3232
additional_bounds: Vec::new(),
3333
generics: LifetimeBounds::empty(),
34+
is_unsafe: false,
3435
methods: vec!(
3536
MethodDef {
3637
name: "clone",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
5151
path: path_std!(cx, core::cmp::Eq),
5252
additional_bounds: Vec::new(),
5353
generics: LifetimeBounds::empty(),
54+
is_unsafe: false,
5455
methods: vec!(
5556
MethodDef {
5657
name: "assert_receiver_is_total_eq",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
3232
path: path_std!(cx, core::cmp::Ord),
3333
additional_bounds: Vec::new(),
3434
generics: LifetimeBounds::empty(),
35+
is_unsafe: false,
3536
methods: vec!(
3637
MethodDef {
3738
name: "cmp",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
8585
path: path_std!(cx, core::cmp::PartialEq),
8686
additional_bounds: Vec::new(),
8787
generics: LifetimeBounds::empty(),
88+
is_unsafe: false,
8889
methods: vec!(
8990
md!("eq", cs_eq),
9091
md!("ne", cs_ne)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
7373
path: path_std!(cx, core::cmp::PartialOrd),
7474
additional_bounds: vec![],
7575
generics: LifetimeBounds::empty(),
76+
is_unsafe: false,
7677
methods: vec![
7778
partial_cmp_def,
7879
md!("lt", true, false),

src/libsyntax/ext/deriving/decodable.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
5959
path: Path::new_(vec!(krate, "Decodable"), None, vec!(), true),
6060
additional_bounds: Vec::new(),
6161
generics: LifetimeBounds::empty(),
62+
is_unsafe: false,
6263
methods: vec!(
6364
MethodDef {
6465
name: "decode",

src/libsyntax/ext/deriving/default.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
3131
path: path_std!(cx, core::default::Default),
3232
additional_bounds: Vec::new(),
3333
generics: LifetimeBounds::empty(),
34+
is_unsafe: false,
3435
methods: vec!(
3536
MethodDef {
3637
name: "default",

src/libsyntax/ext/deriving/encodable.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
135135
path: Path::new_(vec!(krate, "Encodable"), None, vec!(), true),
136136
additional_bounds: Vec::new(),
137137
generics: LifetimeBounds::empty(),
138+
is_unsafe: false,
138139
methods: vec!(
139140
MethodDef {
140141
name: "encode",

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ pub struct TraitDef<'a> {
229229
/// Any extra lifetimes and/or bounds, e.g. `D: serialize::Decoder`
230230
pub generics: LifetimeBounds<'a>,
231231

232+
/// Is it an `unsafe` trait?
233+
pub is_unsafe: bool,
234+
232235
pub methods: Vec<MethodDef<'a>>,
233236

234237
pub associated_types: Vec<(ast::Ident, Ty<'a>)>,
@@ -625,11 +628,18 @@ impl<'a> TraitDef<'a> {
625628
InternedString::new("unused_qualifications"))]));
626629
let mut a = vec![attr, unused_qual];
627630
a.extend(self.attributes.iter().cloned());
631+
632+
let unsafety = if self.is_unsafe {
633+
ast::Unsafety::Unsafe
634+
} else {
635+
ast::Unsafety::Normal
636+
};
637+
628638
cx.item(
629639
self.span,
630640
ident,
631641
a,
632-
ast::ItemImpl(ast::Unsafety::Normal,
642+
ast::ItemImpl(unsafety,
633643
ast::ImplPolarity::Positive,
634644
trait_generics,
635645
opt_trait_ref,

src/libsyntax/ext/deriving/hash.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
3232
path: path,
3333
additional_bounds: Vec::new(),
3434
generics: LifetimeBounds::empty(),
35+
is_unsafe: false,
3536
methods: vec!(
3637
MethodDef {
3738
name: "hash",

src/libsyntax/ext/deriving/primitive.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
3232
path: path_std!(cx, core::num::FromPrimitive),
3333
additional_bounds: Vec::new(),
3434
generics: LifetimeBounds::empty(),
35+
is_unsafe: false,
3536
methods: vec!(
3637
MethodDef {
3738
name: "from_i64",

src/libsyntax/ext/deriving/show.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt,
3434
path: path_std!(cx, core::fmt::Debug),
3535
additional_bounds: Vec::new(),
3636
generics: LifetimeBounds::empty(),
37+
is_unsafe: false,
3738
methods: vec![
3839
MethodDef {
3940
name: "fmt",

src/test/auxiliary/custom_derive_plugin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fn expand(cx: &mut ExtCtxt,
4646
additional_bounds: vec![],
4747
generics: LifetimeBounds::empty(),
4848
associated_types: vec![],
49+
is_unsafe: false,
4950
methods: vec![
5051
MethodDef {
5152
name: "total_sum",

src/test/auxiliary/custom_derive_plugin_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ fn expand(cx: &mut ExtCtxt,
4848
additional_bounds: vec![],
4949
generics: LifetimeBounds::empty(),
5050
associated_types: vec![],
51+
is_unsafe: false,
5152
methods: vec![
5253
MethodDef {
5354
name: "total_sum",

0 commit comments

Comments
 (0)