Fix label on uninit binding field assignment
This commit is contained in:
parent
a86fa4fa38
commit
5f91614d12
3 changed files with 31 additions and 30 deletions
|
@ -350,36 +350,37 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
let mut visitor = ConditionVisitor { spans: &spans, name: &name, errors: vec![] };
|
let mut visitor = ConditionVisitor { spans: &spans, name: &name, errors: vec![] };
|
||||||
visitor.visit_body(&body);
|
visitor.visit_body(&body);
|
||||||
|
|
||||||
let isnt_initialized =
|
let isnt_initialized = if let InitializationRequiringAction::PartialAssignment
|
||||||
if let InitializationRequiringAction::PartialAssignment = desired_action {
|
| 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
|
// The same error is emitted for bindings that are *sometimes* initialized and the ones
|
||||||
// binding. We differentiate between them for more accurate wording here.
|
// that are *partially* initialized by assigning to a field of an uninitialized
|
||||||
"isn't fully initialized"
|
// binding. We differentiate between them for more accurate wording here.
|
||||||
} else if spans
|
"isn't fully initialized"
|
||||||
.iter()
|
} else if spans
|
||||||
.filter(|i| {
|
.iter()
|
||||||
// We filter these to avoid misleading wording in cases like the following,
|
.filter(|i| {
|
||||||
// where `x` has an `init`, but it is in the same place we're looking at:
|
// 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;
|
// let x;
|
||||||
// ```
|
// x += 1;
|
||||||
!i.contains(span)
|
// ```
|
||||||
|
!i.contains(span)
|
||||||
// We filter these to avoid incorrect main message on `match-cfg-fake-edges.rs`
|
// We filter these to avoid incorrect main message on `match-cfg-fake-edges.rs`
|
||||||
&& !visitor
|
&& !visitor
|
||||||
.errors
|
.errors
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(sp, _)| *sp)
|
.map(|(sp, _)| *sp)
|
||||||
.any(|sp| span < sp && !sp.contains(span))
|
.any(|sp| span < sp && !sp.contains(span))
|
||||||
})
|
})
|
||||||
.count()
|
.count()
|
||||||
== 0
|
== 0
|
||||||
{
|
{
|
||||||
"isn't initialized"
|
"isn't initialized"
|
||||||
} else {
|
} else {
|
||||||
"is possibly-uninitialized"
|
"is possibly-uninitialized"
|
||||||
};
|
};
|
||||||
|
|
||||||
let used = desired_action.as_general_verb_in_past_tense();
|
let used = desired_action.as_general_verb_in_past_tense();
|
||||||
let mut err =
|
let mut err =
|
||||||
|
|
|
@ -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
|
--> $DIR/borrowck-partial-reinit-4.rs:17:5
|
||||||
|
|
|
|
||||||
LL | let mut x : (Test2, Test2);
|
LL | let mut x : (Test2, Test2);
|
||||||
| ----- binding declared here but left uninitialized
|
| ----- binding declared here but left uninitialized
|
||||||
LL | (x.0).0 = Some(Test);
|
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
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -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
|
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:28:5
|
||||||
|
|
|
|
||||||
LL | let d: D;
|
LL | let d: D;
|
||||||
| - binding declared here but left uninitialized
|
| - binding declared here but left uninitialized
|
||||||
LL | d.x = 10;
|
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
|
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:33:5
|
||||||
|
|
|
|
||||||
LL | let mut d: D;
|
LL | let mut d: D;
|
||||||
| ----- binding declared here but left uninitialized
|
| ----- binding declared here but left uninitialized
|
||||||
LL | d.x = 10;
|
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`
|
error[E0382]: assign of moved value: `d`
|
||||||
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:39:5
|
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:39:5
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue