Skip to content

Commit a93699f

Browse files
committed
Auto merge of #85952 - JohnTitor:rollup-r00gu9q, r=JohnTitor
Rollup of 13 pull requests Successful merges: - #83362 (Stabilize `vecdeque_binary_search`) - #85706 (Turn off frame pointer elimination on all Apple platforms. ) - #85724 (Fix issue 85435 by restricting Fake Read precision) - #85852 (Clarify meaning of MachineApplicable suggestions.) - #85877 (Intra doc link-ify a reference to a function) - #85880 (convert assertion on rvalue::threadlocalref to delay bug) - #85896 (Add test for forward declared const param defaults) - #85897 (Update I-unsound label for triagebot) - #85900 (Use pattern matching instead of checking lengths explicitly) - #85911 (Avoid a clone of output_filenames.) - #85926 (Update cargo) - #85934 (Add `Ty::is_union` predicate) - #85935 (Validate type of locals used as indices) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 016e9b5 + 0cdbb7d commit a93699f

File tree

36 files changed

+228
-134
lines changed

36 files changed

+228
-134
lines changed

Cargo.lock

+22-3
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ dependencies = [
278278
"humantime 2.0.1",
279279
"ignore",
280280
"im-rc",
281+
"itertools 0.10.0",
281282
"jobserver",
282283
"lazy_static",
283284
"lazycell",
@@ -293,7 +294,7 @@ dependencies = [
293294
"rand 0.8.3",
294295
"rustc-workspace-hack",
295296
"rustfix",
296-
"semver 0.10.0",
297+
"semver 1.0.1",
297298
"serde",
298299
"serde_ignored",
299300
"serde_json",
@@ -1715,6 +1716,15 @@ dependencies = [
17151716
"either",
17161717
]
17171718

1719+
[[package]]
1720+
name = "itertools"
1721+
version = "0.10.0"
1722+
source = "registry+https://github.com/rust-lang/crates.io-index"
1723+
checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319"
1724+
dependencies = [
1725+
"either",
1726+
]
1727+
17181728
[[package]]
17191729
name = "itoa"
17201730
version = "0.4.6"
@@ -4674,6 +4684,15 @@ dependencies = [
46744684
"serde",
46754685
]
46764686

4687+
[[package]]
4688+
name = "semver"
4689+
version = "1.0.1"
4690+
source = "registry+https://github.com/rust-lang/crates.io-index"
4691+
checksum = "d023dabf011d5dcb5ac64e3685d97d3b0ef412911077a2851455c6098524a723"
4692+
dependencies = [
4693+
"serde",
4694+
]
4695+
46774696
[[package]]
46784697
name = "semver-parser"
46794698
version = "0.7.0"
@@ -5033,9 +5052,9 @@ dependencies = [
50335052

50345053
[[package]]
50355054
name = "tar"
5036-
version = "0.4.33"
5055+
version = "0.4.35"
50375056
source = "registry+https://github.com/rust-lang/crates.io-index"
5038-
checksum = "c0bcfbd6a598361fda270d82469fff3d65089dc33e175c9a131f7b4cd395f228"
5057+
checksum = "7d779dc6aeff029314570f666ec83f19df7280bb36ef338442cfa8c604021b80"
50395058
dependencies = [
50405059
"filetime",
50415060
"libc",

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ pub fn create_global_ctxt<'tcx>(
799799
query_result_on_disk_cache,
800800
queries.as_dyn(),
801801
&crate_name,
802-
&outputs,
802+
outputs,
803803
)
804804
})
805805
});

compiler/rustc_lint/src/types.rs

+7-19
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ use rustc_data_structures::fx::FxHashSet;
55
use rustc_errors::Applicability;
66
use rustc_hir as hir;
77
use rustc_hir::{is_range_literal, ExprKind, Node};
8-
use rustc_index::vec::Idx;
98
use rustc_middle::ty::layout::{IntegerExt, SizeSkeleton};
109
use rustc_middle::ty::subst::SubstsRef;
1110
use rustc_middle::ty::{self, AdtKind, Ty, TyCtxt, TypeFoldable};
1211
use rustc_span::source_map;
1312
use rustc_span::symbol::sym;
1413
use rustc_span::{Span, DUMMY_SP};
1514
use rustc_target::abi::Abi;
16-
use rustc_target::abi::{Integer, LayoutOf, TagEncoding, VariantIdx, Variants};
15+
use rustc_target::abi::{Integer, LayoutOf, TagEncoding, Variants};
1716
use rustc_target::spec::abi::Abi as SpecAbi;
1817

1918
use std::cmp;
@@ -783,25 +782,14 @@ crate fn repr_nullable_ptr<'tcx>(
783782
) -> Option<Ty<'tcx>> {
784783
debug!("is_repr_nullable_ptr(cx, ty = {:?})", ty);
785784
if let ty::Adt(ty_def, substs) = ty.kind() {
786-
if ty_def.variants.len() != 2 {
787-
return None;
788-
}
789-
790-
let get_variant_fields = |index| &ty_def.variants[VariantIdx::new(index)].fields;
791-
let variant_fields = [get_variant_fields(0), get_variant_fields(1)];
792-
let fields = if variant_fields[0].is_empty() {
793-
&variant_fields[1]
794-
} else if variant_fields[1].is_empty() {
795-
&variant_fields[0]
796-
} else {
797-
return None;
785+
let field_ty = match &ty_def.variants.raw[..] {
786+
[var_one, var_two] => match (&var_one.fields[..], &var_two.fields[..]) {
787+
([], [field]) | ([field], []) => field.ty(cx.tcx, substs),
788+
_ => return None,
789+
},
790+
_ => return None,
798791
};
799792

800-
if fields.len() != 1 {
801-
return None;
802-
}
803-
804-
let field_ty = fields[0].ty(cx.tcx, substs);
805793
if !ty_is_known_nonnull(cx, field_ty, ckind) {
806794
return None;
807795
}

compiler/rustc_lint_defs/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ macro_rules! pluralize {
2525
/// before applying the suggestion.
2626
#[derive(Copy, Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
2727
pub enum Applicability {
28-
/// The suggestion is definitely what the user intended. This suggestion should be
28+
/// The suggestion is definitely what the user intended, or maintains the exact meaning of the code.
29+
/// This suggestion should be automatically applied.
30+
///
31+
/// In case of multiple `MachineApplicable` suggestions (whether as part of
32+
/// the same `multipart_suggestion` or not), all of them should be
2933
/// automatically applied.
3034
MachineApplicable,
3135

compiler/rustc_middle/src/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ impl<'tcx> TyCtxt<'tcx> {
11351135
on_disk_cache: Option<query::OnDiskCache<'tcx>>,
11361136
queries: &'tcx dyn query::QueryEngine<'tcx>,
11371137
crate_name: &str,
1138-
output_filenames: &OutputFilenames,
1138+
output_filenames: OutputFilenames,
11391139
) -> GlobalCtxt<'tcx> {
11401140
let data_layout = TargetDataLayout::parse(&s.target).unwrap_or_else(|err| {
11411141
s.fatal(&err);
@@ -1179,7 +1179,7 @@ impl<'tcx> TyCtxt<'tcx> {
11791179
stability_interner: Default::default(),
11801180
const_stability_interner: Default::default(),
11811181
alloc_map: Lock::new(interpret::AllocMap::new()),
1182-
output_filenames: Arc::new(output_filenames.clone()),
1182+
output_filenames: Arc::new(output_filenames),
11831183
main_def: resolutions.main_def,
11841184
}
11851185
}

compiler/rustc_middle/src/ty/sty.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1837,10 +1837,12 @@ impl<'tcx> TyS<'tcx> {
18371837

18381838
#[inline]
18391839
pub fn is_enum(&self) -> bool {
1840-
match self.kind() {
1841-
Adt(adt_def, _) => adt_def.is_enum(),
1842-
_ => false,
1843-
}
1840+
matches!(self.kind(), Adt(adt_def, _) if adt_def.is_enum())
1841+
}
1842+
1843+
#[inline]
1844+
pub fn is_union(&self) -> bool {
1845+
matches!(self.kind(), Adt(adt_def, _) if adt_def.is_union())
18441846
}
18451847

18461848
#[inline]

compiler/rustc_mir/src/borrow_check/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1965,13 +1965,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19651965
// no move out from an earlier location) then this is an attempt at initialization
19661966
// of the union - we should error in that case.
19671967
let tcx = this.infcx.tcx;
1968-
if let ty::Adt(def, _) = base.ty(this.body(), tcx).ty.kind() {
1969-
if def.is_union() {
1970-
if this.move_data.path_map[mpi].iter().any(|moi| {
1971-
this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
1972-
}) {
1973-
return;
1974-
}
1968+
if base.ty(this.body(), tcx).ty.is_union() {
1969+
if this.move_data.path_map[mpi].iter().any(|moi| {
1970+
this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
1971+
}) {
1972+
return;
19751973
}
19761974
}
19771975

compiler/rustc_mir/src/borrow_check/places_conflict.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,14 @@ fn place_projection_conflict<'tcx>(
331331
Overlap::EqualOrDisjoint
332332
} else {
333333
let ty = Place::ty_from(pi1_local, pi1_proj_base, body, tcx).ty;
334-
match ty.kind() {
335-
ty::Adt(def, _) if def.is_union() => {
336-
// Different fields of a union, we are basically stuck.
337-
debug!("place_element_conflict: STUCK-UNION");
338-
Overlap::Arbitrary
339-
}
340-
_ => {
341-
// Different fields of a struct (`a.x` vs. `a.y`). Disjoint!
342-
debug!("place_element_conflict: DISJOINT-FIELD");
343-
Overlap::Disjoint
344-
}
334+
if ty.is_union() {
335+
// Different fields of a union, we are basically stuck.
336+
debug!("place_element_conflict: STUCK-UNION");
337+
Overlap::Arbitrary
338+
} else {
339+
// Different fields of a struct (`a.x` vs. `a.y`). Disjoint!
340+
debug!("place_element_conflict: DISJOINT-FIELD");
341+
Overlap::Disjoint
345342
}
346343
}
347344
}

compiler/rustc_mir/src/dataflow/move_paths/builder.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
519519
// Check if we are assigning into a field of a union, if so, lookup the place
520520
// of the union so it is marked as initialized again.
521521
if let Some((place_base, ProjectionElem::Field(_, _))) = place.last_projection() {
522-
if let ty::Adt(def, _) = place_base.ty(self.builder.body, self.builder.tcx).ty.kind() {
523-
if def.is_union() {
524-
place = place_base;
525-
}
522+
if place_base.ty(self.builder.body, self.builder.tcx).ty.is_union() {
523+
place = place_base;
526524
}
527525
}
528526

compiler/rustc_mir/src/transform/check_consts/validation.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,9 @@ impl Validator<'mir, 'tcx> {
356356
}
357357

358358
fn check_static(&mut self, def_id: DefId, span: Span) {
359-
assert!(
360-
!self.tcx.is_thread_local_static(def_id),
361-
"tls access is checked in `Rvalue::ThreadLocalRef"
362-
);
359+
if self.tcx.is_thread_local_static(def_id) {
360+
self.tcx.sess.delay_span_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef");
361+
}
363362
self.check_op_spanned(ops::StaticAccess, span)
364363
}
365364

@@ -753,12 +752,8 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
753752
| ProjectionElem::Field(..)
754753
| ProjectionElem::Index(_) => {
755754
let base_ty = Place::ty_from(place_local, proj_base, self.body, self.tcx).ty;
756-
match base_ty.ty_adt_def() {
757-
Some(def) if def.is_union() => {
758-
self.check_op(ops::UnionAccess);
759-
}
760-
761-
_ => {}
755+
if base_ty.is_union() {
756+
self.check_op(ops::UnionAccess);
762757
}
763758
}
764759
}

compiler/rustc_mir/src/transform/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
221221
}
222222

223223
let base_ty = base.ty(self.body, self.tcx).ty;
224-
if base_ty.ty_adt_def().map_or(false, |adt| adt.is_union()) {
224+
if base_ty.is_union() {
225225
// If we did not hit a `Deref` yet and the overall place use is an assignment, the
226226
// rules are different.
227227
let assign_to_field = !saw_deref

compiler/rustc_mir/src/transform/dest_prop.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ use rustc_middle::mir::{
114114
traversal, Body, InlineAsmOperand, Local, LocalKind, Location, Operand, Place, PlaceElem,
115115
Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
116116
};
117-
use rustc_middle::ty::{self, Ty, TyCtxt};
117+
use rustc_middle::ty::TyCtxt;
118118

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

911911
// Handle the "subtle case" described above by rejecting any `dest` that is or
912912
// projects through a union.
913-
let is_union = |ty: Ty<'_>| {
914-
if let ty::Adt(def, _) = ty.kind() {
915-
if def.is_union() {
916-
return true;
917-
}
918-
}
919-
920-
false
921-
};
922913
let mut place_ty = PlaceTy::from_ty(self.body.local_decls[dest.local].ty);
923-
if is_union(place_ty.ty) {
914+
if place_ty.ty.is_union() {
924915
return;
925916
}
926917
for elem in dest.projection {
@@ -930,7 +921,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindAssignments<'a, 'tcx> {
930921
}
931922

932923
place_ty = place_ty.projection_ty(self.tcx, elem);
933-
if is_union(place_ty.ty) {
924+
if place_ty.ty.is_union() {
934925
return;
935926
}
936927
}

compiler/rustc_mir/src/transform/promote_consts.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,9 @@ impl<'tcx> Validator<'_, 'tcx> {
415415

416416
ProjectionElem::Field(..) => {
417417
let base_ty = place_base.ty(self.body, self.tcx).ty;
418-
if let Some(def) = base_ty.ty_adt_def() {
418+
if base_ty.is_union() {
419419
// No promotion of union field accesses.
420-
if def.is_union() {
421-
return Err(Unpromotable);
422-
}
420+
return Err(Unpromotable);
423421
}
424422
}
425423
}

compiler/rustc_mir/src/transform/remove_zsts.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,14 @@ fn involves_a_union<'tcx>(
6969
tcx: TyCtxt<'tcx>,
7070
) -> bool {
7171
let mut place_ty = PlaceTy::from_ty(local_decls[place.local].ty);
72-
if is_union(place_ty.ty) {
72+
if place_ty.ty.is_union() {
7373
return true;
7474
}
7575
for elem in place.projection {
7676
place_ty = place_ty.projection_ty(tcx, elem);
77-
if is_union(place_ty.ty) {
77+
if place_ty.ty.is_union() {
7878
return true;
7979
}
8080
}
8181
return false;
8282
}
83-
84-
fn is_union(ty: Ty<'_>) -> bool {
85-
match ty.kind() {
86-
ty::Adt(def, _) if def.is_union() => true,
87-
_ => false,
88-
}
89-
}

compiler/rustc_mir/src/transform/validate.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use rustc_middle::mir::interpret::Scalar;
1111
use rustc_middle::mir::traversal;
1212
use rustc_middle::mir::visit::{PlaceContext, Visitor};
1313
use rustc_middle::mir::{
14-
AggregateKind, BasicBlock, Body, BorrowKind, Local, Location, MirPhase, Operand, PlaceRef,
15-
Rvalue, SourceScope, Statement, StatementKind, Terminator, TerminatorKind,
14+
AggregateKind, BasicBlock, Body, BorrowKind, Local, Location, MirPhase, Operand, PlaceElem,
15+
PlaceRef, ProjectionElem, Rvalue, SourceScope, Statement, StatementKind, Terminator,
16+
TerminatorKind,
1617
};
1718
use rustc_middle::ty::fold::BottomUpFolder;
1819
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeFoldable};
@@ -217,6 +218,23 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
217218
self.super_operand(operand, location);
218219
}
219220

221+
fn visit_projection_elem(
222+
&mut self,
223+
local: Local,
224+
proj_base: &[PlaceElem<'tcx>],
225+
elem: PlaceElem<'tcx>,
226+
context: PlaceContext,
227+
location: Location,
228+
) {
229+
if let ProjectionElem::Index(index) = elem {
230+
let index_ty = self.body.local_decls[index].ty;
231+
if index_ty != self.tcx.types.usize {
232+
self.fail(location, format!("bad index ({:?} != usize)", index_ty))
233+
}
234+
}
235+
self.super_projection_elem(local, proj_base, elem, context, location);
236+
}
237+
220238
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
221239
match &statement.kind {
222240
StatementKind::Assign(box (dest, rvalue)) => {

0 commit comments

Comments
 (0)