Skip to content

Commit 2859f8b

Browse files
committed
Add tests + Fix rustdoc regression + Fix rebase
1 parent 9c05fb2 commit 2859f8b

File tree

10 files changed

+134
-4
lines changed

10 files changed

+134
-4
lines changed

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ impl<'a> LoweringContext<'a> {
874874
ddpos)
875875
}
876876
PatKind::Path(ref opt_qself, ref path) => {
877-
let opt_qself = opt_qself.map(|qself| {
877+
let opt_qself = opt_qself.as_ref().map(|qself| {
878878
hir::QSelf { ty: self.lower_ty(&qself.ty), position: qself.position }
879879
});
880880
hir::PatKind::Path(opt_qself, self.lower_path(path))

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3135,7 +3135,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
31353135
Some(self.tcx.expect_variant_def(def))
31363136
}
31373137
Def::TyAlias(did) | Def::AssociatedTy(_, did) => {
3138-
if let ty::TyStruct(adt, _) = self.tcx.lookup_item_type(did).ty.sty {
3138+
if let Some(&ty::TyStruct(adt, _)) = self.tcx.opt_lookup_item_type(did)
3139+
.map(|scheme| &scheme.ty.sty) {
31393140
Some(adt.struct_variant())
31403141
} else {
31413142
None

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2653,7 +2653,7 @@ fn resolve_type(cx: &DocContext,
26532653
Def::SelfTy(..) if path.segments.len() == 1 => {
26542654
return Generic(keywords::SelfType.name().to_string());
26552655
}
2656-
Def::SelfTy(..) | Def::TyParam(..) => true,
2656+
Def::SelfTy(..) | Def::TyParam(..) | Def::AssociatedTy(..) => true,
26572657
_ => false,
26582658
};
26592659
let did = register_def(&*cx, def);

src/test/compile-fail-fulldeps/issue-18986.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ pub use use_from_trait_xc::Trait;
1616
fn main() {
1717
match () {
1818
Trait { x: 42 } => () //~ ERROR expected variant, struct or type alias, found trait `Trait`
19-
//~^ ERROR `Trait` does not name a struct or a struct variant
2019
}
2120
}

src/test/compile-fail/auxiliary/lint_stability.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![crate_name="lint_stability"]
1111
#![crate_type = "lib"]
1212
#![feature(staged_api)]
13+
#![feature(associated_type_defaults)]
1314
#![stable(feature = "lint_stability", since = "1.0.0")]
1415

1516
#[stable(feature = "test_feature", since = "1.0.0")]
@@ -92,6 +93,15 @@ pub trait Trait {
9293
fn trait_stable_text(&self) {}
9394
}
9495

96+
#[stable(feature = "test_feature", since = "1.0.0")]
97+
pub trait TraitWithAssociatedTypes {
98+
#[unstable(feature = "test_feature", issue = "0")]
99+
type TypeUnstable = u8;
100+
#[stable(feature = "test_feature", since = "1.0.0")]
101+
#[rustc_deprecated(since = "1.0.0", reason = "text")]
102+
type TypeDeprecated = u8;
103+
}
104+
95105
#[stable(feature = "test_feature", since = "1.0.0")]
96106
impl Trait for MethodTester {}
97107

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2016 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+
#![feature(rustc_attrs)]
12+
#![allow(warnings)]
13+
14+
struct CNFParser {
15+
token: char,
16+
}
17+
18+
impl CNFParser {
19+
fn is_whitespace(c: char) -> bool {
20+
c == ' ' || c == '\n'
21+
}
22+
23+
fn consume_whitespace(&mut self) {
24+
self.consume_while(&(CNFParser::is_whitespace))
25+
}
26+
27+
fn consume_while(&mut self, p: &Fn(char) -> bool) {
28+
while p(self.token) {
29+
return
30+
}
31+
}
32+
}
33+
34+
#[rustc_error]
35+
fn main() {} //~ ERROR compilation successful
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2016 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+
enum Delicious {
12+
Pie = 0x1,
13+
Apple = 0x2,
14+
ApplePie = Delicious::Apple as isize | Delicious::PIE as isize,
15+
//~^ ERROR constant evaluation error: unresolved path in constant expression
16+
}
17+
18+
const FOO: [u32; u8::MIN as usize] = [];
19+
//~^ ERROR array length constant evaluation error: unresolved path in constant expression
20+
21+
fn main() {}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 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+
enum S {
12+
A,
13+
}
14+
15+
fn bug(l: S) {
16+
match l {
17+
S::B{ } => { },
18+
//~^ ERROR ambiguous associated type; specify the type using the syntax `<S as Trait>::B`
19+
}
20+
}
21+
22+
fn main () {}

src/test/compile-fail/lint-stability.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ mod cross_crate {
128128
<Foo>::trait_stable_text(&foo);
129129
<Foo as Trait>::trait_stable_text(&foo);
130130

131+
struct S1<T: TraitWithAssociatedTypes>(T::TypeUnstable);
132+
//~^ ERROR use of unstable library feature
133+
struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
134+
//~^ ERROR use of deprecated item
135+
131136
let _ = DeprecatedStruct { //~ ERROR use of deprecated item
132137
i: 0 //~ ERROR use of deprecated item
133138
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2016 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+
struct S;
12+
13+
trait Tr {
14+
type A;
15+
}
16+
17+
impl Tr for S {
18+
type A = S;
19+
}
20+
21+
fn f<T: Tr>() {
22+
match S {
23+
T::A {} => {} //~ ERROR `T::A` does not name a struct or a struct variant
24+
}
25+
}
26+
27+
fn g<T: Tr<A = S>>() {
28+
match S {
29+
T::A {} => {} //~ ERROR `T::A` does not name a struct or a struct variant
30+
}
31+
}
32+
33+
fn main() {
34+
match S {
35+
S::A {} => {} //~ ERROR ambiguous associated type
36+
}
37+
}

0 commit comments

Comments
 (0)