Skip to content

Commit 2cf1e4b

Browse files
committed
Honor hidden doc attribute of derivable trait methods
Closes rust-lang#13698
1 parent e049a70 commit 2cf1e4b

File tree

14 files changed

+52
-37
lines changed

14 files changed

+52
-37
lines changed

src/libsyntax/ext/deriving/clone.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ use codemap::Span;
1313
use ext::base::ExtCtxt;
1414
use ext::build::AstBuilder;
1515
use ext::deriving::generic::*;
16+
use parse::token::InternedString;
1617

1718
pub fn expand_deriving_clone(cx: &mut ExtCtxt,
1819
span: Span,
1920
mitem: @MetaItem,
2021
item: @Item,
2122
push: |@Item|) {
23+
let inline = cx.meta_word(span, InternedString::new("inline"));
24+
let attrs = vec!(cx.attribute(span, inline));
2225
let trait_def = TraitDef {
2326
span: span,
2427
attributes: Vec::new(),
@@ -32,7 +35,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
3235
explicit_self: borrowed_explicit_self(),
3336
args: Vec::new(),
3437
ret_ty: Self,
35-
inline: true,
38+
attributes: attrs,
3639
const_nonmatching: false,
3740
combine_substructure: |c, s, sub| cs_clone("Clone", c, s, sub)
3841
}

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use codemap::Span;
1313
use ext::base::ExtCtxt;
1414
use ext::build::AstBuilder;
1515
use ext::deriving::generic::*;
16+
use parse::token::InternedString;
1617

1718
pub fn expand_deriving_eq(cx: &mut ExtCtxt,
1819
span: Span,
@@ -31,18 +32,20 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
3132
}
3233

3334
macro_rules! md (
34-
($name:expr, $f:ident) => {
35+
($name:expr, $f:ident) => { {
36+
let inline = cx.meta_word(span, InternedString::new("inline"));
37+
let attrs = vec!(cx.attribute(span, inline));
3538
MethodDef {
3639
name: $name,
3740
generics: LifetimeBounds::empty(),
3841
explicit_self: borrowed_explicit_self(),
3942
args: vec!(borrowed_self()),
4043
ret_ty: Literal(Path::new(vec!("bool"))),
41-
inline: true,
44+
attributes: attrs,
4245
const_nonmatching: true,
4346
combine_substructure: $f
4447
}
45-
}
48+
} }
4649
);
4750

4851
let trait_def = TraitDef {

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,28 @@ use codemap::Span;
1414
use ext::base::ExtCtxt;
1515
use ext::build::AstBuilder;
1616
use ext::deriving::generic::*;
17+
use parse::token::InternedString;
1718

1819
pub fn expand_deriving_ord(cx: &mut ExtCtxt,
1920
span: Span,
2021
mitem: @MetaItem,
2122
item: @Item,
2223
push: |@Item|) {
2324
macro_rules! md (
24-
($name:expr, $op:expr, $equal:expr) => {
25+
($name:expr, $op:expr, $equal:expr) => { {
26+
let inline = cx.meta_word(span, InternedString::new("inline"));
27+
let attrs = vec!(cx.attribute(span, inline));
2528
MethodDef {
2629
name: $name,
2730
generics: LifetimeBounds::empty(),
2831
explicit_self: borrowed_explicit_self(),
2932
args: vec!(borrowed_self()),
3033
ret_ty: Literal(Path::new(vec!("bool"))),
31-
inline: true,
34+
attributes: attrs,
3235
const_nonmatching: false,
3336
combine_substructure: |cx, span, substr| cs_op($op, $equal, cx, span, substr)
3437
}
35-
}
38+
} }
3639
);
3740

3841
let trait_def = TraitDef {

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use codemap::Span;
1313
use ext::base::ExtCtxt;
1414
use ext::build::AstBuilder;
1515
use ext::deriving::generic::*;
16+
use parse::token::InternedString;
1617

1718
pub fn expand_deriving_totaleq(cx: &mut ExtCtxt,
1819
span: Span,
@@ -33,6 +34,11 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt,
3334
substr)
3435
}
3536

37+
let inline = cx.meta_word(span, InternedString::new("inline"));
38+
let hidden = cx.meta_word(span, InternedString::new("hidden"));
39+
let doc = cx.meta_list(span, InternedString::new("doc"), vec!(hidden));
40+
let attrs = vec!(cx.attribute(span, inline),
41+
cx.attribute(span, doc));
3642
let trait_def = TraitDef {
3743
span: span,
3844
attributes: Vec::new(),
@@ -46,7 +52,7 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt,
4652
explicit_self: borrowed_explicit_self(),
4753
args: vec!(),
4854
ret_ty: nil_ty(),
49-
inline: true,
55+
attributes: attrs,
5056
const_nonmatching: true,
5157
combine_substructure: cs_total_eq_assert
5258
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use codemap::Span;
1414
use ext::base::ExtCtxt;
1515
use ext::build::AstBuilder;
1616
use ext::deriving::generic::*;
17+
use parse::token::InternedString;
1718

1819
use std::cmp::{Ordering, Equal, Less, Greater};
1920

@@ -22,6 +23,8 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt,
2223
mitem: @MetaItem,
2324
item: @Item,
2425
push: |@Item|) {
26+
let inline = cx.meta_word(span, InternedString::new("inline"));
27+
let attrs = vec!(cx.attribute(span, inline));
2528
let trait_def = TraitDef {
2629
span: span,
2730
attributes: Vec::new(),
@@ -35,7 +38,7 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt,
3538
explicit_self: borrowed_explicit_self(),
3639
args: vec!(borrowed_self()),
3740
ret_ty: Literal(Path::new(vec!("std", "cmp", "Ordering"))),
38-
inline: true,
41+
attributes: attrs,
3942
const_nonmatching: false,
4043
combine_substructure: cs_cmp
4144
}

src/libsyntax/ext/deriving/decodable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt,
5050
Borrowed(None, MutMutable))),
5151
ret_ty: Literal(Path::new_(vec!("std", "result", "Result"), None,
5252
vec!(~Self, ~Literal(Path::new_local("__E"))), true)),
53-
inline: false,
53+
attributes: Vec::new(),
5454
const_nonmatching: true,
5555
combine_substructure: decodable_substructure,
5656
})

src/libsyntax/ext/deriving/default.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ use codemap::Span;
1313
use ext::base::ExtCtxt;
1414
use ext::build::AstBuilder;
1515
use ext::deriving::generic::*;
16+
use parse::token::InternedString;
1617

1718
pub fn expand_deriving_default(cx: &mut ExtCtxt,
1819
span: Span,
1920
mitem: @MetaItem,
2021
item: @Item,
2122
push: |@Item|) {
23+
let inline = cx.meta_word(span, InternedString::new("inline"));
24+
let attrs = vec!(cx.attribute(span, inline));
2225
let trait_def = TraitDef {
2326
span: span,
2427
attributes: Vec::new(),
@@ -32,7 +35,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
3235
explicit_self: None,
3336
args: Vec::new(),
3437
ret_ty: Self,
35-
inline: true,
38+
attributes: attrs,
3639
const_nonmatching: false,
3740
combine_substructure: default_substructure
3841
})

src/libsyntax/ext/deriving/encodable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub fn expand_deriving_encodable(cx: &mut ExtCtxt,
121121
vec!(~Tuple(Vec::new()),
122122
~Literal(Path::new_local("__E"))),
123123
true)),
124-
inline: false,
124+
attributes: Vec::new(),
125125
const_nonmatching: true,
126126
combine_substructure: encodable_substructure,
127127
})

src/libsyntax/ext/deriving/generic.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ pub struct MethodDef<'a> {
227227
/// Return type
228228
pub ret_ty: Ty<'a>,
229229

230-
/// Whether to mark this as #[inline]
231-
pub inline: bool,
230+
pub attributes: Vec<ast::Attribute>,
232231

233232
/// if the value of the nonmatching enums is independent of the
234233
/// actual enum variants, i.e. can use _ => .. match.
@@ -604,23 +603,10 @@ impl<'a> MethodDef<'a> {
604603
let fn_decl = cx.fn_decl(args, ret_type);
605604
let body_block = cx.block_expr(body);
606605

607-
let attrs = if self.inline {
608-
vec!(
609-
cx
610-
.attribute(trait_.span,
611-
cx
612-
.meta_word(trait_.span,
613-
InternedString::new(
614-
"inline")))
615-
)
616-
} else {
617-
Vec::new()
618-
};
619-
620606
// Create the method.
621607
@ast::Method {
622608
ident: method_ident,
623-
attrs: attrs,
609+
attrs: self.attributes.clone(),
624610
generics: fn_generics,
625611
explicit_self: explicit_self,
626612
fn_style: ast::NormalFn,

src/libsyntax/ext/deriving/hash.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use codemap::Span;
1414
use ext::base::ExtCtxt;
1515
use ext::build::AstBuilder;
1616
use ext::deriving::generic::*;
17+
use parse::token::InternedString;
1718

1819
pub fn expand_deriving_hash(cx: &mut ExtCtxt,
1920
span: Span,
@@ -34,6 +35,8 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
3435
LifetimeBounds::empty(),
3536
Path::new(vec!("std", "hash", "sip", "SipState")))
3637
};
38+
let inline = cx.meta_word(span, InternedString::new("inline"));
39+
let attrs = vec!(cx.attribute(span, inline));
3740
let hash_trait_def = TraitDef {
3841
span: span,
3942
attributes: Vec::new(),
@@ -47,7 +50,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
4750
explicit_self: borrowed_explicit_self(),
4851
args: vec!(Ptr(~Literal(args), Borrowed(None, MutMutable))),
4952
ret_ty: nil_ty(),
50-
inline: true,
53+
attributes: attrs,
5154
const_nonmatching: false,
5255
combine_substructure: hash_substructure
5356
}

src/libsyntax/ext/deriving/primitive.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
2121
mitem: @MetaItem,
2222
item: @Item,
2323
push: |@Item|) {
24+
let inline = cx.meta_word(span, InternedString::new("inline"));
25+
let attrs = vec!(cx.attribute(span, inline));
2426
let trait_def = TraitDef {
2527
span: span,
2628
attributes: Vec::new(),
@@ -38,8 +40,8 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
3840
None,
3941
vec!(~Self),
4042
true)),
41-
// liable to cause code-bloat
42-
inline: true,
43+
// #[inline] liable to cause code-bloat
44+
attributes: attrs.clone(),
4345
const_nonmatching: false,
4446
combine_substructure: |c, s, sub| cs_from("i64", c, s, sub),
4547
},
@@ -53,8 +55,8 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
5355
None,
5456
vec!(~Self),
5557
true)),
56-
// liable to cause code-bloat
57-
inline: true,
58+
// #[inline] liable to cause code-bloat
59+
attributes: attrs,
5860
const_nonmatching: false,
5961
combine_substructure: |c, s, sub| cs_from("u64", c, s, sub),
6062
})

src/libsyntax/ext/deriving/rand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt,
4141
Borrowed(None, ast::MutMutable))
4242
),
4343
ret_ty: Self,
44-
inline: false,
44+
attributes: Vec::new(),
4545
const_nonmatching: false,
4646
combine_substructure: rand_substructure
4747
}

src/libsyntax/ext/deriving/show.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt,
4242
explicit_self: borrowed_explicit_self(),
4343
args: vec!(fmtr),
4444
ret_ty: Literal(Path::new(vec!("std", "fmt", "Result"))),
45-
inline: false,
45+
attributes: Vec::new(),
4646
const_nonmatching: false,
4747
combine_substructure: show_substructure
4848
}

src/libsyntax/ext/deriving/zero.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ use codemap::Span;
1313
use ext::base::ExtCtxt;
1414
use ext::build::AstBuilder;
1515
use ext::deriving::generic::*;
16+
use parse::token::InternedString;
1617

1718
pub fn expand_deriving_zero(cx: &mut ExtCtxt,
1819
span: Span,
1920
mitem: @MetaItem,
2021
item: @Item,
2122
push: |@Item|) {
23+
let inline = cx.meta_word(span, InternedString::new("inline"));
24+
let attrs = vec!(cx.attribute(span, inline));
2225
let trait_def = TraitDef {
2326
span: span,
2427
attributes: Vec::new(),
@@ -32,7 +35,7 @@ pub fn expand_deriving_zero(cx: &mut ExtCtxt,
3235
explicit_self: None,
3336
args: Vec::new(),
3437
ret_ty: Self,
35-
inline: true,
38+
attributes: attrs.clone(),
3639
const_nonmatching: false,
3740
combine_substructure: zero_substructure
3841
},
@@ -42,7 +45,7 @@ pub fn expand_deriving_zero(cx: &mut ExtCtxt,
4245
explicit_self: borrowed_explicit_self(),
4346
args: Vec::new(),
4447
ret_ty: Literal(Path::new(vec!("bool"))),
45-
inline: true,
48+
attributes: attrs,
4649
const_nonmatching: false,
4750
combine_substructure: |cx, span, substr| {
4851
cs_and(|cx, span, _, _| cx.span_bug(span,

0 commit comments

Comments
 (0)