diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index c5420cee05e..b9cfc3732dc 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -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 { diff --git a/src/test/ui/borrowck/borrowck-init-in-fru.stderr b/src/test/ui/borrowck/borrowck-init-in-fru.stderr index 7a35a9a537c..83a3e3e0e3a 100644 --- a/src/test/ui/borrowck/borrowck-init-in-fru.stderr +++ b/src/test/ui/borrowck/borrowck-init-in-fru.stderr @@ -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; diff --git a/src/test/ui/borrowck/borrowck-partial-reinit-4.stderr b/src/test/ui/borrowck/borrowck-partial-reinit-4.stderr index 7b5b64ff8cd..d12a482cb69 100644 --- a/src/test/ui/borrowck/borrowck-partial-reinit-4.stderr +++ b/src/test/ui/borrowck/borrowck-partial-reinit-4.stderr @@ -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 diff --git a/src/test/ui/borrowck/borrowck-uninit-field-access.stderr b/src/test/ui/borrowck/borrowck-uninit-field-access.stderr index 3bc3a477787..6a38a798919 100644 --- a/src/test/ui/borrowck/borrowck-uninit-field-access.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-field-access.stderr @@ -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; diff --git a/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr b/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr index 9f33a163e08..c486cb6dd0c 100644 --- a/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr @@ -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; @@ -6,7 +6,7 @@ LL | let x: &&Box; 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; @@ -14,7 +14,7 @@ LL | let x: &&S; 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; diff --git a/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr b/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr index 6372096caef..459cf1398b7 100644 --- a/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr +++ b/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr @@ -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]; diff --git a/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast-trait.stderr b/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast-trait.stderr index fea69c2e40d..942ed4fc6ca 100644 --- a/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast-trait.stderr +++ b/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast-trait.stderr @@ -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; diff --git a/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr b/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr index e75e0335296..f3289e23981 100644 --- a/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr +++ b/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr @@ -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; diff --git a/src/test/ui/const-generics/const-generic-default-wont-borrowck.stderr b/src/test/ui/const-generics/const-generic-default-wont-borrowck.stderr index 33f839c2866..c62f1d1d230 100644 --- a/src/test/ui/const-generics/const-generic-default-wont-borrowck.stderr +++ b/src/test/ui/const-generics/const-generic-default-wont-borrowck.stderr @@ -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() diff --git a/src/test/ui/nll/issue-21232-partial-init-and-erroneous-use.stderr b/src/test/ui/nll/issue-21232-partial-init-and-erroneous-use.stderr index 9ecfe2f754a..63f230be7d4 100644 --- a/src/test/ui/nll/issue-21232-partial-init-and-erroneous-use.stderr +++ b/src/test/ui/nll/issue-21232-partial-init-and-erroneous-use.stderr @@ -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; diff --git a/src/test/ui/nll/issue-21232-partial-init-and-use.stderr b/src/test/ui/nll/issue-21232-partial-init-and-use.stderr index 2f5883b1563..947c9e29b45 100644 --- a/src/test/ui/nll/issue-21232-partial-init-and-use.stderr +++ b/src/test/ui/nll/issue-21232-partial-init-and-use.stderr @@ -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>; @@ -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; @@ -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)>`, 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>; @@ -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; @@ -178,7 +178,7 @@ LL | q.r.f.0 = 10; | = note: move occurs because `q.r` has type `R<(u32, Box)>`, 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>; @@ -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;