Skip to content

Commit 23f890f

Browse files
committed
Auto merge of #65804 - Centril:rollup-arlxgch, r=Centril
Rollup of 9 pull requests Successful merges: - #64639 (Stabilize `#[non_exhaustive]` (RFC 2008)) - #65074 (Fix the start/end byte positions in the compiler JSON output) - #65315 (Intern place projection) - #65685 (Fix check of `statx` and handle EPERM) - #65731 (Prevent unnecessary allocation in PathBuf::set_extension.) - #65740 (Fix default "disable-shortcuts" feature value) - #65787 (move panictry! to where it is used.) - #65789 (move Attribute::with_desugared_doc to librustdoc) - #65790 (move report_invalid_macro_expansion_item to item.rs) Failed merges: r? @ghost
2 parents 85943fd + c0bbb4b commit 23f890f

File tree

117 files changed

+1859
-1355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+1859
-1355
lines changed

src/doc/unstable-book/src/language-features/non-exhaustive.md

-76
This file was deleted.

src/libcore/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
#![feature(hexagon_target_feature)]
122122
#![feature(const_int_conversion)]
123123
#![feature(const_transmute)]
124-
#![feature(non_exhaustive)]
124+
#![cfg_attr(bootstrap, feature(non_exhaustive))]
125125
#![feature(structural_match)]
126126
#![feature(abi_unadjusted)]
127127
#![feature(adx_target_feature)]

src/libproc_macro/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#![feature(extern_types)]
2626
#![feature(in_band_lifetimes)]
2727
#![feature(optin_builtin_traits)]
28-
#![feature(non_exhaustive)]
28+
#![cfg_attr(bootstrap, feature(non_exhaustive))]
2929
#![feature(rustc_attrs)]
3030
#![feature(specialization)]
3131

src/librustc/error_codes.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2105,8 +2105,6 @@ on something other than a struct or enum.
21052105
Examples of erroneous code:
21062106
21072107
```compile_fail,E0701
2108-
# #![feature(non_exhaustive)]
2109-
21102108
#[non_exhaustive]
21112109
trait Foo { }
21122110
```

src/librustc/ich/impls_syntax.rs

+19
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
425425
ref lines,
426426
ref multibyte_chars,
427427
ref non_narrow_chars,
428+
ref normalized_pos,
428429
} = *self;
429430

430431
(name_hash as u64).hash_stable(hcx, hasher);
@@ -453,6 +454,12 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
453454
for &char_pos in non_narrow_chars.iter() {
454455
stable_non_narrow_char(char_pos, start_pos).hash_stable(hcx, hasher);
455456
}
457+
458+
normalized_pos.len().hash_stable(hcx, hasher);
459+
for &char_pos in normalized_pos.iter() {
460+
stable_normalized_pos(char_pos, start_pos).hash_stable(hcx, hasher);
461+
}
462+
456463
}
457464
}
458465

@@ -482,6 +489,18 @@ fn stable_non_narrow_char(swc: ::syntax_pos::NonNarrowChar,
482489
(pos.0 - source_file_start.0, width as u32)
483490
}
484491

492+
fn stable_normalized_pos(np: ::syntax_pos::NormalizedPos,
493+
source_file_start: ::syntax_pos::BytePos)
494+
-> (u32, u32) {
495+
let ::syntax_pos::NormalizedPos {
496+
pos,
497+
diff
498+
} = np;
499+
500+
(pos.0 - source_file_start.0, diff)
501+
}
502+
503+
485504
impl<'tcx> HashStable<StableHashingContext<'tcx>> for feature_gate::Features {
486505
fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
487506
// Unfortunately we cannot exhaustively list fields here, since the

src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#![feature(overlapping_marker_traits)]
4242
#![feature(extern_types)]
4343
#![feature(nll)]
44-
#![feature(non_exhaustive)]
44+
#![cfg_attr(bootstrap, feature(non_exhaustive))]
4545
#![feature(optin_builtin_traits)]
4646
#![feature(option_expect_none)]
4747
#![feature(range_is_empty)]

src/librustc/mir/mod.rs

+39-58
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use crate::ty::layout::VariantIdx;
1515
use crate::ty::print::{FmtPrinter, Printer};
1616
use crate::ty::subst::{Subst, SubstsRef};
1717
use crate::ty::{
18-
self, AdtDef, CanonicalUserTypeAnnotations, Region, Ty, TyCtxt,
19-
UserTypeAnnotationIndex,
18+
self, AdtDef, CanonicalUserTypeAnnotations, List, Region, Ty, TyCtxt, UserTypeAnnotationIndex,
2019
};
2120

2221
use polonius_engine::Atom;
@@ -1712,15 +1711,17 @@ impl Debug for Statement<'_> {
17121711
/// A path to a value; something that can be evaluated without
17131712
/// changing or disturbing program state.
17141713
#[derive(
1715-
Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable,
1714+
Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, HashStable,
17161715
)]
17171716
pub struct Place<'tcx> {
17181717
pub base: PlaceBase<'tcx>,
17191718

17201719
/// projection out of a place (access a field, deref a pointer, etc)
1721-
pub projection: Box<[PlaceElem<'tcx>]>,
1720+
pub projection: &'tcx List<PlaceElem<'tcx>>,
17221721
}
17231722

1723+
impl<'tcx> rustc_serialize::UseSpecializedDecodable for Place<'tcx> {}
1724+
17241725
#[derive(
17251726
Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable,
17261727
)]
@@ -1824,6 +1825,8 @@ impl<V, T> ProjectionElem<V, T> {
18241825
/// and the index is a local.
18251826
pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>>;
18261827

1828+
impl<'tcx> Copy for PlaceElem<'tcx> { }
1829+
18271830
// At least on 64 bit systems, `PlaceElem` should not be larger than two pointers.
18281831
#[cfg(target_arch = "x86_64")]
18291832
static_assert_size!(PlaceElem<'_>, 16);
@@ -1846,50 +1849,11 @@ pub struct PlaceRef<'a, 'tcx> {
18461849
}
18471850

18481851
impl<'tcx> Place<'tcx> {
1849-
// FIXME change this back to a const when projection is a shared slice.
1850-
//
1851-
// pub const RETURN_PLACE: Place<'tcx> = Place {
1852-
// base: PlaceBase::Local(RETURN_PLACE),
1853-
// projection: &[],
1854-
// };
1852+
// FIXME change this to a const fn by also making List::empty a const fn.
18551853
pub fn return_place() -> Place<'tcx> {
18561854
Place {
18571855
base: PlaceBase::Local(RETURN_PLACE),
1858-
projection: Box::new([]),
1859-
}
1860-
}
1861-
1862-
pub fn field(self, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {
1863-
self.elem(ProjectionElem::Field(f, ty))
1864-
}
1865-
1866-
pub fn deref(self) -> Place<'tcx> {
1867-
self.elem(ProjectionElem::Deref)
1868-
}
1869-
1870-
pub fn downcast(self, adt_def: &'tcx AdtDef, variant_index: VariantIdx) -> Place<'tcx> {
1871-
self.elem(ProjectionElem::Downcast(
1872-
Some(adt_def.variants[variant_index].ident.name),
1873-
variant_index,
1874-
))
1875-
}
1876-
1877-
pub fn downcast_unnamed(self, variant_index: VariantIdx) -> Place<'tcx> {
1878-
self.elem(ProjectionElem::Downcast(None, variant_index))
1879-
}
1880-
1881-
pub fn index(self, index: Local) -> Place<'tcx> {
1882-
self.elem(ProjectionElem::Index(index))
1883-
}
1884-
1885-
pub fn elem(self, elem: PlaceElem<'tcx>) -> Place<'tcx> {
1886-
// FIXME(spastorino): revisit this again once projection is not a Box<[T]> anymore
1887-
let mut projection = self.projection.into_vec();
1888-
projection.push(elem);
1889-
1890-
Place {
1891-
base: self.base,
1892-
projection: projection.into_boxed_slice(),
1856+
projection: List::empty(),
18931857
}
18941858
}
18951859

@@ -1906,26 +1870,23 @@ impl<'tcx> Place<'tcx> {
19061870
//
19071871
// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
19081872
pub fn local_or_deref_local(&self) -> Option<Local> {
1909-
match self {
1910-
Place {
1911-
base: PlaceBase::Local(local),
1912-
projection: box [],
1873+
match self.as_ref() {
1874+
PlaceRef {
1875+
base: &PlaceBase::Local(local),
1876+
projection: &[],
19131877
} |
1914-
Place {
1915-
base: PlaceBase::Local(local),
1916-
projection: box [ProjectionElem::Deref],
1917-
} => Some(*local),
1878+
PlaceRef {
1879+
base: &PlaceBase::Local(local),
1880+
projection: &[ProjectionElem::Deref],
1881+
} => Some(local),
19181882
_ => None,
19191883
}
19201884
}
19211885

19221886
/// If this place represents a local variable like `_X` with no
19231887
/// projections, return `Some(_X)`.
19241888
pub fn as_local(&self) -> Option<Local> {
1925-
match self {
1926-
Place { projection: box [], base: PlaceBase::Local(l) } => Some(*l),
1927-
_ => None,
1928-
}
1889+
self.as_ref().as_local()
19291890
}
19301891

19311892
pub fn as_ref(&self) -> PlaceRef<'_, 'tcx> {
@@ -1940,7 +1901,7 @@ impl From<Local> for Place<'_> {
19401901
fn from(local: Local) -> Self {
19411902
Place {
19421903
base: local.into(),
1943-
projection: Box::new([]),
1904+
projection: List::empty(),
19441905
}
19451906
}
19461907
}
@@ -1969,6 +1930,15 @@ impl<'a, 'tcx> PlaceRef<'a, 'tcx> {
19691930
_ => None,
19701931
}
19711932
}
1933+
1934+
/// If this place represents a local variable like `_X` with no
1935+
/// projections, return `Some(_X)`.
1936+
pub fn as_local(&self) -> Option<Local> {
1937+
match self {
1938+
PlaceRef { base: PlaceBase::Local(l), projection: [] } => Some(*l),
1939+
_ => None,
1940+
}
1941+
}
19721942
}
19731943

19741944
impl Debug for Place<'_> {
@@ -3182,6 +3152,17 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceBase<'tcx> {
31823152
}
31833153
}
31843154

3155+
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
3156+
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
3157+
let v = self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>();
3158+
folder.tcx().intern_place_elems(&v)
3159+
}
3160+
3161+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
3162+
self.iter().any(|t| t.visit_with(visitor))
3163+
}
3164+
}
3165+
31853166
impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> {
31863167
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
31873168
Static {

src/librustc/mir/visit.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,8 @@ macro_rules! make_mir_visitor {
784784

785785
macro_rules! visit_place_fns {
786786
(mut) => (
787+
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
788+
787789
fn super_place(
788790
&mut self,
789791
place: &mut Place<'tcx>,
@@ -793,19 +795,21 @@ macro_rules! visit_place_fns {
793795
self.visit_place_base(&mut place.base, context, location);
794796

795797
if let Some(new_projection) = self.process_projection(&place.projection) {
796-
place.projection = new_projection;
798+
place.projection = self.tcx().intern_place_elems(&new_projection);
797799
}
798800
}
799801

800802
fn process_projection(
801803
&mut self,
802804
projection: &'a [PlaceElem<'tcx>],
803-
) -> Option<Box<[PlaceElem<'tcx>]>> {
805+
) -> Option<Vec<PlaceElem<'tcx>>> {
804806
let mut projection = Cow::Borrowed(projection);
805807

806808
for i in 0..projection.len() {
807809
if let Some(elem) = projection.get(i) {
808810
if let Some(elem) = self.process_projection_elem(elem) {
811+
// This converts the borrowed projection into `Cow::Owned(_)` and returns a
812+
// clone of the projection so we can mutate and reintern later.
809813
let vec = projection.to_mut();
810814
vec[i] = elem;
811815
}
@@ -814,7 +818,7 @@ macro_rules! visit_place_fns {
814818

815819
match projection {
816820
Cow::Borrowed(_) => None,
817-
Cow::Owned(vec) => Some(vec.into_boxed_slice()),
821+
Cow::Owned(vec) => Some(vec),
818822
}
819823
}
820824

0 commit comments

Comments
 (0)