Auto merge of #98360 - estebank:uninit-binding, r=oli-obk

On partial uninit error point at where we need init

When a binding is declared without a value, borrowck verifies that all
codepaths have *one* assignment to them to initialize them fully. If
there are any cases where a condition can be met that leaves the binding
uninitialized or we attempt to initialize a field of an uninitialized
binding, we emit E0381.

We now look at all the statements that initialize the binding, and use
them to explore branching code paths that *don't* and point at them. If
we find *no* potential places where an assignment to the binding might
be missing, we display the spans of all the existing initializers to
provide some context.

Fix https://github.com/rust-lang/rust/issues/97956.
This commit is contained in:
bors 2022-07-07 23:36:21 +00:00
commit 9b21131278
111 changed files with 1073 additions and 458 deletions

View File

@ -33,22 +33,6 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
err
}
pub(crate) fn cannot_act_on_uninitialized_variable(
&self,
span: Span,
verb: &str,
desc: &str,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
struct_span_err!(
self,
span,
E0381,
"{} of possibly-uninitialized variable: `{}`",
verb,
desc,
)
}
pub(crate) fn cannot_mutably_borrow_multiply(
&self,
new_loan_span: Span,
@ -175,8 +159,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
self,
new_loan_span,
E0501,
"cannot borrow {}{} as {} because previous closure \
requires unique access",
"cannot borrow {}{} as {} because previous closure requires unique access",
desc_new,
opt_via,
kind_new,
@ -453,9 +436,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
self,
closure_span,
E0373,
"{} may outlive the current function, \
but it borrows {}, \
which is owned by the current function",
"{} may outlive the current function, but it borrows {}, which is owned by the current \
function",
closure_kind,
borrowed_path,
);
@ -479,7 +461,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
}
#[rustc_lint_diagnostics]
fn struct_span_err_with_code<S: Into<MultiSpan>>(
pub(crate) fn struct_span_err_with_code<S: Into<MultiSpan>>(
&self,
sp: S,
msg: impl Into<DiagnosticMessage>,

View File

@ -2,9 +2,12 @@ use either::Either;
use rustc_const_eval::util::CallKind;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
use rustc_errors::{
struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::{AsyncGeneratorKind, GeneratorKind};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::ObligationCause;
@ -18,6 +21,7 @@ use rustc_middle::ty::{
self, subst::Subst, suggest_constraining_type_params, EarlyBinder, PredicateKind, Ty,
};
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
use rustc_span::hygiene::DesugaringKind;
use rustc_span::symbol::sym;
use rustc_span::{BytePos, Span};
use rustc_trait_selection::infer::InferCtxtExt;
@ -94,32 +98,20 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
return;
}
let item_msg =
match self.describe_place_with_options(used_place, IncludingDowncast(true)) {
Some(name) => format!("`{}`", name),
None => "value".to_owned(),
};
let mut err = self.cannot_act_on_uninitialized_variable(
let err = self.report_use_of_uninitialized(
mpi,
used_place,
moved_place,
desired_action,
span,
desired_action.as_noun(),
&self
.describe_place_with_options(moved_place, IncludingDowncast(true))
.unwrap_or_else(|| "_".to_owned()),
use_spans,
);
err.span_label(span, format!("use of possibly-uninitialized {}", item_msg));
use_spans.var_span_label_path_only(
&mut err,
format!("{} occurs due to use{}", desired_action.as_noun(), use_spans.describe()),
);
self.buffer_error(err);
} else {
if let Some((reported_place, _)) = self.has_move_error(&move_out_indices) {
if self.prefixes(*reported_place, PrefixSet::All).any(|p| p == used_place) {
debug!(
"report_use_of_moved_or_uninitialized place: error suppressed \
mois={:?}",
"report_use_of_moved_or_uninitialized place: error suppressed mois={:?}",
move_out_indices
);
return;
@ -326,6 +318,130 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
}
fn report_use_of_uninitialized(
&self,
mpi: MovePathIndex,
used_place: PlaceRef<'tcx>,
moved_place: PlaceRef<'tcx>,
desired_action: InitializationRequiringAction,
span: Span,
use_spans: UseSpans<'tcx>,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
// We need all statements in the body where the binding was assigned to to later find all
// the branching code paths where the binding *wasn't* assigned to.
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];
let span = init.span(&self.body);
if !span.is_dummy() {
spans.push(span);
}
}
let (name, desc) =
match self.describe_place_with_options(moved_place, IncludingDowncast(true)) {
Some(name) => (format!("`{name}`"), format!("`{name}` ")),
None => ("the variable".to_string(), String::new()),
};
let path = match self.describe_place_with_options(used_place, IncludingDowncast(true)) {
Some(name) => format!("`{name}`"),
None => "value".to_string(),
};
// We use the statements were the binding was initialized, and inspect the HIR to look
// for the branching codepaths that aren't covered, to point at them.
let hir_id = self.mir_hir_id();
let map = self.infcx.tcx.hir();
let body_id = map.body_owned_by(hir_id);
let body = map.body(body_id);
let mut visitor = ConditionVisitor { spans: &spans, name: &name, errors: vec![] };
visitor.visit_body(&body);
let isnt_initialized = if let InitializationRequiringAction::PartialAssignment
| InitializationRequiringAction::Assignment = desired_action
{
// The same error is emitted for bindings that are *sometimes* initialized and the ones
// that are *partially* initialized by assigning to a field of an uninitialized
// binding. We differentiate between them for more accurate wording here.
"isn't fully initialized"
} else if spans
.iter()
.filter(|i| {
// We filter these to avoid misleading wording in cases like the following,
// where `x` has an `init`, but it is in the same place we're looking at:
// ```
// let x;
// x += 1;
// ```
!i.contains(span)
// We filter these to avoid incorrect main message on `match-cfg-fake-edges.rs`
&& !visitor
.errors
.iter()
.map(|(sp, _)| *sp)
.any(|sp| span < sp && !sp.contains(span))
})
.count()
== 0
{
"isn't initialized"
} else {
"is possibly-uninitialized"
};
let used = desired_action.as_general_verb_in_past_tense();
let mut err =
struct_span_err!(self, span, E0381, "{used} binding {desc}{isnt_initialized}");
use_spans.var_span_label_path_only(
&mut err,
format!("{} occurs due to use{}", desired_action.as_noun(), use_spans.describe()),
);
if let InitializationRequiringAction::PartialAssignment
| InitializationRequiringAction::Assignment = desired_action
{
err.help(
"partial initialization isn't supported, fully initialize the binding with a \
default value and mutate it, or use `std::mem::MaybeUninit`",
);
}
err.span_label(span, format!("{path} {used} here but it {isnt_initialized}"));
let mut shown = false;
for (sp, label) in visitor.errors {
if sp < span && !sp.overlaps(span) {
// When we have a case like `match-cfg-fake-edges.rs`, we don't want to mention
// match arms coming after the primary span because they aren't relevant:
// ```
// let x;
// match y {
// _ if { x = 2; true } => {}
// _ if {
// x; //~ ERROR
// false
// } => {}
// _ => {} // We don't want to point to this.
// };
// ```
err.span_label(sp, &label);
shown = true;
}
}
if !shown {
for sp in &spans {
if *sp < span && !sp.overlaps(span) {
err.span_label(*sp, "binding initialized here in some conditions");
}
}
}
err.span_label(decl_span, "binding declared here but left uninitialized");
err
}
fn suggest_borrow_fn_like(
&self,
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
@ -2448,3 +2564,142 @@ impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
}
}
}
/// Detect whether one of the provided spans is a statement nested within the top-most visited expr
struct ReferencedStatementsVisitor<'a>(&'a [Span], bool);
impl<'a, 'v> Visitor<'v> for ReferencedStatementsVisitor<'a> {
fn visit_stmt(&mut self, s: &'v hir::Stmt<'v>) {
match s.kind {
hir::StmtKind::Semi(expr) if self.0.contains(&expr.span) => {
self.1 = true;
}
_ => {}
}
}
}
/// Given a set of spans representing statements initializing the relevant binding, visit all the
/// function expressions looking for branching code paths that *do not* initialize the binding.
struct ConditionVisitor<'b> {
spans: &'b [Span],
name: &'b str,
errors: Vec<(Span, String)>,
}
impl<'b, 'v> Visitor<'v> for ConditionVisitor<'b> {
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
match ex.kind {
hir::ExprKind::If(cond, body, None) => {
// `if` expressions with no `else` that initialize the binding might be missing an
// `else` arm.
let mut v = ReferencedStatementsVisitor(self.spans, false);
v.visit_expr(body);
if v.1 {
self.errors.push((
cond.span,
format!(
"if this `if` condition is `false`, {} is not initialized",
self.name,
),
));
self.errors.push((
ex.span.shrink_to_hi(),
format!("an `else` arm might be missing here, initializing {}", self.name),
));
}
}
hir::ExprKind::If(cond, body, Some(other)) => {
// `if` expressions where the binding is only initialized in one of the two arms
// might be missing a binding initialization.
let mut a = ReferencedStatementsVisitor(self.spans, false);
a.visit_expr(body);
let mut b = ReferencedStatementsVisitor(self.spans, false);
b.visit_expr(other);
match (a.1, b.1) {
(true, true) | (false, false) => {}
(true, false) => {
if other.span.is_desugaring(DesugaringKind::WhileLoop) {
self.errors.push((
cond.span,
format!(
"if this condition isn't met and the `while` loop runs 0 \
times, {} is not initialized",
self.name
),
));
} else {
self.errors.push((
body.span.shrink_to_hi().until(other.span),
format!(
"if the `if` condition is `false` and this `else` arm is \
executed, {} is not initialized",
self.name
),
));
}
}
(false, true) => {
self.errors.push((
cond.span,
format!(
"if this condition is `true`, {} is not initialized",
self.name
),
));
}
}
}
hir::ExprKind::Match(e, arms, loop_desugar) => {
// If the binding is initialized in one of the match arms, then the other match
// arms might be missing an initialization.
let results: Vec<bool> = arms
.iter()
.map(|arm| {
let mut v = ReferencedStatementsVisitor(self.spans, false);
v.visit_arm(arm);
v.1
})
.collect();
if results.iter().any(|x| *x) && !results.iter().all(|x| *x) {
for (arm, seen) in arms.iter().zip(results) {
if !seen {
if loop_desugar == hir::MatchSource::ForLoopDesugar {
self.errors.push((
e.span,
format!(
"if the `for` loop runs 0 times, {} is not initialized ",
self.name
),
));
} else if let Some(guard) = &arm.guard {
self.errors.push((
arm.pat.span.to(guard.body().span),
format!(
"if this pattern and condition are matched, {} is not \
initialized",
self.name
),
));
} else {
self.errors.push((
arm.pat.span,
format!(
"if this pattern is matched, {} is not initialized",
self.name
),
));
}
}
}
}
}
// FIXME: should we also account for binops, particularly `&&` and `||`? `try` should
// also be accounted for. For now it is fine, as if we don't find *any* relevant
// branching code paths, we point at the places where the binding *is* initialized for
// *some* context.
_ => {}
}
walk_expr(self, ex);
}
}

View File

@ -907,6 +907,16 @@ impl InitializationRequiringAction {
InitializationRequiringAction::PartialAssignment => "partially assigned",
}
}
fn as_general_verb_in_past_tense(self) -> &'static str {
match self {
InitializationRequiringAction::Borrow
| InitializationRequiringAction::MatchOn
| InitializationRequiringAction::Use => "used",
InitializationRequiringAction::Assignment => "assigned",
InitializationRequiringAction::PartialAssignment => "partially assigned",
}
}
}
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

View File

@ -17,10 +17,10 @@ fn main() {
let x: u64;
asm!("{}", in(reg) x);
//~^ ERROR use of possibly-uninitialized variable: `x`
//~^ ERROR used binding `x` isn't initialized
let mut y: u64;
asm!("{}", inout(reg) y);
//~^ ERROR use of possibly-uninitialized variable: `y`
//~^ ERROR used binding `y` isn't initialized
let _ = y;
// Outputs require mutable places

View File

@ -1,14 +1,18 @@
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/type-check-2-2.rs:19:28
|
LL | let x: u64;
| - binding declared here but left uninitialized
LL | asm!("{}", in(reg) x);
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `y`
error[E0381]: used binding `y` isn't initialized
--> $DIR/type-check-2-2.rs:22:9
|
LL | let mut y: u64;
| ----- binding declared here but left uninitialized
LL | asm!("{}", inout(reg) y);
| ^^^^^^^^^^^^^^^^^^^^^^^^ use of possibly-uninitialized `y`
| ^^^^^^^^^^^^^^^^^^^^^^^^ `y` used here but it isn't initialized
error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
--> $DIR/type-check-2-2.rs:30:29

View File

@ -13,10 +13,10 @@ fn main() {
let x: u64;
asm!("{}", in(reg) x);
//~^ ERROR use of possibly-uninitialized variable: `x`
//~^ ERROR E0381
let mut y: u64;
asm!("{}", inout(reg) y);
//~^ ERROR use of possibly-uninitialized variable: `y`
//~^ ERROR E0381
let _ = y;
// Outputs require mutable places

View File

@ -1,14 +1,18 @@
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/type-check-5.rs:15:28
|
LL | let x: u64;
| - binding declared here but left uninitialized
LL | asm!("{}", in(reg) x);
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `y`
error[E0381]: used binding `y` isn't initialized
--> $DIR/type-check-5.rs:18:9
|
LL | let mut y: u64;
| ----- binding declared here but left uninitialized
LL | asm!("{}", inout(reg) y);
| ^^^^^^^^^^^^^^^^^^^^^^^^ use of possibly-uninitialized `y`
| ^^^^^^^^^^^^^^^^^^^^^^^^ `y` used here but it isn't initialized
error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
--> $DIR/type-check-5.rs:26:29

View File

@ -6,8 +6,7 @@ async fn no_non_guaranteed_initialization(x: usize) -> usize {
if x > 5 {
y = echo(10).await;
}
y
//~^ use of possibly-uninitialized variable: `y`
y //~ ERROR E0381
}
async fn echo(x: usize) -> usize { x + 1 }

View File

@ -1,8 +1,15 @@
error[E0381]: use of possibly-uninitialized variable: `y`
error[E0381]: used binding `y` is possibly-uninitialized
--> $DIR/no-non-guaranteed-initialization.rs:9:5
|
LL | let y;
| - binding declared here but left uninitialized
LL | if x > 5 {
| ----- if this `if` condition is `false`, `y` is not initialized
LL | y = echo(10).await;
LL | }
| - an `else` arm might be missing here, initializing `y`
LL | y
| ^ use of possibly-uninitialized `y`
| ^ `y` used here but it is possibly-uninitialized
error: aborting due to previous error

View File

@ -10,8 +10,7 @@ async fn noop() {}
async fn test_tuple() {
let mut t: (i32, i32);
t.0 = 42;
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
t.0 = 42; //~ ERROR E0381
noop().await;
t.1 = 88;
let _ = t;
@ -19,8 +18,7 @@ async fn test_tuple() {
async fn test_tuple_struct() {
let mut t: T;
t.0 = 42;
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
t.0 = 42; //~ ERROR E0381
noop().await;
t.1 = 88;
let _ = t;
@ -28,8 +26,7 @@ async fn test_tuple_struct() {
async fn test_struct() {
let mut t: S;
t.x = 42;
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
t.x = 42; //~ ERROR E0381
noop().await;
t.y = 88;
let _ = t;

View File

@ -1,20 +1,32 @@
error[E0381]: assign to part of possibly-uninitialized variable: `t`
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/partial-initialization-across-await.rs:13:5
|
LL | let mut t: (i32, i32);
| ----- binding declared here but left uninitialized
LL | t.0 = 42;
| ^^^^^^^^ use of possibly-uninitialized `t`
error[E0381]: assign to part of possibly-uninitialized variable: `t`
--> $DIR/partial-initialization-across-await.rs:22:5
| ^^^^^^^^ `t` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/partial-initialization-across-await.rs:21:5
|
LL | let mut t: T;
| ----- binding declared here but left uninitialized
LL | t.0 = 42;
| ^^^^^^^^ use of possibly-uninitialized `t`
error[E0381]: assign to part of possibly-uninitialized variable: `t`
--> $DIR/partial-initialization-across-await.rs:31:5
| ^^^^^^^^ `t` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/partial-initialization-across-await.rs:29:5
|
LL | let mut t: S;
| ----- binding declared here but left uninitialized
LL | t.x = 42;
| ^^^^^^^^ use of possibly-uninitialized `t`
| ^^^^^^^^ `t` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to 3 previous errors

View File

@ -1,14 +1,22 @@
error[E0381]: assign to part of possibly-uninitialized variable: `x`
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/assign_mutable_fields.rs:9:5
|
LL | let mut x: (u32, u32);
| ----- binding declared here but left uninitialized
LL | x.0 = 1;
| ^^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^^ `x` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `x`
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/assign_mutable_fields.rs:17:5
|
LL | let mut x: (u32, u32);
| ----- binding declared here but left uninitialized
LL | x.0 = 1;
| ^^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^^ `x` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to 2 previous errors

View File

@ -2,5 +2,5 @@ fn main() {
let i: isize;
println!("{}", false && { i = 5; true });
println!("{}", i); //~ ERROR borrow of possibly-uninitialized variable: `i`
println!("{}", i); //~ ERROR E0381
}

View File

@ -1,8 +1,13 @@
error[E0381]: borrow of possibly-uninitialized variable: `i`
error[E0381]: used binding `i` is possibly-uninitialized
--> $DIR/borrowck-and-init.rs:5:20
|
LL | let i: isize;
| - binding declared here but left uninitialized
LL |
LL | println!("{}", false && { i = 5; true });
| ----- binding initialized here in some conditions
LL | println!("{}", i);
| ^ use of possibly-uninitialized `i`
| ^ `i` used here but it is possibly-uninitialized
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -1,7 +1,7 @@
fn force<F>(f: F) where F: FnOnce() { f(); }
fn main() {
let x: isize;
force(|| { //~ ERROR borrow of possibly-uninitialized variable: `x`
force(|| { //~ ERROR E0381
println!("{}", x);
});
}

View File

@ -1,8 +1,10 @@
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-block-unint.rs:4:11
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | force(|| {
| ^^ use of possibly-uninitialized `x`
| ^^ `x` used here but it isn't initialized
LL | println!("{}", x);
| - borrow occurs due to use in closure

View File

@ -6,7 +6,7 @@ fn foo() -> isize {
x = 0;
}
println!("{}", x); //~ ERROR borrow of possibly-uninitialized variable: `x`
println!("{}", x); //~ ERROR E0381
return 17;
}

View File

@ -1,8 +1,11 @@
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-break-uninit-2.rs:9:20
|
LL | let x: isize;
| - binding declared here but left uninitialized
...
LL | println!("{}", x);
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -6,7 +6,7 @@ fn foo() -> isize {
x = 0;
}
println!("{}", x); //~ ERROR borrow of possibly-uninitialized variable: `x`
println!("{}", x); //~ ERROR E0381
return 17;
}

View File

@ -1,8 +1,11 @@
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-break-uninit.rs:9:20
|
LL | let x: isize;
| - binding declared here but left uninitialized
...
LL | println!("{}", x);
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -78,20 +78,20 @@ fn fu_move_after_fu_move() {
fn copy_after_field_assign_after_uninit() {
let mut x: A;
x.a = 1; //~ ERROR assign to part of possibly-uninitialized variable: `x`
x.a = 1; //~ ERROR E0381
drop(x.a);
}
fn borrow_after_field_assign_after_uninit() {
let mut x: A;
x.a = 1; //~ ERROR assign to part of possibly-uninitialized variable: `x`
x.a = 1; //~ ERROR E0381
let p = &x.a;
drop(*p);
}
fn move_after_field_assign_after_uninit() {
let mut x: A;
x.b = Box::new(1); //~ ERROR assign to part of possibly-uninitialized variable: `x`
x.b = Box::new(1); //~ ERROR E0381
drop(x.b);
}

View File

@ -108,23 +108,35 @@ LL | let _z = A { a: 4, .. x };
|
= note: move occurs because `x.b` has type `Box<isize>`, which does not implement the `Copy` trait
error[E0381]: assign to part of possibly-uninitialized variable: `x`
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/borrowck-field-sensitivity.rs:81:5
|
LL | let mut x: A;
| ----- binding declared here but left uninitialized
LL | x.a = 1;
| ^^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^^ `x` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `x`
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/borrowck-field-sensitivity.rs:87:5
|
LL | let mut x: A;
| ----- binding declared here but left uninitialized
LL | x.a = 1;
| ^^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^^ `x` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `x`
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/borrowck-field-sensitivity.rs:94:5
|
LL | let mut x: A;
| ----- binding declared here but left uninitialized
LL | x.b = Box::new(1);
| ^^^ use of possibly-uninitialized `x`
| ^^^ `x` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to 14 previous errors

View File

@ -0,0 +1,7 @@
fn f() -> isize {
let mut x: isize;
for _ in 0..0 { x = 10; }
return x; //~ ERROR E0381
}
fn main() { f(); }

View File

@ -0,0 +1,13 @@
error[E0381]: used binding `x` is possibly-uninitialized
--> $DIR/borrowck-for-loop-uninitialized-binding.rs:4:12
|
LL | let mut x: isize;
| ----- binding declared here but left uninitialized
LL | for _ in 0..0 { x = 10; }
| ---- if the `for` loop runs 0 times, `x` is not initialized
LL | return x;
| ^ `x` used here but it is possibly-uninitialized
error: aborting due to previous error
For more information about this error, try `rustc --explain E0381`.

View File

@ -2,5 +2,5 @@ fn foo(x: isize) { println!("{}", x); }
fn main() {
let x: isize; if 1 > 2 { x = 10; }
foo(x); //~ ERROR use of possibly-uninitialized variable: `x`
foo(x); //~ ERROR E0381
}

View File

@ -1,8 +1,13 @@
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` is possibly-uninitialized
--> $DIR/borrowck-if-no-else.rs:5:9
|
LL | let x: isize; if 1 > 2 { x = 10; }
| - ----- - an `else` arm might be missing here, initializing `x`
| | |
| | if this `if` condition is `false`, `x` is not initialized
| binding declared here but left uninitialized
LL | foo(x);
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it is possibly-uninitialized
error: aborting due to previous error

View File

@ -7,5 +7,5 @@ fn main() {
} else {
x = 10;
}
foo(x); //~ ERROR use of possibly-uninitialized variable: `x`
foo(x); //~ ERROR E0381
}

View File

@ -1,8 +1,13 @@
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` is possibly-uninitialized
--> $DIR/borrowck-if-with-else.rs:10:9
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | if 1 > 2 {
| ----- if this condition is `true`, `x` is not initialized
...
LL | foo(x);
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it is possibly-uninitialized
error: aborting due to previous error

View File

@ -1,7 +1,7 @@
fn main() {
let j = || -> isize {
let i: isize;
i //~ ERROR use of possibly-uninitialized variable: `i`
i //~ ERROR E0381
};
j();
}

View File

@ -1,8 +1,10 @@
error[E0381]: use of possibly-uninitialized variable: `i`
error[E0381]: used binding `i` isn't initialized
--> $DIR/borrowck-init-in-called-fn-expr.rs:4:9
|
LL | let i: isize;
| - binding declared here but left uninitialized
LL | i
| ^ use of possibly-uninitialized `i`
| ^ `i` used here but it isn't initialized
error: aborting due to previous error

View File

@ -1,7 +1,7 @@
fn main() {
let f = || -> isize {
let i: isize;
i //~ ERROR use of possibly-uninitialized variable: `i`
i //~ ERROR E0381
};
println!("{}", f());
}

View File

@ -1,8 +1,10 @@
error[E0381]: use of possibly-uninitialized variable: `i`
error[E0381]: used binding `i` isn't initialized
--> $DIR/borrowck-init-in-fn-expr.rs:4:9
|
LL | let i: isize;
| - binding declared here but left uninitialized
LL | i
| ^ use of possibly-uninitialized `i`
| ^ `i` used here but it isn't initialized
error: aborting due to previous error

View File

@ -7,6 +7,6 @@ struct Point {
fn main() {
let mut origin: Point;
origin = Point { x: 10, ..origin };
//~^ ERROR use of possibly-uninitialized variable: `origin` [E0381]
//~^ ERROR E0381
origin.clone();
}

View File

@ -1,8 +1,10 @@
error[E0381]: use of possibly-uninitialized variable: `origin`
error[E0381]: used binding `origin` isn't initialized
--> $DIR/borrowck-init-in-fru.rs:9:14
|
LL | let mut origin: Point;
| ---------- binding declared here but left uninitialized
LL | origin = Point { x: 10, ..origin };
| ^^^^^^^^^^^^^^^^^^^^^^^^^ use of possibly-uninitialized `origin.y`
| ^^^^^^^^^^^^^^^^^^^^^^^^^ `origin.y` used here but it isn't initialized
error: aborting due to previous error

View File

@ -1,6 +1,6 @@
fn test() {
let v: isize;
v += 1; //~ ERROR use of possibly-uninitialized variable: `v`
v += 1; //~ ERROR E0381
v.clone();
}

View File

@ -1,8 +1,10 @@
error[E0381]: use of possibly-uninitialized variable: `v`
error[E0381]: used binding `v` isn't initialized
--> $DIR/borrowck-init-op-equal.rs:3:5
|
LL | let v: isize;
| - binding declared here but left uninitialized
LL | v += 1;
| ^^^^^^ use of possibly-uninitialized `v`
| ^^^^^^ `v` used here but it isn't initialized
error: aborting due to previous error

View File

@ -1,6 +1,6 @@
fn test() {
let mut v: isize;
v = v + 1; //~ ERROR use of possibly-uninitialized variable: `v`
v = v + 1; //~ ERROR E0381
v.clone();
}

View File

@ -1,8 +1,10 @@
error[E0381]: use of possibly-uninitialized variable: `v`
error[E0381]: used binding `v` isn't initialized
--> $DIR/borrowck-init-plus-equal.rs:3:9
|
LL | let mut v: isize;
| ----- binding declared here but left uninitialized
LL | v = v + 1;
| ^ use of possibly-uninitialized `v`
| ^ `v` used here but it isn't initialized
error: aborting due to previous error

View File

@ -2,5 +2,5 @@ fn main() {
let i: isize;
println!("{}", false || { i = 5; true });
println!("{}", i); //~ ERROR borrow of possibly-uninitialized variable: `i`
println!("{}", i); //~ ERROR E0381
}

View File

@ -1,8 +1,13 @@
error[E0381]: borrow of possibly-uninitialized variable: `i`
error[E0381]: used binding `i` is possibly-uninitialized
--> $DIR/borrowck-or-init.rs:5:20
|
LL | let i: isize;
| - binding declared here but left uninitialized
LL |
LL | println!("{}", false || { i = 5; true });
| ----- binding initialized here in some conditions
LL | println!("{}", i);
| ^ use of possibly-uninitialized `i`
| ^ `i` used here but it is possibly-uninitialized
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -14,8 +14,7 @@ impl Drop for Test2 {
fn stuff() {
let mut x : (Test2, Test2);
(x.0).0 = Some(Test);
//~^ ERROR assign of possibly-uninitialized variable: `x.0`
(x.0).0 = Some(Test); //~ ERROR E0381
}
fn main() {

View File

@ -1,8 +1,12 @@
error[E0381]: assign of possibly-uninitialized variable: `x.0`
error[E0381]: assigned binding `x.0` isn't fully initialized
--> $DIR/borrowck-partial-reinit-4.rs:17:5
|
LL | let mut x : (Test2, Test2);
| ----- binding declared here but left uninitialized
LL | (x.0).0 = Some(Test);
| ^^^^^^^ use of possibly-uninitialized `x.0`
| ^^^^^^^ `x.0` assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to previous error

View File

@ -1,6 +1,6 @@
fn f() -> isize {
let x: isize;
return x; //~ ERROR use of possibly-uninitialized variable: `x`
return x; //~ ERROR E0381
}
fn main() { f(); }

View File

@ -1,8 +1,10 @@
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-return.rs:3:12
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | return x;
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
error: aborting due to previous error

View File

@ -1,8 +1,10 @@
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-storage-dead.rs:16:17
|
LL | let x: i32;
| - binding declared here but left uninitialized
LL | let _ = x + 1;
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
error: aborting due to previous error

View File

@ -1,5 +1,5 @@
fn main() {
let bar;
fn baz(_x: isize) { }
baz(bar); //~ ERROR use of possibly-uninitialized variable: `bar`
baz(bar); //~ ERROR E0381
}

View File

@ -1,8 +1,11 @@
error[E0381]: use of possibly-uninitialized variable: `bar`
error[E0381]: used binding `bar` isn't initialized
--> $DIR/borrowck-uninit-after-item.rs:4:9
|
LL | let bar;
| --- binding declared here but left uninitialized
LL | fn baz(_x: isize) { }
LL | baz(bar);
| ^^^ use of possibly-uninitialized `bar`
| ^^^ `bar` used here but it isn't initialized
error: aborting due to previous error

View File

@ -1,8 +1,10 @@
error[E0381]: use of possibly-uninitialized variable: `a`
error[E0381]: used binding `a` isn't initialized
--> $DIR/borrowck-uninit-field-access.rs:21:13
|
LL | let mut a: Point;
| ----- binding declared here but left uninitialized
LL | let _ = a.x + 1;
| ^^^ use of possibly-uninitialized `a.x`
| ^^^ `a.x` used here but it isn't initialized
error[E0382]: use of moved value: `line1.origin`
--> $DIR/borrowck-uninit-field-access.rs:25:13

View File

@ -3,32 +3,32 @@
pub fn main() {
let x: isize;
x += 1; //~ ERROR use of possibly-uninitialized variable: `x`
x += 1; //~ ERROR E0381
let x: isize;
x -= 1; //~ ERROR use of possibly-uninitialized variable: `x`
x -= 1; //~ ERROR E0381
let x: isize;
x *= 1; //~ ERROR use of possibly-uninitialized variable: `x`
x *= 1; //~ ERROR E0381
let x: isize;
x /= 1; //~ ERROR use of possibly-uninitialized variable: `x`
x /= 1; //~ ERROR E0381
let x: isize;
x %= 1; //~ ERROR use of possibly-uninitialized variable: `x`
x %= 1; //~ ERROR E0381
let x: isize;
x ^= 1; //~ ERROR use of possibly-uninitialized variable: `x`
x ^= 1; //~ ERROR E0381
let x: isize;
x &= 1; //~ ERROR use of possibly-uninitialized variable: `x`
x &= 1; //~ ERROR E0381
let x: isize;
x |= 1; //~ ERROR use of possibly-uninitialized variable: `x`
x |= 1; //~ ERROR E0381
let x: isize;
x <<= 1; //~ ERROR use of possibly-uninitialized variable: `x`
x <<= 1; //~ ERROR E0381
let x: isize;
x >>= 1; //~ ERROR use of possibly-uninitialized variable: `x`
x >>= 1; //~ ERROR E0381
}

View File

@ -1,62 +1,82 @@
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:6:5
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | x += 1;
| ^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^ `x` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:9:5
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | x -= 1;
| ^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^ `x` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:12:5
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | x *= 1;
| ^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^ `x` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:15:5
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | x /= 1;
| ^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^ `x` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:18:5
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | x %= 1;
| ^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^ `x` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:21:5
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | x ^= 1;
| ^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^ `x` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:24:5
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | x &= 1;
| ^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^ `x` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:27:5
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | x |= 1;
| ^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^ `x` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:30:5
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | x <<= 1;
| ^^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^^ `x` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:33:5
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | x >>= 1;
| ^^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^^ `x` used here but it isn't initialized
error: aborting due to 10 previous errors

View File

@ -5,29 +5,29 @@ struct S<X, Y> {
fn main() {
let x: &&Box<i32>;
let _y = &**x; //~ [E0381]
let _y = &**x; //~ ERROR [E0381]
let x: &&S<i32, i32>;
let _y = &**x; //~ [E0381]
let _y = &**x; //~ ERROR [E0381]
let x: &&i32;
let _y = &**x; //~ [E0381]
let _y = &**x; //~ ERROR [E0381]
let mut a: S<i32, i32>;
a.x = 0; //~ ERROR assign to part of possibly-uninitialized variable: `a` [E0381]
a.x = 0; //~ ERROR [E0381]
let _b = &a.x;
let mut a: S<&&i32, &&i32>;
a.x = &&0; //~ ERROR assign to part of possibly-uninitialized variable: `a` [E0381]
a.x = &&0; //~ ERROR [E0381]
let _b = &**a.x;
let mut a: S<i32, i32>;
a.x = 0; //~ ERROR assign to part of possibly-uninitialized variable: `a` [E0381]
a.x = 0; //~ ERROR [E0381]
let _b = &a.y;
let mut a: S<&&i32, &&i32>;
a.x = &&0; //~ assign to part of possibly-uninitialized variable: `a` [E0381]
a.x = &&0; //~ ERROR [E0381]
let _b = &**a.y;
}

View File

@ -1,44 +1,66 @@
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-ref-chain.rs:8:14
|
LL | let x: &&Box<i32>;
| - binding declared here but left uninitialized
LL | let _y = &**x;
| ^^^^ use of possibly-uninitialized `**x`
| ^^^^ `**x` used here but it isn't initialized
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-ref-chain.rs:11:14
|
LL | let x: &&S<i32, i32>;
| - binding declared here but left uninitialized
LL | let _y = &**x;
| ^^^^ use of possibly-uninitialized `**x`
| ^^^^ `**x` used here but it isn't initialized
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-ref-chain.rs:14:14
|
LL | let x: &&i32;
| - binding declared here but left uninitialized
LL | let _y = &**x;
| ^^^^ use of possibly-uninitialized `**x`
| ^^^^ `**x` used here but it isn't initialized
error[E0381]: assign to part of possibly-uninitialized variable: `a`
error[E0381]: partially assigned binding `a` isn't fully initialized
--> $DIR/borrowck-uninit-ref-chain.rs:18:5
|
LL | let mut a: S<i32, i32>;
| ----- binding declared here but left uninitialized
LL | a.x = 0;
| ^^^^^^^ use of possibly-uninitialized `a`
| ^^^^^^^ `a` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `a`
error[E0381]: partially assigned binding `a` isn't fully initialized
--> $DIR/borrowck-uninit-ref-chain.rs:22:5
|
LL | let mut a: S<&&i32, &&i32>;
| ----- binding declared here but left uninitialized
LL | a.x = &&0;
| ^^^^^^^^^ use of possibly-uninitialized `a`
| ^^^^^^^^^ `a` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `a`
error[E0381]: partially assigned binding `a` isn't fully initialized
--> $DIR/borrowck-uninit-ref-chain.rs:27:5
|
LL | let mut a: S<i32, i32>;
| ----- binding declared here but left uninitialized
LL | a.x = 0;
| ^^^^^^^ use of possibly-uninitialized `a`
| ^^^^^^^ `a` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `a`
error[E0381]: partially assigned binding `a` isn't fully initialized
--> $DIR/borrowck-uninit-ref-chain.rs:31:5
|
LL | let mut a: S<&&i32, &&i32>;
| ----- binding declared here but left uninitialized
LL | a.x = &&0;
| ^^^^^^^^^ use of possibly-uninitialized `a`
| ^^^^^^^^^ `a` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to 7 previous errors

View File

@ -2,5 +2,5 @@ fn foo(x: isize) { println!("{}", x); }
fn main() {
let x: isize;
foo(x); //~ ERROR use of possibly-uninitialized variable: `x`
foo(x); //~ ERROR E0381
}

View File

@ -1,8 +1,10 @@
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit.rs:5:9
|
LL | let x: isize;
| - binding declared here but left uninitialized
LL | foo(x);
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
error: aborting due to previous error

View File

@ -10,8 +10,8 @@ fn main() {
unsafe {
let mut s: S;
let mut u: U;
s.a = 0; //~ ERROR assign to part of possibly-uninitialized variable: `s`
u.a = 0; //~ ERROR assign to part of possibly-uninitialized variable: `u`
s.a = 0; //~ ERROR E0381
u.a = 0; //~ ERROR E0381
let sa = s.a;
let ua = u.a;
}

View File

@ -1,14 +1,24 @@
error[E0381]: assign to part of possibly-uninitialized variable: `s`
error[E0381]: partially assigned binding `s` isn't fully initialized
--> $DIR/borrowck-union-uninitialized.rs:13:9
|
LL | let mut s: S;
| ----- binding declared here but left uninitialized
LL | let mut u: U;
LL | s.a = 0;
| ^^^^^^^ use of possibly-uninitialized `s`
| ^^^^^^^ `s` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `u`
error[E0381]: partially assigned binding `u` isn't fully initialized
--> $DIR/borrowck-union-uninitialized.rs:14:9
|
LL | let mut u: U;
| ----- binding declared here but left uninitialized
LL | s.a = 0;
LL | u.a = 0;
| ^^^^^^^ use of possibly-uninitialized `u`
| ^^^^^^^ `u` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to 2 previous errors

View File

@ -1,14 +1,18 @@
error[E0381]: use of possibly-uninitialized variable: `w`
error[E0381]: used binding `w` isn't initialized
--> $DIR/borrowck-use-in-index-lvalue.rs:3:5
|
LL | let w: &mut [isize];
| - binding declared here but left uninitialized
LL | w[5] = 0;
| ^^^^ use of possibly-uninitialized `*w`
| ^^^^ `*w` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `w`
error[E0381]: used binding `w` isn't initialized
--> $DIR/borrowck-use-in-index-lvalue.rs:6:5
|
LL | let mut w: &mut [isize];
| ----- binding declared here but left uninitialized
LL | w[5] = 0;
| ^^^^ use of possibly-uninitialized `*w`
| ^^^^ `*w` used here but it isn't initialized
error: aborting due to 2 previous errors

View File

@ -1,8 +1,10 @@
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-use-uninitialized-in-cast-trait.rs:9:13
|
LL | let x: &i32;
| - binding declared here but left uninitialized
LL | let y = x as *const dyn Foo;
| ^ use of possibly-uninitialized `*x`
| ^ `*x` used here but it isn't initialized
error: aborting due to previous error

View File

@ -1,8 +1,10 @@
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-use-uninitialized-in-cast.rs:7:13
|
LL | let x: &i32;
| - binding declared here but left uninitialized
LL | let y = x as *const i32;
| ^ use of possibly-uninitialized `*x`
| ^ `*x` used here but it isn't initialized
error: aborting due to previous error

View File

@ -4,7 +4,7 @@ fn test(cond: bool) {
v = 3;
break;
}
println!("{}", v); //~ ERROR borrow of possibly-uninitialized variable: `v`
println!("{}", v); //~ ERROR E0381
}
fn main() {

View File

@ -1,8 +1,13 @@
error[E0381]: borrow of possibly-uninitialized variable: `v`
error[E0381]: used binding `v` is possibly-uninitialized
--> $DIR/borrowck-while-break.rs:7:20
|
LL | let v;
| - binding declared here but left uninitialized
LL | while cond {
| ---- if this condition isn't met and the `while` loop runs 0 times, `v` is not initialized
...
LL | println!("{}", v);
| ^ use of possibly-uninitialized `v`
| ^ `v` used here but it is possibly-uninitialized
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -1,4 +1,4 @@
fn main() {
let x: bool;
while x { } //~ ERROR use of possibly-uninitialized variable: `x`
while x { } //~ ERROR E0381
}

View File

@ -1,8 +1,10 @@
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-while-cond.rs:3:11
|
LL | let x: bool;
| - binding declared here but left uninitialized
LL | while x { }
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
error: aborting due to previous error

View File

@ -1,7 +1,7 @@
fn f() -> isize {
let mut x: isize;
while 1 == 1 { x = 10; }
return x; //~ ERROR use of possibly-uninitialized variable: `x`
return x; //~ ERROR E0381
}
fn main() { f(); }

View File

@ -1,8 +1,12 @@
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` is possibly-uninitialized
--> $DIR/borrowck-while.rs:4:12
|
LL | let mut x: isize;
| ----- binding declared here but left uninitialized
LL | while 1 == 1 { x = 10; }
| ------ if this condition isn't met and the `while` loop runs 0 times, `x` is not initialized
LL | return x;
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it is possibly-uninitialized
error: aborting due to previous error

View File

@ -4,19 +4,19 @@
fn main() {
let mut t: (u64, u64);
t.0 = 1;
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
//~^ ERROR E0381
t.1 = 1;
let mut t: (u64, u64);
t.1 = 1;
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
//~^ ERROR E0381
t.0 = 1;
let mut t: (u64, u64);
t.0 = 1;
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
//~^ ERROR E0381
let mut t: (u64,);
t.0 = 1;
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
//~^ ERROR E0381
}

View File

@ -1,26 +1,42 @@
error[E0381]: assign to part of possibly-uninitialized variable: `t`
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/disallow-possibly-uninitialized.rs:6:5
|
LL | let mut t: (u64, u64);
| ----- binding declared here but left uninitialized
LL | t.0 = 1;
| ^^^^^^^ use of possibly-uninitialized `t`
| ^^^^^^^ `t` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `t`
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/disallow-possibly-uninitialized.rs:11:5
|
LL | let mut t: (u64, u64);
| ----- binding declared here but left uninitialized
LL | t.1 = 1;
| ^^^^^^^ use of possibly-uninitialized `t`
| ^^^^^^^ `t` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `t`
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/disallow-possibly-uninitialized.rs:16:5
|
LL | let mut t: (u64, u64);
| ----- binding declared here but left uninitialized
LL | t.0 = 1;
| ^^^^^^^ use of possibly-uninitialized `t`
| ^^^^^^^ `t` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `t`
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/disallow-possibly-uninitialized.rs:20:5
|
LL | let mut t: (u64,);
| ----- binding declared here but left uninitialized
LL | t.0 = 1;
| ^^^^^^^ use of possibly-uninitialized `t`
| ^^^^^^^ `t` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to 4 previous errors

View File

@ -9,11 +9,11 @@ pub fn main() {
pub fn foo1() {
let x: i32;
loop { x = break; }
println!("{}", x); //~ ERROR borrow of possibly-uninitialized variable: `x`
println!("{}", x); //~ ERROR E0381
}
pub fn foo2() {
let x: i32;
for _ in 0..10 { x = continue; }
println!("{}", x); //~ ERROR borrow of possibly-uninitialized variable: `x`
println!("{}", x); //~ ERROR E0381
}

View File

@ -1,16 +1,22 @@
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/issue-24267-flow-exit.rs:12:20
|
LL | let x: i32;
| - binding declared here but left uninitialized
LL | loop { x = break; }
LL | println!("{}", x);
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/issue-24267-flow-exit.rs:18:20
|
LL | let x: i32;
| - binding declared here but left uninitialized
LL | for _ in 0..10 { x = continue; }
LL | println!("{}", x);
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -10,7 +10,7 @@ fn main() {
{
let mut t: Tuple;
t.0 = S(1);
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
//~^ ERROR E0381
t.1 = 2;
println!("{:?} {:?}", t.0, t.1);
}
@ -18,7 +18,7 @@ fn main() {
{
let mut u: Tpair;
u.0 = S(1);
//~^ ERROR assign to part of possibly-uninitialized variable: `u` [E0381]
//~^ ERROR E0381
u.1 = 2;
println!("{:?} {:?}", u.0, u.1);
}
@ -26,7 +26,7 @@ fn main() {
{
let mut v: Spair;
v.x = S(1);
//~^ ERROR assign to part of possibly-uninitialized variable: `v` [E0381]
//~^ ERROR E0381
v.y = 2;
println!("{:?} {:?}", v.x, v.y);
}

View File

@ -1,20 +1,32 @@
error[E0381]: assign to part of possibly-uninitialized variable: `t`
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:12:9
|
LL | let mut t: Tuple;
| ----- binding declared here but left uninitialized
LL | t.0 = S(1);
| ^^^^^^^^^^ use of possibly-uninitialized `t`
| ^^^^^^^^^^ `t` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `u`
error[E0381]: partially assigned binding `u` isn't fully initialized
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:20:9
|
LL | let mut u: Tpair;
| ----- binding declared here but left uninitialized
LL | u.0 = S(1);
| ^^^^^^^^^^ use of possibly-uninitialized `u`
| ^^^^^^^^^^ `u` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `v`
error[E0381]: partially assigned binding `v` isn't fully initialized
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:28:9
|
LL | let mut v: Spair;
| ----- binding declared here but left uninitialized
LL | v.x = S(1);
| ^^^^^^^^^^ use of possibly-uninitialized `v`
| ^^^^^^^^^^ `v` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to 3 previous errors

View File

@ -10,7 +10,7 @@ fn main() {
{
let t: Tuple;
t.0 = S(1);
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
//~^ ERROR E0381
t.1 = 2;
println!("{:?} {:?}", t.0, t.1);
}
@ -18,7 +18,7 @@ fn main() {
{
let u: Tpair;
u.0 = S(1);
//~^ ERROR assign to part of possibly-uninitialized variable: `u` [E0381]
//~^ ERROR E0381
u.1 = 2;
println!("{:?} {:?}", u.0, u.1);
}
@ -26,7 +26,7 @@ fn main() {
{
let v: Spair;
v.x = S(1);
//~^ ERROR assign to part of possibly-uninitialized variable: `v` [E0381]
//~^ ERROR E0381
v.y = 2;
println!("{:?} {:?}", v.x, v.y);
}

View File

@ -1,20 +1,32 @@
error[E0381]: assign to part of possibly-uninitialized variable: `t`
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/issue-54499-field-mutation-of-never-init.rs:12:9
|
LL | let t: Tuple;
| - binding declared here but left uninitialized
LL | t.0 = S(1);
| ^^^^^^^^^^ use of possibly-uninitialized `t`
| ^^^^^^^^^^ `t` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `u`
error[E0381]: partially assigned binding `u` isn't fully initialized
--> $DIR/issue-54499-field-mutation-of-never-init.rs:20:9
|
LL | let u: Tpair;
| - binding declared here but left uninitialized
LL | u.0 = S(1);
| ^^^^^^^^^^ use of possibly-uninitialized `u`
| ^^^^^^^^^^ `u` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `v`
error[E0381]: partially assigned binding `v` isn't fully initialized
--> $DIR/issue-54499-field-mutation-of-never-init.rs:28:9
|
LL | let v: Spair;
| - binding declared here but left uninitialized
LL | v.x = S(1);
| ^^^^^^^^^^ use of possibly-uninitialized `v`
| ^^^^^^^^^^ `v` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to 3 previous errors

View File

@ -1,7 +1,7 @@
fn main() {
let e: i32;
match e {
//~^ ERROR use of possibly-uninitialized variable
//~^ ERROR E0381
ref u if true => {}
ref v if true => {
let tx = 0;

View File

@ -1,8 +1,10 @@
error[E0381]: use of possibly-uninitialized variable: `e`
error[E0381]: used binding `e` isn't initialized
--> $DIR/issue-62107-match-arm-scopes.rs:3:11
|
LL | let e: i32;
| - binding declared here but left uninitialized
LL | match e {
| ^ use of possibly-uninitialized `e`
| ^ `e` used here but it isn't initialized
error: aborting due to previous error

View File

@ -1,14 +1,22 @@
error[E0381]: assign to part of possibly-uninitialized variable: `x`
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/reassignment_immutable_fields.rs:7:5
|
LL | let x: (u32, u32);
| - binding declared here but left uninitialized
LL | x.0 = 1;
| ^^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^^ `x` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `x`
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/reassignment_immutable_fields.rs:15:5
|
LL | let x: (u32, u32);
| - binding declared here but left uninitialized
LL | x.0 = 1;
| ^^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^^ `x` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to 2 previous errors

View File

@ -1,8 +1,12 @@
error[E0381]: assign to part of possibly-uninitialized variable: `x`
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/reassignment_immutable_fields_overlapping.rs:12:5
|
LL | let x: Foo;
| - binding declared here but left uninitialized
LL | x.a = 1;
| ^^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^^ `x` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0594]: cannot assign to `x.b`, as `x` is not declared as mutable
--> $DIR/reassignment_immutable_fields_overlapping.rs:13:5

View File

@ -7,11 +7,15 @@ LL | x = (22, 44);
LL | x.0 = 1;
| ^^^^^^^ cannot assign
error[E0381]: assign to part of possibly-uninitialized variable: `x`
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/reassignment_immutable_fields_twice.rs:12:5
|
LL | let x: (u32, u32);
| - binding declared here but left uninitialized
LL | x.0 = 1;
| ^^^^^^^ use of possibly-uninitialized `x`
| ^^^^^^^ `x` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to 2 previous errors

View File

@ -6,14 +6,14 @@
fn test1() {
let x: !;
let c1 = || match x { };
//~^ ERROR: use of possibly-uninitialized variable: `x`
//~^ ERROR E0381
}
// Should fake read the discriminant and throw an error
fn test2() {
let x: !;
let c2 = || match x { _ => () };
//~^ ERROR: borrow of possibly-uninitialized variable: `x`
//~^ ERROR E0381
}
// Testing single variant patterns
@ -25,7 +25,7 @@ enum SingleVariant {
fn test3() {
let variant: !;
let c = || {
//~^ ERROR: borrow of possibly-uninitialized variable: `variant`
//~^ ERROR E0381
match variant {
SingleVariant::Points(_) => {}
}
@ -36,8 +36,7 @@ fn test3() {
// Should fake read the discriminant and throw an error
fn test4() {
let variant: !;
let c = || {
//~^ ERROR: borrow of possibly-uninitialized variable: `variant`
let c = || { //~ ERROR E0381
match variant {
SingleVariant::Points(a) => {
println!("{:?}", a);
@ -52,11 +51,9 @@ fn test5() {
let g: !;
let a = || {
match g { };
//~^ ERROR: use of possibly-uninitialized variable: `g`
match g { }; //~ ERROR E0381
let c = || {
match t { };
//~^ ERROR: use of possibly-uninitialized variable: `t`
match t { }; //~ ERROR E0381
};
c();
@ -68,7 +65,7 @@ fn test5() {
fn test6() {
let x: u8;
let c1 = || match x { };
//~^ ERROR: use of possibly-uninitialized variable: `x`
//~^ ERROR E0381
//~| ERROR: non-exhaustive patterns: type `u8` is non-empty
}

View File

@ -1,5 +1,5 @@
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
--> $DIR/pattern-matching-should-fail.rs:70:23
--> $DIR/pattern-matching-should-fail.rs:67:23
|
LL | let c1 = || match x { };
| ^
@ -12,55 +12,70 @@ LL + _ => todo!(),
LL ~ };
|
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:8:23
|
LL | let x: !;
| - binding declared here but left uninitialized
LL | let c1 = || match x { };
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:15:14
|
LL | let x: !;
| - binding declared here but left uninitialized
LL | let c2 = || match x { _ => () };
| ^^ - borrow occurs due to use in closure
| |
| use of possibly-uninitialized `x`
| `x` used here but it isn't initialized
error[E0381]: borrow of possibly-uninitialized variable: `variant`
error[E0381]: used binding `variant` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:27:13
|
LL | let variant: !;
| ------- binding declared here but left uninitialized
LL | let c = || {
| ^^ use of possibly-uninitialized `variant`
| ^^ `variant` used here but it isn't initialized
LL |
LL | match variant {
| ------- borrow occurs due to use in closure
error[E0381]: borrow of possibly-uninitialized variable: `variant`
error[E0381]: used binding `variant` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:39:13
|
LL | let variant: !;
| ------- binding declared here but left uninitialized
LL | let c = || {
| ^^ use of possibly-uninitialized `variant`
LL |
| ^^ `variant` used here but it isn't initialized
LL | match variant {
| ------- borrow occurs due to use in closure
error[E0381]: use of possibly-uninitialized variable: `g`
--> $DIR/pattern-matching-should-fail.rs:55:15
error[E0381]: used binding `g` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:54:15
|
LL | let g: !;
| - binding declared here but left uninitialized
...
LL | match g { };
| ^ use of possibly-uninitialized `g`
| ^ `g` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `t`
--> $DIR/pattern-matching-should-fail.rs:58:19
error[E0381]: used binding `t` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:56:19
|
LL | let t: !;
| - binding declared here but left uninitialized
...
LL | match t { };
| ^ use of possibly-uninitialized `t`
| ^ `t` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `x`
--> $DIR/pattern-matching-should-fail.rs:70:23
error[E0381]: used binding `x` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:67:23
|
LL | let x: u8;
| - binding declared here but left uninitialized
LL | let c1 = || match x { };
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
error: aborting due to 8 previous errors

View File

@ -1,6 +1,5 @@
struct X<const N: usize = {
let s: &'static str; s.len()
//~^ ERROR borrow of possibly-uninitialized variable
let s: &'static str; s.len() //~ ERROR E0381
}>;
fn main() {}

View File

@ -1,8 +1,10 @@
error[E0381]: borrow of possibly-uninitialized variable: `s`
error[E0381]: used binding `s` isn't initialized
--> $DIR/const-generic-default-wont-borrowck.rs:2:26
|
LL | let s: &'static str; s.len()
| ^^^^^^^ use of possibly-uninitialized `*s`
| - ^^^^^^^ `*s` used here but it isn't initialized
| |
| binding declared here but left uninitialized
error: aborting due to previous error

View File

@ -1,6 +1,6 @@
const FOO: *const u32 = {
let x;
&x //~ ERROR borrow of possibly-uninitialized variable: `x`
&x //~ ERROR E0381
};
fn main() {

View File

@ -1,8 +1,10 @@
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/issue-78655.rs:3:5
|
LL | let x;
| - binding declared here but left uninitialized
LL | &x
| ^^ use of possibly-uninitialized `x`
| ^^ `x` used here but it isn't initialized
error: could not evaluate constant pattern
--> $DIR/issue-78655.rs:7:9

View File

@ -9,7 +9,7 @@ const _: [String; 0] = [String::new(); 0];
fn must_be_init() {
let x: u8;
let _ = [x; 0]; //~ ERROR: use of possibly-uninitialized variable: `x`
let _ = [x; 0]; //~ ERROR E0381
}
fn main() {}

View File

@ -17,11 +17,13 @@ LL | const _: [String; 0] = [String::new(); 0];
| |constants cannot evaluate destructors
| value is dropped here
error[E0381]: use of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/repeat-drop-2.rs:12:14
|
LL | let x: u8;
| - binding declared here but left uninitialized
LL | let _ = [x; 0];
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
error: aborting due to 3 previous errors

View File

@ -9,8 +9,7 @@ struct T(i32, i32);
fn test_tuple() {
let _ = || {
let mut t: (i32, i32);
t.0 = 42;
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
t.0 = 42; //~ ERROR E0381
yield;
t.1 = 88;
let _ = t;
@ -20,8 +19,7 @@ fn test_tuple() {
fn test_tuple_struct() {
let _ = || {
let mut t: T;
t.0 = 42;
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
t.0 = 42; //~ ERROR E0381
yield;
t.1 = 88;
let _ = t;
@ -31,8 +29,7 @@ fn test_tuple_struct() {
fn test_struct() {
let _ = || {
let mut t: S;
t.x = 42;
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
t.x = 42; //~ ERROR E0381
yield;
t.y = 88;
let _ = t;

View File

@ -1,20 +1,32 @@
error[E0381]: assign to part of possibly-uninitialized variable: `t`
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/partial-initialization-across-yield.rs:12:9
|
LL | let mut t: (i32, i32);
| ----- binding declared here but left uninitialized
LL | t.0 = 42;
| ^^^^^^^^ use of possibly-uninitialized `t`
error[E0381]: assign to part of possibly-uninitialized variable: `t`
--> $DIR/partial-initialization-across-yield.rs:23:9
| ^^^^^^^^ `t` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/partial-initialization-across-yield.rs:22:9
|
LL | let mut t: T;
| ----- binding declared here but left uninitialized
LL | t.0 = 42;
| ^^^^^^^^ use of possibly-uninitialized `t`
error[E0381]: assign to part of possibly-uninitialized variable: `t`
--> $DIR/partial-initialization-across-yield.rs:34:9
| ^^^^^^^^ `t` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/partial-initialization-across-yield.rs:32:9
|
LL | let mut t: S;
| ----- binding declared here but left uninitialized
LL | t.x = 42;
| ^^^^^^^^ use of possibly-uninitialized `t`
| ^^^^^^^^ `t` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to 3 previous errors

View File

@ -6,7 +6,7 @@ fn test1() {
'a: loop {
x = loop { break 'a };
}
println!("{:?}", x); //~ ERROR borrow of possibly-uninitialized variable
println!("{:?}", x); //~ ERROR E0381
}
// test2 and test3 should not fail.

View File

@ -1,8 +1,11 @@
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/loop-proper-liveness.rs:9:22
|
LL | let x: i32;
| - binding declared here but left uninitialized
...
LL | println!("{:?}", x);
| ^ use of possibly-uninitialized `x`
| ^ `x` used here but it isn't initialized
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -6,7 +6,7 @@ static A: () = {
//~^ ERROR destructors cannot be evaluated at compile-time
a[0] = String::new();
//~^ ERROR destructors cannot be evaluated at compile-time
//~| ERROR use of possibly-uninitialized variable
//~| ERROR binding `a` isn't initialized
};
struct B<T>([T; 1]);

View File

@ -16,11 +16,14 @@ LL | let a: [String; 1];
LL | };
| - value is dropped here
error[E0381]: use of possibly-uninitialized variable: `a`
error[E0381]: used binding `a` isn't initialized
--> $DIR/drop-elaboration-after-borrowck-error.rs:7:5
|
LL | let a: [String; 1];
| - binding declared here but left uninitialized
LL |
LL | a[0] = String::new();
| ^^^^ use of possibly-uninitialized `a`
| ^^^^ `a` used here but it isn't initialized
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/drop-elaboration-after-borrowck-error.rs:18:9

View File

@ -57,17 +57,17 @@ fn moved_loop_2() {
fn uninit_1() {
loop {
let value: NonCopy;
let _used = value; //~ ERROR use of possibly-uninitialized variable: `value`
//~^ NOTE use of possibly-uninitialized `value`
let value: NonCopy; //~ NOTE declared here
let _used = value; //~ ERROR binding `value` isn't initialized
//~^ NOTE `value` used here but it isn't initialized
}
}
fn uninit_2() {
let mut value: NonCopy;
let mut value: NonCopy; //~ NOTE declared here
loop {
let _used = value; //~ ERROR use of possibly-uninitialized variable: `value`
//~^ NOTE use of possibly-uninitialized `value`
let _used = value; //~ ERROR binding `value` isn't initialized
//~^ NOTE `value` used here but it isn't initialized
}
}

View File

@ -40,17 +40,22 @@ LL | let mut value = NonCopy{};
LL | let _used2 = value;
| ^^^^^ value moved here, in previous iteration of loop
error[E0381]: use of possibly-uninitialized variable: `value`
error[E0381]: used binding `value` isn't initialized
--> $DIR/issue-72649-uninit-in-loop.rs:61:21
|
LL | let value: NonCopy;
| ----- binding declared here but left uninitialized
LL | let _used = value;
| ^^^^^ use of possibly-uninitialized `value`
| ^^^^^ `value` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `value`
error[E0381]: used binding `value` isn't initialized
--> $DIR/issue-72649-uninit-in-loop.rs:69:21
|
LL | let mut value: NonCopy;
| --------- binding declared here but left uninitialized
LL | loop {
LL | let _used = value;
| ^^^^^ use of possibly-uninitialized `value`
| ^^^^^ `value` used here but it isn't initialized
error: aborting due to 6 previous errors

View File

@ -11,5 +11,5 @@ fn main() {
fn foo(i: usize) {
let mut a: [D; 4];
a[i] = d(); //~ ERROR use of possibly-uninitialized variable: `a`
a[i] = d(); //~ ERROR E0381
}

View File

@ -1,8 +1,10 @@
error[E0381]: use of possibly-uninitialized variable: `a`
error[E0381]: used binding `a` isn't initialized
--> $DIR/move-into-dead-array-1.rs:14:5
|
LL | let mut a: [D; 4];
| ----- binding declared here but left uninitialized
LL | a[i] = d();
| ^^^^ use of possibly-uninitialized `a`
| ^^^^ `a` used here but it isn't initialized
error: aborting due to previous error

View File

@ -5,7 +5,7 @@ struct S;
fn main() {
let mut x: S;
std::ptr::addr_of_mut!(x); //~ borrow of
std::ptr::addr_of_mut!(x); //~ ERROR E0381
let y = x; // Should error here if `addr_of_mut` is ever allowed on uninitialized variables
drop(y);

View File

@ -1,8 +1,10 @@
error[E0381]: borrow of possibly-uninitialized variable: `x`
error[E0381]: used binding `x` isn't initialized
--> $DIR/move-of-addr-of-mut.rs:8:5
|
LL | let mut x: S;
| ----- binding declared here but left uninitialized
LL | std::ptr::addr_of_mut!(x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^ use of possibly-uninitialized `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)

View File

@ -25,14 +25,12 @@ impl Drop for D {
fn cannot_partially_init_adt_with_drop() {
let d: D;
d.x = 10;
//~^ ERROR assign of possibly-uninitialized variable: `d` [E0381]
d.x = 10; //~ ERROR E0381
}
fn cannot_partially_init_mutable_adt_with_drop() {
let mut d: D;
d.x = 10;
//~^ ERROR assign of possibly-uninitialized variable: `d` [E0381]
d.x = 10; //~ ERROR E0381
}
fn cannot_partially_reinit_adt_with_drop() {
@ -44,14 +42,12 @@ fn cannot_partially_reinit_adt_with_drop() {
fn cannot_partially_init_inner_adt_via_outer_with_drop() {
let d: D;
d.s.y = 20;
//~^ ERROR assign to part of possibly-uninitialized variable: `d` [E0381]
d.s.y = 20; //~ ERROR E0381
}
fn cannot_partially_init_inner_adt_via_mutable_outer_with_drop() {
let mut d: D;
d.s.y = 20;
//~^ ERROR assign to part of possibly-uninitialized variable: `d` [E0381]
d.s.y = 20; //~ ERROR E0381
}
fn cannot_partially_reinit_inner_adt_via_outer_with_drop() {

View File

@ -1,17 +1,25 @@
error[E0381]: assign of possibly-uninitialized variable: `d`
error[E0381]: assigned binding `d` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:28:5
|
LL | let d: D;
| - binding declared here but left uninitialized
LL | d.x = 10;
| ^^^^^^^^ use of possibly-uninitialized `d`
error[E0381]: assign of possibly-uninitialized variable: `d`
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:34:5
| ^^^^^^^^ `d` assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assigned binding `d` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:33:5
|
LL | let mut d: D;
| ----- binding declared here but left uninitialized
LL | d.x = 10;
| ^^^^^^^^ use of possibly-uninitialized `d`
| ^^^^^^^^ `d` assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0382]: assign of moved value: `d`
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:41:5
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:39:5
|
LL | let mut d = D { x: 0, s: S{ y: 0, z: 0 } };
| ----- move occurs because `d` has type `D`, which does not implement the `Copy` trait
@ -20,20 +28,28 @@ LL | drop(d);
LL | d.x = 10;
| ^^^^^^^^ value assigned here after move
error[E0381]: assign to part of possibly-uninitialized variable: `d`
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:47:5
error[E0381]: partially assigned binding `d` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:45:5
|
LL | let d: D;
| - binding declared here but left uninitialized
LL | d.s.y = 20;
| ^^^^^^^^^^ use of possibly-uninitialized `d.s`
| ^^^^^^^^^^ `d.s` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `d`
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:53:5
error[E0381]: partially assigned binding `d` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:50:5
|
LL | let mut d: D;
| ----- binding declared here but left uninitialized
LL | d.s.y = 20;
| ^^^^^^^^^^ use of possibly-uninitialized `d.s`
| ^^^^^^^^^^ `d.s` partially assigned here but it isn't fully initialized
|
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error[E0382]: assign to part of moved value: `d`
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:60:5
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:56:5
|
LL | let mut d = D { x: 0, s: S{ y: 0, z: 0} };
| ----- move occurs because `d` has type `D`, which does not implement the `Copy` trait

Some files were not shown because too many files have changed in this diff Show More