From bcf780e2ba00dbe5a81502ef541dbc0f4fb76ebb Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 22 Jul 2022 08:50:31 -0700 Subject: [PATCH 01/13] Recover error strings on Unix from_lossy_utf8 Some language settings can result in unreliable UTF-8 being produced. This can result in failing to emit the error string, panicking instead. from_lossy_utf8 allows us to assume these strings usually will be fine. --- library/std/src/sys/unix/os.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/unix/os.rs b/library/std/src/sys/unix/os.rs index 7252ad321844b..3009a9b1f01ca 100644 --- a/library/std/src/sys/unix/os.rs +++ b/library/std/src/sys/unix/os.rs @@ -125,7 +125,9 @@ pub fn error_string(errno: i32) -> String { } let p = p as *const _; - str::from_utf8(CStr::from_ptr(p).to_bytes()).unwrap().to_owned() + // We can't always expect a UTF-8 environment. When we don't get that luxury, + // it's better to give a low-quality error message than none at all. + String::from_utf8_lossy(CStr::from_ptr(p).to_bytes()).into() } } From 71f8fd5c5859fa09587486351f849277a910e4d9 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 19 Sep 2022 14:59:52 +0200 Subject: [PATCH 02/13] improve infer var handling for implied bounds --- .../rustc_infer/src/infer/outlives/env.rs | 2 + .../src/traits/outlives_bounds.rs | 3 +- .../src/implied_outlives_bounds.rs | 69 ++++++++++--------- .../rustc_typeck/src/check/compare_method.rs | 1 + 4 files changed, 41 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_infer/src/infer/outlives/env.rs b/compiler/rustc_infer/src/infer/outlives/env.rs index 872886da36261..9922b156ebf96 100644 --- a/compiler/rustc_infer/src/infer/outlives/env.rs +++ b/compiler/rustc_infer/src/infer/outlives/env.rs @@ -53,6 +53,7 @@ pub struct OutlivesEnvironment<'tcx> { } /// Builder of OutlivesEnvironment. +#[derive(Debug)] struct OutlivesEnvironmentBuilder<'tcx> { param_env: ty::ParamEnv<'tcx>, region_relation: TransitiveRelationBuilder>, @@ -109,6 +110,7 @@ impl<'tcx> OutlivesEnvironment<'tcx> { impl<'a, 'tcx> OutlivesEnvironmentBuilder<'tcx> { #[inline] + #[instrument(level = "debug")] fn build(self) -> OutlivesEnvironment<'tcx> { OutlivesEnvironment { param_env: self.param_env, diff --git a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs index a4b540182280b..3008dfcadde9e 100644 --- a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs +++ b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs @@ -46,7 +46,7 @@ impl<'a, 'cx, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'cx, 'tcx> { /// Note that this may cause outlives obligations to be injected /// into the inference context with this body-id. /// - `ty`, the type that we are supposed to assume is WF. - #[instrument(level = "debug", skip(self, param_env, body_id))] + #[instrument(level = "debug", skip(self, param_env, body_id), ret)] fn implied_outlives_bounds( &self, param_env: ty::ParamEnv<'tcx>, @@ -71,6 +71,7 @@ impl<'a, 'cx, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'cx, 'tcx> { let TypeOpOutput { output, constraints, .. } = result; if let Some(constraints) = constraints { + debug!(?constraints); // Instantiation may have produced new inference variables and constraints on those // variables. Process these constraints. let mut fulfill_cx = >::new(self.tcx); diff --git a/compiler/rustc_traits/src/implied_outlives_bounds.rs b/compiler/rustc_traits/src/implied_outlives_bounds.rs index e3e78f70b15ef..691b79f10533d 100644 --- a/compiler/rustc_traits/src/implied_outlives_bounds.rs +++ b/compiler/rustc_traits/src/implied_outlives_bounds.rs @@ -49,7 +49,8 @@ fn compute_implied_outlives_bounds<'tcx>( let mut checked_wf_args = rustc_data_structures::fx::FxHashSet::default(); let mut wf_args = vec![ty.into()]; - let mut implied_bounds = vec![]; + let mut outlives_bounds: Vec, ty::Region<'tcx>>> = + vec![]; let mut fulfill_cx = >::new(tcx); @@ -65,30 +66,17 @@ fn compute_implied_outlives_bounds<'tcx>( // than the ultimate set. (Note: normally there won't be // unresolved inference variables here anyway, but there might be // during typeck under some circumstances.) + // + // FIXME(@lcnr): It's not really "always fine", having fewer implied + // bounds can be backward incompatible, e.g. #101951 was caused by + // us not dealing with inference vars in `TypeOutlives` predicates. let obligations = wf::obligations(infcx, param_env, hir::CRATE_HIR_ID, 0, arg, DUMMY_SP) .unwrap_or_default(); - // N.B., all of these predicates *ought* to be easily proven - // true. In fact, their correctness is (mostly) implied by - // other parts of the program. However, in #42552, we had - // an annoying scenario where: - // - // - Some `T::Foo` gets normalized, resulting in a - // variable `_1` and a `T: Trait` constraint - // (not sure why it couldn't immediately get - // solved). This result of `_1` got cached. - // - These obligations were dropped on the floor here, - // rather than being registered. - // - Then later we would get a request to normalize - // `T::Foo` which would result in `_1` being used from - // the cache, but hence without the `T: Trait` - // constraint. As a result, `_1` never gets resolved, - // and we get an ICE (in dropck). - // - // Therefore, we register any predicates involving - // inference variables. We restrict ourselves to those - // involving inference variables both for efficiency and - // to avoids duplicate errors that otherwise show up. + // While these predicates should all be implied by other parts of + // the program, they are still relevant as they may constrain + // inference variables, which is necessary to add the correct + // implied bounds in some cases, mostly when dealing with projections. fulfill_cx.register_predicate_obligations( infcx, obligations.iter().filter(|o| o.predicate.has_infer_types_or_consts()).cloned(), @@ -96,10 +84,10 @@ fn compute_implied_outlives_bounds<'tcx>( // From the full set of obligations, just filter down to the // region relationships. - implied_bounds.extend(obligations.into_iter().flat_map(|obligation| { + outlives_bounds.extend(obligations.into_iter().filter_map(|obligation| { assert!(!obligation.has_escaping_bound_vars()); match obligation.predicate.kind().no_bound_vars() { - None => vec![], + None => None, Some(pred) => match pred { ty::PredicateKind::Trait(..) | ty::PredicateKind::Subtype(..) @@ -109,21 +97,18 @@ fn compute_implied_outlives_bounds<'tcx>( | ty::PredicateKind::ObjectSafe(..) | ty::PredicateKind::ConstEvaluatable(..) | ty::PredicateKind::ConstEquate(..) - | ty::PredicateKind::TypeWellFormedFromEnv(..) => vec![], + | ty::PredicateKind::TypeWellFormedFromEnv(..) => None, ty::PredicateKind::WellFormed(arg) => { wf_args.push(arg); - vec![] + None } ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => { - vec![OutlivesBound::RegionSubRegion(r_b, r_a)] + Some(ty::OutlivesPredicate(r_a.into(), r_b)) } ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => { - let ty_a = infcx.resolve_vars_if_possible(ty_a); - let mut components = smallvec![]; - push_outlives_components(tcx, ty_a, &mut components); - implied_bounds_from_components(r_b, components) + Some(ty::OutlivesPredicate(ty_a.into(), r_b)) } }, } @@ -133,9 +118,27 @@ fn compute_implied_outlives_bounds<'tcx>( // Ensure that those obligations that we had to solve // get solved *here*. match fulfill_cx.select_all_or_error(infcx).as_slice() { - [] => Ok(implied_bounds), - _ => Err(NoSolution), + [] => (), + _ => return Err(NoSolution), } + + // We lazily compute the outlives components as + // `select_all_or_error` constrains inference variables. + let implied_bounds = outlives_bounds + .into_iter() + .flat_map(|ty::OutlivesPredicate(a, r_b)| match a.unpack() { + ty::GenericArgKind::Lifetime(r_a) => vec![OutlivesBound::RegionSubRegion(r_b, r_a)], + ty::GenericArgKind::Type(ty_a) => { + let ty_a = infcx.resolve_vars_if_possible(ty_a); + let mut components = smallvec![]; + push_outlives_components(tcx, ty_a, &mut components); + implied_bounds_from_components(r_b, components) + } + ty::GenericArgKind::Const(_) => unreachable!(), + }) + .collect(); + + Ok(implied_bounds) } /// When we have an implied bound that `T: 'a`, we can further break diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index 0c6d8f26f1d63..59d591acdc445 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -140,6 +140,7 @@ pub(crate) fn compare_impl_method<'tcx>( /// /// Finally we register each of these predicates as an obligation and check that /// they hold. +#[instrument(level = "debug", skip(tcx, impl_m_span, impl_trait_ref))] fn compare_predicate_entailment<'tcx>( tcx: TyCtxt<'tcx>, impl_m: &AssocItem, From 72a21027f5bee367bd9ccbeecc2528986f85d90b Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 19 Sep 2022 15:07:01 +0200 Subject: [PATCH 03/13] add test --- src/test/ui/implied-bounds/issue-101951.rs | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/test/ui/implied-bounds/issue-101951.rs diff --git a/src/test/ui/implied-bounds/issue-101951.rs b/src/test/ui/implied-bounds/issue-101951.rs new file mode 100644 index 0000000000000..108fef8a15fb3 --- /dev/null +++ b/src/test/ui/implied-bounds/issue-101951.rs @@ -0,0 +1,50 @@ +// Taken directly from that issue. +// +// This test detected that we didn't correctly resolve +// inference variables when computing implied bounds. +// +// check-pass +pub trait BuilderFn<'a> { + type Output; +} + +impl<'a, F, Out> BuilderFn<'a> for F +where + F: FnOnce(&'a mut ()) -> Out, +{ + type Output = Out; +} + +pub trait ConstructionFirm { + type Builder: for<'a> BuilderFn<'a>; +} + +pub trait Campus +where + T: ConstructionFirm, +{ + fn add_building( + &mut self, + building: &mut <::Builder as BuilderFn<'_>>::Output, + ); +} + +struct ArchitectsInc {} + +impl ConstructionFirm for ArchitectsInc { + type Builder = fn(&mut ()) -> PrettyCondo<'_>; +} + +struct PrettyCondo<'a> { + _marker: &'a mut (), +} + +struct CondoEstate {} + +impl Campus for CondoEstate { + fn add_building(&mut self, _building: &mut PrettyCondo<'_>) { + todo!() + } +} + +fn main() {} From 8a2c0ccac7c2395f80dba09817bb348020ac9c88 Mon Sep 17 00:00:00 2001 From: yukang Date: Fri, 23 Sep 2022 15:28:48 +0800 Subject: [PATCH 04/13] 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 05/13] 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 3d01d43d488553d5fe8391564de36eed8659ca4c Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 23 Sep 2022 18:04:15 -0700 Subject: [PATCH 06/13] rustdoc: Stabilize --diagnostic-width --- src/librustdoc/lib.rs | 2 +- src/test/rustdoc-ui/diagnostic-width.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 14d695582b0f8..23ad0c30f21ed 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -461,7 +461,7 @@ fn opts() -> Vec { "human|json|short", ) }), - unstable("diagnostic-width", |o| { + stable("diagnostic-width", |o| { o.optopt( "", "diagnostic-width", diff --git a/src/test/rustdoc-ui/diagnostic-width.rs b/src/test/rustdoc-ui/diagnostic-width.rs index 61961d5ec710e..290d9db775b73 100644 --- a/src/test/rustdoc-ui/diagnostic-width.rs +++ b/src/test/rustdoc-ui/diagnostic-width.rs @@ -1,4 +1,4 @@ -// compile-flags: -Zunstable-options --diagnostic-width=10 +// compile-flags: --diagnostic-width=10 #![deny(rustdoc::bare_urls)] /// This is a long line that contains a http://link.com From 2bfab8e796d4b35c1518df62e0a223e6ee85c1d6 Mon Sep 17 00:00:00 2001 From: yukang Date: Sat, 24 Sep 2022 19:21:01 +0800 Subject: [PATCH 07/13] 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 08/13] 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!(); | +++++++++ From a0be6c49c89556c9d596c9f430ced9d61c16e6d2 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 24 Sep 2022 10:03:59 -0700 Subject: [PATCH 09/13] rustdoc: remove unused CSS `#main-content > .line-numbers` This selector was added in 10b937028660e079cf15735cfb5c4d58892fb10e. It became unreachable when 09150f81930e035254e58ee56f5905c2eb421617 made it so that `.line-numbers` are always nested below `.example-wrap`, even on source pages. --- src/librustdoc/html/static/css/rustdoc.css | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 4136cb6cab33a..8691d60821504 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1917,10 +1917,6 @@ in storage.js plus the media query with (min-width: 701px) border-bottom: 1px solid; } - #main-content > .line-numbers { - margin-top: 0; - } - .notable-traits .notable-traits-tooltiptext { left: 0; top: 100%; From 55b11cf15cfac6798bf87191c30406486f20d642 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 24 Sep 2022 10:51:37 -0700 Subject: [PATCH 10/13] rustdoc: remove unused CSS `.summary` It was added in 4d16de01d0beb84dc4a351022ea5cb587b4ab557 as part of a stability dashboard that was removed in 0a46933c4d81573e78ce16cd215ba155a3114fce. --- src/librustdoc/html/static/css/rustdoc.css | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 4136cb6cab33a..645f0454aa27d 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1130,10 +1130,6 @@ so that we can apply CSS-filters to change the arrow color in themes */ font-size: 1rem; } -.summary { - padding-right: 0px; -} - pre.rust .question-mark { font-weight: bold; } From 59c4a92bafaf19e2d9039436294aa805d748ce0f Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 22 Sep 2022 22:53:32 +0000 Subject: [PATCH 11/13] Resolve async fn signature even without body (in trait) --- compiler/rustc_resolve/src/late.rs | 5 +- .../ui/async-await/in-trait/issue-102138.rs | 46 +++++++++++++++++++ src/test/ui/async-await/issue-102138.rs | 46 +++++++++++++++++++ .../issue-69401-trait-fn-no-body-ty-local.rs | 2 +- ...sue-69401-trait-fn-no-body-ty-local.stderr | 6 +-- 5 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 src/test/ui/async-await/in-trait/issue-102138.rs create mode 100644 src/test/ui/async-await/issue-102138.rs diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 0aea90bb5aaf3..d38eca23ade10 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -789,9 +789,8 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { let previous_value = self.diagnostic_metadata.current_function; match fn_kind { // Bail if the function is foreign, and thus cannot validly have - // a body, or if there's no body for some other reason. - FnKind::Fn(FnCtxt::Foreign, _, sig, _, generics, _) - | FnKind::Fn(_, _, sig, _, generics, None) => { + // a body. + FnKind::Fn(FnCtxt::Foreign, _, sig, _, generics, _) => { self.visit_fn_header(&sig.header); self.visit_generics(generics); self.with_lifetime_rib( diff --git a/src/test/ui/async-await/in-trait/issue-102138.rs b/src/test/ui/async-await/in-trait/issue-102138.rs new file mode 100644 index 0000000000000..f61b34ed99e00 --- /dev/null +++ b/src/test/ui/async-await/in-trait/issue-102138.rs @@ -0,0 +1,46 @@ +// check-pass +// edition:2021 + +#![feature(async_fn_in_trait)] +#![allow(incomplete_features)] + +use std::future::Future; + +async fn yield_now() {} + +trait AsyncIterator { + type Item; + async fn next(&mut self) -> Option; +} + +struct YieldingRange { + counter: u32, + stop: u32, +} + +impl AsyncIterator for YieldingRange { + type Item = u32; + + async fn next(&mut self) -> Option { + if self.counter == self.stop { + None + } else { + let c = self.counter; + self.counter += 1; + yield_now().await; + Some(c) + } + } +} + +async fn async_main() { + let mut x = YieldingRange { counter: 0, stop: 10 }; + + while let Some(v) = x.next().await { + println!("Hi: {v}"); + } +} + +fn main() { + let _ = async_main(); +} diff --git a/src/test/ui/async-await/issue-102138.rs b/src/test/ui/async-await/issue-102138.rs new file mode 100644 index 0000000000000..91a14523c63b2 --- /dev/null +++ b/src/test/ui/async-await/issue-102138.rs @@ -0,0 +1,46 @@ +// check-pass +// edition:2021 + +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::future::Future; + +async fn yield_now() {} + +trait AsyncIterator { + type Item; + async fn next(&mut self) -> Option; +} + +struct YieldingRange { + counter: u32, + stop: u32, +} + +impl AsyncIterator for YieldingRange { + type Item = u32; + + async fn next(&mut self) -> Option { + if self.counter == self.stop { + None + } else { + let c = self.counter; + self.counter += 1; + yield_now().await; + Some(c) + } + } +} + +async fn async_main() { + let mut x = YieldingRange { counter: 0, stop: 10 }; + + while let Some(v) = x.next().await { + println!("Hi: {v}"); + } +} + +fn main() { + let _ = async_main(); +} diff --git a/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.rs b/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.rs index c377ecea94d0c..4ec4472cc9aea 100644 --- a/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.rs +++ b/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.rs @@ -2,5 +2,5 @@ fn main() {} trait Foo { fn fn_with_type_named_same_as_local_in_param(b: b); - //~^ ERROR cannot find type `b` in this scope [E0412] + //~^ ERROR expected type, found local variable `b` } diff --git a/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.stderr b/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.stderr index 109409d2731c5..c53028e9b2ad7 100644 --- a/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.stderr +++ b/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.stderr @@ -1,9 +1,9 @@ -error[E0412]: cannot find type `b` in this scope +error[E0573]: expected type, found local variable `b` --> $DIR/issue-69401-trait-fn-no-body-ty-local.rs:4:53 | LL | fn fn_with_type_named_same_as_local_in_param(b: b); - | ^ not found in this scope + | ^ not a type error: aborting due to previous error -For more information about this error, try `rustc --explain E0412`. +For more information about this error, try `rustc --explain E0573`. From 3d7e9a7b27c735a8eb2fe05781bb7b4331572983 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 23 Sep 2022 00:49:25 +0000 Subject: [PATCH 12/13] Only record extra lifetime params for async trait fn with no body --- compiler/rustc_resolve/src/late.rs | 78 ++++++++++--------- src/test/ui/async-await/issue-102138.rs | 46 ----------- .../issue-69401-trait-fn-no-body-ty-local.rs | 2 +- ...sue-69401-trait-fn-no-body-ty-local.stderr | 6 +- 4 files changed, 44 insertions(+), 88 deletions(-) delete mode 100644 src/test/ui/async-await/issue-102138.rs diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index d38eca23ade10..558db003867d2 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -789,8 +789,9 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { let previous_value = self.diagnostic_metadata.current_function; match fn_kind { // Bail if the function is foreign, and thus cannot validly have - // a body. - FnKind::Fn(FnCtxt::Foreign, _, sig, _, generics, _) => { + // a body, or if there's no body for some other reason. + FnKind::Fn(FnCtxt::Foreign, _, sig, _, generics, _) + | FnKind::Fn(_, _, sig, _, generics, None) => { self.visit_fn_header(&sig.header); self.visit_generics(generics); self.with_lifetime_rib( @@ -804,7 +805,12 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { sig.decl.has_self(), sig.decl.inputs.iter().map(|Param { ty, .. }| (None, &**ty)), &sig.decl.output, - ) + ); + + this.record_lifetime_params_for_async( + fn_id, + sig.header.asyncness.opt_return_id(), + ); }, ); return; @@ -846,41 +852,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { }, ); - // Construct the list of in-scope lifetime parameters for async lowering. - // We include all lifetime parameters, either named or "Fresh". - // The order of those parameters does not matter, as long as it is - // deterministic. - if let Some((async_node_id, _)) = async_node_id { - let mut extra_lifetime_params = this - .r - .extra_lifetime_params_map - .get(&fn_id) - .cloned() - .unwrap_or_default(); - for rib in this.lifetime_ribs.iter().rev() { - extra_lifetime_params.extend( - rib.bindings - .iter() - .map(|(&ident, &(node_id, res))| (ident, node_id, res)), - ); - match rib.kind { - LifetimeRibKind::Item => break, - LifetimeRibKind::AnonymousCreateParameter { - binder, .. - } => { - if let Some(earlier_fresh) = - this.r.extra_lifetime_params_map.get(&binder) - { - extra_lifetime_params.extend(earlier_fresh); - } - } - _ => {} - } - } - this.r - .extra_lifetime_params_map - .insert(async_node_id, extra_lifetime_params); - } + this.record_lifetime_params_for_async(fn_id, async_node_id); if let Some(body) = body { // Ignore errors in function bodies if this is rustdoc @@ -3925,6 +3897,36 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { Some((ident.name, ns)), ) } + + /// Construct the list of in-scope lifetime parameters for async lowering. + /// We include all lifetime parameters, either named or "Fresh". + /// The order of those parameters does not matter, as long as it is + /// deterministic. + fn record_lifetime_params_for_async( + &mut self, + fn_id: NodeId, + async_node_id: Option<(NodeId, Span)>, + ) { + if let Some((async_node_id, _)) = async_node_id { + let mut extra_lifetime_params = + self.r.extra_lifetime_params_map.get(&fn_id).cloned().unwrap_or_default(); + for rib in self.lifetime_ribs.iter().rev() { + extra_lifetime_params.extend( + rib.bindings.iter().map(|(&ident, &(node_id, res))| (ident, node_id, res)), + ); + match rib.kind { + LifetimeRibKind::Item => break, + LifetimeRibKind::AnonymousCreateParameter { binder, .. } => { + if let Some(earlier_fresh) = self.r.extra_lifetime_params_map.get(&binder) { + extra_lifetime_params.extend(earlier_fresh); + } + } + _ => {} + } + } + self.r.extra_lifetime_params_map.insert(async_node_id, extra_lifetime_params); + } + } } struct LifetimeCountVisitor<'a, 'b> { diff --git a/src/test/ui/async-await/issue-102138.rs b/src/test/ui/async-await/issue-102138.rs deleted file mode 100644 index 91a14523c63b2..0000000000000 --- a/src/test/ui/async-await/issue-102138.rs +++ /dev/null @@ -1,46 +0,0 @@ -// check-pass -// edition:2021 - -#![feature(return_position_impl_trait_in_trait)] -#![allow(incomplete_features)] - -use std::future::Future; - -async fn yield_now() {} - -trait AsyncIterator { - type Item; - async fn next(&mut self) -> Option; -} - -struct YieldingRange { - counter: u32, - stop: u32, -} - -impl AsyncIterator for YieldingRange { - type Item = u32; - - async fn next(&mut self) -> Option { - if self.counter == self.stop { - None - } else { - let c = self.counter; - self.counter += 1; - yield_now().await; - Some(c) - } - } -} - -async fn async_main() { - let mut x = YieldingRange { counter: 0, stop: 10 }; - - while let Some(v) = x.next().await { - println!("Hi: {v}"); - } -} - -fn main() { - let _ = async_main(); -} diff --git a/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.rs b/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.rs index 4ec4472cc9aea..c377ecea94d0c 100644 --- a/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.rs +++ b/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.rs @@ -2,5 +2,5 @@ fn main() {} trait Foo { fn fn_with_type_named_same_as_local_in_param(b: b); - //~^ ERROR expected type, found local variable `b` + //~^ ERROR cannot find type `b` in this scope [E0412] } diff --git a/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.stderr b/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.stderr index c53028e9b2ad7..109409d2731c5 100644 --- a/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.stderr +++ b/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.stderr @@ -1,9 +1,9 @@ -error[E0573]: expected type, found local variable `b` +error[E0412]: cannot find type `b` in this scope --> $DIR/issue-69401-trait-fn-no-body-ty-local.rs:4:53 | LL | fn fn_with_type_named_same_as_local_in_param(b: b); - | ^ not a type + | ^ not found in this scope error: aborting due to previous error -For more information about this error, try `rustc --explain E0573`. +For more information about this error, try `rustc --explain E0412`. From e87fcc026b4e31ffd352a035e58d78142c577dea Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 24 Sep 2022 19:04:25 +0000 Subject: [PATCH 13/13] Add test --- src/test/ui/resolve/name-collision-in-trait-fn-sig.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/test/ui/resolve/name-collision-in-trait-fn-sig.rs diff --git a/src/test/ui/resolve/name-collision-in-trait-fn-sig.rs b/src/test/ui/resolve/name-collision-in-trait-fn-sig.rs new file mode 100644 index 0000000000000..fba4ffa1c6ed2 --- /dev/null +++ b/src/test/ui/resolve/name-collision-in-trait-fn-sig.rs @@ -0,0 +1,11 @@ +// check-pass +// This is currently stable behavior, which was almost accidentally made an +// error in #102161 since there is no test exercising it. I am not sure if +// this _should_ be the desired behavior, but at least we should know if it +// changes. + +fn main() {} + +trait Foo { + fn fn_with_type_named_same_as_local_in_param(b: i32, b: i32); +}