Add tests + Fix rustdoc regression + Fix rebase

This commit is contained in:
Vadim Petrochenkov 2016-06-11 18:47:47 +03:00
parent 9c05fb29d2
commit 2859f8bf39
10 changed files with 134 additions and 4 deletions

View File

@ -874,7 +874,7 @@ impl<'a> LoweringContext<'a> {
ddpos)
}
PatKind::Path(ref opt_qself, ref path) => {
let opt_qself = opt_qself.map(|qself| {
let opt_qself = opt_qself.as_ref().map(|qself| {
hir::QSelf { ty: self.lower_ty(&qself.ty), position: qself.position }
});
hir::PatKind::Path(opt_qself, self.lower_path(path))

View File

@ -3135,7 +3135,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Some(self.tcx.expect_variant_def(def))
}
Def::TyAlias(did) | Def::AssociatedTy(_, did) => {
if let ty::TyStruct(adt, _) = self.tcx.lookup_item_type(did).ty.sty {
if let Some(&ty::TyStruct(adt, _)) = self.tcx.opt_lookup_item_type(did)
.map(|scheme| &scheme.ty.sty) {
Some(adt.struct_variant())
} else {
None

View File

@ -2653,7 +2653,7 @@ fn resolve_type(cx: &DocContext,
Def::SelfTy(..) if path.segments.len() == 1 => {
return Generic(keywords::SelfType.name().to_string());
}
Def::SelfTy(..) | Def::TyParam(..) => true,
Def::SelfTy(..) | Def::TyParam(..) | Def::AssociatedTy(..) => true,
_ => false,
};
let did = register_def(&*cx, def);

View File

@ -16,6 +16,5 @@ pub use use_from_trait_xc::Trait;
fn main() {
match () {
Trait { x: 42 } => () //~ ERROR expected variant, struct or type alias, found trait `Trait`
//~^ ERROR `Trait` does not name a struct or a struct variant
}
}

View File

@ -10,6 +10,7 @@
#![crate_name="lint_stability"]
#![crate_type = "lib"]
#![feature(staged_api)]
#![feature(associated_type_defaults)]
#![stable(feature = "lint_stability", since = "1.0.0")]
#[stable(feature = "test_feature", since = "1.0.0")]
@ -92,6 +93,15 @@ pub trait Trait {
fn trait_stable_text(&self) {}
}
#[stable(feature = "test_feature", since = "1.0.0")]
pub trait TraitWithAssociatedTypes {
#[unstable(feature = "test_feature", issue = "0")]
type TypeUnstable = u8;
#[stable(feature = "test_feature", since = "1.0.0")]
#[rustc_deprecated(since = "1.0.0", reason = "text")]
type TypeDeprecated = u8;
}
#[stable(feature = "test_feature", since = "1.0.0")]
impl Trait for MethodTester {}

View File

@ -0,0 +1,35 @@
// Copyright 2016 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.
#![feature(rustc_attrs)]
#![allow(warnings)]
struct CNFParser {
token: char,
}
impl CNFParser {
fn is_whitespace(c: char) -> bool {
c == ' ' || c == '\n'
}
fn consume_whitespace(&mut self) {
self.consume_while(&(CNFParser::is_whitespace))
}
fn consume_while(&mut self, p: &Fn(char) -> bool) {
while p(self.token) {
return
}
}
}
#[rustc_error]
fn main() {} //~ ERROR compilation successful

View File

@ -0,0 +1,21 @@
// Copyright 2016 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.
enum Delicious {
Pie = 0x1,
Apple = 0x2,
ApplePie = Delicious::Apple as isize | Delicious::PIE as isize,
//~^ ERROR constant evaluation error: unresolved path in constant expression
}
const FOO: [u32; u8::MIN as usize] = [];
//~^ ERROR array length constant evaluation error: unresolved path in constant expression
fn main() {}

View File

@ -0,0 +1,22 @@
// Copyright 2016 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.
enum S {
A,
}
fn bug(l: S) {
match l {
S::B{ } => { },
//~^ ERROR ambiguous associated type; specify the type using the syntax `<S as Trait>::B`
}
}
fn main () {}

View File

@ -128,6 +128,11 @@ mod cross_crate {
<Foo>::trait_stable_text(&foo);
<Foo as Trait>::trait_stable_text(&foo);
struct S1<T: TraitWithAssociatedTypes>(T::TypeUnstable);
//~^ ERROR use of unstable library feature
struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
//~^ ERROR use of deprecated item
let _ = DeprecatedStruct { //~ ERROR use of deprecated item
i: 0 //~ ERROR use of deprecated item
};

View File

@ -0,0 +1,37 @@
// Copyright 2016 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.
struct S;
trait Tr {
type A;
}
impl Tr for S {
type A = S;
}
fn f<T: Tr>() {
match S {
T::A {} => {} //~ ERROR `T::A` does not name a struct or a struct variant
}
}
fn g<T: Tr<A = S>>() {
match S {
T::A {} => {} //~ ERROR `T::A` does not name a struct or a struct variant
}
}
fn main() {
match S {
S::A {} => {} //~ ERROR ambiguous associated type
}
}