Skip to content

Commit 8495c64

Browse files
committed
Fix label on uninit binding field assignment
1 parent 6eadf6e commit 8495c64

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+25-24
Original file line numberDiff line numberDiff line change
@@ -350,36 +350,37 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
350350
let mut visitor = ConditionVisitor { spans: &spans, name: &name, errors: vec![] };
351351
visitor.visit_body(&body);
352352

353-
let isnt_initialized =
354-
if let InitializationRequiringAction::PartialAssignment = desired_action {
355-
// The same error is emitted for bindings that are *sometimes* initialized and the ones
356-
// that are *partially* initialized by assigning to a field of an uninitialized
357-
// binding. We differentiate between them for more accurate wording here.
358-
"isn't fully initialized"
359-
} else if spans
360-
.iter()
361-
.filter(|i| {
362-
// We filter these to avoid misleading wording in cases like the following,
363-
// where `x` has an `init`, but it is in the same place we're looking at:
364-
// ```
365-
// let x;
366-
// x += 1;
367-
// ```
368-
!i.contains(span)
353+
let isnt_initialized = if let InitializationRequiringAction::PartialAssignment
354+
| InitializationRequiringAction::Assignment = desired_action
355+
{
356+
// The same error is emitted for bindings that are *sometimes* initialized and the ones
357+
// that are *partially* initialized by assigning to a field of an uninitialized
358+
// binding. We differentiate between them for more accurate wording here.
359+
"isn't fully initialized"
360+
} else if spans
361+
.iter()
362+
.filter(|i| {
363+
// We filter these to avoid misleading wording in cases like the following,
364+
// where `x` has an `init`, but it is in the same place we're looking at:
365+
// ```
366+
// let x;
367+
// x += 1;
368+
// ```
369+
!i.contains(span)
369370
// We filter these to avoid incorrect main message on `match-cfg-fake-edges.rs`
370371
&& !visitor
371372
.errors
372373
.iter()
373374
.map(|(sp, _)| *sp)
374375
.any(|sp| span < sp && !sp.contains(span))
375-
})
376-
.count()
377-
== 0
378-
{
379-
"isn't initialized"
380-
} else {
381-
"is possibly-uninitialized"
382-
};
376+
})
377+
.count()
378+
== 0
379+
{
380+
"isn't initialized"
381+
} else {
382+
"is possibly-uninitialized"
383+
};
383384

384385
let used = desired_action.as_general_verb_in_past_tense();
385386
let mut err =

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0381]: assigned binding `x.0` isn't initialized
1+
error[E0381]: assigned binding `x.0` isn't fully initialized
22
--> $DIR/borrowck-partial-reinit-4.rs:17:5
33
|
44
LL | let mut x : (Test2, Test2);
55
| ----- binding declared here but left uninitialized
66
LL | (x.0).0 = Some(Test);
7-
| ^^^^^^^ `x.0` assigned here but it isn't initialized
7+
| ^^^^^^^ `x.0` assigned here but it isn't fully initialized
88

99
error: aborting due to previous error
1010

src/test/ui/nll/issue-21232-partial-init-and-erroneous-use.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
error[E0381]: assigned binding `d` isn't initialized
1+
error[E0381]: assigned binding `d` isn't fully initialized
22
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:28:5
33
|
44
LL | let d: D;
55
| - binding declared here but left uninitialized
66
LL | d.x = 10;
7-
| ^^^^^^^^ `d` assigned here but it isn't initialized
7+
| ^^^^^^^^ `d` assigned here but it isn't fully initialized
88

9-
error[E0381]: assigned binding `d` isn't initialized
9+
error[E0381]: assigned binding `d` isn't fully initialized
1010
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:33:5
1111
|
1212
LL | let mut d: D;
1313
| ----- binding declared here but left uninitialized
1414
LL | d.x = 10;
15-
| ^^^^^^^^ `d` assigned here but it isn't initialized
15+
| ^^^^^^^^ `d` assigned here but it isn't fully initialized
1616

1717
error[E0382]: assign of moved value: `d`
1818
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:39:5

0 commit comments

Comments
 (0)