Skip to content

Commit

Permalink
Add tests + Fix rustdoc regression + Fix rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jul 8, 2016
1 parent 9c05fb2 commit 2859f8b
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering.rs
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_typeck/check/mod.rs
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail-fulldeps/issue-18986.rs
Expand Up @@ -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
}
}
10 changes: 10 additions & 0 deletions src/test/compile-fail/auxiliary/lint_stability.rs
Expand Up @@ -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")]
Expand Down Expand Up @@ -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 {}

Expand Down
35 changes: 35 additions & 0 deletions src/test/compile-fail/issue-22933-1.rs
@@ -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
21 changes: 21 additions & 0 deletions src/test/compile-fail/issue-22933-2.rs
@@ -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() {}
22 changes: 22 additions & 0 deletions src/test/compile-fail/issue-34209.rs
@@ -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 () {}
5 changes: 5 additions & 0 deletions src/test/compile-fail/lint-stability.rs
Expand Up @@ -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
};
Expand Down
37 changes: 37 additions & 0 deletions src/test/compile-fail/struct-pat-associated-path.rs
@@ -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
}
}

0 comments on commit 2859f8b

Please sign in to comment.