Use #[rustc_paren_sugar] as a more extensible way of deciding when

paren sugar is legal.
This commit is contained in:
Niko Matsakis 2015-01-26 14:39:58 -05:00
parent 80c793c1d3
commit a962bdb3da
9 changed files with 41 additions and 7 deletions

View file

@ -670,6 +670,7 @@ impl LintPass for UnusedAttributes {
// FIXME: #19470 this shouldn't be needed forever
"old_orphan_check",
"old_impl_check",
"rustc_paren_sugar", // FIXME: #18101 temporary unboxed closure hack
];
static CRATE_ATTRS: &'static [&'static str] = &[

View file

@ -265,3 +265,5 @@ pub const tag_polarity: uint = 0xb4;
pub const tag_macro_defs: uint = 0xb5;
pub const tag_macro_def: uint = 0xb6;
pub const tag_macro_def_body: uint = 0xb7;
pub const tag_paren_sugar: uint = 0xb8;

View file

@ -371,6 +371,11 @@ fn parse_unsafety(item_doc: rbml::Doc) -> ast::Unsafety {
}
}
fn parse_paren_sugar(item_doc: rbml::Doc) -> bool {
let paren_sugar_doc = reader::get_doc(item_doc, tag_paren_sugar);
reader::doc_as_u8(paren_sugar_doc) != 0
}
fn parse_polarity(item_doc: rbml::Doc) -> ast::ImplPolarity {
let polarity_doc = reader::get_doc(item_doc, tag_polarity);
if reader::doc_as_u8(polarity_doc) != 0 {
@ -400,8 +405,10 @@ pub fn get_trait_def<'tcx>(cdata: Cmd,
let bounds = trait_def_bounds(item_doc, tcx, cdata);
let unsafety = parse_unsafety(item_doc);
let associated_type_names = parse_associated_type_names(item_doc);
let paren_sugar = parse_paren_sugar(item_doc);
ty::TraitDef {
paren_sugar: paren_sugar,
unsafety: unsafety,
generics: generics,
bounds: bounds,

View file

@ -1317,6 +1317,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_item_variances(rbml_w, ecx, item.id);
let trait_def = ty::lookup_trait_def(tcx, def_id);
encode_unsafety(rbml_w, trait_def.unsafety);
encode_paren_sugar(rbml_w, trait_def.paren_sugar);
encode_associated_type_names(rbml_w, trait_def.associated_type_names.as_slice());
encode_generics(rbml_w, ecx, &trait_def.generics, tag_item_generics);
encode_trait_ref(rbml_w, ecx, &*trait_def.trait_ref, tag_item_trait_ref);
@ -1697,6 +1698,11 @@ fn encode_unsafety(rbml_w: &mut Encoder, unsafety: ast::Unsafety) {
rbml_w.wr_tagged_u8(tag_unsafety, byte);
}
fn encode_paren_sugar(rbml_w: &mut Encoder, paren_sugar: bool) {
let byte: u8 = if paren_sugar {1} else {0};
rbml_w.wr_tagged_u8(tag_paren_sugar, byte);
}
fn encode_associated_type_names(rbml_w: &mut Encoder, names: &[ast::Name]) {
rbml_w.start_tag(tag_associated_type_names);
for &name in names.iter() {

View file

@ -2221,6 +2221,12 @@ pub struct TypeScheme<'tcx> {
pub struct TraitDef<'tcx> {
pub unsafety: ast::Unsafety,
/// If `true`, then this trait had the `#[rustc_paren_sugar]`
/// attribute, indicating that it should be used with `Foo()`
/// sugar. This is a temporary thing -- eventually any trait wil
/// be usable with the sugar (or without it).
pub paren_sugar: bool,
/// Generic type definitions. Note that `Self` is listed in here
/// as having a single bound, the trait itself (e.g., in the trait
/// `Eq`, there is a single bound `Self : Eq`). This is so that