mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-18 09:53:26 +00:00
Allow #[derive()] to generate unsafe trait impls
This commit is contained in:
parent
3f002a4c6e
commit
38d450fad2
@ -40,6 +40,7 @@ pub fn expand_deriving_copy(cx: &mut ExtCtxt,
|
||||
path: path,
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
is_unsafe: false,
|
||||
methods: Vec::new(),
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
|
@ -31,6 +31,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
|
||||
path: path_std!(cx, core::clone::Clone),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
is_unsafe: false,
|
||||
methods: vec!(
|
||||
MethodDef {
|
||||
name: "clone",
|
||||
|
@ -51,6 +51,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
|
||||
path: path_std!(cx, core::cmp::Eq),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
is_unsafe: false,
|
||||
methods: vec!(
|
||||
MethodDef {
|
||||
name: "assert_receiver_is_total_eq",
|
||||
|
@ -32,6 +32,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
|
||||
path: path_std!(cx, core::cmp::Ord),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
is_unsafe: false,
|
||||
methods: vec!(
|
||||
MethodDef {
|
||||
name: "cmp",
|
||||
|
@ -85,6 +85,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
|
||||
path: path_std!(cx, core::cmp::PartialEq),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
is_unsafe: false,
|
||||
methods: vec!(
|
||||
md!("eq", cs_eq),
|
||||
md!("ne", cs_ne)
|
||||
|
@ -73,6 +73,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
|
||||
path: path_std!(cx, core::cmp::PartialOrd),
|
||||
additional_bounds: vec![],
|
||||
generics: LifetimeBounds::empty(),
|
||||
is_unsafe: false,
|
||||
methods: vec![
|
||||
partial_cmp_def,
|
||||
md!("lt", true, false),
|
||||
|
@ -59,6 +59,7 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
|
||||
path: Path::new_(vec!(krate, "Decodable"), None, vec!(), true),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
is_unsafe: false,
|
||||
methods: vec!(
|
||||
MethodDef {
|
||||
name: "decode",
|
||||
|
@ -31,6 +31,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
|
||||
path: path_std!(cx, core::default::Default),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
is_unsafe: false,
|
||||
methods: vec!(
|
||||
MethodDef {
|
||||
name: "default",
|
||||
|
@ -135,6 +135,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
|
||||
path: Path::new_(vec!(krate, "Encodable"), None, vec!(), true),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
is_unsafe: false,
|
||||
methods: vec!(
|
||||
MethodDef {
|
||||
name: "encode",
|
||||
|
@ -229,6 +229,9 @@ pub struct TraitDef<'a> {
|
||||
/// Any extra lifetimes and/or bounds, e.g. `D: serialize::Decoder`
|
||||
pub generics: LifetimeBounds<'a>,
|
||||
|
||||
/// Is it an `unsafe` trait?
|
||||
pub is_unsafe: bool,
|
||||
|
||||
pub methods: Vec<MethodDef<'a>>,
|
||||
|
||||
pub associated_types: Vec<(ast::Ident, Ty<'a>)>,
|
||||
@ -625,11 +628,18 @@ impl<'a> TraitDef<'a> {
|
||||
InternedString::new("unused_qualifications"))]));
|
||||
let mut a = vec![attr, unused_qual];
|
||||
a.extend(self.attributes.iter().cloned());
|
||||
|
||||
let unsafety = if self.is_unsafe {
|
||||
ast::Unsafety::Unsafe
|
||||
} else {
|
||||
ast::Unsafety::Normal
|
||||
};
|
||||
|
||||
cx.item(
|
||||
self.span,
|
||||
ident,
|
||||
a,
|
||||
ast::ItemImpl(ast::Unsafety::Normal,
|
||||
ast::ItemImpl(unsafety,
|
||||
ast::ImplPolarity::Positive,
|
||||
trait_generics,
|
||||
opt_trait_ref,
|
||||
|
@ -32,6 +32,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
|
||||
path: path,
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
is_unsafe: false,
|
||||
methods: vec!(
|
||||
MethodDef {
|
||||
name: "hash",
|
||||
|
@ -32,6 +32,7 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
|
||||
path: path_std!(cx, core::num::FromPrimitive),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
is_unsafe: false,
|
||||
methods: vec!(
|
||||
MethodDef {
|
||||
name: "from_i64",
|
||||
|
@ -34,6 +34,7 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt,
|
||||
path: path_std!(cx, core::fmt::Debug),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
is_unsafe: false,
|
||||
methods: vec![
|
||||
MethodDef {
|
||||
name: "fmt",
|
||||
|
@ -46,6 +46,7 @@ fn expand(cx: &mut ExtCtxt,
|
||||
additional_bounds: vec![],
|
||||
generics: LifetimeBounds::empty(),
|
||||
associated_types: vec![],
|
||||
is_unsafe: false,
|
||||
methods: vec![
|
||||
MethodDef {
|
||||
name: "total_sum",
|
||||
|
@ -48,6 +48,7 @@ fn expand(cx: &mut ExtCtxt,
|
||||
additional_bounds: vec![],
|
||||
generics: LifetimeBounds::empty(),
|
||||
associated_types: vec![],
|
||||
is_unsafe: false,
|
||||
methods: vec![
|
||||
MethodDef {
|
||||
name: "total_sum",
|
||||
|
Loading…
Reference in New Issue
Block a user