rustc_builtin_macros/deriving/
bounds.rs
1use rustc_ast::MetaItem;
2use rustc_expand::base::{Annotatable, ExtCtxt};
3use rustc_span::Span;
4
5use crate::deriving::generic::*;
6use crate::deriving::path_std;
7
8pub(crate) fn expand_deriving_copy(
9 cx: &ExtCtxt<'_>,
10 span: Span,
11 mitem: &MetaItem,
12 item: &Annotatable,
13 push: &mut dyn FnMut(Annotatable),
14 is_const: bool,
15) {
16 let trait_def = TraitDef {
17 span,
18 path: path_std!(marker::Copy),
19 skip_path_as_bound: false,
20 needs_copy_as_bound_if_packed: false,
21 additional_bounds: Vec::new(),
22 supports_unions: true,
23 methods: Vec::new(),
24 associated_types: Vec::new(),
25 is_const,
26 };
27
28 trait_def.expand(cx, mitem, item, push);
29}
30
31pub(crate) fn expand_deriving_const_param_ty(
32 cx: &ExtCtxt<'_>,
33 span: Span,
34 mitem: &MetaItem,
35 item: &Annotatable,
36 push: &mut dyn FnMut(Annotatable),
37 is_const: bool,
38) {
39 let trait_def = TraitDef {
40 span,
41 path: path_std!(marker::ConstParamTy_),
42 skip_path_as_bound: false,
43 needs_copy_as_bound_if_packed: false,
44 additional_bounds: vec![ty::Ty::Path(path_std!(cmp::Eq))],
45 supports_unions: false,
46 methods: Vec::new(),
47 associated_types: Vec::new(),
48 is_const,
49 };
50
51 trait_def.expand(cx, mitem, item, push);
52
53 let trait_def = TraitDef {
54 span,
55 path: path_std!(marker::UnsizedConstParamTy),
56 skip_path_as_bound: false,
57 needs_copy_as_bound_if_packed: false,
58 additional_bounds: vec![ty::Ty::Path(path_std!(cmp::Eq))],
59 supports_unions: false,
60 methods: Vec::new(),
61 associated_types: Vec::new(),
62 is_const,
63 };
64
65 trait_def.expand(cx, mitem, item, push);
66}
67
68pub(crate) fn expand_deriving_unsized_const_param_ty(
69 cx: &ExtCtxt<'_>,
70 span: Span,
71 mitem: &MetaItem,
72 item: &Annotatable,
73 push: &mut dyn FnMut(Annotatable),
74 is_const: bool,
75) {
76 let trait_def = TraitDef {
77 span,
78 path: path_std!(marker::UnsizedConstParamTy),
79 skip_path_as_bound: false,
80 needs_copy_as_bound_if_packed: false,
81 additional_bounds: vec![ty::Ty::Path(path_std!(cmp::Eq))],
82 supports_unions: false,
83 methods: Vec::new(),
84 associated_types: Vec::new(),
85 is_const,
86 };
87
88 trait_def.expand(cx, mitem, item, push);
89}