Skip to content

Commit

Permalink
Make default associated types not parse
Browse files Browse the repository at this point in the history
They don't do anything ATM.

This is a
[breaking-change]
  • Loading branch information
arielb1 committed May 23, 2015
1 parent 3923108 commit 9d2b640
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ div_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
pub trait Rem<RHS=Self> {
/// The resulting type after applying the `%` operator
#[stable(feature = "rust1", since = "1.0.0")]
type Output = Self;
type Output;

/// The method for the `%` operator
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ fn convert_trait_predicates<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item)
{
trait_items.iter().flat_map(|trait_item| {
let bounds = match trait_item.node {
ast::TypeTraitItem(ref bounds, _) => bounds,
ast::TypeTraitItem(ref bounds) => bounds,
_ => {
return vec!().into_iter();
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,8 +1247,8 @@ impl Clean<Item> for ast::TraitItem {
ast::MethodTraitItem(ref sig, None) => {
TyMethodItem(sig.clean(cx))
}
ast::TypeTraitItem(ref bounds, ref default) => {
AssociatedTypeItem(bounds.clean(cx), default.clean(cx))
ast::TypeTraitItem(ref bounds) => {
AssociatedTypeItem(bounds.clean(cx), None)
}
};
Item {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ pub struct TraitItem {
pub enum TraitItem_ {
ConstTraitItem(P<Ty>, Option<P<Expr>>),
MethodTraitItem(MethodSig, Option<P<Block>>),
TypeTraitItem(TyParamBounds, Option<P<Ty>>),
TypeTraitItem(TyParamBounds),
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,9 +991,8 @@ pub fn noop_fold_trait_item<T: Folder>(i: P<TraitItem>, folder: &mut T)
MethodTraitItem(noop_fold_method_sig(sig, folder),
body.map(|x| folder.fold_block(x)))
}
TypeTraitItem(bounds, default) => {
TypeTraitItem(folder.fold_bounds(bounds),
default.map(|x| folder.fold_ty(x)))
TypeTraitItem(bounds) => {
TypeTraitItem(folder.fold_bounds(bounds))
}
},
span: folder.new_span(span)
Expand Down
6 changes: 5 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,8 +1158,12 @@ impl<'a> Parser<'a> {

let (name, node) = if try!(p.eat_keyword(keywords::Type)) {
let TyParam {ident, bounds, default, ..} = try!(p.parse_ty_param());
if let Some(dty) = default {
p.span_err(dty.span,
"defaults are not supported in associated types");
}
try!(p.expect(&token::Semi));
(ident, TypeTraitItem(bounds, default))
(ident, TypeTraitItem(bounds))
} else if try!(p.eat_keyword(keywords::Const)) {
let ident = try!(p.parse_ident());
try!(p.expect(&token::Colon));
Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,9 +1272,8 @@ impl<'a> State<'a> {
try!(word(&mut self.s, ";"));
}
}
ast::TypeTraitItem(ref bounds, ref default) => {
try!(self.print_associated_type(ti.ident, Some(bounds),
default.as_ref().map(|ty| &**ty)));
ast::TypeTraitItem(ref bounds) => {
try!(self.print_associated_type(ti.ident, Some(bounds), None))
}
}
self.ann.post(self, NodeSubItem(ti.id))
Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,8 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
visitor.visit_fn(FkMethod(trait_item.ident, sig, None), &sig.decl,
body, trait_item.span, trait_item.id);
}
TypeTraitItem(ref bounds, ref default) => {
TypeTraitItem(ref bounds) => {
walk_ty_param_bounds_helper(visitor, bounds);
walk_ty_opt(visitor, default);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/lang-item-public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub trait Copy {

#[lang="rem"]
pub trait Rem<RHS=Self> {
type Output = Self;
type Output;
fn rem(self, rhs: RHS) -> Self::Output;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-22673.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

trait Expr : PartialEq<Self::Item> {
//~^ ERROR: unsupported cyclic reference between types/traits detected
type Item = Expr;
type Item;
}

fn main() {}
3 changes: 0 additions & 3 deletions src/test/compile-fail/lint-missing-doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,10 @@ pub trait D {
/// dox
pub trait E {
type AssociatedType; //~ ERROR: missing documentation for an associated type
type AssociatedTypeDef = Self; //~ ERROR: missing documentation for an associated type

/// dox
type DocumentedType;
/// dox
type DocumentedTypeDef = Self;
/// dox
fn dummy(&self) {}
}

Expand Down
3 changes: 0 additions & 3 deletions src/test/compile-fail/wf-non-well-formed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ fn b7() -> &'static (u32,[u8],u32)
fn main() {}

trait TrBogus {
type T = &'static [[u32]];
//^^ Associated type defaults don't work yet

const X1: &'static [[u16]];
//~^ ERROR the trait `core::marker::Sized` is not implemented
}
Expand Down
19 changes: 19 additions & 0 deletions src/test/parse-fail/associated-types-defaults.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only

// Replace this with a real test-of-functionality when we implement
// default associated types.

trait Foo {
type Assoc = [u8];
//~^ ERROR defaults are not supported in associated types
}

0 comments on commit 9d2b640

Please sign in to comment.