Skip to content

Commit 1be38e0

Browse files
committed
MIR: Fix value moved diagnose messages
MIR: adopt borrowck test Fix trailing whitespace span_bug! on unexpected action Make RegionVid use newtype_index! Closes #45843 Check rvalue aggregates during check_stmt in tycheck, add initial, (not passing) test Fix failing test Remove attributes and test comments accidentally left behind, add in span_mirbugs Normalize LvalueTy for ops and format code to satisfy tidy check only normalize operand types when in an ADT constructor avoid early return handle the active field index in unions normalize types in ADT constructor Fixes #45940 Fix borrowck compiler errors for upvars contain "spurious" dereferences Fixes #46003 added associated function Box::leak Box::leak - improve documentation Box::leak - fixed bug in documentation Box::leak - relaxed constraints wrt. lifetimes Box::leak - updated documentation Box::leak - made an oops, fixed now =) Box::leak: update unstable issue number (46179). Add test for #44953 Add missing Debug impls to std_unicode Also adds #![deny(missing_debug_implementations)] so they don't get missed again. Amend RELEASES for 1.22.1 and fix the date for 1.22.0 Rename param in `[T]::swap_with_slice` from `src` to `other`. The idea of ‘source’ and ‘destination’ aren’t very applicable for this operation since both slices can both be considered sources and destinations. Clarify stdin behavior of `Command::output`. Fixes #44929. Add hints for the case of confusing enum with its variants Add failing testcases Add module population and case of enum in place of expression Use for_each_child_stable in find_module Use multiline text for crate conflict diagnostics Make float::from_bits transmute (and update the documentation to reflect this). The current implementation/documentation was made to avoid sNaN because of potential safety issues implied by old/bad LLVM documentation. These issues aren't real, so we can just make the implementation transmute (as permitted by the existing documentation of this method). Also the documentation didn't actually match the behaviour: it said we may change sNaNs, but in fact we canonicalized *all* NaNs. Also an example in the documentation was wrong: it said we *always* change sNaNs, when the documentation was explicitly written to indicate it was implementation-defined. This makes to_bits and from_bits perfectly roundtrip cross-platform, except for one caveat: although the 2008 edition of IEEE-754 specifies how to interpet the signaling bit, earlier editions didn't. This lead to some platforms picking the opposite interpretation, so all signaling NaNs on x86/ARM are quiet on MIPS, and vice-versa. NaN-boxing is a fairly important optimization, while we don't even guarantee that float operations properly preserve signalingness. As such, this seems like the more natural strategy to take (as opposed to trying to mangle the signaling bit on a per-platform basis). This implementation is also, of course, faster. Simplify an Iterator::fold to Iterator::any This method of once-diagnostics doesn't allow nesting UI tests extract the regular output from the 'rendered' field in json Merge cfail and ui tests into ui tests Add a MIR pass to lower 128-bit operators to lang item calls Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet. Include tuple projections in MIR tests Add type checking for the lang item As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement. Handle shifts properly * The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)` * The unchecked ones just take u32, like the `*_sh?` methods in core * Because shift-by-anything is allowed, cast into a new local for every shift incr.comp.: Make sure we don't lose unused green results from the query cache. rustbuild: Update LLVM and enable ThinLTO This commit updates LLVM to fix #45511 (https://reviews.llvm.org/D39981) and also reenables ThinLTO for libtest now that we shouldn't hit #45768. This also opportunistically enables ThinLTO for libstd which was previously blocked (#45661) on test failures related to debuginfo with a presumed cause of #45511. Closes #45511 std: Flag Windows TLS dtor symbol as #[used] Turns out ThinLTO was internalizing this symbol and eliminating it. Worse yet if you compiled with LTO turns out no TLS destructors would run on Windows! The `#[used]` annotation should be a more bulletproof implementation (in the face of LTO) of preserving this symbol all the way through in LLVM and ensuring it makes it all the way to the linker which will take care of it. Add enum InitializationRequiringAction Fix tidy tests
1 parent 2c11555 commit 1be38e0

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

src/librustc_mir/borrow_check.rs

+45-10
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,34 @@ enum WriteKind {
444444
Move,
445445
}
446446

447+
#[derive(Copy, Clone)]
448+
enum InitializationRequiringAction {
449+
Update,
450+
Borrow,
451+
Use,
452+
Assignment,
453+
}
454+
455+
impl InitializationRequiringAction {
456+
fn as_noun(self) -> &'static str {
457+
match self {
458+
InitializationRequiringAction::Update => "update",
459+
InitializationRequiringAction::Borrow => "borrow",
460+
InitializationRequiringAction::Use => "use",
461+
InitializationRequiringAction::Assignment => "assign"
462+
}
463+
}
464+
465+
fn as_verb_in_past_tense(self) -> &'static str {
466+
match self {
467+
InitializationRequiringAction::Update => "updated",
468+
InitializationRequiringAction::Borrow => "borrowed",
469+
InitializationRequiringAction::Use => "used",
470+
InitializationRequiringAction::Assignment => "assigned"
471+
}
472+
}
473+
}
474+
447475
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
448476
/// Checks an access to the given lvalue to see if it is allowed. Examines the set of borrows
449477
/// that are in scope, as well as which paths have been initialized, to ensure that (a) the
@@ -534,7 +562,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
534562
// Write of P[i] or *P, or WriteAndRead of any P, requires P init'd.
535563
match mode {
536564
MutateMode::WriteAndRead => {
537-
self.check_if_path_is_moved(context, "update", lvalue_span, flow_state);
565+
self.check_if_path_is_moved(context, InitializationRequiringAction::Update,
566+
lvalue_span, flow_state);
538567
}
539568
MutateMode::JustWrite => {
540569
self.check_if_assigned_path_is_moved(context, lvalue_span, flow_state);
@@ -560,7 +589,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
560589
BorrowKind::Mut => (Deep, Write(WriteKind::MutableBorrow(bk))),
561590
};
562591
self.access_lvalue(context, (lvalue, span), access_kind, flow_state);
563-
self.check_if_path_is_moved(context, "borrow", (lvalue, span), flow_state);
592+
self.check_if_path_is_moved(context, InitializationRequiringAction::Borrow,
593+
(lvalue, span), flow_state);
564594
}
565595

566596
Rvalue::Use(ref operand) |
@@ -579,7 +609,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
579609
};
580610
self.access_lvalue(
581611
context, (lvalue, span), (Shallow(Some(af)), Read(ReadKind::Copy)), flow_state);
582-
self.check_if_path_is_moved(context, "use", (lvalue, span), flow_state);
612+
self.check_if_path_is_moved(context, InitializationRequiringAction::Use,
613+
(lvalue, span), flow_state);
583614
}
584615

585616
Rvalue::BinaryOp(_bin_op, ref operand1, ref operand2) |
@@ -680,7 +711,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
680711
// skip this check in that case).
681712
}
682713
ConsumeKind::Consume => {
683-
self.check_if_path_is_moved(context, "use", lvalue_span, flow_state);
714+
self.check_if_path_is_moved(context, InitializationRequiringAction::Use,
715+
lvalue_span, flow_state);
684716
}
685717
}
686718
}
@@ -741,7 +773,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
741773

742774
fn check_if_path_is_moved(&mut self,
743775
context: Context,
744-
desired_action: &str,
776+
desired_action: InitializationRequiringAction,
745777
lvalue_span: (&Lvalue<'tcx>, Span),
746778
flow_state: &InProgress<'cx, 'gcx, 'tcx>) {
747779
// FIXME: analogous code in check_loans first maps `lvalue` to
@@ -912,7 +944,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
912944
// `base` to its base_path.
913945

914946
self.check_if_path_is_moved(
915-
context, "assignment", (base, span), flow_state);
947+
context, InitializationRequiringAction::Assignment,
948+
(base, span), flow_state);
916949

917950
// (base initialized; no need to
918951
// recur further)
@@ -1316,7 +1349,7 @@ mod prefixes {
13161349
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
13171350
fn report_use_of_moved_or_uninitialized(&mut self,
13181351
_context: Context,
1319-
desired_action: &str,
1352+
desired_action: InitializationRequiringAction,
13201353
(lvalue, span): (&Lvalue<'tcx>, Span),
13211354
mpi: MovePathIndex,
13221355
curr_move_out: &IdxSetBuf<MoveOutIndex>) {
@@ -1326,7 +1359,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
13261359

13271360
if mois.is_empty() {
13281361
self.tcx.cannot_act_on_uninitialized_variable(span,
1329-
desired_action,
1362+
desired_action.as_noun(),
13301363
&self.describe_lvalue(lvalue),
13311364
Origin::Mir)
13321365
.span_label(span, format!("use of possibly uninitialized `{}`",
@@ -1336,11 +1369,13 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
13361369
let msg = ""; //FIXME: add "partially " or "collaterally "
13371370

13381371
let mut err = self.tcx.cannot_act_on_moved_value(span,
1339-
desired_action,
1372+
desired_action.as_noun(),
13401373
msg,
13411374
&self.describe_lvalue(lvalue),
13421375
Origin::Mir);
1343-
err.span_label(span, format!("value {} here after move", desired_action));
1376+
1377+
err.span_label(span, format!("value {} here after move",
1378+
desired_action.as_verb_in_past_tense()));
13441379
for moi in mois {
13451380
let move_msg = ""; //FIXME: add " (into closure)"
13461381
let move_span = self.mir.source_info(self.move_data.moves[*moi].source).span;

src/test/ui/borrowck/borrowck-reinit.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ error[E0382]: use of moved value: `x` (Mir)
1414
17 | drop(x);
1515
| - value moved here
1616
18 | let _ = (1,x); //~ ERROR use of moved value: `x` (Ast)
17-
| ^ value use here after move
17+
| ^ value used here after move
1818

1919
error: aborting due to 2 previous errors
2020

0 commit comments

Comments
 (0)