Skip to content

Commit a34b8de

Browse files
committed
auto merge of #18171 : jakub-/rust/match-typeck, r=pcwalton
Rather than doing it top-down, with a known expected type, we will now simply establish the appropriate constraints between the pattern and the expression it destructures. Closes #8783. Closes #10200.
2 parents 172b59a + 1484f9c commit a34b8de

25 files changed

+490
-747
lines changed

src/librustc/diagnostics.rs

-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ register_diagnostics!(
4444
E0025,
4545
E0026,
4646
E0027,
47-
E0028,
4847
E0029,
4948
E0030,
5049
E0031,
51-
E0032,
5250
E0033,
5351
E0034,
5452
E0035,

src/librustc/metadata/decoder.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,14 @@ pub fn get_enum_variants(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
673673
let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
674674
item, tcx, cdata);
675675
let name = item_name(&*intr, item);
676-
let arg_tys = match ty::get(ctor_ty).sty {
677-
ty::ty_bare_fn(ref f) => f.sig.inputs.clone(),
678-
_ => Vec::new(), // Nullary enum variant.
676+
let (ctor_ty, arg_tys) = match ty::get(ctor_ty).sty {
677+
ty::ty_bare_fn(ref f) =>
678+
(Some(ctor_ty), f.sig.inputs.clone()),
679+
_ => // Nullary or struct enum variant.
680+
(None, get_struct_fields(intr.clone(), cdata, did.node)
681+
.iter()
682+
.map(|field_ty| get_type(cdata, field_ty.id.node, tcx).ty)
683+
.collect())
679684
};
680685
match variant_disr_val(item) {
681686
Some(val) => { disr_val = val; }

src/librustc/middle/privacy.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -667,21 +667,12 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
667667

668668
let struct_type = ty::lookup_item_type(self.tcx, id).ty;
669669
let struct_desc = match ty::get(struct_type).sty {
670-
ty::ty_struct(_, _) => format!("struct `{}`", ty::item_path_str(self.tcx, id)),
671-
ty::ty_bare_fn(ty::BareFnTy { sig: ty::FnSig { output, .. }, .. }) => {
672-
// Struct `id` is really a struct variant of an enum,
673-
// and we're really looking at the variant's constructor
674-
// function. So get the return type for a detailed error
675-
// message.
676-
let enum_id = match ty::get(output).sty {
677-
ty::ty_enum(id, _) => id,
678-
_ => self.tcx.sess.span_bug(span, "enum variant doesn't \
679-
belong to an enum")
680-
};
670+
ty::ty_struct(_, _) =>
671+
format!("struct `{}`", ty::item_path_str(self.tcx, id)),
672+
ty::ty_enum(enum_id, _) =>
681673
format!("variant `{}` of enum `{}`",
682674
ty::with_path(self.tcx, id, |mut p| p.last().unwrap()),
683-
ty::item_path_str(self.tcx, enum_id))
684-
}
675+
ty::item_path_str(self.tcx, enum_id)),
685676
_ => self.tcx.sess.span_bug(span, "can't find struct for field")
686677
};
687678
let msg = match name {

src/librustc/middle/resolve.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5077,7 +5077,6 @@ impl<'a> Resolver<'a> {
50775077
PatEnum(ref path, _) => {
50785078
// This must be an enum variant, struct or const.
50795079
match self.resolve_path(pat_id, path, ValueNS, false) {
5080-
Some(def @ (DefFn(..), _)) |
50815080
Some(def @ (DefVariant(..), _)) |
50825081
Some(def @ (DefStruct(..), _)) |
50835082
Some(def @ (DefConst(..), _)) => {

src/librustc/middle/ty.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use syntax::ast::{CrateNum, DefId, FnStyle, Ident, ItemTrait, LOCAL_CRATE};
5050
use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
5151
use syntax::ast::{Onceness, StmtExpr, StmtSemi, StructField, UnnamedField};
5252
use syntax::ast::{Visibility};
53-
use syntax::ast_util::{mod, PostExpansionMethod, is_local, lit_is_str};
53+
use syntax::ast_util::{mod, is_local, lit_is_str, local_def, PostExpansionMethod};
5454
use syntax::attr::{mod, AttrMetaMethods};
5555
use syntax::codemap::Span;
5656
use syntax::parse::token::{mod, InternedString};
@@ -4221,7 +4221,7 @@ pub fn ty_to_def_id(ty: t) -> Option<ast::DefId> {
42214221
pub struct VariantInfo {
42224222
pub args: Vec<t>,
42234223
pub arg_names: Option<Vec<ast::Ident> >,
4224-
pub ctor_ty: t,
4224+
pub ctor_ty: Option<t>,
42254225
pub name: ast::Name,
42264226
pub id: ast::DefId,
42274227
pub disr_val: Disr,
@@ -4249,7 +4249,7 @@ impl VariantInfo {
42494249
return VariantInfo {
42504250
args: arg_tys,
42514251
arg_names: None,
4252-
ctor_ty: ctor_ty,
4252+
ctor_ty: Some(ctor_ty),
42534253
name: ast_variant.node.name.name,
42544254
id: ast_util::local_def(ast_variant.node.id),
42554255
disr_val: discriminant,
@@ -4262,7 +4262,8 @@ impl VariantInfo {
42624262

42634263
assert!(fields.len() > 0);
42644264

4265-
let arg_tys = ty_fn_args(ctor_ty).iter().map(|a| *a).collect();
4265+
let arg_tys = struct_def.fields.iter()
4266+
.map(|field| node_id_to_type(cx, field.node.id)).collect();
42664267
let arg_names = fields.iter().map(|field| {
42674268
match field.node.kind {
42684269
NamedField(ident, _) => ident,
@@ -4274,7 +4275,7 @@ impl VariantInfo {
42744275
return VariantInfo {
42754276
args: arg_tys,
42764277
arg_names: Some(arg_names),
4277-
ctor_ty: ctor_ty,
4278+
ctor_ty: None,
42784279
name: ast_variant.node.name.name,
42794280
id: ast_util::local_def(ast_variant.node.id),
42804281
disr_val: discriminant,

0 commit comments

Comments
 (0)