Skip to content

Commit

Permalink
Auto merge of rust-lang#85952 - JohnTitor:rollup-r00gu9q, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 13 pull requests

Successful merges:

 - rust-lang#83362 (Stabilize `vecdeque_binary_search`)
 - rust-lang#85706 (Turn off frame pointer elimination on all Apple platforms. )
 - rust-lang#85724 (Fix issue 85435 by restricting Fake Read precision)
 - rust-lang#85852 (Clarify meaning of MachineApplicable suggestions.)
 - rust-lang#85877 (Intra doc link-ify a reference to a function)
 - rust-lang#85880 (convert assertion on rvalue::threadlocalref to delay bug)
 - rust-lang#85896 (Add test for forward declared const param defaults)
 - rust-lang#85897 (Update I-unsound label for triagebot)
 - rust-lang#85900 (Use pattern matching instead of checking lengths explicitly)
 - rust-lang#85911 (Avoid a clone of output_filenames.)
 - rust-lang#85926 (Update cargo)
 - rust-lang#85934 (Add `Ty::is_union` predicate)
 - rust-lang#85935 (Validate type of locals used as indices)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jun 3, 2021
2 parents 016e9b5 + 0cdbb7d commit a93699f
Show file tree
Hide file tree
Showing 36 changed files with 228 additions and 134 deletions.
25 changes: 22 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ dependencies = [
"humantime 2.0.1",
"ignore",
"im-rc",
"itertools 0.10.0",
"jobserver",
"lazy_static",
"lazycell",
Expand All @@ -293,7 +294,7 @@ dependencies = [
"rand 0.8.3",
"rustc-workspace-hack",
"rustfix",
"semver 0.10.0",
"semver 1.0.1",
"serde",
"serde_ignored",
"serde_json",
Expand Down Expand Up @@ -1715,6 +1716,15 @@ dependencies = [
"either",
]

[[package]]
name = "itertools"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319"
dependencies = [
"either",
]

[[package]]
name = "itoa"
version = "0.4.6"
Expand Down Expand Up @@ -4674,6 +4684,15 @@ dependencies = [
"serde",
]

[[package]]
name = "semver"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d023dabf011d5dcb5ac64e3685d97d3b0ef412911077a2851455c6098524a723"
dependencies = [
"serde",
]

[[package]]
name = "semver-parser"
version = "0.7.0"
Expand Down Expand Up @@ -5033,9 +5052,9 @@ dependencies = [

[[package]]
name = "tar"
version = "0.4.33"
version = "0.4.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0bcfbd6a598361fda270d82469fff3d65089dc33e175c9a131f7b4cd395f228"
checksum = "7d779dc6aeff029314570f666ec83f19df7280bb36ef338442cfa8c604021b80"
dependencies = [
"filetime",
"libc",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ pub fn create_global_ctxt<'tcx>(
query_result_on_disk_cache,
queries.as_dyn(),
&crate_name,
&outputs,
outputs,
)
})
});
Expand Down
26 changes: 7 additions & 19 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::{is_range_literal, ExprKind, Node};
use rustc_index::vec::Idx;
use rustc_middle::ty::layout::{IntegerExt, SizeSkeleton};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, AdtKind, Ty, TyCtxt, TypeFoldable};
use rustc_span::source_map;
use rustc_span::symbol::sym;
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::Abi;
use rustc_target::abi::{Integer, LayoutOf, TagEncoding, VariantIdx, Variants};
use rustc_target::abi::{Integer, LayoutOf, TagEncoding, Variants};
use rustc_target::spec::abi::Abi as SpecAbi;

use std::cmp;
Expand Down Expand Up @@ -783,25 +782,14 @@ crate fn repr_nullable_ptr<'tcx>(
) -> Option<Ty<'tcx>> {
debug!("is_repr_nullable_ptr(cx, ty = {:?})", ty);
if let ty::Adt(ty_def, substs) = ty.kind() {
if ty_def.variants.len() != 2 {
return None;
}

let get_variant_fields = |index| &ty_def.variants[VariantIdx::new(index)].fields;
let variant_fields = [get_variant_fields(0), get_variant_fields(1)];
let fields = if variant_fields[0].is_empty() {
&variant_fields[1]
} else if variant_fields[1].is_empty() {
&variant_fields[0]
} else {
return None;
let field_ty = match &ty_def.variants.raw[..] {
[var_one, var_two] => match (&var_one.fields[..], &var_two.fields[..]) {
([], [field]) | ([field], []) => field.ty(cx.tcx, substs),
_ => return None,
},
_ => return None,
};

if fields.len() != 1 {
return None;
}

let field_ty = fields[0].ty(cx.tcx, substs);
if !ty_is_known_nonnull(cx, field_ty, ckind) {
return None;
}
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ macro_rules! pluralize {
/// before applying the suggestion.
#[derive(Copy, Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
pub enum Applicability {
/// The suggestion is definitely what the user intended. This suggestion should be
/// The suggestion is definitely what the user intended, or maintains the exact meaning of the code.
/// This suggestion should be automatically applied.
///
/// In case of multiple `MachineApplicable` suggestions (whether as part of
/// the same `multipart_suggestion` or not), all of them should be
/// automatically applied.
MachineApplicable,

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ impl<'tcx> TyCtxt<'tcx> {
on_disk_cache: Option<query::OnDiskCache<'tcx>>,
queries: &'tcx dyn query::QueryEngine<'tcx>,
crate_name: &str,
output_filenames: &OutputFilenames,
output_filenames: OutputFilenames,
) -> GlobalCtxt<'tcx> {
let data_layout = TargetDataLayout::parse(&s.target).unwrap_or_else(|err| {
s.fatal(&err);
Expand Down Expand Up @@ -1179,7 +1179,7 @@ impl<'tcx> TyCtxt<'tcx> {
stability_interner: Default::default(),
const_stability_interner: Default::default(),
alloc_map: Lock::new(interpret::AllocMap::new()),
output_filenames: Arc::new(output_filenames.clone()),
output_filenames: Arc::new(output_filenames),
main_def: resolutions.main_def,
}
}
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1837,10 +1837,12 @@ impl<'tcx> TyS<'tcx> {

#[inline]
pub fn is_enum(&self) -> bool {
match self.kind() {
Adt(adt_def, _) => adt_def.is_enum(),
_ => false,
}
matches!(self.kind(), Adt(adt_def, _) if adt_def.is_enum())
}

#[inline]
pub fn is_union(&self) -> bool {
matches!(self.kind(), Adt(adt_def, _) if adt_def.is_union())
}

#[inline]
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_mir/src/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1965,13 +1965,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// no move out from an earlier location) then this is an attempt at initialization
// of the union - we should error in that case.
let tcx = this.infcx.tcx;
if let ty::Adt(def, _) = base.ty(this.body(), tcx).ty.kind() {
if def.is_union() {
if this.move_data.path_map[mpi].iter().any(|moi| {
this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
}) {
return;
}
if base.ty(this.body(), tcx).ty.is_union() {
if this.move_data.path_map[mpi].iter().any(|moi| {
this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
}) {
return;
}
}

Expand Down
19 changes: 8 additions & 11 deletions compiler/rustc_mir/src/borrow_check/places_conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,14 @@ fn place_projection_conflict<'tcx>(
Overlap::EqualOrDisjoint
} else {
let ty = Place::ty_from(pi1_local, pi1_proj_base, body, tcx).ty;
match ty.kind() {
ty::Adt(def, _) if def.is_union() => {
// Different fields of a union, we are basically stuck.
debug!("place_element_conflict: STUCK-UNION");
Overlap::Arbitrary
}
_ => {
// Different fields of a struct (`a.x` vs. `a.y`). Disjoint!
debug!("place_element_conflict: DISJOINT-FIELD");
Overlap::Disjoint
}
if ty.is_union() {
// Different fields of a union, we are basically stuck.
debug!("place_element_conflict: STUCK-UNION");
Overlap::Arbitrary
} else {
// Different fields of a struct (`a.x` vs. `a.y`). Disjoint!
debug!("place_element_conflict: DISJOINT-FIELD");
Overlap::Disjoint
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_mir/src/dataflow/move_paths/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
// Check if we are assigning into a field of a union, if so, lookup the place
// of the union so it is marked as initialized again.
if let Some((place_base, ProjectionElem::Field(_, _))) = place.last_projection() {
if let ty::Adt(def, _) = place_base.ty(self.builder.body, self.builder.tcx).ty.kind() {
if def.is_union() {
place = place_base;
}
if place_base.ty(self.builder.body, self.builder.tcx).ty.is_union() {
place = place_base;
}
}

Expand Down
15 changes: 5 additions & 10 deletions compiler/rustc_mir/src/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,9 @@ impl Validator<'mir, 'tcx> {
}

fn check_static(&mut self, def_id: DefId, span: Span) {
assert!(
!self.tcx.is_thread_local_static(def_id),
"tls access is checked in `Rvalue::ThreadLocalRef"
);
if self.tcx.is_thread_local_static(def_id) {
self.tcx.sess.delay_span_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef");
}
self.check_op_spanned(ops::StaticAccess, span)
}

Expand Down Expand Up @@ -753,12 +752,8 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
| ProjectionElem::Field(..)
| ProjectionElem::Index(_) => {
let base_ty = Place::ty_from(place_local, proj_base, self.body, self.tcx).ty;
match base_ty.ty_adt_def() {
Some(def) if def.is_union() => {
self.check_op(ops::UnionAccess);
}

_ => {}
if base_ty.is_union() {
self.check_op(ops::UnionAccess);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
}

let base_ty = base.ty(self.body, self.tcx).ty;
if base_ty.ty_adt_def().map_or(false, |adt| adt.is_union()) {
if base_ty.is_union() {
// If we did not hit a `Deref` yet and the overall place use is an assignment, the
// rules are different.
let assign_to_field = !saw_deref
Expand Down
15 changes: 3 additions & 12 deletions compiler/rustc_mir/src/transform/dest_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ use rustc_middle::mir::{
traversal, Body, InlineAsmOperand, Local, LocalKind, Location, Operand, Place, PlaceElem,
Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::TyCtxt;

// Empirical measurements have resulted in some observations:
// - Running on a body with a single block and 500 locals takes barely any time
Expand Down Expand Up @@ -910,17 +910,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindAssignments<'a, 'tcx> {

// Handle the "subtle case" described above by rejecting any `dest` that is or
// projects through a union.
let is_union = |ty: Ty<'_>| {
if let ty::Adt(def, _) = ty.kind() {
if def.is_union() {
return true;
}
}

false
};
let mut place_ty = PlaceTy::from_ty(self.body.local_decls[dest.local].ty);
if is_union(place_ty.ty) {
if place_ty.ty.is_union() {
return;
}
for elem in dest.projection {
Expand All @@ -930,7 +921,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindAssignments<'a, 'tcx> {
}

place_ty = place_ty.projection_ty(self.tcx, elem);
if is_union(place_ty.ty) {
if place_ty.ty.is_union() {
return;
}
}
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_mir/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,9 @@ impl<'tcx> Validator<'_, 'tcx> {

ProjectionElem::Field(..) => {
let base_ty = place_base.ty(self.body, self.tcx).ty;
if let Some(def) = base_ty.ty_adt_def() {
if base_ty.is_union() {
// No promotion of union field accesses.
if def.is_union() {
return Err(Unpromotable);
}
return Err(Unpromotable);
}
}
}
Expand Down
11 changes: 2 additions & 9 deletions compiler/rustc_mir/src/transform/remove_zsts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,14 @@ fn involves_a_union<'tcx>(
tcx: TyCtxt<'tcx>,
) -> bool {
let mut place_ty = PlaceTy::from_ty(local_decls[place.local].ty);
if is_union(place_ty.ty) {
if place_ty.ty.is_union() {
return true;
}
for elem in place.projection {
place_ty = place_ty.projection_ty(tcx, elem);
if is_union(place_ty.ty) {
if place_ty.ty.is_union() {
return true;
}
}
return false;
}

fn is_union(ty: Ty<'_>) -> bool {
match ty.kind() {
ty::Adt(def, _) if def.is_union() => true,
_ => false,
}
}
22 changes: 20 additions & 2 deletions compiler/rustc_mir/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use rustc_middle::mir::interpret::Scalar;
use rustc_middle::mir::traversal;
use rustc_middle::mir::visit::{PlaceContext, Visitor};
use rustc_middle::mir::{
AggregateKind, BasicBlock, Body, BorrowKind, Local, Location, MirPhase, Operand, PlaceRef,
Rvalue, SourceScope, Statement, StatementKind, Terminator, TerminatorKind,
AggregateKind, BasicBlock, Body, BorrowKind, Local, Location, MirPhase, Operand, PlaceElem,
PlaceRef, ProjectionElem, Rvalue, SourceScope, Statement, StatementKind, Terminator,
TerminatorKind,
};
use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeFoldable};
Expand Down Expand Up @@ -217,6 +218,23 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
self.super_operand(operand, location);
}

fn visit_projection_elem(
&mut self,
local: Local,
proj_base: &[PlaceElem<'tcx>],
elem: PlaceElem<'tcx>,
context: PlaceContext,
location: Location,
) {
if let ProjectionElem::Index(index) = elem {
let index_ty = self.body.local_decls[index].ty;
if index_ty != self.tcx.types.usize {
self.fail(location, format!("bad index ({:?} != usize)", index_ty))
}
}
self.super_projection_elem(local, proj_base, elem, context, location);
}

fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
match &statement.kind {
StatementKind::Assign(box (dest, rvalue)) => {
Expand Down
Loading

0 comments on commit a93699f

Please sign in to comment.