From 8a2c0ccac7c2395f80dba09817bb348020ac9c88 Mon Sep 17 00:00:00 2001 From: yukang Date: Fri, 23 Sep 2022 15:28:48 +0800 Subject: [PATCH 1/4] fix #102087, Suggest Default::default() when binding isn't initialized --- .../src/diagnostics/conflict_errors.rs | 63 +++++++++ src/test/ui/asm/x86_64/type-check-5.stderr | 10 ++ .../ui/borrowck/borrowck-block-unint.stderr | 5 + .../borrowck/borrowck-break-uninit-2.stderr | 4 + .../ui/borrowck/borrowck-break-uninit.stderr | 4 + .../borrowck-init-in-called-fn-expr.stderr | 5 + .../borrowck/borrowck-init-in-fn-expr.stderr | 5 + .../ui/borrowck/borrowck-init-in-fru.stderr | 5 + .../ui/borrowck/borrowck-init-op-equal.stderr | 5 + .../borrowck/borrowck-init-plus-equal.stderr | 5 + src/test/ui/borrowck/borrowck-return.stderr | 5 + .../ui/borrowck/borrowck-storage-dead.stderr | 5 + .../borrowck-uninit-after-item.stderr | 5 + .../borrowck-uninit-field-access.stderr | 5 + .../borrowck-uninit-in-assignop.stderr | 50 +++++++ .../borrowck/borrowck-uninit-ref-chain.stderr | 15 +++ src/test/ui/borrowck/borrowck-uninit.stderr | 5 + .../borrowck-use-in-index-lvalue.stderr | 10 ++ ...wck-use-uninitialized-in-cast-trait.stderr | 5 + .../borrowck-use-uninitialized-in-cast.stderr | 5 + .../ui/borrowck/borrowck-while-cond.stderr | 5 + .../ui/borrowck/issue-24267-flow-exit.stderr | 8 ++ .../issue-62107-match-arm-scopes.stderr | 5 + src/test/ui/borrowck/suggest-assign-rvalue.rs | 47 +++++++ .../ui/borrowck/suggest-assign-rvalue.stderr | 125 ++++++++++++++++++ .../match/pattern-matching-should-fail.stderr | 5 + ...const-generic-default-wont-borrowck.stderr | 5 + src/test/ui/consts/issue-78655.stderr | 5 + src/test/ui/drop/repeat-drop-2.stderr | 5 + src/test/ui/loops/loop-proper-liveness.stderr | 4 + ...op-elaboration-after-borrowck-error.stderr | 5 + .../moves/issue-72649-uninit-in-loop.stderr | 10 ++ .../ui/moves/move-into-dead-array-1.stderr | 5 + src/test/ui/moves/move-of-addr-of-mut.stderr | 4 + src/test/ui/nll/match-cfg-fake-edges.stderr | 5 + src/test/ui/nll/match-on-borrowed.stderr | 5 + .../privately-uninhabited-mir-call.stderr | 5 + 37 files changed, 474 insertions(+) create mode 100644 src/test/ui/borrowck/suggest-assign-rvalue.rs create mode 100644 src/test/ui/borrowck/suggest-assign-rvalue.stderr diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 69ad7f6627500..66ee25a357b4c 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -16,6 +16,7 @@ use rustc_middle::mir::{ FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm, }; +//use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty}; use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex}; use rustc_span::def_id::LocalDefId; @@ -336,6 +337,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let inits = &self.move_data.init_path_map[mpi]; let move_path = &self.move_data.move_paths[mpi]; let decl_span = self.body.local_decls[move_path.place.local].source_info.span; + let mut spans = vec![]; for init_idx in inits { let init = &self.move_data.inits[*init_idx]; @@ -369,6 +371,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let mut visitor = ConditionVisitor { spans: &spans, name: &name, errors: vec![] }; visitor.visit_body(&body); + let mut show_assign_sugg = false; let isnt_initialized = if let InitializationRequiringAction::PartialAssignment | InitializationRequiringAction::Assignment = desired_action { @@ -396,6 +399,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { .count() == 0 { + show_assign_sugg = true; "isn't initialized" } else { "is possibly-uninitialized" @@ -446,10 +450,69 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } } } + err.span_label(decl_span, "binding declared here but left uninitialized"); + if show_assign_sugg { + self.suggest_assign_rvalue(&mut err, moved_place, &name, decl_span); + } err } + fn suggest_assign_rvalue( + &self, + err: &mut Diagnostic, + moved_place: PlaceRef<'tcx>, + name: &str, + decl_span: Span, + ) { + let ty = moved_place.ty(self.body, self.infcx.tcx).ty; + debug!("ty: {:?}, kind: {:?}", ty, ty.kind()); + + let initilize_msg = match ty.kind() { + ty::Array(_, n) => format!("[val; {}]", n), + ty::Int(_) | ty::Uint(_) => format!("0"), + ty::Float(_) => format!("0.0"), + ty::Bool => format!("false"), + ty::Never | ty::Error(_) => "".to_string(), + ty::Adt(def, _substs) => { + if format!("{:?}", def).starts_with("std::vec::Vec") { + format!("vec![]") + } else if let Some(default_trait) = self.infcx.tcx.get_diagnostic_item(sym::Default) && + self.infcx.tcx.infer_ctxt().enter(|infcx| { + infcx.type_implements_trait(default_trait, ty, ty::List::empty(), self.param_env).may_apply() + }) { + format!("Default::default()") + } else { + format!("something") + } + }, + _ => format!("something"), + }; + + if initilize_msg.is_empty() { + return; + } + + let sugg_span = self + .infcx + .tcx + .sess + .source_map() + .span_extend_while(decl_span, |c| c != '\n') + .unwrap_or(decl_span); + let mut prefix = self.infcx.tcx.sess.source_map().span_to_snippet(sugg_span).unwrap(); + // remove last char if eq ';' + if prefix.ends_with(';') { + prefix.pop(); + } + err.span_suggestion_verbose( + sugg_span, + format!("use `=` to assign some value to {}", name), + format!("{} = {};", prefix, initilize_msg), + Applicability::MaybeIncorrect, + ); + } + fn suggest_borrow_fn_like( &self, err: &mut Diagnostic, diff --git a/src/test/ui/asm/x86_64/type-check-5.stderr b/src/test/ui/asm/x86_64/type-check-5.stderr index e9c93fea561a8..768f22f10f0ca 100644 --- a/src/test/ui/asm/x86_64/type-check-5.stderr +++ b/src/test/ui/asm/x86_64/type-check-5.stderr @@ -5,6 +5,11 @@ LL | let x: u64; | - binding declared here but left uninitialized LL | asm!("{}", in(reg) x); | ^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: u64 = 0; + | ~~~~~~~~~~~ error[E0381]: used binding `y` isn't initialized --> $DIR/type-check-5.rs:18:9 @@ -13,6 +18,11 @@ LL | let mut y: u64; | ----- binding declared here but left uninitialized LL | asm!("{}", inout(reg) y); | ^^^^^^^^^^^^^^^^^^^^^^^^ `y` used here but it isn't initialized + | +help: use `=` to assign some value to `y` + | +LL | let mut y: u64 = 0; + | ~~~~~~~~~~~~~~~ error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable --> $DIR/type-check-5.rs:26:29 diff --git a/src/test/ui/borrowck/borrowck-block-unint.stderr b/src/test/ui/borrowck/borrowck-block-unint.stderr index e720db1c6961b..e77ec994081bb 100644 --- a/src/test/ui/borrowck/borrowck-block-unint.stderr +++ b/src/test/ui/borrowck/borrowck-block-unint.stderr @@ -7,6 +7,11 @@ LL | force(|| { | ^^ `x` used here but it isn't initialized LL | println!("{}", x); | - borrow occurs due to use in closure + | +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-break-uninit-2.stderr b/src/test/ui/borrowck/borrowck-break-uninit-2.stderr index 91038b3adca9d..ce02c966d23a3 100644 --- a/src/test/ui/borrowck/borrowck-break-uninit-2.stderr +++ b/src/test/ui/borrowck/borrowck-break-uninit-2.stderr @@ -8,6 +8,10 @@ LL | println!("{}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-break-uninit.stderr b/src/test/ui/borrowck/borrowck-break-uninit.stderr index 8d0c9582fda92..84c0df39a1421 100644 --- a/src/test/ui/borrowck/borrowck-break-uninit.stderr +++ b/src/test/ui/borrowck/borrowck-break-uninit.stderr @@ -8,6 +8,10 @@ LL | println!("{}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr b/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr index e8a2fbc91ea64..438924c65886a 100644 --- a/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr +++ b/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr @@ -5,6 +5,11 @@ LL | let i: isize; | - binding declared here but left uninitialized LL | i | ^ `i` used here but it isn't initialized + | +help: use `=` to assign some value to `i` + | +LL | let i: isize = 0; + | ~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr b/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr index 1e950d6a20def..aa8d1442521cc 100644 --- a/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr +++ b/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr @@ -5,6 +5,11 @@ LL | let i: isize; | - binding declared here but left uninitialized LL | i | ^ `i` used here but it isn't initialized + | +help: use `=` to assign some value to `i` + | +LL | let i: isize = 0; + | ~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-init-in-fru.stderr b/src/test/ui/borrowck/borrowck-init-in-fru.stderr index 83a3e3e0e3ae0..9515c46df6567 100644 --- a/src/test/ui/borrowck/borrowck-init-in-fru.stderr +++ b/src/test/ui/borrowck/borrowck-init-in-fru.stderr @@ -5,6 +5,11 @@ LL | let mut origin: Point; | ---------- binding declared here but left uninitialized LL | origin = Point { x: 10, ..origin }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ `origin.y` used here but it isn't initialized + | +help: use `=` to assign some value to `origin` + | +LL | let mut origin: Point = something; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-init-op-equal.stderr b/src/test/ui/borrowck/borrowck-init-op-equal.stderr index 74704b2abfee8..61b4a3831348f 100644 --- a/src/test/ui/borrowck/borrowck-init-op-equal.stderr +++ b/src/test/ui/borrowck/borrowck-init-op-equal.stderr @@ -5,6 +5,11 @@ LL | let v: isize; | - binding declared here but left uninitialized LL | v += 1; | ^^^^^^ `v` used here but it isn't initialized + | +help: use `=` to assign some value to `v` + | +LL | let v: isize = 0; + | ~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-init-plus-equal.stderr b/src/test/ui/borrowck/borrowck-init-plus-equal.stderr index 7542576d636be..709db53c12390 100644 --- a/src/test/ui/borrowck/borrowck-init-plus-equal.stderr +++ b/src/test/ui/borrowck/borrowck-init-plus-equal.stderr @@ -5,6 +5,11 @@ LL | let mut v: isize; | ----- binding declared here but left uninitialized LL | v = v + 1; | ^ `v` used here but it isn't initialized + | +help: use `=` to assign some value to `v` + | +LL | let mut v: isize = 0; + | ~~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-return.stderr b/src/test/ui/borrowck/borrowck-return.stderr index 1c916e223175c..9f64fde939615 100644 --- a/src/test/ui/borrowck/borrowck-return.stderr +++ b/src/test/ui/borrowck/borrowck-return.stderr @@ -5,6 +5,11 @@ LL | let x: isize; | - binding declared here but left uninitialized LL | return x; | ^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-storage-dead.stderr b/src/test/ui/borrowck/borrowck-storage-dead.stderr index 2cea4392d6adb..2cd6da96f4469 100644 --- a/src/test/ui/borrowck/borrowck-storage-dead.stderr +++ b/src/test/ui/borrowck/borrowck-storage-dead.stderr @@ -5,6 +5,11 @@ LL | let x: i32; | - binding declared here but left uninitialized LL | let _ = x + 1; | ^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: i32 = 0; + | ~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-uninit-after-item.stderr b/src/test/ui/borrowck/borrowck-uninit-after-item.stderr index 588b1b0c9729c..cae2bd9e69a95 100644 --- a/src/test/ui/borrowck/borrowck-uninit-after-item.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-after-item.stderr @@ -6,6 +6,11 @@ LL | let bar; LL | fn baz(_x: isize) { } LL | baz(bar); | ^^^ `bar` used here but it isn't initialized + | +help: use `=` to assign some value to `bar` + | +LL | let bar = 0; + | ~~~~~~~~ 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 6a38a79891970..ccfeb40834afc 100644 --- a/src/test/ui/borrowck/borrowck-uninit-field-access.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-field-access.stderr @@ -5,6 +5,11 @@ LL | let mut a: Point; | ----- binding declared here but left uninitialized LL | let _ = a.x + 1; | ^^^ `a.x` used here but it isn't initialized + | +help: use `=` to assign some value to `a` + | +LL | let mut a: Point = Default::default(); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0382]: use of moved value: `line1.origin` --> $DIR/borrowck-uninit-field-access.rs:25:13 diff --git a/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr b/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr index 744cb14e662b3..65228593775c1 100644 --- a/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr @@ -5,6 +5,11 @@ LL | let x: isize; | - binding declared here but left uninitialized LL | x += 1; | ^^^^^^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:9:5 @@ -13,6 +18,11 @@ LL | let x: isize; | - binding declared here but left uninitialized LL | x -= 1; | ^^^^^^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:12:5 @@ -21,6 +31,11 @@ LL | let x: isize; | - binding declared here but left uninitialized LL | x *= 1; | ^^^^^^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:15:5 @@ -29,6 +44,11 @@ LL | let x: isize; | - binding declared here but left uninitialized LL | x /= 1; | ^^^^^^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:18:5 @@ -37,6 +57,11 @@ LL | let x: isize; | - binding declared here but left uninitialized LL | x %= 1; | ^^^^^^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:21:5 @@ -45,6 +70,11 @@ LL | let x: isize; | - binding declared here but left uninitialized LL | x ^= 1; | ^^^^^^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:24:5 @@ -53,6 +83,11 @@ LL | let x: isize; | - binding declared here but left uninitialized LL | x &= 1; | ^^^^^^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:27:5 @@ -61,6 +96,11 @@ LL | let x: isize; | - binding declared here but left uninitialized LL | x |= 1; | ^^^^^^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:30:5 @@ -69,6 +109,11 @@ LL | let x: isize; | - binding declared here but left uninitialized LL | x <<= 1; | ^^^^^^^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:33:5 @@ -77,6 +122,11 @@ LL | let x: isize; | - binding declared here but left uninitialized LL | x >>= 1; | ^^^^^^^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error: aborting due to 10 previous errors diff --git a/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr b/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr index c486cb6dd0cd3..4084454e36b97 100644 --- a/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr @@ -5,6 +5,11 @@ LL | let x: &&Box; | - binding declared here but left uninitialized LL | let _y = &**x; | ^^^^ `**x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: &&Box = something; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-ref-chain.rs:11:14 @@ -13,6 +18,11 @@ LL | let x: &&S; | - binding declared here but left uninitialized LL | let _y = &**x; | ^^^^ `**x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: &&S = something; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-ref-chain.rs:14:14 @@ -21,6 +31,11 @@ LL | let x: &&i32; | - binding declared here but left uninitialized LL | let _y = &**x; | ^^^^ `**x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: &&i32 = something; + | ~~~~~~~~~~~~~~~~~~~~~ error[E0381]: partially assigned binding `a` isn't fully initialized --> $DIR/borrowck-uninit-ref-chain.rs:18:5 diff --git a/src/test/ui/borrowck/borrowck-uninit.stderr b/src/test/ui/borrowck/borrowck-uninit.stderr index d5566691a8200..e16bdbc14e07c 100644 --- a/src/test/ui/borrowck/borrowck-uninit.stderr +++ b/src/test/ui/borrowck/borrowck-uninit.stderr @@ -5,6 +5,11 @@ LL | let x: isize; | - binding declared here but left uninitialized LL | foo(x); | ^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: isize = 0; + | ~~~~~~~~~~~~~ error: aborting due to previous error 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 459cf1398b750..a8f797c163911 100644 --- a/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr +++ b/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr @@ -5,6 +5,11 @@ LL | let w: &mut [isize]; | - binding declared here but left uninitialized LL | w[5] = 0; | ^^^^ `*w` used here but it isn't initialized + | +help: use `=` to assign some value to `w` + | +LL | let w: &mut [isize] = something; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0381]: used binding `w` isn't initialized --> $DIR/borrowck-use-in-index-lvalue.rs:6:5 @@ -13,6 +18,11 @@ LL | let mut w: &mut [isize]; | ----- binding declared here but left uninitialized LL | w[5] = 0; | ^^^^ `*w` used here but it isn't initialized + | +help: use `=` to assign some value to `w` + | +LL | let mut w: &mut [isize] = something; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 2 previous errors 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 942ed4fc6cabf..92ac4c1b46f27 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 @@ -5,6 +5,11 @@ LL | let x: &i32; | - binding declared here but left uninitialized LL | let y = x as *const dyn Foo; | ^ `*x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: &i32 = something; + | ~~~~~~~~~~~~~~~~~~~~ error: aborting due to previous error 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 f3289e239818a..18821c2008315 100644 --- a/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr +++ b/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr @@ -5,6 +5,11 @@ LL | let x: &i32; | - binding declared here but left uninitialized LL | let y = x as *const i32; | ^ `*x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: &i32 = something; + | ~~~~~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-while-cond.stderr b/src/test/ui/borrowck/borrowck-while-cond.stderr index e41c1c55e6024..447a5687c3217 100644 --- a/src/test/ui/borrowck/borrowck-while-cond.stderr +++ b/src/test/ui/borrowck/borrowck-while-cond.stderr @@ -5,6 +5,11 @@ LL | let x: bool; | - binding declared here but left uninitialized LL | while x { } | ^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: bool = false; + | ~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/issue-24267-flow-exit.stderr b/src/test/ui/borrowck/issue-24267-flow-exit.stderr index b85e8f216e5df..2a17a111d8d3d 100644 --- a/src/test/ui/borrowck/issue-24267-flow-exit.stderr +++ b/src/test/ui/borrowck/issue-24267-flow-exit.stderr @@ -8,6 +8,10 @@ LL | println!("{}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `x` + | +LL | let x: i32 = 0; + | ~~~~~~~~~~~ error[E0381]: used binding `x` isn't initialized --> $DIR/issue-24267-flow-exit.rs:18:20 @@ -19,6 +23,10 @@ LL | println!("{}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `x` + | +LL | let x: i32 = 0; + | ~~~~~~~~~~~ error: aborting due to 2 previous errors diff --git a/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr b/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr index f5d2eecfa91a3..4a27c0a06f7ff 100644 --- a/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr +++ b/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr @@ -5,6 +5,11 @@ LL | let e: i32; | - binding declared here but left uninitialized LL | match e { | ^ `e` used here but it isn't initialized + | +help: use `=` to assign some value to `e` + | +LL | let e: i32 = 0; + | ~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/suggest-assign-rvalue.rs b/src/test/ui/borrowck/suggest-assign-rvalue.rs new file mode 100644 index 0000000000000..1db3cecdd8b13 --- /dev/null +++ b/src/test/ui/borrowck/suggest-assign-rvalue.rs @@ -0,0 +1,47 @@ +#![allow(dead_code)] +#![feature(never_type)] + +#[derive(Debug, Default)] +struct Demo {} + +#[derive(Debug)] +struct DemoNoDef {} + +fn main() { + let my_bool: bool = bool::default(); + println!("my_bool: {}", my_bool); + + let my_float: f32; + println!("my_float: {}", my_float); + //~^ ERROR used binding `my_float` isn't initialized + let demo: Demo; + println!("demo: {:?}", demo); + //~^ ERROR used binding `demo` isn't initialized + + let demo_no: DemoNoDef; + println!("demo_no: {:?}", demo_no); + //~^ ERROR used binding `demo_no` isn't initialized + + let arr: [i32; 5]; + println!("arr: {:?}", arr); + //~^ ERROR used binding `arr` isn't initialized + let foo: Vec<&str>; + println!("foo: {:?}", foo); + //~^ ERROR used binding `foo` isn't initialized + + let my_string: String; + println!("my_string: {}", my_string); + //~^ ERROR used binding `my_string` isn't initialized + + let my_int: &i32; + println!("my_int: {}", *my_int); + //~^ ERROR used binding `my_int` isn't initialized + + let hello: &str; + println!("hello: {}", hello); + //~^ ERROR used binding `hello` isn't initialized + + let never: !; + println!("never: {}", never); + //~^ ERROR used binding `never` isn't initialized [E0381] +} diff --git a/src/test/ui/borrowck/suggest-assign-rvalue.stderr b/src/test/ui/borrowck/suggest-assign-rvalue.stderr new file mode 100644 index 0000000000000..585967e086dd8 --- /dev/null +++ b/src/test/ui/borrowck/suggest-assign-rvalue.stderr @@ -0,0 +1,125 @@ +error[E0381]: used binding `my_float` isn't initialized + --> $DIR/suggest-assign-rvalue.rs:15:30 + | +LL | let my_float: f32; + | -------- binding declared here but left uninitialized +LL | println!("my_float: {}", my_float); + | ^^^^^^^^ `my_float` used here but it isn't initialized + | + = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `my_float` + | +LL | let my_float: f32 = 0.0; + | ~~~~~~~~~~~~~~~~~~~~ + +error[E0381]: used binding `demo` isn't initialized + --> $DIR/suggest-assign-rvalue.rs:18:28 + | +LL | let demo: Demo; + | ---- binding declared here but left uninitialized +LL | println!("demo: {:?}", demo); + | ^^^^ `demo` used here but it isn't initialized + | + = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `demo` + | +LL | let demo: Demo = Default::default(); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0381]: used binding `demo_no` isn't initialized + --> $DIR/suggest-assign-rvalue.rs:22:31 + | +LL | let demo_no: DemoNoDef; + | ------- binding declared here but left uninitialized +LL | println!("demo_no: {:?}", demo_no); + | ^^^^^^^ `demo_no` used here but it isn't initialized + | + = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `demo_no` + | +LL | let demo_no: DemoNoDef = something; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0381]: used binding `arr` isn't initialized + --> $DIR/suggest-assign-rvalue.rs:26:27 + | +LL | let arr: [i32; 5]; + | --- binding declared here but left uninitialized +LL | println!("arr: {:?}", arr); + | ^^^ `arr` used here but it isn't initialized + | + = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `arr` + | +LL | let arr: [i32; 5] = [val; 5]; + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0381]: used binding `foo` isn't initialized + --> $DIR/suggest-assign-rvalue.rs:29:27 + | +LL | let foo: Vec<&str>; + | --- binding declared here but left uninitialized +LL | println!("foo: {:?}", foo); + | ^^^ `foo` used here but it isn't initialized + | + = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `foo` + | +LL | let foo: Vec<&str> = vec![]; + | ~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0381]: used binding `my_string` isn't initialized + --> $DIR/suggest-assign-rvalue.rs:33:31 + | +LL | let my_string: String; + | --------- binding declared here but left uninitialized +LL | println!("my_string: {}", my_string); + | ^^^^^^^^^ `my_string` used here but it isn't initialized + | + = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `my_string` + | +LL | let my_string: String = Default::default(); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0381]: used binding `my_int` isn't initialized + --> $DIR/suggest-assign-rvalue.rs:37:28 + | +LL | let my_int: &i32; + | ------ binding declared here but left uninitialized +LL | println!("my_int: {}", *my_int); + | ^^^^^^^ `*my_int` used here but it isn't initialized + | + = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `my_int` + | +LL | let my_int: &i32 = something; + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0381]: used binding `hello` isn't initialized + --> $DIR/suggest-assign-rvalue.rs:41:27 + | +LL | let hello: &str; + | ----- binding declared here but left uninitialized +LL | println!("hello: {}", hello); + | ^^^^^ `hello` used here but it isn't initialized + | + = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `hello` + | +LL | let hello: &str = something; + | ~~~~~~~~~~~~~~~~~~~~~~~~ + +error[E0381]: used binding `never` isn't initialized + --> $DIR/suggest-assign-rvalue.rs:45:27 + | +LL | let never: !; + | ----- binding declared here but left uninitialized +LL | println!("never: {}", never); + | ^^^^^ `never` used here but it isn't initialized + | + = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 9 previous errors + +For more information about this error, try `rustc --explain E0381`. diff --git a/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr b/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr index fea5441ec673d..80ff0f761e3ae 100644 --- a/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr +++ b/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr @@ -76,6 +76,11 @@ LL | let x: u8; | - binding declared here but left uninitialized LL | let c1 = || match x { }; | ^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: u8 = 0; + | ~~~~~~~~~~ error: aborting due to 8 previous errors 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 c62f1d1d23061..4207058e858a6 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 @@ -5,6 +5,11 @@ LL | let s: &'static str; s.len() | - ^^^^^^^ `*s` used here but it isn't initialized | | | binding declared here but left uninitialized + | +help: use `=` to assign some value to `s` + | +LL | let s: &'static str; s.len() + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/consts/issue-78655.stderr b/src/test/ui/consts/issue-78655.stderr index f5b1123e7f343..256920cfaebc0 100644 --- a/src/test/ui/consts/issue-78655.stderr +++ b/src/test/ui/consts/issue-78655.stderr @@ -5,6 +5,11 @@ LL | let x; | - binding declared here but left uninitialized LL | &x | ^^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x = 0; + | ~~~~~~ error: could not evaluate constant pattern --> $DIR/issue-78655.rs:7:9 diff --git a/src/test/ui/drop/repeat-drop-2.stderr b/src/test/ui/drop/repeat-drop-2.stderr index 48fa2bfa975c0..dd55b1a860e23 100644 --- a/src/test/ui/drop/repeat-drop-2.stderr +++ b/src/test/ui/drop/repeat-drop-2.stderr @@ -24,6 +24,11 @@ LL | let x: u8; | - binding declared here but left uninitialized LL | let _ = [x; 0]; | ^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x: u8 = 0; + | ~~~~~~~~~~ error: aborting due to 3 previous errors diff --git a/src/test/ui/loops/loop-proper-liveness.stderr b/src/test/ui/loops/loop-proper-liveness.stderr index 14e86aee059b2..801b5e62db19b 100644 --- a/src/test/ui/loops/loop-proper-liveness.stderr +++ b/src/test/ui/loops/loop-proper-liveness.stderr @@ -8,6 +8,10 @@ LL | println!("{:?}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `x` + | +LL | let x: i32 = 0; + | ~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr b/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr index d8154f8d2cbc4..764182484da4f 100644 --- a/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr +++ b/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr @@ -24,6 +24,11 @@ LL | let a: [String; 1]; LL | LL | a[0] = String::new(); | ^^^^ `a` used here but it isn't initialized + | +help: use `=` to assign some value to `a` + | +LL | let a: [String; 1] = [val; 1]; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0493]: destructors cannot be evaluated at compile-time --> $DIR/drop-elaboration-after-borrowck-error.rs:18:9 diff --git a/src/test/ui/moves/issue-72649-uninit-in-loop.stderr b/src/test/ui/moves/issue-72649-uninit-in-loop.stderr index c7373b5be9d8d..305ff7c093c54 100644 --- a/src/test/ui/moves/issue-72649-uninit-in-loop.stderr +++ b/src/test/ui/moves/issue-72649-uninit-in-loop.stderr @@ -47,6 +47,11 @@ LL | let value: NonCopy; | ----- binding declared here but left uninitialized LL | let _used = value; | ^^^^^ `value` used here but it isn't initialized + | +help: use `=` to assign some value to `value` + | +LL | let value: NonCopy; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0381]: used binding `value` isn't initialized --> $DIR/issue-72649-uninit-in-loop.rs:69:21 @@ -56,6 +61,11 @@ LL | let mut value: NonCopy; LL | loop { LL | let _used = value; | ^^^^^ `value` used here but it isn't initialized + | +help: use `=` to assign some value to `value` + | +LL | let mut value: NonCopy; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 6 previous errors diff --git a/src/test/ui/moves/move-into-dead-array-1.stderr b/src/test/ui/moves/move-into-dead-array-1.stderr index 344a6bbf0c92c..756276caa09e8 100644 --- a/src/test/ui/moves/move-into-dead-array-1.stderr +++ b/src/test/ui/moves/move-into-dead-array-1.stderr @@ -5,6 +5,11 @@ LL | let mut a: [D; 4]; | ----- binding declared here but left uninitialized LL | a[i] = d(); | ^^^^ `a` used here but it isn't initialized + | +help: use `=` to assign some value to `a` + | +LL | let mut a: [D; 4] = [val; 4]; + | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/moves/move-of-addr-of-mut.stderr b/src/test/ui/moves/move-of-addr-of-mut.stderr index e75f2b1c0894c..f2325fb3e576b 100644 --- a/src/test/ui/moves/move-of-addr-of-mut.stderr +++ b/src/test/ui/moves/move-of-addr-of-mut.stderr @@ -7,6 +7,10 @@ LL | std::ptr::addr_of_mut!(x); | ^^^^^^^^^^^^^^^^^^^^^^^^^ `x` used here but it isn't initialized | = note: this error originates in the macro `std::ptr::addr_of_mut` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use `=` to assign some value to `x` + | +LL | let mut x: S = something; + | ~~~~~~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/nll/match-cfg-fake-edges.stderr b/src/test/ui/nll/match-cfg-fake-edges.stderr index 250aa482e5c67..73eb5137f3705 100644 --- a/src/test/ui/nll/match-cfg-fake-edges.stderr +++ b/src/test/ui/nll/match-cfg-fake-edges.stderr @@ -9,6 +9,11 @@ LL | _ if { x = 2; true } => 1, LL | _ if { LL | x; | ^ `x` used here but it isn't initialized + | +help: use `=` to assign some value to `x` + | +LL | let x = 0; + | ~~~~~~ error[E0382]: use of moved value: `x` --> $DIR/match-cfg-fake-edges.rs:35:13 diff --git a/src/test/ui/nll/match-on-borrowed.stderr b/src/test/ui/nll/match-on-borrowed.stderr index 664f36f695cf3..40c3d5141c6d9 100644 --- a/src/test/ui/nll/match-on-borrowed.stderr +++ b/src/test/ui/nll/match-on-borrowed.stderr @@ -40,6 +40,11 @@ LL | let n: Never; | - binding declared here but left uninitialized LL | match n {} | ^ `n` used here but it isn't initialized + | +help: use `=` to assign some value to `n` + | +LL | let n: Never = something; + | ~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 4 previous errors diff --git a/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr b/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr index 95c209f47c92a..68504f3c03987 100644 --- a/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr +++ b/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr @@ -6,6 +6,11 @@ LL | let y: &mut u32; ... LL | *y = 2; | ^^^^^^ `y` used here but it isn't initialized + | +help: use `=` to assign some value to `y` + | +LL | let y: &mut u32 = something; + | ~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to previous error From 719e41e218deacc265899070a74573494894f905 Mon Sep 17 00:00:00 2001 From: yukang Date: Fri, 23 Sep 2022 18:51:57 +0800 Subject: [PATCH 2/4] cleanup --- compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 66ee25a357b4c..8ce0a149cb3c6 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -16,7 +16,6 @@ use rustc_middle::mir::{ FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm, }; -//use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty}; use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex}; use rustc_span::def_id::LocalDefId; @@ -337,7 +336,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let inits = &self.move_data.init_path_map[mpi]; let move_path = &self.move_data.move_paths[mpi]; let decl_span = self.body.local_decls[move_path.place.local].source_info.span; - let mut spans = vec![]; for init_idx in inits { let init = &self.move_data.inits[*init_idx]; From 2bfab8e796d4b35c1518df62e0a223e6ee85c1d6 Mon Sep 17 00:00:00 2001 From: yukang Date: Sat, 24 Sep 2022 19:21:01 +0800 Subject: [PATCH 3/4] add LetVisitor for more accurate span --- .../src/diagnostics/conflict_errors.rs | 62 +++++++++++-------- src/test/ui/asm/x86_64/type-check-5.stderr | 8 +-- .../ui/borrowck/borrowck-block-unint.stderr | 4 +- .../borrowck/borrowck-break-uninit-2.stderr | 4 +- .../ui/borrowck/borrowck-break-uninit.stderr | 4 +- .../borrowck-init-in-called-fn-expr.stderr | 4 +- .../borrowck/borrowck-init-in-fn-expr.stderr | 4 +- .../ui/borrowck/borrowck-init-in-fru.stderr | 6 +- .../ui/borrowck/borrowck-init-op-equal.stderr | 4 +- .../borrowck/borrowck-init-plus-equal.stderr | 4 +- src/test/ui/borrowck/borrowck-return.stderr | 4 +- .../ui/borrowck/borrowck-storage-dead.stderr | 4 +- .../borrowck-uninit-after-item.stderr | 5 -- .../borrowck-uninit-field-access.stderr | 4 +- .../borrowck-uninit-in-assignop.stderr | 40 ++++++------ .../borrowck/borrowck-uninit-ref-chain.stderr | 18 +++--- src/test/ui/borrowck/borrowck-uninit.stderr | 4 +- .../borrowck-use-in-index-lvalue.stderr | 12 ++-- ...wck-use-uninitialized-in-cast-trait.stderr | 6 +- .../borrowck-use-uninitialized-in-cast.stderr | 6 +- .../ui/borrowck/borrowck-while-cond.stderr | 4 +- .../ui/borrowck/issue-24267-flow-exit.stderr | 8 +-- .../issue-62107-match-arm-scopes.stderr | 4 +- .../ui/borrowck/suggest-assign-rvalue.stderr | 40 ++++++------ .../match/pattern-matching-should-fail.stderr | 4 +- ...const-generic-default-wont-borrowck.stderr | 6 +- src/test/ui/consts/issue-78655.stderr | 5 -- src/test/ui/drop/repeat-drop-2.stderr | 4 +- src/test/ui/loops/loop-proper-liveness.stderr | 4 +- ...op-elaboration-after-borrowck-error.stderr | 6 +- .../moves/issue-72649-uninit-in-loop.stderr | 12 ++-- .../ui/moves/move-into-dead-array-1.stderr | 6 +- src/test/ui/moves/move-of-addr-of-mut.stderr | 6 +- src/test/ui/nll/match-cfg-fake-edges.stderr | 5 -- src/test/ui/nll/match-on-borrowed.stderr | 6 +- .../privately-uninhabited-mir-call.stderr | 6 +- 36 files changed, 163 insertions(+), 170 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 8ce0a149cb3c6..b6992805e08f6 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -451,29 +451,50 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { err.span_label(decl_span, "binding declared here but left uninitialized"); if show_assign_sugg { - self.suggest_assign_rvalue(&mut err, moved_place, &name, decl_span); + struct LetVisitor { + decl_span: Span, + ty_span: Option, + } + + impl<'v> Visitor<'v> for LetVisitor { + fn visit_stmt(&mut self, ex: &'v hir::Stmt<'v>) { + if self.ty_span.is_some() { + return; + } + if let hir::StmtKind::Local(hir::Local { + span, init: None, ty: Some(ty), .. + }) = &ex.kind && span.contains(self.decl_span) { + self.ty_span = Some(ty.span); + } + hir::intravisit::walk_stmt(self, ex); + } + } + + let mut visitor = LetVisitor { decl_span, ty_span: None }; + visitor.visit_body(&body); + if let Some(ty_span) = visitor.ty_span { + self.suggest_assign_value(&mut err, moved_place, ty_span); + } } err } - fn suggest_assign_rvalue( + fn suggest_assign_value( &self, err: &mut Diagnostic, moved_place: PlaceRef<'tcx>, - name: &str, - decl_span: Span, + ty_span: Span, ) { let ty = moved_place.ty(self.body, self.infcx.tcx).ty; debug!("ty: {:?}, kind: {:?}", ty, ty.kind()); - let initilize_msg = match ty.kind() { - ty::Array(_, n) => format!("[val; {}]", n), + let assign_value = match ty.kind() { ty::Int(_) | ty::Uint(_) => format!("0"), ty::Float(_) => format!("0.0"), ty::Bool => format!("false"), ty::Never | ty::Error(_) => "".to_string(), ty::Adt(def, _substs) => { - if format!("{:?}", def).starts_with("std::vec::Vec") { + if Some(def.did()) == self.infcx.tcx.get_diagnostic_item(sym::Vec) { format!("vec![]") } else if let Some(default_trait) = self.infcx.tcx.get_diagnostic_item(sym::Default) && self.infcx.tcx.infer_ctxt().enter(|infcx| { @@ -481,32 +502,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { }) { format!("Default::default()") } else { - format!("something") + format!("todo!()") } - }, - _ => format!("something"), + } + _ => format!("todo!()"), }; - if initilize_msg.is_empty() { + if assign_value.is_empty() { return; } - - let sugg_span = self - .infcx - .tcx - .sess - .source_map() - .span_extend_while(decl_span, |c| c != '\n') - .unwrap_or(decl_span); - let mut prefix = self.infcx.tcx.sess.source_map().span_to_snippet(sugg_span).unwrap(); - // remove last char if eq ';' - if prefix.ends_with(';') { - prefix.pop(); - } err.span_suggestion_verbose( - sugg_span, - format!("use `=` to assign some value to {}", name), - format!("{} = {};", prefix, initilize_msg), + ty_span.shrink_to_hi(), + format!("consider assigning a default value"), + format!(" = {}", assign_value), Applicability::MaybeIncorrect, ); } diff --git a/src/test/ui/asm/x86_64/type-check-5.stderr b/src/test/ui/asm/x86_64/type-check-5.stderr index 768f22f10f0ca..7cb80f0e4873b 100644 --- a/src/test/ui/asm/x86_64/type-check-5.stderr +++ b/src/test/ui/asm/x86_64/type-check-5.stderr @@ -6,10 +6,10 @@ LL | let x: u64; LL | asm!("{}", in(reg) x); | ^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: u64 = 0; - | ~~~~~~~~~~~ + | +++ error[E0381]: used binding `y` isn't initialized --> $DIR/type-check-5.rs:18:9 @@ -19,10 +19,10 @@ LL | let mut y: u64; LL | asm!("{}", inout(reg) y); | ^^^^^^^^^^^^^^^^^^^^^^^^ `y` used here but it isn't initialized | -help: use `=` to assign some value to `y` +help: consider assigning a default value | LL | let mut y: u64 = 0; - | ~~~~~~~~~~~~~~~ + | +++ error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable --> $DIR/type-check-5.rs:26:29 diff --git a/src/test/ui/borrowck/borrowck-block-unint.stderr b/src/test/ui/borrowck/borrowck-block-unint.stderr index e77ec994081bb..c1010b174798c 100644 --- a/src/test/ui/borrowck/borrowck-block-unint.stderr +++ b/src/test/ui/borrowck/borrowck-block-unint.stderr @@ -8,10 +8,10 @@ LL | force(|| { LL | println!("{}", x); | - borrow occurs due to use in closure | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-break-uninit-2.stderr b/src/test/ui/borrowck/borrowck-break-uninit-2.stderr index ce02c966d23a3..05e9f0a645218 100644 --- a/src/test/ui/borrowck/borrowck-break-uninit-2.stderr +++ b/src/test/ui/borrowck/borrowck-break-uninit-2.stderr @@ -8,10 +8,10 @@ LL | println!("{}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-break-uninit.stderr b/src/test/ui/borrowck/borrowck-break-uninit.stderr index 84c0df39a1421..005cdf324c775 100644 --- a/src/test/ui/borrowck/borrowck-break-uninit.stderr +++ b/src/test/ui/borrowck/borrowck-break-uninit.stderr @@ -8,10 +8,10 @@ LL | println!("{}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr b/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr index 438924c65886a..2541416b2d689 100644 --- a/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr +++ b/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr @@ -6,10 +6,10 @@ LL | let i: isize; LL | i | ^ `i` used here but it isn't initialized | -help: use `=` to assign some value to `i` +help: consider assigning a default value | LL | let i: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr b/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr index aa8d1442521cc..1c8a480fc2196 100644 --- a/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr +++ b/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr @@ -6,10 +6,10 @@ LL | let i: isize; LL | i | ^ `i` used here but it isn't initialized | -help: use `=` to assign some value to `i` +help: consider assigning a default value | LL | let i: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-init-in-fru.stderr b/src/test/ui/borrowck/borrowck-init-in-fru.stderr index 9515c46df6567..42db880775e8c 100644 --- a/src/test/ui/borrowck/borrowck-init-in-fru.stderr +++ b/src/test/ui/borrowck/borrowck-init-in-fru.stderr @@ -6,10 +6,10 @@ LL | let mut origin: Point; LL | origin = Point { x: 10, ..origin }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ `origin.y` used here but it isn't initialized | -help: use `=` to assign some value to `origin` +help: consider assigning a default value | -LL | let mut origin: Point = something; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let mut origin: Point = todo!(); + | +++++++++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-init-op-equal.stderr b/src/test/ui/borrowck/borrowck-init-op-equal.stderr index 61b4a3831348f..5667beb525898 100644 --- a/src/test/ui/borrowck/borrowck-init-op-equal.stderr +++ b/src/test/ui/borrowck/borrowck-init-op-equal.stderr @@ -6,10 +6,10 @@ LL | let v: isize; LL | v += 1; | ^^^^^^ `v` used here but it isn't initialized | -help: use `=` to assign some value to `v` +help: consider assigning a default value | LL | let v: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-init-plus-equal.stderr b/src/test/ui/borrowck/borrowck-init-plus-equal.stderr index 709db53c12390..45527d29e83eb 100644 --- a/src/test/ui/borrowck/borrowck-init-plus-equal.stderr +++ b/src/test/ui/borrowck/borrowck-init-plus-equal.stderr @@ -6,10 +6,10 @@ LL | let mut v: isize; LL | v = v + 1; | ^ `v` used here but it isn't initialized | -help: use `=` to assign some value to `v` +help: consider assigning a default value | LL | let mut v: isize = 0; - | ~~~~~~~~~~~~~~~~~ + | +++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-return.stderr b/src/test/ui/borrowck/borrowck-return.stderr index 9f64fde939615..d6ca7bf433332 100644 --- a/src/test/ui/borrowck/borrowck-return.stderr +++ b/src/test/ui/borrowck/borrowck-return.stderr @@ -6,10 +6,10 @@ LL | let x: isize; LL | return x; | ^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-storage-dead.stderr b/src/test/ui/borrowck/borrowck-storage-dead.stderr index 2cd6da96f4469..dce4352b3a33a 100644 --- a/src/test/ui/borrowck/borrowck-storage-dead.stderr +++ b/src/test/ui/borrowck/borrowck-storage-dead.stderr @@ -6,10 +6,10 @@ LL | let x: i32; LL | let _ = x + 1; | ^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: i32 = 0; - | ~~~~~~~~~~~ + | +++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-uninit-after-item.stderr b/src/test/ui/borrowck/borrowck-uninit-after-item.stderr index cae2bd9e69a95..588b1b0c9729c 100644 --- a/src/test/ui/borrowck/borrowck-uninit-after-item.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-after-item.stderr @@ -6,11 +6,6 @@ LL | let bar; LL | fn baz(_x: isize) { } LL | baz(bar); | ^^^ `bar` used here but it isn't initialized - | -help: use `=` to assign some value to `bar` - | -LL | let bar = 0; - | ~~~~~~~~ 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 ccfeb40834afc..cd895d8fcb4e2 100644 --- a/src/test/ui/borrowck/borrowck-uninit-field-access.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-field-access.stderr @@ -6,10 +6,10 @@ LL | let mut a: Point; LL | let _ = a.x + 1; | ^^^ `a.x` used here but it isn't initialized | -help: use `=` to assign some value to `a` +help: consider assigning a default value | LL | let mut a: Point = Default::default(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + | ++++++++++++++++++++ error[E0382]: use of moved value: `line1.origin` --> $DIR/borrowck-uninit-field-access.rs:25:13 diff --git a/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr b/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr index 65228593775c1..cdbb3df572361 100644 --- a/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr @@ -6,10 +6,10 @@ LL | let x: isize; LL | x += 1; | ^^^^^^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:9:5 @@ -19,10 +19,10 @@ LL | let x: isize; LL | x -= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:12:5 @@ -32,10 +32,10 @@ LL | let x: isize; LL | x *= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:15:5 @@ -45,10 +45,10 @@ LL | let x: isize; LL | x /= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:18:5 @@ -58,10 +58,10 @@ LL | let x: isize; LL | x %= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:21:5 @@ -71,10 +71,10 @@ LL | let x: isize; LL | x ^= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:24:5 @@ -84,10 +84,10 @@ LL | let x: isize; LL | x &= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:27:5 @@ -97,10 +97,10 @@ LL | let x: isize; LL | x |= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:30:5 @@ -110,10 +110,10 @@ LL | let x: isize; LL | x <<= 1; | ^^^^^^^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-in-assignop.rs:33:5 @@ -123,10 +123,10 @@ LL | let x: isize; LL | x >>= 1; | ^^^^^^^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error: aborting due to 10 previous errors diff --git a/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr b/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr index 4084454e36b97..5fb8fd2e16987 100644 --- a/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr @@ -6,10 +6,10 @@ LL | let x: &&Box; LL | let _y = &**x; | ^^^^ `**x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | -LL | let x: &&Box = something; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let x: &&Box = todo!(); + | +++++++++ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-ref-chain.rs:11:14 @@ -19,10 +19,10 @@ LL | let x: &&S; LL | let _y = &**x; | ^^^^ `**x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | -LL | let x: &&S = something; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let x: &&S = todo!(); + | +++++++++ error[E0381]: used binding `x` isn't initialized --> $DIR/borrowck-uninit-ref-chain.rs:14:14 @@ -32,10 +32,10 @@ LL | let x: &&i32; LL | let _y = &**x; | ^^^^ `**x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | -LL | let x: &&i32 = something; - | ~~~~~~~~~~~~~~~~~~~~~ +LL | let x: &&i32 = todo!(); + | +++++++++ error[E0381]: partially assigned binding `a` isn't fully initialized --> $DIR/borrowck-uninit-ref-chain.rs:18:5 diff --git a/src/test/ui/borrowck/borrowck-uninit.stderr b/src/test/ui/borrowck/borrowck-uninit.stderr index e16bdbc14e07c..d86d384b3f29a 100644 --- a/src/test/ui/borrowck/borrowck-uninit.stderr +++ b/src/test/ui/borrowck/borrowck-uninit.stderr @@ -6,10 +6,10 @@ LL | let x: isize; LL | foo(x); | ^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: isize = 0; - | ~~~~~~~~~~~~~ + | +++ error: aborting due to previous error 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 a8f797c163911..f86e61b1b4434 100644 --- a/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr +++ b/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr @@ -6,10 +6,10 @@ LL | let w: &mut [isize]; LL | w[5] = 0; | ^^^^ `*w` used here but it isn't initialized | -help: use `=` to assign some value to `w` +help: consider assigning a default value | -LL | let w: &mut [isize] = something; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let w: &mut [isize] = todo!(); + | +++++++++ error[E0381]: used binding `w` isn't initialized --> $DIR/borrowck-use-in-index-lvalue.rs:6:5 @@ -19,10 +19,10 @@ LL | let mut w: &mut [isize]; LL | w[5] = 0; | ^^^^ `*w` used here but it isn't initialized | -help: use `=` to assign some value to `w` +help: consider assigning a default value | -LL | let mut w: &mut [isize] = something; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let mut w: &mut [isize] = todo!(); + | +++++++++ error: aborting due to 2 previous errors 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 92ac4c1b46f27..cc89b615cdbb5 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 @@ -6,10 +6,10 @@ LL | let x: &i32; LL | let y = x as *const dyn Foo; | ^ `*x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | -LL | let x: &i32 = something; - | ~~~~~~~~~~~~~~~~~~~~ +LL | let x: &i32 = todo!(); + | +++++++++ error: aborting due to previous error 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 18821c2008315..0edf66a9fcef3 100644 --- a/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr +++ b/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr @@ -6,10 +6,10 @@ LL | let x: &i32; LL | let y = x as *const i32; | ^ `*x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | -LL | let x: &i32 = something; - | ~~~~~~~~~~~~~~~~~~~~ +LL | let x: &i32 = todo!(); + | +++++++++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrowck-while-cond.stderr b/src/test/ui/borrowck/borrowck-while-cond.stderr index 447a5687c3217..0991518e2cf38 100644 --- a/src/test/ui/borrowck/borrowck-while-cond.stderr +++ b/src/test/ui/borrowck/borrowck-while-cond.stderr @@ -6,10 +6,10 @@ LL | let x: bool; LL | while x { } | ^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: bool = false; - | ~~~~~~~~~~~~~~~~ + | +++++++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/issue-24267-flow-exit.stderr b/src/test/ui/borrowck/issue-24267-flow-exit.stderr index 2a17a111d8d3d..c3f72607f4aa5 100644 --- a/src/test/ui/borrowck/issue-24267-flow-exit.stderr +++ b/src/test/ui/borrowck/issue-24267-flow-exit.stderr @@ -8,10 +8,10 @@ LL | println!("{}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: i32 = 0; - | ~~~~~~~~~~~ + | +++ error[E0381]: used binding `x` isn't initialized --> $DIR/issue-24267-flow-exit.rs:18:20 @@ -23,10 +23,10 @@ LL | println!("{}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: i32 = 0; - | ~~~~~~~~~~~ + | +++ error: aborting due to 2 previous errors diff --git a/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr b/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr index 4a27c0a06f7ff..f928865de5e24 100644 --- a/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr +++ b/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr @@ -6,10 +6,10 @@ LL | let e: i32; LL | match e { | ^ `e` used here but it isn't initialized | -help: use `=` to assign some value to `e` +help: consider assigning a default value | LL | let e: i32 = 0; - | ~~~~~~~~~~~ + | +++ error: aborting due to previous error diff --git a/src/test/ui/borrowck/suggest-assign-rvalue.stderr b/src/test/ui/borrowck/suggest-assign-rvalue.stderr index 585967e086dd8..be68b9eb38985 100644 --- a/src/test/ui/borrowck/suggest-assign-rvalue.stderr +++ b/src/test/ui/borrowck/suggest-assign-rvalue.stderr @@ -7,10 +7,10 @@ LL | println!("my_float: {}", my_float); | ^^^^^^^^ `my_float` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `my_float` +help: consider assigning a default value | LL | let my_float: f32 = 0.0; - | ~~~~~~~~~~~~~~~~~~~~ + | +++++ error[E0381]: used binding `demo` isn't initialized --> $DIR/suggest-assign-rvalue.rs:18:28 @@ -21,10 +21,10 @@ LL | println!("demo: {:?}", demo); | ^^^^ `demo` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `demo` +help: consider assigning a default value | LL | let demo: Demo = Default::default(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + | ++++++++++++++++++++ error[E0381]: used binding `demo_no` isn't initialized --> $DIR/suggest-assign-rvalue.rs:22:31 @@ -35,10 +35,10 @@ LL | println!("demo_no: {:?}", demo_no); | ^^^^^^^ `demo_no` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `demo_no` +help: consider assigning a default value | -LL | let demo_no: DemoNoDef = something; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let demo_no: DemoNoDef = todo!(); + | +++++++++ error[E0381]: used binding `arr` isn't initialized --> $DIR/suggest-assign-rvalue.rs:26:27 @@ -49,10 +49,10 @@ LL | println!("arr: {:?}", arr); | ^^^ `arr` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `arr` +help: consider assigning a default value | -LL | let arr: [i32; 5] = [val; 5]; - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let arr: [i32; 5] = todo!(); + | +++++++++ error[E0381]: used binding `foo` isn't initialized --> $DIR/suggest-assign-rvalue.rs:29:27 @@ -63,10 +63,10 @@ LL | println!("foo: {:?}", foo); | ^^^ `foo` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `foo` +help: consider assigning a default value | LL | let foo: Vec<&str> = vec![]; - | ~~~~~~~~~~~~~~~~~~~~~~~~ + | ++++++++ error[E0381]: used binding `my_string` isn't initialized --> $DIR/suggest-assign-rvalue.rs:33:31 @@ -77,10 +77,10 @@ LL | println!("my_string: {}", my_string); | ^^^^^^^^^ `my_string` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `my_string` +help: consider assigning a default value | LL | let my_string: String = Default::default(); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + | ++++++++++++++++++++ error[E0381]: used binding `my_int` isn't initialized --> $DIR/suggest-assign-rvalue.rs:37:28 @@ -91,10 +91,10 @@ LL | println!("my_int: {}", *my_int); | ^^^^^^^ `*my_int` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `my_int` +help: consider assigning a default value | -LL | let my_int: &i32 = something; - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let my_int: &i32 = todo!(); + | +++++++++ error[E0381]: used binding `hello` isn't initialized --> $DIR/suggest-assign-rvalue.rs:41:27 @@ -105,10 +105,10 @@ LL | println!("hello: {}", hello); | ^^^^^ `hello` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `hello` +help: consider assigning a default value | -LL | let hello: &str = something; - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let hello: &str = todo!(); + | +++++++++ error[E0381]: used binding `never` isn't initialized --> $DIR/suggest-assign-rvalue.rs:45:27 diff --git a/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr b/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr index 80ff0f761e3ae..bc8e52180bbbc 100644 --- a/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr +++ b/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr @@ -77,10 +77,10 @@ LL | let x: u8; LL | let c1 = || match x { }; | ^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: u8 = 0; - | ~~~~~~~~~~ + | +++ error: aborting due to 8 previous errors 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 4207058e858a6..0c48fa4043785 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 @@ -6,10 +6,10 @@ LL | let s: &'static str; s.len() | | | binding declared here but left uninitialized | -help: use `=` to assign some value to `s` +help: consider assigning a default value | -LL | let s: &'static str; s.len() - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let s: &'static str = todo!(); s.len() + | +++++++++ error: aborting due to previous error diff --git a/src/test/ui/consts/issue-78655.stderr b/src/test/ui/consts/issue-78655.stderr index 256920cfaebc0..f5b1123e7f343 100644 --- a/src/test/ui/consts/issue-78655.stderr +++ b/src/test/ui/consts/issue-78655.stderr @@ -5,11 +5,6 @@ LL | let x; | - binding declared here but left uninitialized LL | &x | ^^ `x` used here but it isn't initialized - | -help: use `=` to assign some value to `x` - | -LL | let x = 0; - | ~~~~~~ error: could not evaluate constant pattern --> $DIR/issue-78655.rs:7:9 diff --git a/src/test/ui/drop/repeat-drop-2.stderr b/src/test/ui/drop/repeat-drop-2.stderr index dd55b1a860e23..613268bbc9ac6 100644 --- a/src/test/ui/drop/repeat-drop-2.stderr +++ b/src/test/ui/drop/repeat-drop-2.stderr @@ -25,10 +25,10 @@ LL | let x: u8; LL | let _ = [x; 0]; | ^ `x` used here but it isn't initialized | -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: u8 = 0; - | ~~~~~~~~~~ + | +++ error: aborting due to 3 previous errors diff --git a/src/test/ui/loops/loop-proper-liveness.stderr b/src/test/ui/loops/loop-proper-liveness.stderr index 801b5e62db19b..c256c970feb37 100644 --- a/src/test/ui/loops/loop-proper-liveness.stderr +++ b/src/test/ui/loops/loop-proper-liveness.stderr @@ -8,10 +8,10 @@ LL | println!("{:?}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `x` +help: consider assigning a default value | LL | let x: i32 = 0; - | ~~~~~~~~~~~ + | +++ error: aborting due to previous error diff --git a/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr b/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr index 764182484da4f..34a1a7488d2bd 100644 --- a/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr +++ b/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr @@ -25,10 +25,10 @@ LL | LL | a[0] = String::new(); | ^^^^ `a` used here but it isn't initialized | -help: use `=` to assign some value to `a` +help: consider assigning a default value | -LL | let a: [String; 1] = [val; 1]; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let a: [String; 1] = todo!(); + | +++++++++ error[E0493]: destructors cannot be evaluated at compile-time --> $DIR/drop-elaboration-after-borrowck-error.rs:18:9 diff --git a/src/test/ui/moves/issue-72649-uninit-in-loop.stderr b/src/test/ui/moves/issue-72649-uninit-in-loop.stderr index 305ff7c093c54..a13bdf769e1ef 100644 --- a/src/test/ui/moves/issue-72649-uninit-in-loop.stderr +++ b/src/test/ui/moves/issue-72649-uninit-in-loop.stderr @@ -48,10 +48,10 @@ LL | let value: NonCopy; LL | let _used = value; | ^^^^^ `value` used here but it isn't initialized | -help: use `=` to assign some value to `value` +help: consider assigning a default value | -LL | let value: NonCopy; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let value: NonCopy = todo!(); + | +++++++++ error[E0381]: used binding `value` isn't initialized --> $DIR/issue-72649-uninit-in-loop.rs:69:21 @@ -62,10 +62,10 @@ LL | loop { LL | let _used = value; | ^^^^^ `value` used here but it isn't initialized | -help: use `=` to assign some value to `value` +help: consider assigning a default value | -LL | let mut value: NonCopy; - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let mut value: NonCopy = todo!(); + | +++++++++ error: aborting due to 6 previous errors diff --git a/src/test/ui/moves/move-into-dead-array-1.stderr b/src/test/ui/moves/move-into-dead-array-1.stderr index 756276caa09e8..7a05f28dac628 100644 --- a/src/test/ui/moves/move-into-dead-array-1.stderr +++ b/src/test/ui/moves/move-into-dead-array-1.stderr @@ -6,10 +6,10 @@ LL | let mut a: [D; 4]; LL | a[i] = d(); | ^^^^ `a` used here but it isn't initialized | -help: use `=` to assign some value to `a` +help: consider assigning a default value | -LL | let mut a: [D; 4] = [val; 4]; - | ~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let mut a: [D; 4] = todo!(); + | +++++++++ error: aborting due to previous error diff --git a/src/test/ui/moves/move-of-addr-of-mut.stderr b/src/test/ui/moves/move-of-addr-of-mut.stderr index f2325fb3e576b..07a685806be14 100644 --- a/src/test/ui/moves/move-of-addr-of-mut.stderr +++ b/src/test/ui/moves/move-of-addr-of-mut.stderr @@ -7,10 +7,10 @@ LL | std::ptr::addr_of_mut!(x); | ^^^^^^^^^^^^^^^^^^^^^^^^^ `x` used here but it isn't initialized | = note: this error originates in the macro `std::ptr::addr_of_mut` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use `=` to assign some value to `x` +help: consider assigning a default value | -LL | let mut x: S = something; - | ~~~~~~~~~~~~~~~~~~~~~ +LL | let mut x: S = todo!(); + | +++++++++ error: aborting due to previous error diff --git a/src/test/ui/nll/match-cfg-fake-edges.stderr b/src/test/ui/nll/match-cfg-fake-edges.stderr index 73eb5137f3705..250aa482e5c67 100644 --- a/src/test/ui/nll/match-cfg-fake-edges.stderr +++ b/src/test/ui/nll/match-cfg-fake-edges.stderr @@ -9,11 +9,6 @@ LL | _ if { x = 2; true } => 1, LL | _ if { LL | x; | ^ `x` used here but it isn't initialized - | -help: use `=` to assign some value to `x` - | -LL | let x = 0; - | ~~~~~~ error[E0382]: use of moved value: `x` --> $DIR/match-cfg-fake-edges.rs:35:13 diff --git a/src/test/ui/nll/match-on-borrowed.stderr b/src/test/ui/nll/match-on-borrowed.stderr index 40c3d5141c6d9..827ed655854ef 100644 --- a/src/test/ui/nll/match-on-borrowed.stderr +++ b/src/test/ui/nll/match-on-borrowed.stderr @@ -41,10 +41,10 @@ LL | let n: Never; LL | match n {} | ^ `n` used here but it isn't initialized | -help: use `=` to assign some value to `n` +help: consider assigning a default value | -LL | let n: Never = something; - | ~~~~~~~~~~~~~~~~~~~~~ +LL | let n: Never = todo!(); + | +++++++++ error: aborting due to 4 previous errors diff --git a/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr b/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr index 68504f3c03987..a88b0a8d05041 100644 --- a/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr +++ b/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr @@ -7,10 +7,10 @@ LL | let y: &mut u32; LL | *y = 2; | ^^^^^^ `y` used here but it isn't initialized | -help: use `=` to assign some value to `y` +help: consider assigning a default value | -LL | let y: &mut u32 = something; - | ~~~~~~~~~~~~~~~~~~~~~~~~ +LL | let y: &mut u32 = todo!(); + | +++++++++ error: aborting due to previous error From 21b9222e1a56e7f9ad3d997b326259034c3f29e6 Mon Sep 17 00:00:00 2001 From: yukang Date: Sat, 24 Sep 2022 22:58:24 +0800 Subject: [PATCH 4/4] suggest assign value for let without a type decl --- .../src/diagnostics/conflict_errors.rs | 67 ++++++++++--------- src/test/ui/asm/x86_64/type-check-5.stderr | 4 +- .../ui/borrowck/borrowck-block-unint.stderr | 2 +- .../borrowck/borrowck-break-uninit-2.stderr | 2 +- .../ui/borrowck/borrowck-break-uninit.stderr | 2 +- .../borrowck-init-in-called-fn-expr.stderr | 2 +- .../borrowck/borrowck-init-in-fn-expr.stderr | 2 +- .../ui/borrowck/borrowck-init-in-fru.stderr | 2 +- .../ui/borrowck/borrowck-init-op-equal.stderr | 2 +- .../borrowck/borrowck-init-plus-equal.stderr | 2 +- src/test/ui/borrowck/borrowck-return.stderr | 2 +- .../ui/borrowck/borrowck-storage-dead.stderr | 2 +- .../borrowck-uninit-after-item.stderr | 5 ++ .../borrowck-uninit-field-access.stderr | 2 +- .../borrowck-uninit-in-assignop.stderr | 20 +++--- .../borrowck/borrowck-uninit-ref-chain.stderr | 6 +- src/test/ui/borrowck/borrowck-uninit.stderr | 2 +- .../borrowck-use-in-index-lvalue.stderr | 4 +- ...wck-use-uninitialized-in-cast-trait.stderr | 2 +- .../borrowck-use-uninitialized-in-cast.stderr | 2 +- .../ui/borrowck/borrowck-while-cond.stderr | 2 +- .../ui/borrowck/issue-24267-flow-exit.stderr | 4 +- .../issue-62107-match-arm-scopes.stderr | 2 +- src/test/ui/borrowck/suggest-assign-rvalue.rs | 10 +++ .../ui/borrowck/suggest-assign-rvalue.stderr | 49 +++++++++----- .../match/pattern-matching-should-fail.stderr | 2 +- ...const-generic-default-wont-borrowck.stderr | 2 +- src/test/ui/consts/issue-78655.stderr | 5 ++ src/test/ui/drop/repeat-drop-2.stderr | 2 +- src/test/ui/loops/loop-proper-liveness.stderr | 2 +- ...op-elaboration-after-borrowck-error.stderr | 2 +- .../moves/issue-72649-uninit-in-loop.stderr | 4 +- .../ui/moves/move-into-dead-array-1.stderr | 2 +- src/test/ui/moves/move-of-addr-of-mut.stderr | 2 +- src/test/ui/nll/match-cfg-fake-edges.stderr | 5 ++ src/test/ui/nll/match-on-borrowed.stderr | 2 +- .../privately-uninhabited-mir-call.stderr | 2 +- 37 files changed, 136 insertions(+), 97 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index b6992805e08f6..3182656b6aa92 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -453,27 +453,27 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { if show_assign_sugg { struct LetVisitor { decl_span: Span, - ty_span: Option, + sugg_span: Option, } impl<'v> Visitor<'v> for LetVisitor { fn visit_stmt(&mut self, ex: &'v hir::Stmt<'v>) { - if self.ty_span.is_some() { + if self.sugg_span.is_some() { return; } if let hir::StmtKind::Local(hir::Local { - span, init: None, ty: Some(ty), .. + span, ty, init: None, .. }) = &ex.kind && span.contains(self.decl_span) { - self.ty_span = Some(ty.span); + self.sugg_span = ty.map_or(Some(self.decl_span), |ty| Some(ty.span)); } hir::intravisit::walk_stmt(self, ex); } } - let mut visitor = LetVisitor { decl_span, ty_span: None }; + let mut visitor = LetVisitor { decl_span, sugg_span: None }; visitor.visit_body(&body); - if let Some(ty_span) = visitor.ty_span { - self.suggest_assign_value(&mut err, moved_place, ty_span); + if let Some(span) = visitor.sugg_span { + self.suggest_assign_value(&mut err, moved_place, span); } } err @@ -483,40 +483,41 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { &self, err: &mut Diagnostic, moved_place: PlaceRef<'tcx>, - ty_span: Span, + sugg_span: Span, ) { let ty = moved_place.ty(self.body, self.infcx.tcx).ty; debug!("ty: {:?}, kind: {:?}", ty, ty.kind()); + let tcx = self.infcx.tcx; + let implements_default = |ty, param_env| { + let Some(default_trait) = tcx.get_diagnostic_item(sym::Default) else { + return false; + }; + tcx.infer_ctxt().enter(|infcx| { + infcx + .type_implements_trait(default_trait, ty, ty::List::empty(), param_env) + .may_apply() + }) + }; + let assign_value = match ty.kind() { - ty::Int(_) | ty::Uint(_) => format!("0"), - ty::Float(_) => format!("0.0"), - ty::Bool => format!("false"), - ty::Never | ty::Error(_) => "".to_string(), - ty::Adt(def, _substs) => { - if Some(def.did()) == self.infcx.tcx.get_diagnostic_item(sym::Vec) { - format!("vec![]") - } else if let Some(default_trait) = self.infcx.tcx.get_diagnostic_item(sym::Default) && - self.infcx.tcx.infer_ctxt().enter(|infcx| { - infcx.type_implements_trait(default_trait, ty, ty::List::empty(), self.param_env).may_apply() - }) { - format!("Default::default()") - } else { - format!("todo!()") - } - } - _ => format!("todo!()"), + ty::Bool => "false", + ty::Float(_) => "0.0", + ty::Int(_) | ty::Uint(_) => "0", + ty::Never | ty::Error(_) => "", + ty::Adt(def, _) if Some(def.did()) == tcx.get_diagnostic_item(sym::Vec) => "vec![]", + ty::Adt(_, _) if implements_default(ty, self.param_env) => "Default::default()", + _ => "todo!()", }; - if assign_value.is_empty() { - return; + if !assign_value.is_empty() { + err.span_suggestion_verbose( + sugg_span.shrink_to_hi(), + format!("consider assigning a value"), + format!(" = {}", assign_value), + Applicability::MaybeIncorrect, + ); } - err.span_suggestion_verbose( - ty_span.shrink_to_hi(), - format!("consider assigning a default value"), - format!(" = {}", assign_value), - Applicability::MaybeIncorrect, - ); } fn suggest_borrow_fn_like( diff --git a/src/test/ui/asm/x86_64/type-check-5.stderr b/src/test/ui/asm/x86_64/type-check-5.stderr index 7cb80f0e4873b..bd90461e52c17 100644 --- a/src/test/ui/asm/x86_64/type-check-5.stderr +++ b/src/test/ui/asm/x86_64/type-check-5.stderr @@ -6,7 +6,7 @@ LL | let x: u64; LL | asm!("{}", in(reg) x); | ^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: u64 = 0; | +++ @@ -19,7 +19,7 @@ LL | let mut y: u64; LL | asm!("{}", inout(reg) y); | ^^^^^^^^^^^^^^^^^^^^^^^^ `y` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let mut y: u64 = 0; | +++ diff --git a/src/test/ui/borrowck/borrowck-block-unint.stderr b/src/test/ui/borrowck/borrowck-block-unint.stderr index c1010b174798c..f47921a975269 100644 --- a/src/test/ui/borrowck/borrowck-block-unint.stderr +++ b/src/test/ui/borrowck/borrowck-block-unint.stderr @@ -8,7 +8,7 @@ LL | force(|| { LL | println!("{}", x); | - borrow occurs due to use in closure | -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ diff --git a/src/test/ui/borrowck/borrowck-break-uninit-2.stderr b/src/test/ui/borrowck/borrowck-break-uninit-2.stderr index 05e9f0a645218..ea93a8f409ce4 100644 --- a/src/test/ui/borrowck/borrowck-break-uninit-2.stderr +++ b/src/test/ui/borrowck/borrowck-break-uninit-2.stderr @@ -8,7 +8,7 @@ LL | println!("{}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ diff --git a/src/test/ui/borrowck/borrowck-break-uninit.stderr b/src/test/ui/borrowck/borrowck-break-uninit.stderr index 005cdf324c775..a7a8fc2ff8378 100644 --- a/src/test/ui/borrowck/borrowck-break-uninit.stderr +++ b/src/test/ui/borrowck/borrowck-break-uninit.stderr @@ -8,7 +8,7 @@ LL | println!("{}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ diff --git a/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr b/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr index 2541416b2d689..1a22b5f0975c0 100644 --- a/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr +++ b/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr @@ -6,7 +6,7 @@ LL | let i: isize; LL | i | ^ `i` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let i: isize = 0; | +++ diff --git a/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr b/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr index 1c8a480fc2196..f1b9b9aa7090a 100644 --- a/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr +++ b/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr @@ -6,7 +6,7 @@ LL | let i: isize; LL | i | ^ `i` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let i: isize = 0; | +++ diff --git a/src/test/ui/borrowck/borrowck-init-in-fru.stderr b/src/test/ui/borrowck/borrowck-init-in-fru.stderr index 42db880775e8c..39b28811a0c27 100644 --- a/src/test/ui/borrowck/borrowck-init-in-fru.stderr +++ b/src/test/ui/borrowck/borrowck-init-in-fru.stderr @@ -6,7 +6,7 @@ LL | let mut origin: Point; LL | origin = Point { x: 10, ..origin }; | ^^^^^^^^^^^^^^^^^^^^^^^^^ `origin.y` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let mut origin: Point = todo!(); | +++++++++ diff --git a/src/test/ui/borrowck/borrowck-init-op-equal.stderr b/src/test/ui/borrowck/borrowck-init-op-equal.stderr index 5667beb525898..ef0fa6df4fb7e 100644 --- a/src/test/ui/borrowck/borrowck-init-op-equal.stderr +++ b/src/test/ui/borrowck/borrowck-init-op-equal.stderr @@ -6,7 +6,7 @@ LL | let v: isize; LL | v += 1; | ^^^^^^ `v` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let v: isize = 0; | +++ diff --git a/src/test/ui/borrowck/borrowck-init-plus-equal.stderr b/src/test/ui/borrowck/borrowck-init-plus-equal.stderr index 45527d29e83eb..cec0533183647 100644 --- a/src/test/ui/borrowck/borrowck-init-plus-equal.stderr +++ b/src/test/ui/borrowck/borrowck-init-plus-equal.stderr @@ -6,7 +6,7 @@ LL | let mut v: isize; LL | v = v + 1; | ^ `v` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let mut v: isize = 0; | +++ diff --git a/src/test/ui/borrowck/borrowck-return.stderr b/src/test/ui/borrowck/borrowck-return.stderr index d6ca7bf433332..9799357c9ca19 100644 --- a/src/test/ui/borrowck/borrowck-return.stderr +++ b/src/test/ui/borrowck/borrowck-return.stderr @@ -6,7 +6,7 @@ LL | let x: isize; LL | return x; | ^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ diff --git a/src/test/ui/borrowck/borrowck-storage-dead.stderr b/src/test/ui/borrowck/borrowck-storage-dead.stderr index dce4352b3a33a..3a413153acd19 100644 --- a/src/test/ui/borrowck/borrowck-storage-dead.stderr +++ b/src/test/ui/borrowck/borrowck-storage-dead.stderr @@ -6,7 +6,7 @@ LL | let x: i32; LL | let _ = x + 1; | ^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: i32 = 0; | +++ diff --git a/src/test/ui/borrowck/borrowck-uninit-after-item.stderr b/src/test/ui/borrowck/borrowck-uninit-after-item.stderr index 588b1b0c9729c..071598b42eecd 100644 --- a/src/test/ui/borrowck/borrowck-uninit-after-item.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-after-item.stderr @@ -6,6 +6,11 @@ LL | let bar; LL | fn baz(_x: isize) { } LL | baz(bar); | ^^^ `bar` used here but it isn't initialized + | +help: consider assigning a value + | +LL | let bar = 0; + | +++ 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 cd895d8fcb4e2..f0f4ad704b7ca 100644 --- a/src/test/ui/borrowck/borrowck-uninit-field-access.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-field-access.stderr @@ -6,7 +6,7 @@ LL | let mut a: Point; LL | let _ = a.x + 1; | ^^^ `a.x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let mut a: Point = Default::default(); | ++++++++++++++++++++ diff --git a/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr b/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr index cdbb3df572361..fdbb451bde4e8 100644 --- a/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr @@ -6,7 +6,7 @@ LL | let x: isize; LL | x += 1; | ^^^^^^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ @@ -19,7 +19,7 @@ LL | let x: isize; LL | x -= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ @@ -32,7 +32,7 @@ LL | let x: isize; LL | x *= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ @@ -45,7 +45,7 @@ LL | let x: isize; LL | x /= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ @@ -58,7 +58,7 @@ LL | let x: isize; LL | x %= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ @@ -71,7 +71,7 @@ LL | let x: isize; LL | x ^= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ @@ -84,7 +84,7 @@ LL | let x: isize; LL | x &= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ @@ -97,7 +97,7 @@ LL | let x: isize; LL | x |= 1; | ^^^^^^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ @@ -110,7 +110,7 @@ LL | let x: isize; LL | x <<= 1; | ^^^^^^^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ @@ -123,7 +123,7 @@ LL | let x: isize; LL | x >>= 1; | ^^^^^^^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ diff --git a/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr b/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr index 5fb8fd2e16987..73fded7545cc6 100644 --- a/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr +++ b/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr @@ -6,7 +6,7 @@ LL | let x: &&Box; LL | let _y = &**x; | ^^^^ `**x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: &&Box = todo!(); | +++++++++ @@ -19,7 +19,7 @@ LL | let x: &&S; LL | let _y = &**x; | ^^^^ `**x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: &&S = todo!(); | +++++++++ @@ -32,7 +32,7 @@ LL | let x: &&i32; LL | let _y = &**x; | ^^^^ `**x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: &&i32 = todo!(); | +++++++++ diff --git a/src/test/ui/borrowck/borrowck-uninit.stderr b/src/test/ui/borrowck/borrowck-uninit.stderr index d86d384b3f29a..eeafc4ce191c6 100644 --- a/src/test/ui/borrowck/borrowck-uninit.stderr +++ b/src/test/ui/borrowck/borrowck-uninit.stderr @@ -6,7 +6,7 @@ LL | let x: isize; LL | foo(x); | ^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: isize = 0; | +++ 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 f86e61b1b4434..18e808f10d0c6 100644 --- a/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr +++ b/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr @@ -6,7 +6,7 @@ LL | let w: &mut [isize]; LL | w[5] = 0; | ^^^^ `*w` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let w: &mut [isize] = todo!(); | +++++++++ @@ -19,7 +19,7 @@ LL | let mut w: &mut [isize]; LL | w[5] = 0; | ^^^^ `*w` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let mut w: &mut [isize] = todo!(); | +++++++++ 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 cc89b615cdbb5..55f3ff553c13c 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 @@ -6,7 +6,7 @@ LL | let x: &i32; LL | let y = x as *const dyn Foo; | ^ `*x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: &i32 = todo!(); | +++++++++ 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 0edf66a9fcef3..ea3d0d3ef51cb 100644 --- a/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr +++ b/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr @@ -6,7 +6,7 @@ LL | let x: &i32; LL | let y = x as *const i32; | ^ `*x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: &i32 = todo!(); | +++++++++ diff --git a/src/test/ui/borrowck/borrowck-while-cond.stderr b/src/test/ui/borrowck/borrowck-while-cond.stderr index 0991518e2cf38..5d01949895639 100644 --- a/src/test/ui/borrowck/borrowck-while-cond.stderr +++ b/src/test/ui/borrowck/borrowck-while-cond.stderr @@ -6,7 +6,7 @@ LL | let x: bool; LL | while x { } | ^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: bool = false; | +++++++ diff --git a/src/test/ui/borrowck/issue-24267-flow-exit.stderr b/src/test/ui/borrowck/issue-24267-flow-exit.stderr index c3f72607f4aa5..58d1c8c0f73ad 100644 --- a/src/test/ui/borrowck/issue-24267-flow-exit.stderr +++ b/src/test/ui/borrowck/issue-24267-flow-exit.stderr @@ -8,7 +8,7 @@ LL | println!("{}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let x: i32 = 0; | +++ @@ -23,7 +23,7 @@ LL | println!("{}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let x: i32 = 0; | +++ diff --git a/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr b/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr index f928865de5e24..9683da919aaf3 100644 --- a/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr +++ b/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr @@ -6,7 +6,7 @@ LL | let e: i32; LL | match e { | ^ `e` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let e: i32 = 0; | +++ diff --git a/src/test/ui/borrowck/suggest-assign-rvalue.rs b/src/test/ui/borrowck/suggest-assign-rvalue.rs index 1db3cecdd8b13..aaca9d47f0aee 100644 --- a/src/test/ui/borrowck/suggest-assign-rvalue.rs +++ b/src/test/ui/borrowck/suggest-assign-rvalue.rs @@ -7,6 +7,14 @@ struct Demo {} #[derive(Debug)] struct DemoNoDef {} +fn apple(_: u32) {} + +fn banana() { + let chaenomeles; + apple(chaenomeles); + //~^ ERROR used binding `chaenomeles` isn't initialized [E0381] +} + fn main() { let my_bool: bool = bool::default(); println!("my_bool: {}", my_bool); @@ -44,4 +52,6 @@ fn main() { let never: !; println!("never: {}", never); //~^ ERROR used binding `never` isn't initialized [E0381] + + banana(); } diff --git a/src/test/ui/borrowck/suggest-assign-rvalue.stderr b/src/test/ui/borrowck/suggest-assign-rvalue.stderr index be68b9eb38985..92acba640d756 100644 --- a/src/test/ui/borrowck/suggest-assign-rvalue.stderr +++ b/src/test/ui/borrowck/suggest-assign-rvalue.stderr @@ -1,5 +1,18 @@ +error[E0381]: used binding `chaenomeles` isn't initialized + --> $DIR/suggest-assign-rvalue.rs:14:11 + | +LL | let chaenomeles; + | ----------- binding declared here but left uninitialized +LL | apple(chaenomeles); + | ^^^^^^^^^^^ `chaenomeles` used here but it isn't initialized + | +help: consider assigning a value + | +LL | let chaenomeles = 0; + | +++ + error[E0381]: used binding `my_float` isn't initialized - --> $DIR/suggest-assign-rvalue.rs:15:30 + --> $DIR/suggest-assign-rvalue.rs:23:30 | LL | let my_float: f32; | -------- binding declared here but left uninitialized @@ -7,13 +20,13 @@ LL | println!("my_float: {}", my_float); | ^^^^^^^^ `my_float` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let my_float: f32 = 0.0; | +++++ error[E0381]: used binding `demo` isn't initialized - --> $DIR/suggest-assign-rvalue.rs:18:28 + --> $DIR/suggest-assign-rvalue.rs:26:28 | LL | let demo: Demo; | ---- binding declared here but left uninitialized @@ -21,13 +34,13 @@ LL | println!("demo: {:?}", demo); | ^^^^ `demo` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let demo: Demo = Default::default(); | ++++++++++++++++++++ error[E0381]: used binding `demo_no` isn't initialized - --> $DIR/suggest-assign-rvalue.rs:22:31 + --> $DIR/suggest-assign-rvalue.rs:30:31 | LL | let demo_no: DemoNoDef; | ------- binding declared here but left uninitialized @@ -35,13 +48,13 @@ LL | println!("demo_no: {:?}", demo_no); | ^^^^^^^ `demo_no` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let demo_no: DemoNoDef = todo!(); | +++++++++ error[E0381]: used binding `arr` isn't initialized - --> $DIR/suggest-assign-rvalue.rs:26:27 + --> $DIR/suggest-assign-rvalue.rs:34:27 | LL | let arr: [i32; 5]; | --- binding declared here but left uninitialized @@ -49,13 +62,13 @@ LL | println!("arr: {:?}", arr); | ^^^ `arr` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let arr: [i32; 5] = todo!(); | +++++++++ error[E0381]: used binding `foo` isn't initialized - --> $DIR/suggest-assign-rvalue.rs:29:27 + --> $DIR/suggest-assign-rvalue.rs:37:27 | LL | let foo: Vec<&str>; | --- binding declared here but left uninitialized @@ -63,13 +76,13 @@ LL | println!("foo: {:?}", foo); | ^^^ `foo` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let foo: Vec<&str> = vec![]; | ++++++++ error[E0381]: used binding `my_string` isn't initialized - --> $DIR/suggest-assign-rvalue.rs:33:31 + --> $DIR/suggest-assign-rvalue.rs:41:31 | LL | let my_string: String; | --------- binding declared here but left uninitialized @@ -77,13 +90,13 @@ LL | println!("my_string: {}", my_string); | ^^^^^^^^^ `my_string` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let my_string: String = Default::default(); | ++++++++++++++++++++ error[E0381]: used binding `my_int` isn't initialized - --> $DIR/suggest-assign-rvalue.rs:37:28 + --> $DIR/suggest-assign-rvalue.rs:45:28 | LL | let my_int: &i32; | ------ binding declared here but left uninitialized @@ -91,13 +104,13 @@ LL | println!("my_int: {}", *my_int); | ^^^^^^^ `*my_int` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let my_int: &i32 = todo!(); | +++++++++ error[E0381]: used binding `hello` isn't initialized - --> $DIR/suggest-assign-rvalue.rs:41:27 + --> $DIR/suggest-assign-rvalue.rs:49:27 | LL | let hello: &str; | ----- binding declared here but left uninitialized @@ -105,13 +118,13 @@ LL | println!("hello: {}", hello); | ^^^^^ `hello` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let hello: &str = todo!(); | +++++++++ error[E0381]: used binding `never` isn't initialized - --> $DIR/suggest-assign-rvalue.rs:45:27 + --> $DIR/suggest-assign-rvalue.rs:53:27 | LL | let never: !; | ----- binding declared here but left uninitialized @@ -120,6 +133,6 @@ LL | println!("never: {}", never); | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 9 previous errors +error: aborting due to 10 previous errors For more information about this error, try `rustc --explain E0381`. diff --git a/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr b/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr index bc8e52180bbbc..ad061d93cb242 100644 --- a/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr +++ b/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr @@ -77,7 +77,7 @@ LL | let x: u8; LL | let c1 = || match x { }; | ^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: u8 = 0; | +++ 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 0c48fa4043785..0ed370b83c552 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 @@ -6,7 +6,7 @@ LL | let s: &'static str; s.len() | | | binding declared here but left uninitialized | -help: consider assigning a default value +help: consider assigning a value | LL | let s: &'static str = todo!(); s.len() | +++++++++ diff --git a/src/test/ui/consts/issue-78655.stderr b/src/test/ui/consts/issue-78655.stderr index f5b1123e7f343..6b83fa0e5a01f 100644 --- a/src/test/ui/consts/issue-78655.stderr +++ b/src/test/ui/consts/issue-78655.stderr @@ -5,6 +5,11 @@ LL | let x; | - binding declared here but left uninitialized LL | &x | ^^ `x` used here but it isn't initialized + | +help: consider assigning a value + | +LL | let x = 0; + | +++ error: could not evaluate constant pattern --> $DIR/issue-78655.rs:7:9 diff --git a/src/test/ui/drop/repeat-drop-2.stderr b/src/test/ui/drop/repeat-drop-2.stderr index 613268bbc9ac6..e8d98477d3268 100644 --- a/src/test/ui/drop/repeat-drop-2.stderr +++ b/src/test/ui/drop/repeat-drop-2.stderr @@ -25,7 +25,7 @@ LL | let x: u8; LL | let _ = [x; 0]; | ^ `x` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let x: u8 = 0; | +++ diff --git a/src/test/ui/loops/loop-proper-liveness.stderr b/src/test/ui/loops/loop-proper-liveness.stderr index c256c970feb37..f9d94b6810cb0 100644 --- a/src/test/ui/loops/loop-proper-liveness.stderr +++ b/src/test/ui/loops/loop-proper-liveness.stderr @@ -8,7 +8,7 @@ LL | println!("{:?}", x); | ^ `x` used here but it isn't initialized | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let x: i32 = 0; | +++ diff --git a/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr b/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr index 34a1a7488d2bd..49f24ed39b427 100644 --- a/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr +++ b/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr @@ -25,7 +25,7 @@ LL | LL | a[0] = String::new(); | ^^^^ `a` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let a: [String; 1] = todo!(); | +++++++++ diff --git a/src/test/ui/moves/issue-72649-uninit-in-loop.stderr b/src/test/ui/moves/issue-72649-uninit-in-loop.stderr index a13bdf769e1ef..974994223a3fd 100644 --- a/src/test/ui/moves/issue-72649-uninit-in-loop.stderr +++ b/src/test/ui/moves/issue-72649-uninit-in-loop.stderr @@ -48,7 +48,7 @@ LL | let value: NonCopy; LL | let _used = value; | ^^^^^ `value` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let value: NonCopy = todo!(); | +++++++++ @@ -62,7 +62,7 @@ LL | loop { LL | let _used = value; | ^^^^^ `value` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let mut value: NonCopy = todo!(); | +++++++++ diff --git a/src/test/ui/moves/move-into-dead-array-1.stderr b/src/test/ui/moves/move-into-dead-array-1.stderr index 7a05f28dac628..6db0f0bcbffee 100644 --- a/src/test/ui/moves/move-into-dead-array-1.stderr +++ b/src/test/ui/moves/move-into-dead-array-1.stderr @@ -6,7 +6,7 @@ LL | let mut a: [D; 4]; LL | a[i] = d(); | ^^^^ `a` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let mut a: [D; 4] = todo!(); | +++++++++ diff --git a/src/test/ui/moves/move-of-addr-of-mut.stderr b/src/test/ui/moves/move-of-addr-of-mut.stderr index 07a685806be14..ddebaa0129a43 100644 --- a/src/test/ui/moves/move-of-addr-of-mut.stderr +++ b/src/test/ui/moves/move-of-addr-of-mut.stderr @@ -7,7 +7,7 @@ LL | std::ptr::addr_of_mut!(x); | ^^^^^^^^^^^^^^^^^^^^^^^^^ `x` used here but it isn't initialized | = note: this error originates in the macro `std::ptr::addr_of_mut` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider assigning a default value +help: consider assigning a value | LL | let mut x: S = todo!(); | +++++++++ diff --git a/src/test/ui/nll/match-cfg-fake-edges.stderr b/src/test/ui/nll/match-cfg-fake-edges.stderr index 250aa482e5c67..2d48a914218fd 100644 --- a/src/test/ui/nll/match-cfg-fake-edges.stderr +++ b/src/test/ui/nll/match-cfg-fake-edges.stderr @@ -9,6 +9,11 @@ LL | _ if { x = 2; true } => 1, LL | _ if { LL | x; | ^ `x` used here but it isn't initialized + | +help: consider assigning a value + | +LL | let x = 0; + | +++ error[E0382]: use of moved value: `x` --> $DIR/match-cfg-fake-edges.rs:35:13 diff --git a/src/test/ui/nll/match-on-borrowed.stderr b/src/test/ui/nll/match-on-borrowed.stderr index 827ed655854ef..32666529f3f95 100644 --- a/src/test/ui/nll/match-on-borrowed.stderr +++ b/src/test/ui/nll/match-on-borrowed.stderr @@ -41,7 +41,7 @@ LL | let n: Never; LL | match n {} | ^ `n` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let n: Never = todo!(); | +++++++++ diff --git a/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr b/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr index a88b0a8d05041..0dfd22a30acc7 100644 --- a/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr +++ b/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr @@ -7,7 +7,7 @@ LL | let y: &mut u32; LL | *y = 2; | ^^^^^^ `y` used here but it isn't initialized | -help: consider assigning a default value +help: consider assigning a value | LL | let y: &mut u32 = todo!(); | +++++++++