mirror of
https://github.com/rust-lang/rust
synced 2024-09-15 22:50:55 +00:00
Address comments + Fix rebase
This commit is contained in:
parent
eada951f9c
commit
8a38928b44
|
@ -802,34 +802,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
|
@ -436,7 +436,7 @@ fn lower_variant_or_leaf(
|
|||
}
|
||||
|
||||
Def::Struct(..) | Def::StructCtor(..) | Def::Union(..) |
|
||||
Def::TyAlias(..) | Def::AssociatedTy(..) => {
|
||||
Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) => {
|
||||
PatternKind::Leaf { subpatterns: subpatterns }
|
||||
}
|
||||
|
||||
|
|
|
@ -1520,17 +1520,11 @@ fn base_def_to_ty(&self,
|
|||
// 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);
|
||||
|
|
|
@ -3216,9 +3216,9 @@ fn check_struct_fields_on_error(&self,
|
|||
}
|
||||
|
||||
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 => {
|
||||
|
@ -3263,8 +3263,8 @@ pub fn check_struct_path(&self,
|
|||
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
|
||||
|
|
|
@ -20,13 +20,13 @@ impl Tr for S {
|
|||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
38
src/test/compile-fail/struct-path-self-type-mismatch.rs
Normal file
38
src/test/compile-fail/struct-path-self-type-mismatch.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
// 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() {}
|
|
@ -13,13 +13,13 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,4 +54,7 @@ fn main() {
|
|||
if let None::<u8> { .. } = Some(8) {
|
||||
panic!();
|
||||
}
|
||||
if let Option::None::<u8> { .. } = Some(8) {
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue