• A
    rustc: Switch tuple structs to have private fields · 68319797
    Alex Crichton 提交于
    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
    68319797
decoder.rs 45.7 KB