Fix label on uninit binding field assignment

This commit is contained in:
Esteban Küber 2022-06-22 15:36:26 -07:00
parent a86fa4fa38
commit 5f91614d12
3 changed files with 31 additions and 30 deletions

View File

@ -350,36 +350,37 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let mut visitor = ConditionVisitor { spans: &spans, name: &name, errors: vec![] };
visitor.visit_body(&body);
let isnt_initialized =
if let InitializationRequiringAction::PartialAssignment = desired_action {
// The same error is emitted for bindings that are *sometimes* initialized and the ones
// that are *partially* initialized by assigning to a field of an uninitialized
// binding. We differentiate between them for more accurate wording here.
"isn't fully initialized"
} else if spans
.iter()
.filter(|i| {
// We filter these to avoid misleading wording in cases like the following,
// where `x` has an `init`, but it is in the same place we're looking at:
// ```
// let x;
// x += 1;
// ```
!i.contains(span)
let isnt_initialized = if let InitializationRequiringAction::PartialAssignment
| InitializationRequiringAction::Assignment = desired_action
{
// The same error is emitted for bindings that are *sometimes* initialized and the ones
// that are *partially* initialized by assigning to a field of an uninitialized
// binding. We differentiate between them for more accurate wording here.
"isn't fully initialized"
} else if spans
.iter()
.filter(|i| {
// We filter these to avoid misleading wording in cases like the following,
// where `x` has an `init`, but it is in the same place we're looking at:
// ```
// let x;
// x += 1;
// ```
!i.contains(span)
// We filter these to avoid incorrect main message on `match-cfg-fake-edges.rs`
&& !visitor
.errors
.iter()
.map(|(sp, _)| *sp)
.any(|sp| span < sp && !sp.contains(span))
})
.count()
== 0
{
"isn't initialized"
} else {
"is possibly-uninitialized"
};
})
.count()
== 0
{
"isn't initialized"
} else {
"is possibly-uninitialized"
};
let used = desired_action.as_general_verb_in_past_tense();
let mut err =

View File

@ -1,10 +1,10 @@
error[E0381]: assigned binding `x.0` isn't initialized
error[E0381]: assigned binding `x.0` isn't fully initialized
--> $DIR/borrowck-partial-reinit-4.rs:17:5
|
LL | let mut x : (Test2, Test2);
| ----- binding declared here but left uninitialized
LL | (x.0).0 = Some(Test);
| ^^^^^^^ `x.0` assigned here but it isn't initialized
| ^^^^^^^ `x.0` assigned here but it isn't fully initialized
error: aborting due to previous error

View File

@ -1,18 +1,18 @@
error[E0381]: assigned binding `d` isn't initialized
error[E0381]: assigned binding `d` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:28:5
|
LL | let d: D;
| - binding declared here but left uninitialized
LL | d.x = 10;
| ^^^^^^^^ `d` assigned here but it isn't initialized
| ^^^^^^^^ `d` assigned here but it isn't fully initialized
error[E0381]: assigned binding `d` isn't initialized
error[E0381]: assigned binding `d` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:33:5
|
LL | let mut d: D;
| ----- binding declared here but left uninitialized
LL | d.x = 10;
| ^^^^^^^^ `d` assigned here but it isn't initialized
| ^^^^^^^^ `d` assigned here but it isn't fully initialized
error[E0382]: assign of moved value: `d`
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:39:5