Skip to content

Commit 8a38928

Browse files
committed
Address comments + Fix rebase
1 parent eada951 commit 8a38928

File tree

8 files changed

+58
-51
lines changed

8 files changed

+58
-51
lines changed

src/librustc/util/ppaux.rs

-28
Original file line numberDiff line numberDiff line change
@@ -802,34 +802,6 @@ impl<'tcx> fmt::Display for ty::TraitRef<'tcx> {
802802
}
803803
}
804804

805-
impl<'tcx> ty::TypeVariants<'tcx> {
806-
pub fn descr(&self) -> &'static str {
807-
match *self {
808-
TyInt(..) | TyUint(..) | TyFloat(..) |
809-
TyBool | TyChar | TyStr => "builtin type",
810-
TyRawPtr(..) => "pointer",
811-
TyRef(..) => "reference",
812-
TyTuple(..) => "tuple",
813-
TyFnDef(..) => "function type",
814-
TyFnPtr(..) => "function pointer",
815-
TyArray(..) => "array",
816-
TySlice(..) => "slice",
817-
TyParam(..) => "type parameter",
818-
TyProjection(..) => "associated type",
819-
TyTrait(..) => "trait type",
820-
TyClosure(..) => "closure type",
821-
TyBox(..) => "struct",
822-
TyAdt(def, ..) => match def.adt_kind() {
823-
ty::AdtKind::Struct => "struct",
824-
ty::AdtKind::Union => "union",
825-
ty::AdtKind::Enum => "enum",
826-
},
827-
TyInfer(..) | TyAnon(..) |
828-
TyNever | TyError => "type",
829-
}
830-
}
831-
}
832-
833805
impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
834806
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
835807
match *self {

src/librustc_const_eval/pattern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
436436
}
437437

438438
Def::Struct(..) | Def::StructCtor(..) | Def::Union(..) |
439-
Def::TyAlias(..) | Def::AssociatedTy(..) => {
439+
Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) => {
440440
PatternKind::Leaf { subpatterns: subpatterns }
441441
}
442442

src/librustc_typeck/astconv.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1520,17 +1520,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
15201520
// Convert "variant type" as if it were a real type.
15211521
// The resulting `Ty` is type of the variant's enum for now.
15221522
tcx.prohibit_type_params(base_segments.split_last().unwrap().1);
1523-
let mut ty = self.ast_path_to_ty(rscope,
1524-
span,
1525-
param_mode,
1526-
tcx.parent_def_id(did).unwrap(),
1527-
base_segments.last().unwrap());
1528-
if ty.is_fn() {
1529-
// Tuple variants have fn type even in type namespace,
1530-
// extract true variant type from it.
1531-
ty = tcx.no_late_bound_regions(&ty.fn_ret()).unwrap();
1532-
}
1533-
ty
1523+
self.ast_path_to_ty(rscope,
1524+
span,
1525+
param_mode,
1526+
tcx.parent_def_id(did).unwrap(),
1527+
base_segments.last().unwrap())
15341528
}
15351529
Def::TyParam(did) => {
15361530
tcx.prohibit_type_params(base_segments);

src/librustc_typeck/check/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3216,9 +3216,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
32163216
}
32173217

32183218
pub fn check_struct_path(&self,
3219-
path: &hir::Path,
3220-
node_id: ast::NodeId)
3221-
-> Option<(ty::VariantDef<'tcx>, Ty<'tcx>)> {
3219+
path: &hir::Path,
3220+
node_id: ast::NodeId)
3221+
-> Option<(ty::VariantDef<'tcx>, Ty<'tcx>)> {
32223222
let (def, ty) = self.finish_resolving_struct_path(path, node_id);
32233223
let variant = match def {
32243224
Def::Err => {
@@ -3263,8 +3263,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
32633263
Some((variant, ty))
32643264
} else {
32653265
struct_span_err!(self.tcx.sess, path.span, E0071,
3266-
"expected struct, variant or union type, found {} `{}`",
3267-
ty.sty.descr(), ty)
3266+
"expected struct, variant or union type, found {}",
3267+
ty.sort_string(self.tcx))
32683268
.span_label(path.span, &format!("not a struct"))
32693269
.emit();
32703270
None

src/test/compile-fail/struct-path-associated-type.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ impl Tr for S {
2020

2121
fn f<T: Tr>() {
2222
let s = T::A {};
23-
//~^ ERROR expected struct, variant or union type, found associated type `<T as Tr>::A`
23+
//~^ ERROR expected struct, variant or union type, found associated type
2424
let z = T::A::<u8> {};
25-
//~^ ERROR expected struct, variant or union type, found associated type `<T as Tr>::A`
25+
//~^ ERROR expected struct, variant or union type, found associated type
2626
//~| ERROR type parameters are not allowed on this type
2727
match S {
2828
T::A {} => {}
29-
//~^ ERROR expected struct, variant or union type, found associated type `<T as Tr>::A`
29+
//~^ ERROR expected struct, variant or union type, found associated type
3030
}
3131
}
3232

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 Foo<A> { inner: A }
12+
13+
trait Bar { fn bar(); }
14+
15+
impl Bar for Foo<i32> {
16+
fn bar() {
17+
Self { inner: 1.5f32 }; //~ ERROR mismatched types
18+
//~^ NOTE expected i32, found f32
19+
}
20+
}
21+
22+
impl<T> Foo<T> {
23+
fn new<U>(u: U) -> Foo<U> {
24+
Self {
25+
//~^ ERROR mismatched types
26+
//~| expected type parameter, found a different type parameter
27+
//~| expected type `Foo<U>`
28+
//~| found type `Foo<T>`
29+
inner: u
30+
//~^ ERROR mismatched types
31+
//~| expected type parameter, found a different type parameter
32+
//~| expected type `T`
33+
//~| found type `U`
34+
}
35+
}
36+
}
37+
38+
fn main() {}

src/test/compile-fail/struct-path-self.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ struct S;
1313
trait Tr {
1414
fn f() {
1515
let s = Self {};
16-
//~^ ERROR expected struct, variant or union type, found type parameter `Self`
16+
//~^ ERROR expected struct, variant or union type, found Self
1717
let z = Self::<u8> {};
18-
//~^ ERROR expected struct, variant or union type, found type parameter `Self`
18+
//~^ ERROR expected struct, variant or union type, found Self
1919
//~| ERROR type parameters are not allowed on this type
2020
match s {
2121
Self { .. } => {}
22-
//~^ ERROR expected struct, variant or union type, found type parameter `Self`
22+
//~^ ERROR expected struct, variant or union type, found Self
2323
}
2424
}
2525
}

src/test/run-pass/issue-22546.rs

+3
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ fn main() {
5454
if let None::<u8> { .. } = Some(8) {
5555
panic!();
5656
}
57+
if let Option::None::<u8> { .. } = Some(8) {
58+
panic!();
59+
}
5760
}

0 commit comments

Comments
 (0)