Skip to content

Commit 9d2b640

Browse files
committed
Make default associated types not parse
They don't do anything ATM. This is a [breaking-change]
1 parent 3923108 commit 9d2b640

File tree

13 files changed

+36
-22
lines changed

13 files changed

+36
-22
lines changed

src/libcore/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ div_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
405405
pub trait Rem<RHS=Self> {
406406
/// The resulting type after applying the `%` operator
407407
#[stable(feature = "rust1", since = "1.0.0")]
408-
type Output = Self;
408+
type Output;
409409

410410
/// The method for the `%` operator
411411
#[stable(feature = "rust1", since = "1.0.0")]

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ fn convert_trait_predicates<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item)
13761376
{
13771377
trait_items.iter().flat_map(|trait_item| {
13781378
let bounds = match trait_item.node {
1379-
ast::TypeTraitItem(ref bounds, _) => bounds,
1379+
ast::TypeTraitItem(ref bounds) => bounds,
13801380
_ => {
13811381
return vec!().into_iter();
13821382
}

src/librustdoc/clean/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,8 +1247,8 @@ impl Clean<Item> for ast::TraitItem {
12471247
ast::MethodTraitItem(ref sig, None) => {
12481248
TyMethodItem(sig.clean(cx))
12491249
}
1250-
ast::TypeTraitItem(ref bounds, ref default) => {
1251-
AssociatedTypeItem(bounds.clean(cx), default.clean(cx))
1250+
ast::TypeTraitItem(ref bounds) => {
1251+
AssociatedTypeItem(bounds.clean(cx), None)
12521252
}
12531253
};
12541254
Item {

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ pub struct TraitItem {
12381238
pub enum TraitItem_ {
12391239
ConstTraitItem(P<Ty>, Option<P<Expr>>),
12401240
MethodTraitItem(MethodSig, Option<P<Block>>),
1241-
TypeTraitItem(TyParamBounds, Option<P<Ty>>),
1241+
TypeTraitItem(TyParamBounds),
12421242
}
12431243

12441244
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]

src/libsyntax/fold.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,8 @@ pub fn noop_fold_trait_item<T: Folder>(i: P<TraitItem>, folder: &mut T)
991991
MethodTraitItem(noop_fold_method_sig(sig, folder),
992992
body.map(|x| folder.fold_block(x)))
993993
}
994-
TypeTraitItem(bounds, default) => {
995-
TypeTraitItem(folder.fold_bounds(bounds),
996-
default.map(|x| folder.fold_ty(x)))
994+
TypeTraitItem(bounds) => {
995+
TypeTraitItem(folder.fold_bounds(bounds))
997996
}
998997
},
999998
span: folder.new_span(span)

src/libsyntax/parse/parser.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,8 +1158,12 @@ impl<'a> Parser<'a> {
11581158

11591159
let (name, node) = if try!(p.eat_keyword(keywords::Type)) {
11601160
let TyParam {ident, bounds, default, ..} = try!(p.parse_ty_param());
1161+
if let Some(dty) = default {
1162+
p.span_err(dty.span,
1163+
"defaults are not supported in associated types");
1164+
}
11611165
try!(p.expect(&token::Semi));
1162-
(ident, TypeTraitItem(bounds, default))
1166+
(ident, TypeTraitItem(bounds))
11631167
} else if try!(p.eat_keyword(keywords::Const)) {
11641168
let ident = try!(p.parse_ident());
11651169
try!(p.expect(&token::Colon));

src/libsyntax/print/pprust.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,9 +1272,8 @@ impl<'a> State<'a> {
12721272
try!(word(&mut self.s, ";"));
12731273
}
12741274
}
1275-
ast::TypeTraitItem(ref bounds, ref default) => {
1276-
try!(self.print_associated_type(ti.ident, Some(bounds),
1277-
default.as_ref().map(|ty| &**ty)));
1275+
ast::TypeTraitItem(ref bounds) => {
1276+
try!(self.print_associated_type(ti.ident, Some(bounds), None))
12781277
}
12791278
}
12801279
self.ann.post(self, NodeSubItem(ti.id))

src/libsyntax/visit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,8 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
638638
visitor.visit_fn(FkMethod(trait_item.ident, sig, None), &sig.decl,
639639
body, trait_item.span, trait_item.id);
640640
}
641-
TypeTraitItem(ref bounds, ref default) => {
641+
TypeTraitItem(ref bounds) => {
642642
walk_ty_param_bounds_helper(visitor, bounds);
643-
walk_ty_opt(visitor, default);
644643
}
645644
}
646645
}

src/test/auxiliary/lang-item-public.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub trait Copy {
3131

3232
#[lang="rem"]
3333
pub trait Rem<RHS=Self> {
34-
type Output = Self;
34+
type Output;
3535
fn rem(self, rhs: RHS) -> Self::Output;
3636
}
3737

src/test/compile-fail/issue-22673.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
trait Expr : PartialEq<Self::Item> {
1212
//~^ ERROR: unsupported cyclic reference between types/traits detected
13-
type Item = Expr;
13+
type Item;
1414
}
1515

1616
fn main() {}

src/test/compile-fail/lint-missing-doc.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,10 @@ pub trait D {
7171
/// dox
7272
pub trait E {
7373
type AssociatedType; //~ ERROR: missing documentation for an associated type
74-
type AssociatedTypeDef = Self; //~ ERROR: missing documentation for an associated type
7574

7675
/// dox
7776
type DocumentedType;
7877
/// dox
79-
type DocumentedTypeDef = Self;
80-
/// dox
8178
fn dummy(&self) {}
8279
}
8380

src/test/compile-fail/wf-non-well-formed.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ fn b7() -> &'static (u32,[u8],u32)
4343
fn main() {}
4444

4545
trait TrBogus {
46-
type T = &'static [[u32]];
47-
//^^ Associated type defaults don't work yet
48-
4946
const X1: &'static [[u16]];
5047
//~^ ERROR the trait `core::marker::Sized` is not implemented
5148
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -Z parse-only
12+
13+
// Replace this with a real test-of-functionality when we implement
14+
// default associated types.
15+
16+
trait Foo {
17+
type Assoc = [u8];
18+
//~^ ERROR defaults are not supported in associated types
19+
}

0 commit comments

Comments
 (0)