-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement untagged unions (RFC 1444) #36016
Changes from all commits
1db878f
4001c03
35d52a0
cbd912b
a014323
641d8e9
6792bd9
5f9ef3c
c2ca153
957971b
f3b41c1
e88d4ca
bea0b15
0cb1938
2dc2fc5
d9b332b
079c390
59ccb7b
5f975e9
e67c228
93067ca
436cfe5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,14 @@ | |
use self::RootUnsafeContext::*; | ||
|
||
use dep_graph::DepNode; | ||
use hir::def::Def; | ||
use ty::{self, Ty, TyCtxt}; | ||
use ty::MethodCall; | ||
|
||
use syntax::ast; | ||
use syntax_pos::Span; | ||
use hir; | ||
use hir::intravisit; | ||
use hir::intravisit::{FnKind, Visitor}; | ||
use hir::{self, PatKind}; | ||
use hir::def::Def; | ||
use hir::intravisit::{self, FnKind, Visitor}; | ||
|
||
#[derive(Copy, Clone)] | ||
struct UnsafeContext { | ||
|
@@ -178,11 +177,28 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> { | |
self.require_unsafe(expr.span, "use of mutable static"); | ||
} | ||
} | ||
hir::ExprField(ref base_expr, field) => { | ||
if let ty::TyUnion(..) = self.tcx.expr_ty_adjusted(base_expr).sty { | ||
self.require_unsafe(field.span, "access to union field"); | ||
} | ||
} | ||
_ => {} | ||
} | ||
|
||
intravisit::walk_expr(self, expr); | ||
} | ||
|
||
fn visit_pat(&mut self, pat: &hir::Pat) { | ||
if let PatKind::Struct(_, ref fields, _) = pat.node { | ||
if let ty::TyUnion(..) = self.tcx.pat_ty(pat).sty { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here; I wonder if we should factor this into some form of helper where you just pass in the type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case and the case above can't be unified reasonably, pattern fields and expr fields are different types. |
||
for field in fields { | ||
self.require_unsafe(field.span, "matching on union field"); | ||
} | ||
} | ||
} | ||
|
||
intravisit::walk_pat(self, pat); | ||
} | ||
} | ||
|
||
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I feel like it'd be nice to
match
the sty (exhaustively) and have abug!
call for the unexpected cases. This makes me mildly nervous that some bug or addition might slip through.