}
}
-impl<'tcx> ty::TypeVariants<'tcx> {
- pub fn descr(&self) -> &'static str {
- match *self {
- TyInt(..) | TyUint(..) | TyFloat(..) |
- TyBool | TyChar | TyStr => "builtin type",
- TyRawPtr(..) => "pointer",
- TyRef(..) => "reference",
- TyTuple(..) => "tuple",
- TyFnDef(..) => "function type",
- TyFnPtr(..) => "function pointer",
- TyArray(..) => "array",
- TySlice(..) => "slice",
- TyParam(..) => "type parameter",
- TyProjection(..) => "associated type",
- TyTrait(..) => "trait type",
- TyClosure(..) => "closure type",
- TyBox(..) => "struct",
- TyAdt(def, ..) => match def.adt_kind() {
- ty::AdtKind::Struct => "struct",
- ty::AdtKind::Union => "union",
- ty::AdtKind::Enum => "enum",
- },
- TyInfer(..) | TyAnon(..) |
- TyNever | TyError => "type",
- }
- }
-}
-
impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
}
Def::Struct(..) | Def::StructCtor(..) | Def::Union(..) |
- Def::TyAlias(..) | Def::AssociatedTy(..) => {
+ Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) => {
PatternKind::Leaf { subpatterns: subpatterns }
}
// Convert "variant type" as if it were a real type.
// The resulting `Ty` is type of the variant's enum for now.
tcx.prohibit_type_params(base_segments.split_last().unwrap().1);
- let mut ty = self.ast_path_to_ty(rscope,
- span,
- param_mode,
- tcx.parent_def_id(did).unwrap(),
- base_segments.last().unwrap());
- if ty.is_fn() {
- // Tuple variants have fn type even in type namespace,
- // extract true variant type from it.
- ty = tcx.no_late_bound_regions(&ty.fn_ret()).unwrap();
- }
- ty
+ self.ast_path_to_ty(rscope,
+ span,
+ param_mode,
+ tcx.parent_def_id(did).unwrap(),
+ base_segments.last().unwrap())
}
Def::TyParam(did) => {
tcx.prohibit_type_params(base_segments);
}
pub fn check_struct_path(&self,
- path: &hir::Path,
- node_id: ast::NodeId)
- -> Option<(ty::VariantDef<'tcx>, Ty<'tcx>)> {
+ path: &hir::Path,
+ node_id: ast::NodeId)
+ -> Option<(ty::VariantDef<'tcx>, Ty<'tcx>)> {
let (def, ty) = self.finish_resolving_struct_path(path, node_id);
let variant = match def {
Def::Err => {
Some((variant, ty))
} else {
struct_span_err!(self.tcx.sess, path.span, E0071,
- "expected struct, variant or union type, found {} `{}`",
- ty.sty.descr(), ty)
+ "expected struct, variant or union type, found {}",
+ ty.sort_string(self.tcx))
.span_label(path.span, &format!("not a struct"))
.emit();
None
fn f<T: Tr>() {
let s = T::A {};
- //~^ ERROR expected struct, variant or union type, found associated type `<T as Tr>::A`
+ //~^ ERROR expected struct, variant or union type, found associated type
let z = T::A::<u8> {};
- //~^ ERROR expected struct, variant or union type, found associated type `<T as Tr>::A`
+ //~^ ERROR expected struct, variant or union type, found associated type
//~| ERROR type parameters are not allowed on this type
match S {
T::A {} => {}
- //~^ ERROR expected struct, variant or union type, found associated type `<T as Tr>::A`
+ //~^ ERROR expected struct, variant or union type, found associated type
}
}
--- /dev/null
+// 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 Foo<A> { inner: A }
+
+trait Bar { fn bar(); }
+
+impl Bar for Foo<i32> {
+ fn bar() {
+ Self { inner: 1.5f32 }; //~ ERROR mismatched types
+ //~^ NOTE expected i32, found f32
+ }
+}
+
+impl<T> Foo<T> {
+ fn new<U>(u: U) -> Foo<U> {
+ Self {
+ //~^ ERROR mismatched types
+ //~| expected type parameter, found a different type parameter
+ //~| expected type `Foo<U>`
+ //~| found type `Foo<T>`
+ inner: u
+ //~^ ERROR mismatched types
+ //~| expected type parameter, found a different type parameter
+ //~| expected type `T`
+ //~| found type `U`
+ }
+ }
+}
+
+fn main() {}
trait Tr {
fn f() {
let s = Self {};
- //~^ ERROR expected struct, variant or union type, found type parameter `Self`
+ //~^ ERROR expected struct, variant or union type, found Self
let z = Self::<u8> {};
- //~^ ERROR expected struct, variant or union type, found type parameter `Self`
+ //~^ ERROR expected struct, variant or union type, found Self
//~| ERROR type parameters are not allowed on this type
match s {
Self { .. } => {}
- //~^ ERROR expected struct, variant or union type, found type parameter `Self`
+ //~^ ERROR expected struct, variant or union type, found Self
}
}
}
if let None::<u8> { .. } = Some(8) {
panic!();
}
+ if let Option::None::<u8> { .. } = Some(8) {
+ panic!();
+ }
}