Skip to content

Commit

Permalink
Auto merge of #65804 - Centril:rollup-arlxgch, r=Centril
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Oct 25, 2019
2 parents 85943fd + c0bbb4b commit 23f890f
Show file tree
Hide file tree
Showing 117 changed files with 1,859 additions and 1,355 deletions.
76 changes: 0 additions & 76 deletions src/doc/unstable-book/src/language-features/non-exhaustive.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
#![feature(hexagon_target_feature)]
#![feature(const_int_conversion)]
#![feature(const_transmute)]
#![feature(non_exhaustive)]
#![cfg_attr(bootstrap, feature(non_exhaustive))]
#![feature(structural_match)]
#![feature(abi_unadjusted)]
#![feature(adx_target_feature)]
Expand Down
2 changes: 1 addition & 1 deletion src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#![feature(extern_types)]
#![feature(in_band_lifetimes)]
#![feature(optin_builtin_traits)]
#![feature(non_exhaustive)]
#![cfg_attr(bootstrap, feature(non_exhaustive))]
#![feature(rustc_attrs)]
#![feature(specialization)]

Expand Down
2 changes: 0 additions & 2 deletions src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2105,8 +2105,6 @@ on something other than a struct or enum.
Examples of erroneous code:
```compile_fail,E0701
# #![feature(non_exhaustive)]
#[non_exhaustive]
trait Foo { }
```
Expand Down
19 changes: 19 additions & 0 deletions src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
ref lines,
ref multibyte_chars,
ref non_narrow_chars,
ref normalized_pos,
} = *self;

(name_hash as u64).hash_stable(hcx, hasher);
Expand Down Expand Up @@ -453,6 +454,12 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
for &char_pos in non_narrow_chars.iter() {
stable_non_narrow_char(char_pos, start_pos).hash_stable(hcx, hasher);
}

normalized_pos.len().hash_stable(hcx, hasher);
for &char_pos in normalized_pos.iter() {
stable_normalized_pos(char_pos, start_pos).hash_stable(hcx, hasher);
}

}
}

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

fn stable_normalized_pos(np: ::syntax_pos::NormalizedPos,
source_file_start: ::syntax_pos::BytePos)
-> (u32, u32) {
let ::syntax_pos::NormalizedPos {
pos,
diff
} = np;

(pos.0 - source_file_start.0, diff)
}


impl<'tcx> HashStable<StableHashingContext<'tcx>> for feature_gate::Features {
fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
// Unfortunately we cannot exhaustively list fields here, since the
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#![feature(overlapping_marker_traits)]
#![feature(extern_types)]
#![feature(nll)]
#![feature(non_exhaustive)]
#![cfg_attr(bootstrap, feature(non_exhaustive))]
#![feature(optin_builtin_traits)]
#![feature(option_expect_none)]
#![feature(range_is_empty)]
Expand Down
97 changes: 39 additions & 58 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use crate::ty::layout::VariantIdx;
use crate::ty::print::{FmtPrinter, Printer};
use crate::ty::subst::{Subst, SubstsRef};
use crate::ty::{
self, AdtDef, CanonicalUserTypeAnnotations, Region, Ty, TyCtxt,
UserTypeAnnotationIndex,
self, AdtDef, CanonicalUserTypeAnnotations, List, Region, Ty, TyCtxt, UserTypeAnnotationIndex,
};

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

/// projection out of a place (access a field, deref a pointer, etc)
pub projection: Box<[PlaceElem<'tcx>]>,
pub projection: &'tcx List<PlaceElem<'tcx>>,
}

impl<'tcx> rustc_serialize::UseSpecializedDecodable for Place<'tcx> {}

#[derive(
Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable,
)]
Expand Down Expand Up @@ -1824,6 +1825,8 @@ impl<V, T> ProjectionElem<V, T> {
/// and the index is a local.
pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>>;

impl<'tcx> Copy for PlaceElem<'tcx> { }

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

impl<'tcx> Place<'tcx> {
// FIXME change this back to a const when projection is a shared slice.
//
// pub const RETURN_PLACE: Place<'tcx> = Place {
// base: PlaceBase::Local(RETURN_PLACE),
// projection: &[],
// };
// FIXME change this to a const fn by also making List::empty a const fn.
pub fn return_place() -> Place<'tcx> {
Place {
base: PlaceBase::Local(RETURN_PLACE),
projection: Box::new([]),
}
}

pub fn field(self, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {
self.elem(ProjectionElem::Field(f, ty))
}

pub fn deref(self) -> Place<'tcx> {
self.elem(ProjectionElem::Deref)
}

pub fn downcast(self, adt_def: &'tcx AdtDef, variant_index: VariantIdx) -> Place<'tcx> {
self.elem(ProjectionElem::Downcast(
Some(adt_def.variants[variant_index].ident.name),
variant_index,
))
}

pub fn downcast_unnamed(self, variant_index: VariantIdx) -> Place<'tcx> {
self.elem(ProjectionElem::Downcast(None, variant_index))
}

pub fn index(self, index: Local) -> Place<'tcx> {
self.elem(ProjectionElem::Index(index))
}

pub fn elem(self, elem: PlaceElem<'tcx>) -> Place<'tcx> {
// FIXME(spastorino): revisit this again once projection is not a Box<[T]> anymore
let mut projection = self.projection.into_vec();
projection.push(elem);

Place {
base: self.base,
projection: projection.into_boxed_slice(),
projection: List::empty(),
}
}

Expand All @@ -1906,26 +1870,23 @@ impl<'tcx> Place<'tcx> {
//
// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
pub fn local_or_deref_local(&self) -> Option<Local> {
match self {
Place {
base: PlaceBase::Local(local),
projection: box [],
match self.as_ref() {
PlaceRef {
base: &PlaceBase::Local(local),
projection: &[],
} |
Place {
base: PlaceBase::Local(local),
projection: box [ProjectionElem::Deref],
} => Some(*local),
PlaceRef {
base: &PlaceBase::Local(local),
projection: &[ProjectionElem::Deref],
} => Some(local),
_ => None,
}
}

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

pub fn as_ref(&self) -> PlaceRef<'_, 'tcx> {
Expand All @@ -1940,7 +1901,7 @@ impl From<Local> for Place<'_> {
fn from(local: Local) -> Self {
Place {
base: local.into(),
projection: Box::new([]),
projection: List::empty(),
}
}
}
Expand Down Expand Up @@ -1969,6 +1930,15 @@ impl<'a, 'tcx> PlaceRef<'a, 'tcx> {
_ => None,
}
}

/// If this place represents a local variable like `_X` with no
/// projections, return `Some(_X)`.
pub fn as_local(&self) -> Option<Local> {
match self {
PlaceRef { base: PlaceBase::Local(l), projection: [] } => Some(*l),
_ => None,
}
}
}

impl Debug for Place<'_> {
Expand Down Expand Up @@ -3182,6 +3152,17 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceBase<'tcx> {
}
}

impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
let v = self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>();
folder.tcx().intern_place_elems(&v)
}

fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
self.iter().any(|t| t.visit_with(visitor))
}
}

impl<'tcx> TypeFoldable<'tcx> for Static<'tcx> {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
Static {
Expand Down
10 changes: 7 additions & 3 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,8 @@ macro_rules! make_mir_visitor {

macro_rules! visit_place_fns {
(mut) => (
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;

fn super_place(
&mut self,
place: &mut Place<'tcx>,
Expand All @@ -793,19 +795,21 @@ macro_rules! visit_place_fns {
self.visit_place_base(&mut place.base, context, location);

if let Some(new_projection) = self.process_projection(&place.projection) {
place.projection = new_projection;
place.projection = self.tcx().intern_place_elems(&new_projection);
}
}

fn process_projection(
&mut self,
projection: &'a [PlaceElem<'tcx>],
) -> Option<Box<[PlaceElem<'tcx>]>> {
) -> Option<Vec<PlaceElem<'tcx>>> {
let mut projection = Cow::Borrowed(projection);

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

match projection {
Cow::Borrowed(_) => None,
Cow::Owned(vec) => Some(vec.into_boxed_slice()),
Cow::Owned(vec) => Some(vec),
}
}

Expand Down
Loading

0 comments on commit 23f890f

Please sign in to comment.