@@ -154,6 +154,16 @@ pub struct Body<'tcx> {
154
154
155
155
/// A span representing this MIR, for error reporting.
156
156
pub span : Span ,
157
+
158
+ /// The user may be writing e.g. &[(SOME_CELL, 42)][i].1 and this would get promoted, because
159
+ /// we'd statically know that no thing with interior mutability will ever be available to the
160
+ /// user without some serious unsafe code. Now this means that our promoted is actually
161
+ /// &[(SOME_CELL, 42)] and the MIR using it will do the &promoted[i].1 projection because the
162
+ /// index may be a runtime value. Such a promoted value is illegal because it has reachable
163
+ /// interior mutability. This flag just makes this situation very obvious where the previous
164
+ /// implementation without the flag hid this situation silently.
165
+ /// FIXME(oli-obk): rewrite the promoted during promotion to eliminate the cell components.
166
+ pub ignore_interior_mut_in_const_validation : bool ,
157
167
}
158
168
159
169
impl < ' tcx > Body < ' tcx > {
@@ -190,6 +200,7 @@ impl<'tcx> Body<'tcx> {
190
200
spread_arg : None ,
191
201
var_debug_info,
192
202
span,
203
+ ignore_interior_mut_in_const_validation : false ,
193
204
control_flow_destroyed,
194
205
}
195
206
}
@@ -1649,52 +1660,17 @@ impl Debug for Statement<'_> {
1649
1660
/// A path to a value; something that can be evaluated without
1650
1661
/// changing or disturbing program state.
1651
1662
#[ derive(
1652
- Clone , PartialEq , Eq , PartialOrd , Ord , Hash , RustcEncodable , HashStable ,
1663
+ Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , RustcEncodable , HashStable ,
1653
1664
) ]
1654
1665
pub struct Place < ' tcx > {
1655
- pub base : PlaceBase < ' tcx > ,
1666
+ pub local : Local ,
1656
1667
1657
1668
/// projection out of a place (access a field, deref a pointer, etc)
1658
1669
pub projection : & ' tcx List < PlaceElem < ' tcx > > ,
1659
1670
}
1660
1671
1661
1672
impl < ' tcx > rustc_serialize:: UseSpecializedDecodable for Place < ' tcx > { }
1662
1673
1663
- #[ derive(
1664
- Clone , PartialEq , Eq , PartialOrd , Ord , Hash , RustcEncodable , RustcDecodable , HashStable ,
1665
- ) ]
1666
- pub enum PlaceBase < ' tcx > {
1667
- /// local variable
1668
- Local ( Local ) ,
1669
-
1670
- /// static or static mut variable
1671
- Static ( Box < Static < ' tcx > > ) ,
1672
- }
1673
-
1674
- /// We store the normalized type to avoid requiring normalization when reading MIR
1675
- #[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ,
1676
- RustcEncodable , RustcDecodable , HashStable ) ]
1677
- pub struct Static < ' tcx > {
1678
- pub ty : Ty < ' tcx > ,
1679
- pub kind : StaticKind < ' tcx > ,
1680
- /// The `DefId` of the item this static was declared in. For promoted values, usually, this is
1681
- /// the same as the `DefId` of the `mir::Body` containing the `Place` this promoted appears in.
1682
- /// However, after inlining, that might no longer be the case as inlined `Place`s are copied
1683
- /// into the calling frame.
1684
- pub def_id : DefId ,
1685
- }
1686
-
1687
- #[ derive(
1688
- Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash , HashStable , RustcEncodable , RustcDecodable ,
1689
- ) ]
1690
- pub enum StaticKind < ' tcx > {
1691
- /// Promoted references consist of an id (`Promoted`) and the substs necessary to monomorphize
1692
- /// it. Usually, these substs are just the identity substs for the item. However, the inliner
1693
- /// will adjust these substs when it inlines a function based on the substs at the callsite.
1694
- Promoted ( Promoted , SubstsRef < ' tcx > ) ,
1695
- Static ,
1696
- }
1697
-
1698
1674
#[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
1699
1675
#[ derive( RustcEncodable , RustcDecodable , HashStable ) ]
1700
1676
pub enum ProjectionElem < V , T > {
@@ -1783,15 +1759,15 @@ rustc_index::newtype_index! {
1783
1759
1784
1760
#[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
1785
1761
pub struct PlaceRef < ' a , ' tcx > {
1786
- pub base : & ' a PlaceBase < ' tcx > ,
1762
+ pub local : & ' a Local ,
1787
1763
pub projection : & ' a [ PlaceElem < ' tcx > ] ,
1788
1764
}
1789
1765
1790
1766
impl < ' tcx > Place < ' tcx > {
1791
1767
// FIXME change this to a const fn by also making List::empty a const fn.
1792
1768
pub fn return_place ( ) -> Place < ' tcx > {
1793
1769
Place {
1794
- base : PlaceBase :: Local ( RETURN_PLACE ) ,
1770
+ local : RETURN_PLACE ,
1795
1771
projection : List :: empty ( ) ,
1796
1772
}
1797
1773
}
@@ -1811,13 +1787,13 @@ impl<'tcx> Place<'tcx> {
1811
1787
pub fn local_or_deref_local ( & self ) -> Option < Local > {
1812
1788
match self . as_ref ( ) {
1813
1789
PlaceRef {
1814
- base : & PlaceBase :: Local ( local) ,
1790
+ local,
1815
1791
projection : & [ ] ,
1816
1792
} |
1817
1793
PlaceRef {
1818
- base : & PlaceBase :: Local ( local) ,
1794
+ local,
1819
1795
projection : & [ ProjectionElem :: Deref ] ,
1820
- } => Some ( local) ,
1796
+ } => Some ( * local) ,
1821
1797
_ => None ,
1822
1798
}
1823
1799
}
@@ -1830,7 +1806,7 @@ impl<'tcx> Place<'tcx> {
1830
1806
1831
1807
pub fn as_ref ( & self ) -> PlaceRef < ' _ , ' tcx > {
1832
1808
PlaceRef {
1833
- base : & self . base ,
1809
+ local : & self . local ,
1834
1810
projection : & self . projection ,
1835
1811
}
1836
1812
}
@@ -1839,18 +1815,12 @@ impl<'tcx> Place<'tcx> {
1839
1815
impl From < Local > for Place < ' _ > {
1840
1816
fn from ( local : Local ) -> Self {
1841
1817
Place {
1842
- base : local. into ( ) ,
1818
+ local,
1843
1819
projection : List :: empty ( ) ,
1844
1820
}
1845
1821
}
1846
1822
}
1847
1823
1848
- impl From < Local > for PlaceBase < ' _ > {
1849
- fn from ( local : Local ) -> Self {
1850
- PlaceBase :: Local ( local)
1851
- }
1852
- }
1853
-
1854
1824
impl < ' a , ' tcx > PlaceRef < ' a , ' tcx > {
1855
1825
/// Finds the innermost `Local` from this `Place`, *if* it is either a local itself or
1856
1826
/// a single deref of a local.
@@ -1859,13 +1829,13 @@ impl<'a, 'tcx> PlaceRef<'a, 'tcx> {
1859
1829
pub fn local_or_deref_local ( & self ) -> Option < Local > {
1860
1830
match self {
1861
1831
PlaceRef {
1862
- base : PlaceBase :: Local ( local) ,
1832
+ local,
1863
1833
projection : [ ] ,
1864
1834
} |
1865
1835
PlaceRef {
1866
- base : PlaceBase :: Local ( local) ,
1836
+ local,
1867
1837
projection : [ ProjectionElem :: Deref ] ,
1868
- } => Some ( * local) ,
1838
+ } => Some ( * * local) ,
1869
1839
_ => None ,
1870
1840
}
1871
1841
}
@@ -1874,7 +1844,7 @@ impl<'a, 'tcx> PlaceRef<'a, 'tcx> {
1874
1844
/// projections, return `Some(_X)`.
1875
1845
pub fn as_local ( & self ) -> Option < Local > {
1876
1846
match self {
1877
- PlaceRef { base : PlaceBase :: Local ( l ) , projection : [ ] } => Some ( * l ) ,
1847
+ PlaceRef { local , projection : [ ] } => Some ( * * local ) ,
1878
1848
_ => None ,
1879
1849
}
1880
1850
}
@@ -1896,7 +1866,7 @@ impl Debug for Place<'_> {
1896
1866
}
1897
1867
}
1898
1868
1899
- write ! ( fmt, "{:?}" , self . base ) ?;
1869
+ write ! ( fmt, "{:?}" , self . local ) ?;
1900
1870
1901
1871
for elem in self . projection . iter ( ) {
1902
1872
match elem {
@@ -1940,22 +1910,6 @@ impl Debug for Place<'_> {
1940
1910
}
1941
1911
}
1942
1912
1943
- impl Debug for PlaceBase < ' _ > {
1944
- fn fmt ( & self , fmt : & mut Formatter < ' _ > ) -> fmt:: Result {
1945
- match * self {
1946
- PlaceBase :: Local ( id) => write ! ( fmt, "{:?}" , id) ,
1947
- PlaceBase :: Static ( box self :: Static { ty, kind : StaticKind :: Static , def_id } ) => {
1948
- write ! ( fmt, "({}: {:?})" , ty:: tls:: with( |tcx| tcx. def_path_str( def_id) ) , ty)
1949
- }
1950
- PlaceBase :: Static ( box self :: Static {
1951
- ty, kind : StaticKind :: Promoted ( promoted, _) , def_id : _
1952
- } ) => {
1953
- write ! ( fmt, "({:?}: {:?})" , promoted, ty)
1954
- }
1955
- }
1956
- }
1957
- }
1958
-
1959
1913
///////////////////////////////////////////////////////////////////////////
1960
1914
// Scopes
1961
1915
@@ -3019,29 +2973,13 @@ impl<'tcx> TypeFoldable<'tcx> for GeneratorKind {
3019
2973
impl < ' tcx > TypeFoldable < ' tcx > for Place < ' tcx > {
3020
2974
fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
3021
2975
Place {
3022
- base : self . base . fold_with ( folder) ,
2976
+ local : self . local . fold_with ( folder) ,
3023
2977
projection : self . projection . fold_with ( folder) ,
3024
2978
}
3025
2979
}
3026
2980
3027
2981
fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
3028
- self . base . visit_with ( visitor) || self . projection . visit_with ( visitor)
3029
- }
3030
- }
3031
-
3032
- impl < ' tcx > TypeFoldable < ' tcx > for PlaceBase < ' tcx > {
3033
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
3034
- match self {
3035
- PlaceBase :: Local ( local) => PlaceBase :: Local ( local. fold_with ( folder) ) ,
3036
- PlaceBase :: Static ( static_) => PlaceBase :: Static ( static_. fold_with ( folder) ) ,
3037
- }
3038
- }
3039
-
3040
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
3041
- match self {
3042
- PlaceBase :: Local ( local) => local. visit_with ( visitor) ,
3043
- PlaceBase :: Static ( static_) => ( * * static_) . visit_with ( visitor) ,
3044
- }
2982
+ self . local . visit_with ( visitor) || self . projection . visit_with ( visitor)
3045
2983
}
3046
2984
}
3047
2985
@@ -3056,40 +2994,6 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
3056
2994
}
3057
2995
}
3058
2996
3059
- impl < ' tcx > TypeFoldable < ' tcx > for Static < ' tcx > {
3060
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
3061
- Static {
3062
- ty : self . ty . fold_with ( folder) ,
3063
- kind : self . kind . fold_with ( folder) ,
3064
- def_id : self . def_id ,
3065
- }
3066
- }
3067
-
3068
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
3069
- let Static { ty, kind, def_id : _ } = self ;
3070
-
3071
- ty. visit_with ( visitor) || kind. visit_with ( visitor)
3072
- }
3073
- }
3074
-
3075
- impl < ' tcx > TypeFoldable < ' tcx > for StaticKind < ' tcx > {
3076
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
3077
- match self {
3078
- StaticKind :: Promoted ( promoted, substs) =>
3079
- StaticKind :: Promoted ( promoted. fold_with ( folder) , substs. fold_with ( folder) ) ,
3080
- StaticKind :: Static => StaticKind :: Static
3081
- }
3082
- }
3083
-
3084
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
3085
- match self {
3086
- StaticKind :: Promoted ( promoted, substs) =>
3087
- promoted. visit_with ( visitor) || substs. visit_with ( visitor) ,
3088
- StaticKind :: Static => { false }
3089
- }
3090
- }
3091
- }
3092
-
3093
2997
impl < ' tcx > TypeFoldable < ' tcx > for Rvalue < ' tcx > {
3094
2998
fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
3095
2999
use crate :: mir:: Rvalue :: * ;
0 commit comments