Commit 6831979
committed
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-fields1 parent b8ef9fd commit 6831979
File tree
6 files changed
+270
-31
lines changed- src
- librustc
- metadata
- middle
- libsyntax
- test
- auxiliary
- compile-fail
6 files changed
+270
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
962 | 962 | | |
963 | 963 | | |
964 | 964 | | |
965 | | - | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
966 | 968 | | |
967 | 969 | | |
968 | 970 | | |
969 | 971 | | |
970 | 972 | | |
971 | 973 | | |
972 | | - | |
| 974 | + | |
973 | 975 | | |
974 | 976 | | |
975 | 977 | | |
976 | | - | |
| 978 | + | |
977 | 979 | | |
978 | 980 | | |
979 | 981 | | |
980 | 982 | | |
981 | | - | |
| 983 | + | |
| 984 | + | |
982 | 985 | | |
983 | 986 | | |
984 | 987 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
358 | 359 | | |
359 | 360 | | |
360 | 361 | | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
361 | 368 | | |
362 | 369 | | |
363 | 370 | | |
| |||
560 | 567 | | |
561 | 568 | | |
562 | 569 | | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
573 | 576 | | |
574 | | - | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
575 | 587 | | |
576 | 588 | | |
577 | 589 | | |
| |||
634 | 646 | | |
635 | 647 | | |
636 | 648 | | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
641 | 654 | | |
642 | 655 | | |
643 | 656 | | |
| |||
701 | 714 | | |
702 | 715 | | |
703 | 716 | | |
704 | | - | |
| 717 | + | |
| 718 | + | |
705 | 719 | | |
706 | 720 | | |
707 | 721 | | |
| |||
726 | 740 | | |
727 | 741 | | |
728 | 742 | | |
729 | | - | |
| 743 | + | |
730 | 744 | | |
731 | 745 | | |
732 | 746 | | |
| |||
749 | 763 | | |
750 | 764 | | |
751 | 765 | | |
752 | | - | |
| 766 | + | |
| 767 | + | |
753 | 768 | | |
754 | 769 | | |
755 | 770 | | |
756 | 771 | | |
757 | 772 | | |
758 | 773 | | |
759 | 774 | | |
760 | | - | |
| 775 | + | |
761 | 776 | | |
762 | 777 | | |
763 | 778 | | |
| |||
772 | 787 | | |
773 | 788 | | |
774 | 789 | | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
775 | 830 | | |
776 | 831 | | |
777 | 832 | | |
| |||
821 | 876 | | |
822 | 877 | | |
823 | 878 | | |
824 | | - | |
| 879 | + | |
| 880 | + | |
825 | 881 | | |
826 | 882 | | |
827 | 883 | | |
828 | 884 | | |
829 | 885 | | |
830 | 886 | | |
831 | 887 | | |
832 | | - | |
| 888 | + | |
833 | 889 | | |
834 | 890 | | |
835 | 891 | | |
| |||
844 | 900 | | |
845 | 901 | | |
846 | 902 | | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
847 | 924 | | |
848 | 925 | | |
849 | 926 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
| |||
508 | 508 | | |
509 | 509 | | |
510 | 510 | | |
511 | | - | |
| 511 | + | |
512 | 512 | | |
513 | 513 | | |
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
517 | 517 | | |
518 | | - | |
| 518 | + | |
519 | 519 | | |
520 | 520 | | |
521 | 521 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
0 commit comments