diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 435bdcc2607..0fdc071dfe3 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -540,19 +540,6 @@ impl<'a> PrivacyVisitor<'a> { return false; } - // Checks that a dereference of a univariant enum can occur. - fn check_variant(&self, span: Span, enum_id: ast::DefId) { - let variant_info = ty::enum_variants(self.tcx, enum_id)[0]; - - match self.def_privacy(variant_info.id) { - Allowable => {} - ExternallyDenied | DisallowedBy(..) => { - self.tcx.sess.span_err(span, "can only dereference enums \ - with a single, public variant"); - } - } - } - // Checks that a field is in scope. // FIXME #6993: change type (and name) from Ident to Name fn check_field(&mut self, span: Span, id: ast::DefId, ident: ast::Ident) { @@ -713,18 +700,6 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> { struct type?!"), } } - ast::ExprUnary(_, ast::UnDeref, operand) => { - // In *e, we need to check that if e's type is an - // enum type t, then t's first variant is public or - // privileged. (We can assume it has only one variant - // since typeck already happened.) - match ty::get(ty::expr_ty(self.tcx, operand)).sty { - ty::ty_enum(id, _) => { - self.check_variant(expr.span, id); - } - _ => { /* No check needed */ } - } - } _ => {} } diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index f57f31a56f4..f547e370bb1 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -628,37 +628,6 @@ impl Datum { ty::ty_rptr(_, mt) => { return (Some(deref_ptr(bcx, self, mt.ty)), bcx); } - ty::ty_enum(did, ref substs) => { - // Check whether this enum is a newtype enum: - let variants = ty::enum_variants(ccx.tcx, did); - if (*variants).len() != 1 || variants[0].args.len() != 1 { - return (None, bcx); - } - - let repr = adt::represent_type(ccx, self.ty); - let ty = ty::subst(ccx.tcx, substs, variants[0].args[0]); - return match self.mode { - ByRef(_) => { - // Recast lv.val as a pointer to the newtype - // rather than a ptr to the enum type. - ( - Some(Datum { - val: adt::trans_field_ptr(bcx, repr, self.val, - 0, 0), - ty: ty, - mode: ByRef(ZeroMem) - }), - bcx - ) - } - ByValue => { - // Actually, this case cannot happen right - // now, because enums are never immediate. - assert!(type_is_immediate(bcx.ccx(), ty)); - (Some(Datum {ty: ty, ..*self}), bcx) - } - }; - } ty::ty_struct(did, ref substs) => { // Check whether this struct is a newtype struct. let fields = ty::struct_fields(ccx.tcx, did, substs); diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 3ae29eade77..6a2fd3c7f5f 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -2631,16 +2631,6 @@ pub fn deref_sty(cx: ctxt, sty: &sty, explicit: bool) -> Option { Some(mt) } - ty_enum(did, ref substs) => { - let variants = enum_variants(cx, did); - if (*variants).len() == 1u && variants[0].args.len() == 1u { - let v_t = subst(cx, substs, variants[0].args[0]); - Some(mt {ty: v_t, mutbl: ast::MutImmutable}) - } else { - None - } - } - ty_struct(did, ref substs) => { let fields = struct_fields(cx, did, substs); if fields.len() == 1 && fields[0].ident == diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 088104e84ef..defd0893daa 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -2765,12 +2765,6 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt, } None => { match *sty { - ty::ty_enum(..) => { - tcx.sess.span_err( - expr.span, - "can only dereference enums with a single variant which \ - has a single argument"); - } ty::ty_struct(..) => { tcx.sess.span_err( expr.span, diff --git a/src/test/compile-fail/issue-818.rs b/src/test/compile-fail/issue-818.rs deleted file mode 100644 index df08652ea0a..00000000000 --- a/src/test/compile-fail/issue-818.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2012 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -mod ctr { - - pub enum ctr { priv mkCtr(int) } - - pub fn new(i: int) -> ctr { mkCtr(i) } - pub fn inc(c: ctr) -> ctr { mkCtr(*c + 1) } -} - - -fn main() { - let c = ctr::new(42); - let c2 = ctr::inc(c); - assert!(*c2 == 5); //~ ERROR can only dereference enums with a single, public variant -} diff --git a/src/test/run-pass/explicit-self-generic.rs b/src/test/run-pass/explicit-self-generic.rs index 023381949a3..fb533a3de58 100644 --- a/src/test/run-pass/explicit-self-generic.rs +++ b/src/test/run-pass/explicit-self-generic.rs @@ -32,7 +32,9 @@ fn linear_map() -> HashMap { impl HashMap { pub fn len(&mut self) -> uint { - self.size + match *self { + HashMap_(l) => l.size + } } }