diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-03-31 18:13:44 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-03-31 18:59:46 -0700 |
| commit | 683197975c119e4c03588fa729dee4f87902f534 (patch) | |
| tree | 3f547b7f4bd572eda171dd378a455584e60eefed /src/libsyntax | |
| parent | b8ef9fd9c9f642ce7b8aed82782a1ed745d08d64 (diff) | |
| download | rust-683197975c119e4c03588fa729dee4f87902f534.tar.gz rust-683197975c119e4c03588fa729dee4f87902f534.zip | |
rustc: Switch tuple structs to have private fields
This is a continuation of the work done in #13184 to make struct fields private
by default. This commit finishes RFC 4 by making all tuple structs have private
fields by default. Note that enum variants are not affected.
A tuple struct having a private field means that it cannot be matched on in a
pattern match (both refutable and irrefutable), and it also cannot have a value
specified to be constructed. Similarly to private fields, switching the type of
a private field in a tuple struct should be able to be done in a backwards
compatible way.
The one snag that I ran into which wasn't mentioned in the RFC is that this
commit also forbids taking the value of a tuple struct constructor. For example,
this code now fails to compile:
mod a {
pub struct A(int);
}
let a: fn(int) -> a::A = a::A; //~ ERROR: first field is private
Although no fields are bound in this example, it exposes implementation details
through the type itself. For this reason, taking the value of a struct
constructor with private fields is forbidden (outside the containing module).
RFC: 0004-private-fields
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 3a9cdfb56e3..0f082c7e2f1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -493,10 +493,10 @@ pub enum Expr_ { ExprVstore(@Expr, ExprVstore), // First expr is the place; second expr is the value. ExprBox(@Expr, @Expr), - ExprVec(Vec<@Expr> , Mutability), - ExprCall(@Expr, Vec<@Expr> ), - ExprMethodCall(Ident, Vec<P<Ty>> , Vec<@Expr> ), - ExprTup(Vec<@Expr> ), + ExprVec(Vec<@Expr>, Mutability), + ExprCall(@Expr, Vec<@Expr>), + ExprMethodCall(Ident, Vec<P<Ty>>, Vec<@Expr>), + ExprTup(Vec<@Expr>), ExprBinary(BinOp, @Expr, @Expr), ExprUnary(UnOp, @Expr), ExprLit(@Lit), @@ -508,14 +508,14 @@ pub enum Expr_ { // Conditionless loop (can be exited with break, cont, or ret) // FIXME #6993: change to Option<Name> ExprLoop(P<Block>, Option<Ident>), - ExprMatch(@Expr, Vec<Arm> ), + ExprMatch(@Expr, Vec<Arm>), ExprFnBlock(P<FnDecl>, P<Block>), ExprProc(P<FnDecl>, P<Block>), ExprBlock(P<Block>), ExprAssign(@Expr, @Expr), ExprAssignOp(BinOp, @Expr, @Expr), - ExprField(@Expr, Ident, Vec<P<Ty>> ), + ExprField(@Expr, Ident, Vec<P<Ty>>), ExprIndex(@Expr, @Expr), /// Expression that looks like a "name". For example, |
