Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8196407

Browse files
committedJun 27, 2020
Auto merge of #73766 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] backports This PR backports the following: * Make novel structural match violations not a `bug` #73446 * linker: Never pass `-no-pie` to non-gnu linkers #73384 * Disable the `SimplifyArmIdentity` pass #73262 * Allow inference regions when relating consts #73225 * Fix link error with #[thread_local] introduced by #71192 #73065 * Ensure stack when building MIR for matches #72941 * Don't create impl candidates when obligation contains errors #73005 r? @ghost
2 parents 1dc0f6d + 8e8d53f commit 8196407

File tree

22 files changed

+5449
-279
lines changed

22 files changed

+5449
-279
lines changed
 

‎src/librustc_codegen_ssa/back/linker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl<'a> Linker for GccLinker<'a> {
280280
fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path) {
281281
match output_kind {
282282
LinkOutputKind::DynamicNoPicExe => {
283-
if !self.is_ld {
283+
if !self.is_ld && self.sess.target.target.options.linker_is_gnu {
284284
self.cmd.arg("-no-pie");
285285
}
286286
}
@@ -291,7 +291,7 @@ impl<'a> Linker for GccLinker<'a> {
291291
LinkOutputKind::StaticNoPicExe => {
292292
// `-static` works for both gcc wrapper and ld.
293293
self.cmd.arg("-static");
294-
if !self.is_ld {
294+
if !self.is_ld && self.sess.target.target.options.linker_is_gnu {
295295
self.cmd.arg("-no-pie");
296296
}
297297
}

‎src/librustc_middle/ty/relate.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -508,16 +508,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
508508
debug!("{}.super_relate_consts(a = {:?}, b = {:?})", relation.tag(), a, b);
509509
let tcx = relation.tcx();
510510

511-
let eagerly_eval = |x: &'tcx ty::Const<'tcx>| {
512-
// FIXME(eddyb) this doesn't account for lifetime inference variables
513-
// being erased by `eval`, *nor* for the polymorphic aspect of `eval`.
514-
// That is, we could always use `eval` and it will just return the
515-
// old value back if it doesn't succeed.
516-
if !x.val.needs_infer() {
517-
return x.eval(tcx, relation.param_env()).val;
518-
}
519-
x.val
520-
};
511+
let eagerly_eval = |x: &'tcx ty::Const<'tcx>| x.eval(tcx, relation.param_env()).val;
521512

522513
// FIXME(eddyb) doesn't look like everything below checks that `a.ty == b.ty`.
523514
// We could probably always assert it early, as `const` generic parameters

‎src/librustc_mir/monomorphize/collector.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,14 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
586586
self.output.push(create_fn_mono_item(instance));
587587
}
588588
}
589+
mir::Rvalue::ThreadLocalRef(def_id) => {
590+
assert!(self.tcx.is_thread_local_static(def_id));
591+
let instance = Instance::mono(self.tcx, def_id);
592+
if should_monomorphize_locally(self.tcx, &instance) {
593+
trace!("collecting thread-local static {:?}", def_id);
594+
self.output.push(MonoItem::Static(def_id));
595+
}
596+
}
589597
_ => { /* not interesting */ }
590598
}
591599

‎src/librustc_mir/transform/simplify_try.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,11 @@ fn optimization_applies<'tcx>(
306306
}
307307

308308
impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity {
309-
fn run_pass(&self, _: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) {
309+
fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) {
310+
if tcx.sess.opts.debugging_opts.mir_opt_level < 2 {
311+
return;
312+
}
313+
310314
trace!("running SimplifyArmIdentity on {:?}", source);
311315
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
312316
for bb in basic_blocks {

‎src/librustc_mir_build/build/matches/mod.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};
1010
use crate::build::{BlockAnd, BlockAndExtension, Builder};
1111
use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode};
1212
use crate::hair::{self, *};
13-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
13+
use rustc_data_structures::{fx::{FxHashMap, FxHashSet}, stack::ensure_sufficient_stack};
1414
use rustc_hir::HirId;
1515
use rustc_index::bit_set::BitSet;
1616
use rustc_middle::middle::region;
@@ -909,30 +909,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
909909
split_or_candidate |= self.simplify_candidate(candidate);
910910
}
911911

912-
if split_or_candidate {
913-
// At least one of the candidates has been split into subcandidates.
914-
// We need to change the candidate list to include those.
915-
let mut new_candidates = Vec::new();
912+
ensure_sufficient_stack(|| {
913+
if split_or_candidate {
914+
// At least one of the candidates has been split into subcandidates.
915+
// We need to change the candidate list to include those.
916+
let mut new_candidates = Vec::new();
916917

917-
for candidate in candidates {
918-
candidate.visit_leaves(|leaf_candidate| new_candidates.push(leaf_candidate));
918+
for candidate in candidates {
919+
candidate.visit_leaves(|leaf_candidate| new_candidates.push(leaf_candidate));
920+
}
921+
self.match_simplified_candidates(
922+
span,
923+
start_block,
924+
otherwise_block,
925+
&mut *new_candidates,
926+
fake_borrows,
927+
);
928+
} else {
929+
self.match_simplified_candidates(
930+
span,
931+
start_block,
932+
otherwise_block,
933+
candidates,
934+
fake_borrows,
935+
);
919936
}
920-
self.match_simplified_candidates(
921-
span,
922-
start_block,
923-
otherwise_block,
924-
&mut *new_candidates,
925-
fake_borrows,
926-
);
927-
} else {
928-
self.match_simplified_candidates(
929-
span,
930-
start_block,
931-
otherwise_block,
932-
candidates,
933-
fake_borrows,
934-
);
935-
};
937+
});
936938
}
937939

938940
fn match_simplified_candidates(

‎src/librustc_mir_build/hair/pattern/const_to_pat.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,15 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
107107
cv.ty, structural
108108
);
109109

110+
// This can occur because const qualification treats all associated constants as
111+
// opaque, whereas `search_for_structural_match_violation` tries to monomorphize them
112+
// before it runs.
113+
//
114+
// FIXME(#73448): Find a way to bring const qualification into parity with
115+
// `search_for_structural_match_violation`.
110116
if structural.is_none() && mir_structural_match_violation {
111-
bug!("MIR const-checker found novel structural match violation");
117+
warn!("MIR const-checker found novel structural match violation. See #73448.");
118+
return inlined_const_as_pat;
112119
}
113120

114121
if let Some(non_sm_ty) = structural {

‎src/librustc_trait_selection/traits/select.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11731173
// who might care about this case, like coherence, should use
11741174
// that function).
11751175
if candidates.is_empty() {
1176+
// If there's an error type, 'downgrade' our result from
1177+
// `Err(Unimplemented)` to `Ok(None)`. This helps us avoid
1178+
// emitting additional spurious errors, since we're guaranteed
1179+
// to have emitted at least one.
1180+
if stack.obligation.references_error() {
1181+
debug!("no results for error type, treating as ambiguous");
1182+
return Ok(None);
1183+
}
11761184
return Err(Unimplemented);
11771185
}
11781186

@@ -1697,6 +1705,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16971705
) -> Result<(), SelectionError<'tcx>> {
16981706
debug!("assemble_candidates_from_impls(obligation={:?})", obligation);
16991707

1708+
// Essentially any user-written impl will match with an error type,
1709+
// so creating `ImplCandidates` isn't useful. However, we might
1710+
// end up finding a candidate elsewhere (e.g. a `BuiltinCandidate` for `Sized)
1711+
// This helps us avoid overflow: see issue #72839
1712+
// Since compilation is already guaranteed to fail, this is just
1713+
// to try to show the 'nicest' possible errors to the user.
1714+
if obligation.references_error() {
1715+
return Ok(());
1716+
}
1717+
17001718
self.tcx().for_each_relevant_impl(
17011719
obligation.predicate.def_id(),
17021720
obligation.predicate.skip_binder().trait_ref.self_ty(),

‎src/test/mir-opt/simplify-arm/rustc.id.SimplifyArmIdentity.diff

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@
2626
}
2727

2828
bb3: {
29-
- StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
30-
- _3 = ((_1 as Some).0: u8); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
31-
- StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
32-
- _4 = _3; // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
33-
- ((_0 as Some).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
34-
- discriminant(_0) = 1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
35-
- StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27
36-
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:27: 11:28
37-
+ _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
29+
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
30+
_3 = ((_1 as Some).0: u8); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
31+
StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
32+
_4 = _3; // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
33+
((_0 as Some).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
34+
discriminant(_0) = 1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
35+
StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27
36+
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:27: 11:28
3837
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
3938
}
4039

‎src/test/mir-opt/simplify-arm/rustc.id.SimplifyBranchSame.diff

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@
2626
}
2727

2828
bb3: {
29-
_0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
29+
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
30+
_3 = ((_1 as Some).0: u8); // scope 0 at $DIR/simplify-arm.rs:11:14: 11:15
31+
StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
32+
_4 = _3; // scope 1 at $DIR/simplify-arm.rs:11:25: 11:26
33+
((_0 as Some).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
34+
discriminant(_0) = 1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
35+
StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27
36+
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:27: 11:28
3037
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
3138
}
3239

‎src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyArmIdentity.diff

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222
}
2323

2424
bb1: {
25-
- StorageLive(_5); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
26-
- _5 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
27-
- StorageLive(_6); // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
28-
- _6 = _5; // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
29-
- ((_0 as Err).0: i32) = move _6; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
30-
- discriminant(_0) = 1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
31-
- StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25
32-
- StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:25: 19:26
33-
+ _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
25+
StorageLive(_5); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
26+
_5 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
27+
StorageLive(_6); // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
28+
_6 = _5; // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
29+
((_0 as Err).0: i32) = move _6; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
30+
discriminant(_0) = 1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
31+
StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25
32+
StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:25: 19:26
3433
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
3534
}
3635

@@ -39,15 +38,14 @@
3938
}
4039

4140
bb3: {
42-
- StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
43-
- _3 = ((_1 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
44-
- StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
45-
- _4 = _3; // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
46-
- ((_0 as Ok).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
47-
- discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
48-
- StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23
49-
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:23: 18:24
50-
+ _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
41+
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
42+
_3 = ((_1 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
43+
StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
44+
_4 = _3; // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
45+
((_0 as Ok).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
46+
discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
47+
StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23
48+
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:23: 18:24
5149
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
5250
}
5351

‎src/test/mir-opt/simplify-arm/rustc.id_result.SimplifyBranchSame.diff

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,38 @@
1818

1919
bb0: {
2020
_2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14
21-
- switchInt(move _2) -> [0isize: bb3, 1isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14
22-
+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14
21+
switchInt(move _2) -> [0isize: bb3, 1isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14
2322
}
2423

2524
bb1: {
26-
- _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
27-
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
28-
- }
29-
-
30-
- bb2: {
31-
- unreachable; // scope 0 at $DIR/simplify-arm.rs:17:11: 17:12
32-
- }
33-
-
34-
- bb3: {
35-
_0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
36-
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
37-
+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
25+
StorageLive(_5); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
26+
_5 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:19:13: 19:14
27+
StorageLive(_6); // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
28+
_6 = _5; // scope 2 at $DIR/simplify-arm.rs:19:23: 19:24
29+
((_0 as Err).0: i32) = move _6; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
30+
discriminant(_0) = 1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25
31+
StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25
32+
StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:25: 19:26
33+
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
3834
}
3935

40-
- bb4: {
41-
+ bb2: {
36+
bb2: {
37+
unreachable; // scope 0 at $DIR/simplify-arm.rs:17:11: 17:12
38+
}
39+
40+
bb3: {
41+
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
42+
_3 = ((_1 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:18:12: 18:13
43+
StorageLive(_4); // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
44+
_4 = _3; // scope 1 at $DIR/simplify-arm.rs:18:21: 18:22
45+
((_0 as Ok).0: u8) = move _4; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
46+
discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23
47+
StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23
48+
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:23: 18:24
49+
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6
50+
}
51+
52+
bb4: {
4253
return; // scope 0 at $DIR/simplify-arm.rs:21:2: 21:2
4354
}
4455
}

‎src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyArmIdentity.diff

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,16 @@
4949
}
5050

5151
bb2: {
52-
- StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
53-
- _10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
54-
- _2 = _10; // scope 5 at $DIR/simplify-arm.rs:24:13: 24:15
55-
- StorageDead(_10); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
56-
+ _0 = move _3; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
52+
StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
53+
_10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
54+
_2 = _10; // scope 5 at $DIR/simplify-arm.rs:24:13: 24:15
55+
StorageDead(_10); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
5756
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
58-
- StorageLive(_11); // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
59-
- _11 = _2; // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
60-
- ((_0 as Ok).0: u8) = move _11; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
61-
- discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
62-
- StorageDead(_11); // scope 1 at $DIR/simplify-arm.rs:25:9: 25:10
57+
StorageLive(_11); // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
58+
_11 = _2; // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
59+
((_0 as Ok).0: u8) = move _11; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
60+
discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
61+
StorageDead(_11); // scope 1 at $DIR/simplify-arm.rs:25:9: 25:10
6362
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
6463
goto -> bb5; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
6564
}

‎src/test/mir-opt/simplify-arm/rustc.id_try.SimplifyBranchSame.diff

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,16 @@
4949
}
5050

5151
bb2: {
52-
_0 = move _3; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
52+
StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
53+
_10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
54+
_2 = _10; // scope 5 at $DIR/simplify-arm.rs:24:13: 24:15
55+
StorageDead(_10); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
5356
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
57+
StorageLive(_11); // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
58+
_11 = _2; // scope 1 at $DIR/simplify-arm.rs:25:8: 25:9
59+
((_0 as Ok).0: u8) = move _11; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
60+
discriminant(_0) = 0; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
61+
StorageDead(_11); // scope 1 at $DIR/simplify-arm.rs:25:9: 25:10
5462
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
5563
goto -> bb5; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
5664
}

‎src/test/mir-opt/simplify_try_if_let/rustc.{{impl}}-append.SimplifyArmIdentity.diff

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,11 @@
8080
StorageLive(_8); // scope 1 at $DIR/simplify_try_if_let.rs:26:29: 26:39
8181
_8 = ((_5 as Some).0: std::ptr::NonNull<Node>); // scope 1 at $DIR/simplify_try_if_let.rs:26:29: 26:39
8282
StorageLive(_9); // scope 3 at $DIR/simplify_try_if_let.rs:28:46: 28:62
83-
- StorageLive(_10); // scope 3 at $DIR/simplify_try_if_let.rs:28:51: 28:61
84-
- _10 = _8; // scope 3 at $DIR/simplify_try_if_let.rs:28:51: 28:61
85-
- ((_9 as Some).0: std::ptr::NonNull<Node>) = move _10; // scope 3 at $DIR/simplify_try_if_let.rs:28:46: 28:62
86-
- discriminant(_9) = 1; // scope 3 at $DIR/simplify_try_if_let.rs:28:46: 28:62
87-
- StorageDead(_10); // scope 3 at $DIR/simplify_try_if_let.rs:28:61: 28:62
88-
+ _9 = move _5; // scope 3 at $DIR/simplify_try_if_let.rs:28:46: 28:62
83+
StorageLive(_10); // scope 3 at $DIR/simplify_try_if_let.rs:28:51: 28:61
84+
_10 = _8; // scope 3 at $DIR/simplify_try_if_let.rs:28:51: 28:61
85+
((_9 as Some).0: std::ptr::NonNull<Node>) = move _10; // scope 3 at $DIR/simplify_try_if_let.rs:28:46: 28:62
86+
discriminant(_9) = 1; // scope 3 at $DIR/simplify_try_if_let.rs:28:46: 28:62
87+
StorageDead(_10); // scope 3 at $DIR/simplify_try_if_let.rs:28:61: 28:62
8988
StorageLive(_11); // scope 3 at $DIR/simplify_try_if_let.rs:28:25: 28:38
9089
StorageLive(_12); // scope 3 at $DIR/simplify_try_if_let.rs:28:25: 28:29
9190
_12 = &mut _4; // scope 3 at $DIR/simplify_try_if_let.rs:28:25: 28:29
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check-pass
2+
// edition:2018
3+
4+
#[allow(unused)]
5+
async fn foo<'a>() {
6+
let _data = &mut [0u8; { 1 + 4 }];
7+
bar().await
8+
}
9+
10+
async fn bar() {}
11+
12+
fn main() {}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// run-pass
2+
3+
// Regression test for https://github.com/rust-lang/rust/issues/73431.
4+
5+
pub trait Zero {
6+
const ZERO: Self;
7+
}
8+
9+
impl Zero for usize {
10+
const ZERO: Self = 0;
11+
}
12+
13+
impl<T: Zero> Zero for Wrapper<T> {
14+
const ZERO: Self = Wrapper(T::ZERO);
15+
}
16+
17+
#[derive(Debug, PartialEq, Eq)]
18+
pub struct Wrapper<T>(T);
19+
20+
fn is_zero(x: Wrapper<usize>) -> bool {
21+
match x {
22+
Zero::ZERO => true,
23+
_ => false,
24+
}
25+
}
26+
27+
fn main() {
28+
let _ = is_zero(Wrapper(42));
29+
}

‎src/test/ui/impl-trait/auto-trait-leak.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ fn main() {
1111
// return type, which can't depend on the obligation.
1212
fn cycle1() -> impl Clone {
1313
//~^ ERROR cycle detected
14-
//~| ERROR cycle detected
15-
//~| ERROR cycle detected
1614
send(cycle2().clone());
1715
//~^ ERROR cannot be sent between threads safely
1816

‎src/test/ui/impl-trait/auto-trait-leak.stderr

Lines changed: 9 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,37 @@ LL | fn cycle1() -> impl Clone {
3636
| ^^^^^^^^^^^^^^^^^^^^^^^^^
3737
= note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
3838
note: ...which requires computing type of `cycle2::{{opaque}}#0`...
39-
--> $DIR/auto-trait-leak.rs:22:16
39+
--> $DIR/auto-trait-leak.rs:20:16
4040
|
4141
LL | fn cycle2() -> impl Clone {
4242
| ^^^^^^^^^^
4343
note: ...which requires borrow-checking `cycle2`...
44-
--> $DIR/auto-trait-leak.rs:22:1
44+
--> $DIR/auto-trait-leak.rs:20:1
4545
|
4646
LL | fn cycle2() -> impl Clone {
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^
4848
note: ...which requires processing `cycle2`...
49-
--> $DIR/auto-trait-leak.rs:22:1
49+
--> $DIR/auto-trait-leak.rs:20:1
5050
|
5151
LL | fn cycle2() -> impl Clone {
5252
| ^^^^^^^^^^^^^^^^^^^^^^^^^
5353
note: ...which requires processing MIR for `cycle2`...
54-
--> $DIR/auto-trait-leak.rs:22:1
54+
--> $DIR/auto-trait-leak.rs:20:1
5555
|
5656
LL | fn cycle2() -> impl Clone {
5757
| ^^^^^^^^^^^^^^^^^^^^^^^^^
5858
note: ...which requires unsafety-checking `cycle2`...
59-
--> $DIR/auto-trait-leak.rs:22:1
59+
--> $DIR/auto-trait-leak.rs:20:1
6060
|
6161
LL | fn cycle2() -> impl Clone {
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6363
note: ...which requires building MIR for `cycle2`...
64-
--> $DIR/auto-trait-leak.rs:22:1
64+
--> $DIR/auto-trait-leak.rs:20:1
6565
|
6666
LL | fn cycle2() -> impl Clone {
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6868
note: ...which requires type-checking `cycle2`...
69-
--> $DIR/auto-trait-leak.rs:22:1
69+
--> $DIR/auto-trait-leak.rs:20:1
7070
|
7171
LL | fn cycle2() -> impl Clone {
7272
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -84,178 +84,8 @@ LL | | Rc::new(String::from("foo"))
8484
LL | | }
8585
| |_^
8686

87-
error[E0391]: cycle detected when computing type of `cycle1::{{opaque}}#0`
88-
--> $DIR/auto-trait-leak.rs:12:16
89-
|
90-
LL | fn cycle1() -> impl Clone {
91-
| ^^^^^^^^^^
92-
|
93-
note: ...which requires borrow-checking `cycle1`...
94-
--> $DIR/auto-trait-leak.rs:12:1
95-
|
96-
LL | fn cycle1() -> impl Clone {
97-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
98-
note: ...which requires processing `cycle1`...
99-
--> $DIR/auto-trait-leak.rs:12:1
100-
|
101-
LL | fn cycle1() -> impl Clone {
102-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
103-
note: ...which requires processing MIR for `cycle1`...
104-
--> $DIR/auto-trait-leak.rs:12:1
105-
|
106-
LL | fn cycle1() -> impl Clone {
107-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
108-
note: ...which requires unsafety-checking `cycle1`...
109-
--> $DIR/auto-trait-leak.rs:12:1
110-
|
111-
LL | fn cycle1() -> impl Clone {
112-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
113-
note: ...which requires building MIR for `cycle1`...
114-
--> $DIR/auto-trait-leak.rs:12:1
115-
|
116-
LL | fn cycle1() -> impl Clone {
117-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
118-
note: ...which requires type-checking `cycle1`...
119-
--> $DIR/auto-trait-leak.rs:12:1
120-
|
121-
LL | fn cycle1() -> impl Clone {
122-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
123-
= note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
124-
note: ...which requires computing type of `cycle2::{{opaque}}#0`...
125-
--> $DIR/auto-trait-leak.rs:22:16
126-
|
127-
LL | fn cycle2() -> impl Clone {
128-
| ^^^^^^^^^^
129-
note: ...which requires borrow-checking `cycle2`...
130-
--> $DIR/auto-trait-leak.rs:22:1
131-
|
132-
LL | fn cycle2() -> impl Clone {
133-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
134-
note: ...which requires processing `cycle2`...
135-
--> $DIR/auto-trait-leak.rs:22:1
136-
|
137-
LL | fn cycle2() -> impl Clone {
138-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
139-
note: ...which requires processing MIR for `cycle2`...
140-
--> $DIR/auto-trait-leak.rs:22:1
141-
|
142-
LL | fn cycle2() -> impl Clone {
143-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
144-
note: ...which requires unsafety-checking `cycle2`...
145-
--> $DIR/auto-trait-leak.rs:22:1
146-
|
147-
LL | fn cycle2() -> impl Clone {
148-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
149-
note: ...which requires building MIR for `cycle2`...
150-
--> $DIR/auto-trait-leak.rs:22:1
151-
|
152-
LL | fn cycle2() -> impl Clone {
153-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
154-
note: ...which requires type-checking `cycle2`...
155-
--> $DIR/auto-trait-leak.rs:22:1
156-
|
157-
LL | fn cycle2() -> impl Clone {
158-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
159-
= note: ...which again requires computing type of `cycle1::{{opaque}}#0`, completing the cycle
160-
note: cycle used when checking item types in top-level module
161-
--> $DIR/auto-trait-leak.rs:1:1
162-
|
163-
LL | / use std::cell::Cell;
164-
LL | | use std::rc::Rc;
165-
LL | |
166-
LL | | fn send<T: Send>(_: T) {}
167-
... |
168-
LL | | Rc::new(String::from("foo"))
169-
LL | | }
170-
| |_^
171-
172-
error[E0391]: cycle detected when computing type of `cycle1::{{opaque}}#0`
173-
--> $DIR/auto-trait-leak.rs:12:16
174-
|
175-
LL | fn cycle1() -> impl Clone {
176-
| ^^^^^^^^^^
177-
|
178-
note: ...which requires borrow-checking `cycle1`...
179-
--> $DIR/auto-trait-leak.rs:12:1
180-
|
181-
LL | fn cycle1() -> impl Clone {
182-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
183-
note: ...which requires processing `cycle1`...
184-
--> $DIR/auto-trait-leak.rs:12:1
185-
|
186-
LL | fn cycle1() -> impl Clone {
187-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
188-
note: ...which requires processing MIR for `cycle1`...
189-
--> $DIR/auto-trait-leak.rs:12:1
190-
|
191-
LL | fn cycle1() -> impl Clone {
192-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
193-
note: ...which requires unsafety-checking `cycle1`...
194-
--> $DIR/auto-trait-leak.rs:12:1
195-
|
196-
LL | fn cycle1() -> impl Clone {
197-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
198-
note: ...which requires building MIR for `cycle1`...
199-
--> $DIR/auto-trait-leak.rs:12:1
200-
|
201-
LL | fn cycle1() -> impl Clone {
202-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
203-
note: ...which requires type-checking `cycle1`...
204-
--> $DIR/auto-trait-leak.rs:12:1
205-
|
206-
LL | fn cycle1() -> impl Clone {
207-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
208-
= note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
209-
note: ...which requires computing type of `cycle2::{{opaque}}#0`...
210-
--> $DIR/auto-trait-leak.rs:22:16
211-
|
212-
LL | fn cycle2() -> impl Clone {
213-
| ^^^^^^^^^^
214-
note: ...which requires borrow-checking `cycle2`...
215-
--> $DIR/auto-trait-leak.rs:22:1
216-
|
217-
LL | fn cycle2() -> impl Clone {
218-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
219-
note: ...which requires processing `cycle2`...
220-
--> $DIR/auto-trait-leak.rs:22:1
221-
|
222-
LL | fn cycle2() -> impl Clone {
223-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
224-
note: ...which requires processing MIR for `cycle2`...
225-
--> $DIR/auto-trait-leak.rs:22:1
226-
|
227-
LL | fn cycle2() -> impl Clone {
228-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
229-
note: ...which requires unsafety-checking `cycle2`...
230-
--> $DIR/auto-trait-leak.rs:22:1
231-
|
232-
LL | fn cycle2() -> impl Clone {
233-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
234-
note: ...which requires building MIR for `cycle2`...
235-
--> $DIR/auto-trait-leak.rs:22:1
236-
|
237-
LL | fn cycle2() -> impl Clone {
238-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
239-
note: ...which requires type-checking `cycle2`...
240-
--> $DIR/auto-trait-leak.rs:22:1
241-
|
242-
LL | fn cycle2() -> impl Clone {
243-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
244-
= note: ...which again requires computing type of `cycle1::{{opaque}}#0`, completing the cycle
245-
note: cycle used when checking item types in top-level module
246-
--> $DIR/auto-trait-leak.rs:1:1
247-
|
248-
LL | / use std::cell::Cell;
249-
LL | | use std::rc::Rc;
250-
LL | |
251-
LL | | fn send<T: Send>(_: T) {}
252-
... |
253-
LL | | Rc::new(String::from("foo"))
254-
LL | | }
255-
| |_^
256-
25787
error[E0277]: `std::rc::Rc<std::string::String>` cannot be sent between threads safely
258-
--> $DIR/auto-trait-leak.rs:16:5
88+
--> $DIR/auto-trait-leak.rs:14:5
25989
|
26090
LL | fn send<T: Send>(_: T) {}
26191
| ---- required by this bound in `send`
@@ -269,7 +99,7 @@ LL | fn cycle2() -> impl Clone {
26999
= help: within `impl std::clone::Clone`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::string::String>`
270100
= note: required because it appears within the type `impl std::clone::Clone`
271101

272-
error: aborting due to 4 previous errors
102+
error: aborting due to 2 previous errors
273103

274104
Some errors have detailed explanations: E0277, E0391.
275105
For more information about an error, try `rustc --explain E0277`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Regression test for issue #72839
2+
// Tests that we do not overflow during trait selection after
3+
// a type error occurs
4+
use std::ops::Rem;
5+
trait Foo {}
6+
struct MyStruct<T>(T);
7+
8+
impl<T, U> Rem<MyStruct<T>> for MyStruct<U> where MyStruct<U>: Rem<MyStruct<T>> {
9+
type Output = u8;
10+
fn rem(self, _: MyStruct<T>) -> Self::Output {
11+
panic!()
12+
}
13+
}
14+
15+
fn main() {}
16+
17+
fn foo() {
18+
if missing_var % 8 == 0 {} //~ ERROR cannot find
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0425]: cannot find value `missing_var` in this scope
2+
--> $DIR/issue-72839-error-overflow.rs:18:8
3+
|
4+
LL | if missing_var % 8 == 0 {}
5+
| ^^^^^^^^^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0425`.

‎src/test/ui/issues/issue-72933-match-stack-overflow.rs

Lines changed: 5208 additions & 0 deletions
Large diffs are not rendered by default.

‎src/test/ui/tls.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-pass
2+
// ignore-emscripten no threads support
3+
// compile-flags: -O
4+
5+
#![feature(thread_local)]
6+
7+
#[thread_local]
8+
static S: u32 = 222;
9+
10+
fn main() {
11+
let local = &S as *const u32 as usize;
12+
let foreign = std::thread::spawn(|| &S as *const u32 as usize).join().unwrap();
13+
assert_ne!(local, foreign);
14+
}

0 commit comments

Comments
 (0)
Please sign in to comment.