Wording tweak

This commit is contained in:
Esteban Küber 2022-06-23 10:42:17 -07:00
parent 5f91614d12
commit d09851cfba
11 changed files with 45 additions and 26 deletions

View File

@ -98,8 +98,14 @@ pub(crate) fn report_use_of_moved_or_uninitialized(
return;
}
let err =
self.report_use_of_uninitialized(mpi, used_place, desired_action, span, use_spans);
let err = self.report_use_of_uninitialized(
mpi,
used_place,
moved_place,
desired_action,
span,
use_spans,
);
self.buffer_error(err);
} else {
if let Some((reported_place, _)) = self.has_move_error(&move_out_indices) {
@ -316,6 +322,7 @@ fn report_use_of_uninitialized(
&self,
mpi: MovePathIndex,
used_place: PlaceRef<'tcx>,
moved_place: PlaceRef<'tcx>,
desired_action: InitializationRequiringAction,
span: Span,
use_spans: UseSpans<'tcx>,
@ -334,11 +341,15 @@ fn report_use_of_uninitialized(
}
}
let (binding, name, desc) =
match self.describe_place_with_options(used_place, IncludingDowncast(true)) {
Some(name) => (format!("`{name}`"), format!("`{name}`"), format!("`{name}` ")),
None => ("value".to_string(), "the variable".to_string(), String::new()),
let (name, desc) =
match self.describe_place_with_options(moved_place, IncludingDowncast(true)) {
Some(name) => (format!("`{name}`"), format!("`{name}` ")),
None => ("the variable".to_string(), String::new()),
};
let path = match self.describe_place_with_options(used_place, IncludingDowncast(true)) {
Some(name) => format!("`{name}`"),
None => "value".to_string(),
};
// We use the statements were the binding was initialized, and inspect the HIR to look
// for the branching codepaths that aren't covered, to point at them.
@ -390,13 +401,15 @@ fn report_use_of_uninitialized(
format!("{} occurs due to use{}", desired_action.as_noun(), use_spans.describe()),
);
if let InitializationRequiringAction::PartialAssignment = desired_action {
if let InitializationRequiringAction::PartialAssignment
| InitializationRequiringAction::Assignment = desired_action
{
err.help(
"partial initialization isn't supported, fully initialize the binding with a \
default value and mutate it, or use `std::mem::MaybeUninit`",
);
}
err.span_label(span, format!("{binding} {used} here but it {isnt_initialized}"));
err.span_label(span, format!("{path} {used} here but it {isnt_initialized}"));
let mut shown = false;
for (sp, label) in visitor.errors {

View File

@ -1,4 +1,4 @@
error[E0381]: used binding `origin.y` isn't initialized
error[E0381]: used binding `origin` isn't initialized
--> $DIR/borrowck-init-in-fru.rs:9:14
|
LL | let mut origin: Point;

View File

@ -5,6 +5,8 @@ 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 fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to previous error

View File

@ -1,4 +1,4 @@
error[E0381]: used binding `a.x` isn't initialized
error[E0381]: used binding `a` isn't initialized
--> $DIR/borrowck-uninit-field-access.rs:21:13
|
LL | let mut a: Point;

View File

@ -1,4 +1,4 @@
error[E0381]: used binding `**x` isn't initialized
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-ref-chain.rs:8:14
|
LL | let x: &&Box<i32>;
@ -6,7 +6,7 @@ LL | let x: &&Box<i32>;
LL | let _y = &**x;
| ^^^^ `**x` used here but it isn't initialized
error[E0381]: used binding `**x` isn't initialized
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-ref-chain.rs:11:14
|
LL | let x: &&S<i32, i32>;
@ -14,7 +14,7 @@ LL | let x: &&S<i32, i32>;
LL | let _y = &**x;
| ^^^^ `**x` used here but it isn't initialized
error[E0381]: used binding `**x` isn't initialized
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-ref-chain.rs:14:14
|
LL | let x: &&i32;

View File

@ -1,4 +1,4 @@
error[E0381]: used binding `*w` isn't initialized
error[E0381]: used binding `w` isn't initialized
--> $DIR/borrowck-use-in-index-lvalue.rs:3:5
|
LL | let w: &mut [isize];
@ -6,7 +6,7 @@ LL | let w: &mut [isize];
LL | w[5] = 0;
| ^^^^ `*w` used here but it isn't initialized
error[E0381]: used binding `*w` isn't initialized
error[E0381]: used binding `w` isn't initialized
--> $DIR/borrowck-use-in-index-lvalue.rs:6:5
|
LL | let mut w: &mut [isize];

View File

@ -1,4 +1,4 @@
error[E0381]: used binding `*x` isn't initialized
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-use-uninitialized-in-cast-trait.rs:9:13
|
LL | let x: &i32;

View File

@ -1,4 +1,4 @@
error[E0381]: used binding `*x` isn't initialized
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-use-uninitialized-in-cast.rs:7:13
|
LL | let x: &i32;

View File

@ -1,4 +1,4 @@
error[E0381]: used binding `*s` isn't initialized
error[E0381]: used binding `s` isn't initialized
--> $DIR/const-generic-default-wont-borrowck.rs:2:26
|
LL | let s: &'static str; s.len()

View File

@ -5,6 +5,8 @@ LL | let d: D;
| - binding declared here but left uninitialized
LL | d.x = 10;
| ^^^^^^^^ `d` assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assigned binding `d` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:33:5
@ -13,6 +15,8 @@ LL | let mut d: D;
| ----- binding declared here but left uninitialized
LL | d.x = 10;
| ^^^^^^^^ `d` assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0382]: assign of moved value: `d`
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:39:5
@ -24,7 +28,7 @@ LL | drop(d);
LL | d.x = 10;
| ^^^^^^^^ value assigned here after move
error[E0381]: partially assigned binding `d.s` isn't fully initialized
error[E0381]: partially assigned binding `d` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:45:5
|
LL | let d: D;
@ -34,7 +38,7 @@ LL | d.s.y = 20;
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: partially assigned binding `d.s` isn't fully initialized
error[E0381]: partially assigned binding `d` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:50:5
|
LL | let mut d: D;

View File

@ -98,7 +98,7 @@ LL | t.0 = 10;
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: partially assigned binding `q.r.f` isn't fully initialized
error[E0381]: partially assigned binding `q` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:170:5
|
LL | let q: Q<S<B>>;
@ -108,7 +108,7 @@ LL | q.r.f.x = 10; q.r.f.y = Box::new(20);
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: partially assigned binding `q.r.f` isn't fully initialized
error[E0381]: partially assigned binding `q` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:176:5
|
LL | let q: Q<T>;
@ -138,7 +138,7 @@ LL | q.r.f.0 = 10; q.r.f.1 = Box::new(20);
|
= note: move occurs because `q.r` has type `R<(u32, Box<u32>)>`, which does not implement the `Copy` trait
error[E0381]: partially assigned binding `q.r.f` isn't fully initialized
error[E0381]: partially assigned binding `q` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:196:5
|
LL | let q: Q<S<B>>;
@ -148,7 +148,7 @@ LL | q.r.f.x = 10;
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: partially assigned binding `q.r.f` isn't fully initialized
error[E0381]: partially assigned binding `q` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:202:5
|
LL | let q: Q<T>;
@ -178,7 +178,7 @@ LL | q.r.f.0 = 10;
|
= note: move occurs because `q.r` has type `R<(u32, Box<u32>)>`, which does not implement the `Copy` trait
error[E0381]: partially assigned binding `q.r.f` isn't fully initialized
error[E0381]: partially assigned binding `q` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:222:5
|
LL | let mut q: Q<S<Void>>;
@ -188,7 +188,7 @@ LL | q.r.f.x = 10;
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: partially assigned binding `q.r.f` isn't fully initialized
error[E0381]: partially assigned binding `q` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:228:5
|
LL | let mut q: Q<Tvoid>;