Skip to content

Commit

Permalink
Address comments + Fix rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Oct 27, 2016
1 parent eada951 commit 8a38928
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 51 deletions.
28 changes: 0 additions & 28 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,34 +802,6 @@ impl<'tcx> fmt::Display for ty::TraitRef<'tcx> {
}
}

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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_const_eval/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
}

Def::Struct(..) | Def::StructCtor(..) | Def::Union(..) |
Def::TyAlias(..) | Def::AssociatedTy(..) => {
Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) => {
PatternKind::Leaf { subpatterns: subpatterns }
}

Expand Down
16 changes: 5 additions & 11 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,17 +1520,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
// 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);
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3216,9 +3216,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}

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 => {
Expand Down Expand Up @@ -3263,8 +3263,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
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
Expand Down
6 changes: 3 additions & 3 deletions src/test/compile-fail/struct-path-associated-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
38 changes: 38 additions & 0 deletions src/test/compile-fail/struct-path-self-type-mismatch.rs
Original file line number Diff line number Diff line change
@@ -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() {}
6 changes: 3 additions & 3 deletions src/test/compile-fail/struct-path-self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ struct S;
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
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/run-pass/issue-22546.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ fn main() {
if let None::<u8> { .. } = Some(8) {
panic!();
}
if let Option::None::<u8> { .. } = Some(8) {
panic!();
}
}

0 comments on commit 8a38928

Please sign in to comment.