diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 3e6a82ed47617..9d124dadb766a 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -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)) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 929ab580fc3c1..f6f7ee069008a 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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 diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c33e8159d19c4..7da17b3749104 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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); diff --git a/src/test/compile-fail-fulldeps/issue-18986.rs b/src/test/compile-fail-fulldeps/issue-18986.rs index 4245786295b34..3c32cb947b382 100644 --- a/src/test/compile-fail-fulldeps/issue-18986.rs +++ b/src/test/compile-fail-fulldeps/issue-18986.rs @@ -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 } } diff --git a/src/test/compile-fail/auxiliary/lint_stability.rs b/src/test/compile-fail/auxiliary/lint_stability.rs index 3100aba4b72be..1049bcd15644f 100644 --- a/src/test/compile-fail/auxiliary/lint_stability.rs +++ b/src/test/compile-fail/auxiliary/lint_stability.rs @@ -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 {} diff --git a/src/test/compile-fail/issue-22933-1.rs b/src/test/compile-fail/issue-22933-1.rs new file mode 100644 index 0000000000000..afb972faaca0e --- /dev/null +++ b/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 or the MIT license +// , 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 diff --git a/src/test/compile-fail/issue-22933-2.rs b/src/test/compile-fail/issue-22933-2.rs new file mode 100644 index 0000000000000..7d619c270d32b --- /dev/null +++ b/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 or the MIT license +// , 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() {} diff --git a/src/test/compile-fail/issue-34209.rs b/src/test/compile-fail/issue-34209.rs new file mode 100644 index 0000000000000..6fae18dec10a6 --- /dev/null +++ b/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 or the MIT license +// , 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 `::B` + } +} + +fn main () {} diff --git a/src/test/compile-fail/lint-stability.rs b/src/test/compile-fail/lint-stability.rs index 414d2a857acc7..953cd4a2ff5ea 100644 --- a/src/test/compile-fail/lint-stability.rs +++ b/src/test/compile-fail/lint-stability.rs @@ -128,6 +128,11 @@ mod cross_crate { ::trait_stable_text(&foo); ::trait_stable_text(&foo); + struct S1(T::TypeUnstable); + //~^ ERROR use of unstable library feature + struct S2(T::TypeDeprecated); + //~^ ERROR use of deprecated item + let _ = DeprecatedStruct { //~ ERROR use of deprecated item i: 0 //~ ERROR use of deprecated item }; diff --git a/src/test/compile-fail/struct-pat-associated-path.rs b/src/test/compile-fail/struct-pat-associated-path.rs new file mode 100644 index 0000000000000..d3f840f4fe976 --- /dev/null +++ b/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 or the MIT license +// , 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() { + match S { + T::A {} => {} //~ ERROR `T::A` does not name a struct or a struct variant + } +} + +fn g>() { + 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 + } +}