1
Fork 0

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 unitialized
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.
This commit is contained in:
Esteban Küber 2022-06-21 11:57:45 -07:00
parent 3e51277fe6
commit 29e2aa12ff
106 changed files with 947 additions and 453 deletions

View file

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

View file

@ -2,9 +2,12 @@ use either::Either;
use rustc_const_eval::util::CallKind; use rustc_const_eval::util::CallKind;
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet; 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 as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::{AsyncGeneratorKind, GeneratorKind}; use rustc_hir::{AsyncGeneratorKind, GeneratorKind};
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::ObligationCause; use rustc_infer::traits::ObligationCause;
@ -94,32 +97,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
return; return;
} }
let item_msg = let err =
match self.describe_place_with_options(used_place, IncludingDowncast(true)) { self.report_use_of_uninitialized(mpi, used_place, desired_action, span, use_spans);
Some(name) => format!("`{}`", name),
None => "value".to_owned(),
};
let mut err = self.cannot_act_on_uninitialized_variable(
span,
desired_action.as_noun(),
&self
.describe_place_with_options(moved_place, IncludingDowncast(true))
.unwrap_or_else(|| "_".to_owned()),
);
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); self.buffer_error(err);
} else { } else {
if let Some((reported_place, _)) = self.has_move_error(&move_out_indices) { if let Some((reported_place, _)) = self.has_move_error(&move_out_indices) {
if self.prefixes(*reported_place, PrefixSet::All).any(|p| p == used_place) { if self.prefixes(*reported_place, PrefixSet::All).any(|p| p == used_place) {
debug!( debug!(
"report_use_of_moved_or_uninitialized place: error suppressed \ "report_use_of_moved_or_uninitialized place: error suppressed mois={:?}",
mois={:?}",
move_out_indices move_out_indices
); );
return; return;
@ -326,6 +311,99 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
} }
} }
fn report_use_of_uninitialized(
&self,
mpi: MovePathIndex,
used_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);
spans.push(span);
}
let (item_msg, name, desc) =
match self.describe_place_with_options(used_place, IncludingDowncast(true)) {
Some(name) => (format!("`{name}`"), format!("`{name}`"), format!("`{name}` ")),
None => ("value".to_string(), "the variable".to_string(), String::new()),
};
let initialized = if let InitializationRequiringAction::PartialAssignment = 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.
"fully initialized"
} else if spans.iter().filter(|i| !i.contains(span)).count() == 0 {
// We filter above to avoid misleading wording in cases like:
// ```
// let x;
// x += 1;
// ```
"initialized"
} else {
"initialized in all conditions"
};
let mut err = struct_span_err!(self, span, E0381, "binding {desc}isn't {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 = desired_action {
err.help(
"partial initialization isn't supported, fully initialize the binding with \
a default value and mutate, or use `std::mem::MaybeUninit`",
);
}
let verb = desired_action.as_verb_in_past_tense();
err.span_label(span, format!("{item_msg} {verb} here but it isn't {initialized}",));
// 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);
if visitor.errors.is_empty() {
for sp in &spans {
if *sp < span && !sp.overlaps(span) {
err.span_label(*sp, "binding initialized here in some conditions");
}
}
}
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);
}
}
err.span_label(decl_span, "variable declared here");
err
}
fn suggest_borrow_fn_like( fn suggest_borrow_fn_like(
&self, &self,
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>, err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
@ -2448,3 +2526,103 @@ 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!(
"this `if` expression might be missing an `else` arm where {} is \
initialized",
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) => {
self.errors.push((
cond.span,
format!("{} is uninitialized if this condition isn't met", self.name,),
));
}
(false, true) => {
self.errors.push((
cond.span,
format!("{} is uninitialized if this condition is met", self.name),
));
}
}
}
hir::ExprKind::Match(_, arms, _) => {
// 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 {
self.errors.push((
arm.pat.span,
format!(
"{} is uninitialized if this pattern is matched",
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. We should also specialize the output for `while` and `for` loops,
// but for now we can rely on their desugaring to provide appropriate output.
_ => {}
}
walk_expr(self, ex);
}
}

View file

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

View file

@ -1,14 +1,18 @@
error[E0381]: use of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't initialized
--> $DIR/type-check-5.rs:15:28 --> $DIR/type-check-5.rs:15:28
| |
LL | let x: u64;
| - variable declared here
LL | asm!("{}", in(reg) x); 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]: binding `y` isn't initialized
--> $DIR/type-check-5.rs:18:9 --> $DIR/type-check-5.rs:18:9
| |
LL | let mut y: u64;
| ----- variable declared here
LL | asm!("{}", inout(reg) y); 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 error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
--> $DIR/type-check-5.rs:26:29 --> $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 { if x > 5 {
y = echo(10).await; y = echo(10).await;
} }
y y //~ ERROR E0381
//~^ use of possibly-uninitialized variable: `y`
} }
async fn echo(x: usize) -> usize { x + 1 } async fn echo(x: usize) -> usize { x + 1 }

View file

@ -1,8 +1,13 @@
error[E0381]: use of possibly-uninitialized variable: `y` error[E0381]: binding `y` isn't initialized in all conditions
--> $DIR/no-non-guaranteed-initialization.rs:9:5 --> $DIR/no-non-guaranteed-initialization.rs:9:5
| |
LL | let y;
| - variable declared here
LL | if x > 5 {
| ----- this `if` expression might be missing an `else` arm where `y` is initialized
...
LL | y LL | y
| ^ use of possibly-uninitialized `y` | ^ `y` used here but it isn't initialized in all conditions
error: aborting due to previous error error: aborting due to previous error

View file

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

View file

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

View file

@ -2,5 +2,5 @@ fn main() {
let i: isize; let i: isize;
println!("{}", false && { i = 5; true }); 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]: binding `i` isn't initialized in all conditions
--> $DIR/borrowck-and-init.rs:5:20 --> $DIR/borrowck-and-init.rs:5:20
| |
LL | let i: isize;
| - variable declared here
LL |
LL | println!("{}", false && { i = 5; true });
| ----- binding initialized here in some conditions
LL | println!("{}", i); LL | println!("{}", i);
| ^ use of possibly-uninitialized `i` | ^ `i` borrowed here but it isn't initialized in all conditions
| |
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) = 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 force<F>(f: F) where F: FnOnce() { f(); }
fn main() { fn main() {
let x: isize; let x: isize;
force(|| { //~ ERROR borrow of possibly-uninitialized variable: `x` force(|| { //~ ERROR E0381
println!("{}", x); println!("{}", x);
}); });
} }

View file

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

View file

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

View file

@ -1,8 +1,11 @@
error[E0381]: borrow of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't initialized
--> $DIR/borrowck-break-uninit-2.rs:9:20 --> $DIR/borrowck-break-uninit-2.rs:9:20
| |
LL | let x: isize;
| - variable declared here
...
LL | println!("{}", x); LL | println!("{}", x);
| ^ use of possibly-uninitialized `x` | ^ `x` borrowed 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) = 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; x = 0;
} }
println!("{}", x); //~ ERROR borrow of possibly-uninitialized variable: `x` println!("{}", x); //~ ERROR E0381
return 17; return 17;
} }

View file

@ -1,8 +1,11 @@
error[E0381]: borrow of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't initialized
--> $DIR/borrowck-break-uninit.rs:9:20 --> $DIR/borrowck-break-uninit.rs:9:20
| |
LL | let x: isize;
| - variable declared here
...
LL | println!("{}", x); LL | println!("{}", x);
| ^ use of possibly-uninitialized `x` | ^ `x` borrowed 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) = 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() { fn copy_after_field_assign_after_uninit() {
let mut x: A; let mut x: A;
x.a = 1; //~ ERROR assign to part of possibly-uninitialized variable: `x` x.a = 1; //~ ERROR E0381
drop(x.a); drop(x.a);
} }
fn borrow_after_field_assign_after_uninit() { fn borrow_after_field_assign_after_uninit() {
let mut x: A; 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; let p = &x.a;
drop(*p); drop(*p);
} }
fn move_after_field_assign_after_uninit() { fn move_after_field_assign_after_uninit() {
let mut x: A; 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); 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 = 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]: binding `x` isn't fully initialized
--> $DIR/borrowck-field-sensitivity.rs:81:5 --> $DIR/borrowck-field-sensitivity.rs:81:5
| |
LL | let mut x: A;
| ----- variable declared here
LL | x.a = 1; 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, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't fully initialized
--> $DIR/borrowck-field-sensitivity.rs:87:5 --> $DIR/borrowck-field-sensitivity.rs:87:5
| |
LL | let mut x: A;
| ----- variable declared here
LL | x.a = 1; 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, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't fully initialized
--> $DIR/borrowck-field-sensitivity.rs:94:5 --> $DIR/borrowck-field-sensitivity.rs:94:5
| |
LL | let mut x: A;
| ----- variable declared here
LL | x.b = Box::new(1); 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, or use `std::mem::MaybeUninit`
error: aborting due to 14 previous errors error: aborting due to 14 previous errors

View file

@ -2,5 +2,5 @@ fn foo(x: isize) { println!("{}", x); }
fn main() { fn main() {
let x: isize; if 1 > 2 { x = 10; } 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,12 @@
error[E0381]: use of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't initialized in all conditions
--> $DIR/borrowck-if-no-else.rs:5:9 --> $DIR/borrowck-if-no-else.rs:5:9
| |
LL | let x: isize; if 1 > 2 { x = 10; }
| - ----- this `if` expression might be missing an `else` arm where `x` is initialized
| |
| variable declared here
LL | foo(x); LL | foo(x);
| ^ use of possibly-uninitialized `x` | ^ `x` used here but it isn't initialized in all conditions
error: aborting due to previous error error: aborting due to previous error

View file

@ -7,5 +7,5 @@ fn main() {
} else { } else {
x = 10; 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]: binding `x` isn't initialized in all conditions
--> $DIR/borrowck-if-with-else.rs:10:9 --> $DIR/borrowck-if-with-else.rs:10:9
| |
LL | let x: isize;
| - variable declared here
LL | if 1 > 2 {
| ----- `x` is uninitialized if this condition is met
...
LL | foo(x); LL | foo(x);
| ^ use of possibly-uninitialized `x` | ^ `x` used here but it isn't initialized in all conditions
error: aborting due to previous error error: aborting due to previous error

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,5 +2,5 @@ fn main() {
let i: isize; let i: isize;
println!("{}", false || { i = 5; true }); 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]: binding `i` isn't initialized in all conditions
--> $DIR/borrowck-or-init.rs:5:20 --> $DIR/borrowck-or-init.rs:5:20
| |
LL | let i: isize;
| - variable declared here
LL |
LL | println!("{}", false || { i = 5; true });
| ----- binding initialized here in some conditions
LL | println!("{}", i); LL | println!("{}", i);
| ^ use of possibly-uninitialized `i` | ^ `i` borrowed here but it isn't initialized in all conditions
| |
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) = 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() { fn stuff() {
let mut x : (Test2, Test2); let mut x : (Test2, Test2);
(x.0).0 = Some(Test); (x.0).0 = Some(Test); //~ ERROR E0381
//~^ ERROR assign of possibly-uninitialized variable: `x.0`
} }
fn main() { fn main() {

View file

@ -1,8 +1,10 @@
error[E0381]: assign of possibly-uninitialized variable: `x.0` error[E0381]: binding `x.0` isn't initialized
--> $DIR/borrowck-partial-reinit-4.rs:17:5 --> $DIR/borrowck-partial-reinit-4.rs:17:5
| |
LL | let mut x : (Test2, Test2);
| ----- variable declared here
LL | (x.0).0 = Some(Test); LL | (x.0).0 = Some(Test);
| ^^^^^^^ use of possibly-uninitialized `x.0` | ^^^^^^^ `x.0` assigned here but it isn't initialized
error: aborting due to previous error error: aborting due to previous error

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3,32 +3,32 @@
pub fn main() { pub fn main() {
let x: isize; let x: isize;
x += 1; //~ ERROR use of possibly-uninitialized variable: `x` x += 1; //~ ERROR E0381
let x: isize; let x: isize;
x -= 1; //~ ERROR use of possibly-uninitialized variable: `x` x -= 1; //~ ERROR E0381
let x: isize; let x: isize;
x *= 1; //~ ERROR use of possibly-uninitialized variable: `x` x *= 1; //~ ERROR E0381
let x: isize; let x: isize;
x /= 1; //~ ERROR use of possibly-uninitialized variable: `x` x /= 1; //~ ERROR E0381
let x: isize; let x: isize;
x %= 1; //~ ERROR use of possibly-uninitialized variable: `x` x %= 1; //~ ERROR E0381
let x: isize; let x: isize;
x ^= 1; //~ ERROR use of possibly-uninitialized variable: `x` x ^= 1; //~ ERROR E0381
let x: isize; let x: isize;
x &= 1; //~ ERROR use of possibly-uninitialized variable: `x` x &= 1; //~ ERROR E0381
let x: isize; let x: isize;
x |= 1; //~ ERROR use of possibly-uninitialized variable: `x` x |= 1; //~ ERROR E0381
let x: isize; let x: isize;
x <<= 1; //~ ERROR use of possibly-uninitialized variable: `x` x <<= 1; //~ ERROR E0381
let x: isize; 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]: binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:6:5 --> $DIR/borrowck-uninit-in-assignop.rs:6:5
| |
LL | let x: isize;
| - variable declared here
LL | x += 1; 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]: binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:9:5 --> $DIR/borrowck-uninit-in-assignop.rs:9:5
| |
LL | let x: isize;
| - variable declared here
LL | x -= 1; 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]: binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:12:5 --> $DIR/borrowck-uninit-in-assignop.rs:12:5
| |
LL | let x: isize;
| - variable declared here
LL | x *= 1; 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]: binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:15:5 --> $DIR/borrowck-uninit-in-assignop.rs:15:5
| |
LL | let x: isize;
| - variable declared here
LL | x /= 1; 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]: binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:18:5 --> $DIR/borrowck-uninit-in-assignop.rs:18:5
| |
LL | let x: isize;
| - variable declared here
LL | x %= 1; 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]: binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:21:5 --> $DIR/borrowck-uninit-in-assignop.rs:21:5
| |
LL | let x: isize;
| - variable declared here
LL | x ^= 1; 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]: binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:24:5 --> $DIR/borrowck-uninit-in-assignop.rs:24:5
| |
LL | let x: isize;
| - variable declared here
LL | x &= 1; 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]: binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:27:5 --> $DIR/borrowck-uninit-in-assignop.rs:27:5
| |
LL | let x: isize;
| - variable declared here
LL | x |= 1; 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]: binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:30:5 --> $DIR/borrowck-uninit-in-assignop.rs:30:5
| |
LL | let x: isize;
| - variable declared here
LL | x <<= 1; 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]: binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:33:5 --> $DIR/borrowck-uninit-in-assignop.rs:33:5
| |
LL | let x: isize;
| - variable declared here
LL | x >>= 1; LL | x >>= 1;
| ^^^^^^^ use of possibly-uninitialized `x` | ^^^^^^^ `x` used here but it isn't initialized
error: aborting due to 10 previous errors error: aborting due to 10 previous errors

View file

@ -5,29 +5,29 @@ struct S<X, Y> {
fn main() { fn main() {
let x: &&Box<i32>; let x: &&Box<i32>;
let _y = &**x; //~ [E0381] let _y = &**x; //~ ERROR [E0381]
let x: &&S<i32, i32>; let x: &&S<i32, i32>;
let _y = &**x; //~ [E0381] let _y = &**x; //~ ERROR [E0381]
let x: &&i32; let x: &&i32;
let _y = &**x; //~ [E0381] let _y = &**x; //~ ERROR [E0381]
let mut a: S<i32, i32>; 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 _b = &a.x;
let mut a: S<&&i32, &&i32>; 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 _b = &**a.x;
let mut a: S<i32, i32>; 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 _b = &a.y;
let mut a: S<&&i32, &&i32>; 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; let _b = &**a.y;
} }

View file

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

View file

@ -2,5 +2,5 @@ fn foo(x: isize) { println!("{}", x); }
fn main() { fn main() {
let x: isize; 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]: binding `x` isn't initialized
--> $DIR/borrowck-uninit.rs:5:9 --> $DIR/borrowck-uninit.rs:5:9
| |
LL | let x: isize;
| - variable declared here
LL | foo(x); LL | foo(x);
| ^ use of possibly-uninitialized `x` | ^ `x` used here but it isn't initialized
error: aborting due to previous error error: aborting due to previous error

View file

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

View file

@ -1,14 +1,24 @@
error[E0381]: assign to part of possibly-uninitialized variable: `s` error[E0381]: binding `s` isn't fully initialized
--> $DIR/borrowck-union-uninitialized.rs:13:9 --> $DIR/borrowck-union-uninitialized.rs:13:9
| |
LL | let mut s: S;
| ----- variable declared here
LL | let mut u: U;
LL | s.a = 0; 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, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `u` error[E0381]: binding `u` isn't fully initialized
--> $DIR/borrowck-union-uninitialized.rs:14:9 --> $DIR/borrowck-union-uninitialized.rs:14:9
| |
LL | let mut u: U;
| ----- variable declared here
LL | s.a = 0;
LL | u.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, or use `std::mem::MaybeUninit`
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

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

View file

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

View file

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

View file

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

View file

@ -1,8 +1,13 @@
error[E0381]: borrow of possibly-uninitialized variable: `v` error[E0381]: binding `v` isn't initialized in all conditions
--> $DIR/borrowck-while-break.rs:7:20 --> $DIR/borrowck-while-break.rs:7:20
| |
LL | let v;
| - variable declared here
LL | while cond {
| ---- `v` is uninitialized if this condition isn't met
...
LL | println!("{}", v); LL | println!("{}", v);
| ^ use of possibly-uninitialized `v` | ^ `v` borrowed here but it isn't initialized in all conditions
| |
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) = 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() { fn main() {
let x: bool; 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]: binding `x` isn't initialized
--> $DIR/borrowck-while-cond.rs:3:11 --> $DIR/borrowck-while-cond.rs:3:11
| |
LL | let x: bool;
| - variable declared here
LL | while x { } LL | while x { }
| ^ use of possibly-uninitialized `x` | ^ `x` used here but it isn't initialized
error: aborting due to previous error error: aborting due to previous error

View file

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

View file

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

View file

@ -4,19 +4,19 @@
fn main() { fn main() {
let mut t: (u64, u64); let mut t: (u64, u64);
t.0 = 1; t.0 = 1;
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381] //~^ ERROR E0381
t.1 = 1; t.1 = 1;
let mut t: (u64, u64); let mut t: (u64, u64);
t.1 = 1; t.1 = 1;
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381] //~^ ERROR E0381
t.0 = 1; t.0 = 1;
let mut t: (u64, u64); let mut t: (u64, u64);
t.0 = 1; t.0 = 1;
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381] //~^ ERROR E0381
let mut t: (u64,); let mut t: (u64,);
t.0 = 1; 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]: binding `t` isn't fully initialized
--> $DIR/disallow-possibly-uninitialized.rs:6:5 --> $DIR/disallow-possibly-uninitialized.rs:6:5
| |
LL | let mut t: (u64, u64);
| ----- variable declared here
LL | t.0 = 1; 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, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `t` error[E0381]: binding `t` isn't fully initialized
--> $DIR/disallow-possibly-uninitialized.rs:11:5 --> $DIR/disallow-possibly-uninitialized.rs:11:5
| |
LL | let mut t: (u64, u64);
| ----- variable declared here
LL | t.1 = 1; 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, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `t` error[E0381]: binding `t` isn't fully initialized
--> $DIR/disallow-possibly-uninitialized.rs:16:5 --> $DIR/disallow-possibly-uninitialized.rs:16:5
| |
LL | let mut t: (u64, u64);
| ----- variable declared here
LL | t.0 = 1; 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, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `t` error[E0381]: binding `t` isn't fully initialized
--> $DIR/disallow-possibly-uninitialized.rs:20:5 --> $DIR/disallow-possibly-uninitialized.rs:20:5
| |
LL | let mut t: (u64,);
| ----- variable declared here
LL | t.0 = 1; 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, or use `std::mem::MaybeUninit`
error: aborting due to 4 previous errors error: aborting due to 4 previous errors

View file

@ -9,11 +9,11 @@ pub fn main() {
pub fn foo1() { pub fn foo1() {
let x: i32; let x: i32;
loop { x = break; } loop { x = break; }
println!("{}", x); //~ ERROR borrow of possibly-uninitialized variable: `x` println!("{}", x); //~ ERROR E0381
} }
pub fn foo2() { pub fn foo2() {
let x: i32; let x: i32;
for _ in 0..10 { x = continue; } 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]: binding `x` isn't initialized
--> $DIR/issue-24267-flow-exit.rs:12:20 --> $DIR/issue-24267-flow-exit.rs:12:20
| |
LL | let x: i32;
| - variable declared here
LL | loop { x = break; }
LL | println!("{}", x); LL | println!("{}", x);
| ^ use of possibly-uninitialized `x` | ^ `x` borrowed 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) = 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]: binding `x` isn't initialized
--> $DIR/issue-24267-flow-exit.rs:18:20 --> $DIR/issue-24267-flow-exit.rs:18:20
| |
LL | let x: i32;
| - variable declared here
LL | for _ in 0..10 { x = continue; }
LL | println!("{}", x); LL | println!("{}", x);
| ^ use of possibly-uninitialized `x` | ^ `x` borrowed 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) = 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; let mut t: Tuple;
t.0 = S(1); t.0 = S(1);
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381] //~^ ERROR E0381
t.1 = 2; t.1 = 2;
println!("{:?} {:?}", t.0, t.1); println!("{:?} {:?}", t.0, t.1);
} }
@ -18,7 +18,7 @@ fn main() {
{ {
let mut u: Tpair; let mut u: Tpair;
u.0 = S(1); u.0 = S(1);
//~^ ERROR assign to part of possibly-uninitialized variable: `u` [E0381] //~^ ERROR E0381
u.1 = 2; u.1 = 2;
println!("{:?} {:?}", u.0, u.1); println!("{:?} {:?}", u.0, u.1);
} }
@ -26,7 +26,7 @@ fn main() {
{ {
let mut v: Spair; let mut v: Spair;
v.x = S(1); v.x = S(1);
//~^ ERROR assign to part of possibly-uninitialized variable: `v` [E0381] //~^ ERROR E0381
v.y = 2; v.y = 2;
println!("{:?} {:?}", v.x, v.y); println!("{:?} {:?}", v.x, v.y);
} }

View file

@ -1,20 +1,32 @@
error[E0381]: assign to part of possibly-uninitialized variable: `t` error[E0381]: binding `t` isn't fully initialized
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:12:9 --> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:12:9
| |
LL | let mut t: Tuple;
| ----- variable declared here
LL | t.0 = S(1); 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, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `u` error[E0381]: binding `u` isn't fully initialized
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:20:9 --> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:20:9
| |
LL | let mut u: Tpair;
| ----- variable declared here
LL | u.0 = S(1); 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, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `v` error[E0381]: binding `v` isn't fully initialized
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:28:9 --> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:28:9
| |
LL | let mut v: Spair;
| ----- variable declared here
LL | v.x = S(1); 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, or use `std::mem::MaybeUninit`
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

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

View file

@ -1,20 +1,32 @@
error[E0381]: assign to part of possibly-uninitialized variable: `t` error[E0381]: binding `t` isn't fully initialized
--> $DIR/issue-54499-field-mutation-of-never-init.rs:12:9 --> $DIR/issue-54499-field-mutation-of-never-init.rs:12:9
| |
LL | let t: Tuple;
| - variable declared here
LL | t.0 = S(1); 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, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `u` error[E0381]: binding `u` isn't fully initialized
--> $DIR/issue-54499-field-mutation-of-never-init.rs:20:9 --> $DIR/issue-54499-field-mutation-of-never-init.rs:20:9
| |
LL | let u: Tpair;
| - variable declared here
LL | u.0 = S(1); 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, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `v` error[E0381]: binding `v` isn't fully initialized
--> $DIR/issue-54499-field-mutation-of-never-init.rs:28:9 --> $DIR/issue-54499-field-mutation-of-never-init.rs:28:9
| |
LL | let v: Spair;
| - variable declared here
LL | v.x = S(1); 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, or use `std::mem::MaybeUninit`
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

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

View file

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

View file

@ -1,14 +1,22 @@
error[E0381]: assign to part of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't fully initialized
--> $DIR/reassignment_immutable_fields.rs:7:5 --> $DIR/reassignment_immutable_fields.rs:7:5
| |
LL | let x: (u32, u32);
| - variable declared here
LL | x.0 = 1; 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, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't fully initialized
--> $DIR/reassignment_immutable_fields.rs:15:5 --> $DIR/reassignment_immutable_fields.rs:15:5
| |
LL | let x: (u32, u32);
| - variable declared here
LL | x.0 = 1; 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, or use `std::mem::MaybeUninit`
error: aborting due to 2 previous errors 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]: binding `x` isn't fully initialized
--> $DIR/reassignment_immutable_fields_overlapping.rs:12:5 --> $DIR/reassignment_immutable_fields_overlapping.rs:12:5
| |
LL | let x: Foo;
| - variable declared here
LL | x.a = 1; 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, or use `std::mem::MaybeUninit`
error[E0594]: cannot assign to `x.b`, as `x` is not declared as mutable error[E0594]: cannot assign to `x.b`, as `x` is not declared as mutable
--> $DIR/reassignment_immutable_fields_overlapping.rs:13:5 --> $DIR/reassignment_immutable_fields_overlapping.rs:13:5

View file

@ -7,11 +7,15 @@ LL | x = (22, 44);
LL | x.0 = 1; LL | x.0 = 1;
| ^^^^^^^ cannot assign | ^^^^^^^ cannot assign
error[E0381]: assign to part of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't fully initialized
--> $DIR/reassignment_immutable_fields_twice.rs:12:5 --> $DIR/reassignment_immutable_fields_twice.rs:12:5
| |
LL | let x: (u32, u32);
| - variable declared here
LL | x.0 = 1; 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, or use `std::mem::MaybeUninit`
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -6,14 +6,14 @@
fn test1() { fn test1() {
let x: !; let x: !;
let c1 = || match x { }; let c1 = || match x { };
//~^ ERROR: use of possibly-uninitialized variable: `x` //~^ ERROR E0381
} }
// Should fake read the discriminant and throw an error // Should fake read the discriminant and throw an error
fn test2() { fn test2() {
let x: !; let x: !;
let c2 = || match x { _ => () }; let c2 = || match x { _ => () };
//~^ ERROR: borrow of possibly-uninitialized variable: `x` //~^ ERROR E0381
} }
// Testing single variant patterns // Testing single variant patterns
@ -25,7 +25,7 @@ enum SingleVariant {
fn test3() { fn test3() {
let variant: !; let variant: !;
let c = || { let c = || {
//~^ ERROR: borrow of possibly-uninitialized variable: `variant` //~^ ERROR E0381
match variant { match variant {
SingleVariant::Points(_) => {} SingleVariant::Points(_) => {}
} }
@ -36,8 +36,7 @@ fn test3() {
// Should fake read the discriminant and throw an error // Should fake read the discriminant and throw an error
fn test4() { fn test4() {
let variant: !; let variant: !;
let c = || { let c = || { //~ ERROR E0381
//~^ ERROR: borrow of possibly-uninitialized variable: `variant`
match variant { match variant {
SingleVariant::Points(a) => { SingleVariant::Points(a) => {
println!("{:?}", a); println!("{:?}", a);
@ -52,11 +51,9 @@ fn test5() {
let g: !; let g: !;
let a = || { let a = || {
match g { }; match g { }; //~ ERROR E0381
//~^ ERROR: use of possibly-uninitialized variable: `g`
let c = || { let c = || {
match t { }; match t { }; //~ ERROR E0381
//~^ ERROR: use of possibly-uninitialized variable: `t`
}; };
c(); c();
@ -68,7 +65,7 @@ fn test5() {
fn test6() { fn test6() {
let x: u8; let x: u8;
let c1 = || match x { }; let c1 = || match x { };
//~^ ERROR: use of possibly-uninitialized variable: `x` //~^ ERROR E0381
//~| ERROR: non-exhaustive patterns: type `u8` is non-empty //~| 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 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 { }; LL | let c1 = || match x { };
| ^ | ^
@ -12,55 +12,70 @@ LL + _ => todo!(),
LL ~ }; LL ~ };
| |
error[E0381]: use of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:8:23 --> $DIR/pattern-matching-should-fail.rs:8:23
| |
LL | let x: !;
| - variable declared here
LL | let c1 = || match x { }; 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]: binding `x` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:15:14 --> $DIR/pattern-matching-should-fail.rs:15:14
| |
LL | let x: !;
| - variable declared here
LL | let c2 = || match x { _ => () }; LL | let c2 = || match x { _ => () };
| ^^ - borrow occurs due to use in closure | ^^ - borrow occurs due to use in closure
| | | |
| use of possibly-uninitialized `x` | `x` borrowed here but it isn't initialized
error[E0381]: borrow of possibly-uninitialized variable: `variant` error[E0381]: binding `variant` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:27:13 --> $DIR/pattern-matching-should-fail.rs:27:13
| |
LL | let variant: !;
| ------- variable declared here
LL | let c = || { LL | let c = || {
| ^^ use of possibly-uninitialized `variant` | ^^ `variant` borrowed here but it isn't initialized
LL | LL |
LL | match variant { LL | match variant {
| ------- borrow occurs due to use in closure | ------- borrow occurs due to use in closure
error[E0381]: borrow of possibly-uninitialized variable: `variant` error[E0381]: binding `variant` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:39:13 --> $DIR/pattern-matching-should-fail.rs:39:13
| |
LL | let variant: !;
| ------- variable declared here
LL | let c = || { LL | let c = || {
| ^^ use of possibly-uninitialized `variant` | ^^ `variant` borrowed here but it isn't initialized
LL |
LL | match variant { LL | match variant {
| ------- borrow occurs due to use in closure | ------- borrow occurs due to use in closure
error[E0381]: use of possibly-uninitialized variable: `g` error[E0381]: binding `g` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:55:15 --> $DIR/pattern-matching-should-fail.rs:54:15
| |
LL | let g: !;
| - variable declared here
...
LL | match g { }; LL | match g { };
| ^ use of possibly-uninitialized `g` | ^ `g` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `t` error[E0381]: binding `t` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:58:19 --> $DIR/pattern-matching-should-fail.rs:56:19
| |
LL | let t: !;
| - variable declared here
...
LL | match t { }; LL | match t { };
| ^ use of possibly-uninitialized `t` | ^ `t` used here but it isn't initialized
error[E0381]: use of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't initialized
--> $DIR/pattern-matching-should-fail.rs:70:23 --> $DIR/pattern-matching-should-fail.rs:67:23
| |
LL | let x: u8;
| - variable declared here
LL | let c1 = || match x { }; 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 error: aborting due to 8 previous errors

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,8 +1,11 @@
error[E0381]: borrow of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't initialized
--> $DIR/loop-proper-liveness.rs:9:22 --> $DIR/loop-proper-liveness.rs:9:22
| |
LL | let x: i32;
| - variable declared here
...
LL | println!("{:?}", x); LL | println!("{:?}", x);
| ^ use of possibly-uninitialized `x` | ^ `x` borrowed 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) = 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 //~^ ERROR destructors cannot be evaluated at compile-time
a[0] = String::new(); a[0] = String::new();
//~^ ERROR destructors cannot be evaluated at compile-time //~^ 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]); struct B<T>([T; 1]);

View file

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

View file

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

View file

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

View file

@ -11,5 +11,5 @@ fn main() {
fn foo(i: usize) { fn foo(i: usize) {
let mut a: [D; 4]; 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]: binding `a` isn't initialized
--> $DIR/move-into-dead-array-1.rs:14:5 --> $DIR/move-into-dead-array-1.rs:14:5
| |
LL | let mut a: [D; 4];
| ----- variable declared here
LL | a[i] = d(); LL | a[i] = d();
| ^^^^ use of possibly-uninitialized `a` | ^^^^ `a` used here but it isn't initialized
error: aborting due to previous error error: aborting due to previous error

View file

@ -5,7 +5,7 @@ struct S;
fn main() { fn main() {
let mut x: S; 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 let y = x; // Should error here if `addr_of_mut` is ever allowed on uninitialized variables
drop(y); drop(y);

View file

@ -1,8 +1,10 @@
error[E0381]: borrow of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't initialized
--> $DIR/move-of-addr-of-mut.rs:8:5 --> $DIR/move-of-addr-of-mut.rs:8:5
| |
LL | let mut x: S;
| ----- variable declared here
LL | std::ptr::addr_of_mut!(x); LL | std::ptr::addr_of_mut!(x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^ use of possibly-uninitialized `x` | ^^^^^^^^^^^^^^^^^^^^^^^^^ `x` borrowed 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) = 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() { fn cannot_partially_init_adt_with_drop() {
let d: D; let d: D;
d.x = 10; d.x = 10; //~ ERROR E0381
//~^ ERROR assign of possibly-uninitialized variable: `d` [E0381]
} }
fn cannot_partially_init_mutable_adt_with_drop() { fn cannot_partially_init_mutable_adt_with_drop() {
let mut d: D; let mut d: D;
d.x = 10; d.x = 10; //~ ERROR E0381
//~^ ERROR assign of possibly-uninitialized variable: `d` [E0381]
} }
fn cannot_partially_reinit_adt_with_drop() { 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() { fn cannot_partially_init_inner_adt_via_outer_with_drop() {
let d: D; let d: D;
d.s.y = 20; d.s.y = 20; //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `d` [E0381]
} }
fn cannot_partially_init_inner_adt_via_mutable_outer_with_drop() { fn cannot_partially_init_inner_adt_via_mutable_outer_with_drop() {
let mut d: D; let mut d: D;
d.s.y = 20; d.s.y = 20; //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `d` [E0381]
} }
fn cannot_partially_reinit_inner_adt_via_outer_with_drop() { fn cannot_partially_reinit_inner_adt_via_outer_with_drop() {

View file

@ -1,17 +1,21 @@
error[E0381]: assign of possibly-uninitialized variable: `d` error[E0381]: binding `d` isn't initialized
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:28:5 --> $DIR/issue-21232-partial-init-and-erroneous-use.rs:28:5
| |
LL | let d: D;
| - variable declared here
LL | d.x = 10; LL | d.x = 10;
| ^^^^^^^^ use of possibly-uninitialized `d` | ^^^^^^^^ `d` assigned here but it isn't initialized
error[E0381]: assign of possibly-uninitialized variable: `d` error[E0381]: binding `d` isn't initialized
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:34:5 --> $DIR/issue-21232-partial-init-and-erroneous-use.rs:33:5
| |
LL | let mut d: D;
| ----- variable declared here
LL | d.x = 10; LL | d.x = 10;
| ^^^^^^^^ use of possibly-uninitialized `d` | ^^^^^^^^ `d` assigned here but it isn't initialized
error[E0382]: assign of moved value: `d` 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 } }; 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 | ----- move occurs because `d` has type `D`, which does not implement the `Copy` trait
@ -20,20 +24,28 @@ LL | drop(d);
LL | d.x = 10; LL | d.x = 10;
| ^^^^^^^^ value assigned here after move | ^^^^^^^^ value assigned here after move
error[E0381]: assign to part of possibly-uninitialized variable: `d` error[E0381]: binding `d.s` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:47:5 --> $DIR/issue-21232-partial-init-and-erroneous-use.rs:45:5
| |
LL | let d: D;
| - variable declared here
LL | d.s.y = 20; 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, or use `std::mem::MaybeUninit`
error[E0381]: assign to part of possibly-uninitialized variable: `d` error[E0381]: binding `d.s` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-erroneous-use.rs:53:5 --> $DIR/issue-21232-partial-init-and-erroneous-use.rs:50:5
| |
LL | let mut d: D;
| ----- variable declared here
LL | d.s.y = 20; 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, or use `std::mem::MaybeUninit`
error[E0382]: assign to part of moved value: `d` 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} }; 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 | ----- move occurs because `d` has type `D`, which does not implement the `Copy` trait

View file

@ -94,15 +94,13 @@ macro_rules! use_part {
fn test_0000_local_fully_init_and_use_struct() { fn test_0000_local_fully_init_and_use_struct() {
let s: S<B>; let s: S<B>;
s.x = 10; s.y = Box::new(20); s.x = 10; s.y = Box::new(20); //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `s` [E0381]
use_fully!(struct s); use_fully!(struct s);
} }
fn test_0001_local_fully_init_and_use_tuple() { fn test_0001_local_fully_init_and_use_tuple() {
let t: T; let t: T;
t.0 = 10; t.1 = Box::new(20); t.0 = 10; t.1 = Box::new(20); //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
use_fully!(tuple t); use_fully!(tuple t);
} }
@ -122,15 +120,13 @@ fn test_0011_local_fully_reinit_and_use_tuple() {
fn test_0100_local_partial_init_and_use_struct() { fn test_0100_local_partial_init_and_use_struct() {
let s: S<B>; let s: S<B>;
s.x = 10; s.x = 10; //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `s` [E0381]
use_part!(struct s); use_part!(struct s);
} }
fn test_0101_local_partial_init_and_use_tuple() { fn test_0101_local_partial_init_and_use_tuple() {
let t: T; let t: T;
t.0 = 10; t.0 = 10; //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
use_part!(tuple t); use_part!(tuple t);
} }
@ -150,15 +146,13 @@ fn test_0111_local_partial_reinit_and_use_tuple() {
fn test_0200_local_void_init_and_use_struct() { fn test_0200_local_void_init_and_use_struct() {
let s: S<Void>; let s: S<Void>;
s.x = 10; s.x = 10; //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `s` [E0381]
use_part!(struct s); use_part!(struct s);
} }
fn test_0201_local_void_init_and_use_tuple() { fn test_0201_local_void_init_and_use_tuple() {
let t: Tvoid; let t: Tvoid;
t.0 = 10; t.0 = 10; //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `t` [E0381]
use_part!(tuple t); use_part!(tuple t);
} }
@ -173,15 +167,13 @@ fn test_0201_local_void_init_and_use_tuple() {
fn test_1000_field_fully_init_and_use_struct() { fn test_1000_field_fully_init_and_use_struct() {
let q: Q<S<B>>; let q: Q<S<B>>;
q.r.f.x = 10; q.r.f.y = Box::new(20); q.r.f.x = 10; q.r.f.y = Box::new(20); //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `q` [E0381]
use_fully!(struct q.r.f); use_fully!(struct q.r.f);
} }
fn test_1001_field_fully_init_and_use_tuple() { fn test_1001_field_fully_init_and_use_tuple() {
let q: Q<T>; let q: Q<T>;
q.r.f.0 = 10; q.r.f.1 = Box::new(20); q.r.f.0 = 10; q.r.f.1 = Box::new(20); //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `q` [E0381]
use_fully!(tuple q.r.f); use_fully!(tuple q.r.f);
} }
@ -201,15 +193,13 @@ fn test_1011_field_fully_reinit_and_use_tuple() {
fn test_1100_field_partial_init_and_use_struct() { fn test_1100_field_partial_init_and_use_struct() {
let q: Q<S<B>>; let q: Q<S<B>>;
q.r.f.x = 10; q.r.f.x = 10; //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `q` [E0381]
use_part!(struct q.r.f); use_part!(struct q.r.f);
} }
fn test_1101_field_partial_init_and_use_tuple() { fn test_1101_field_partial_init_and_use_tuple() {
let q: Q<T>; let q: Q<T>;
q.r.f.0 = 10; q.r.f.0 = 10; //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `q` [E0381]
use_part!(tuple q.r.f); use_part!(tuple q.r.f);
} }
@ -229,15 +219,13 @@ fn test_1111_field_partial_reinit_and_use_tuple() {
fn test_1200_field_void_init_and_use_struct() { fn test_1200_field_void_init_and_use_struct() {
let mut q: Q<S<Void>>; let mut q: Q<S<Void>>;
q.r.f.x = 10; q.r.f.x = 10; //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `q` [E0381]
use_part!(struct q.r.f); use_part!(struct q.r.f);
} }
fn test_1201_field_void_init_and_use_tuple() { fn test_1201_field_void_init_and_use_tuple() {
let mut q: Q<Tvoid>; let mut q: Q<Tvoid>;
q.r.f.0 = 10; q.r.f.0 = 10; //~ ERROR E0381
//~^ ERROR assign to part of possibly-uninitialized variable: `q` [E0381]
use_part!(tuple q.r.f); use_part!(tuple q.r.f);
} }

View file

@ -1,17 +1,25 @@
error[E0381]: assign to part of possibly-uninitialized variable: `s` error[E0381]: binding `s` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:97:5 --> $DIR/issue-21232-partial-init-and-use.rs:97:5
| |
LL | let s: S<B>;
| - variable declared here
LL | s.x = 10; s.y = Box::new(20); LL | s.x = 10; s.y = Box::new(20);
| ^^^^^^^^ use of possibly-uninitialized `s` | ^^^^^^^^ `s` partially assigned here but it isn't fully initialized
error[E0381]: assign to part of possibly-uninitialized variable: `t`
--> $DIR/issue-21232-partial-init-and-use.rs:104:5
| |
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate, or use `std::mem::MaybeUninit`
error[E0381]: binding `t` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:103:5
|
LL | let t: T;
| - variable declared here
LL | t.0 = 10; t.1 = Box::new(20); LL | t.0 = 10; t.1 = Box::new(20);
| ^^^^^^^^ 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, or use `std::mem::MaybeUninit`
error[E0382]: assign to part of moved value: `s` error[E0382]: assign to part of moved value: `s`
--> $DIR/issue-21232-partial-init-and-use.rs:111:5 --> $DIR/issue-21232-partial-init-and-use.rs:109:5
| |
LL | let mut s: S<B> = S::new(); drop(s); LL | let mut s: S<B> = S::new(); drop(s);
| ----- - value moved here | ----- - value moved here
@ -21,7 +29,7 @@ LL | s.x = 10; s.y = Box::new(20);
| ^^^^^^^^ value partially assigned here after move | ^^^^^^^^ value partially assigned here after move
error[E0382]: assign to part of moved value: `t` error[E0382]: assign to part of moved value: `t`
--> $DIR/issue-21232-partial-init-and-use.rs:118:5 --> $DIR/issue-21232-partial-init-and-use.rs:116:5
| |
LL | let mut t: T = (0, Box::new(0)); drop(t); LL | let mut t: T = (0, Box::new(0)); drop(t);
| ----- - value moved here | ----- - value moved here
@ -30,20 +38,28 @@ LL | let mut t: T = (0, Box::new(0)); drop(t);
LL | t.0 = 10; t.1 = Box::new(20); LL | t.0 = 10; t.1 = Box::new(20);
| ^^^^^^^^ value partially assigned here after move | ^^^^^^^^ value partially assigned here after move
error[E0381]: assign to part of possibly-uninitialized variable: `s` error[E0381]: binding `s` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:125:5 --> $DIR/issue-21232-partial-init-and-use.rs:123:5
| |
LL | let s: S<B>;
| - variable declared here
LL | s.x = 10; LL | s.x = 10;
| ^^^^^^^^ use of possibly-uninitialized `s` | ^^^^^^^^ `s` partially assigned here but it isn't fully initialized
error[E0381]: assign to part of possibly-uninitialized variable: `t`
--> $DIR/issue-21232-partial-init-and-use.rs:132:5
| |
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate, or use `std::mem::MaybeUninit`
error[E0381]: binding `t` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:129:5
|
LL | let t: T;
| - variable declared here
LL | t.0 = 10; LL | t.0 = 10;
| ^^^^^^^^ 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, or use `std::mem::MaybeUninit`
error[E0382]: assign to part of moved value: `s` error[E0382]: assign to part of moved value: `s`
--> $DIR/issue-21232-partial-init-and-use.rs:139:5 --> $DIR/issue-21232-partial-init-and-use.rs:135:5
| |
LL | let mut s: S<B> = S::new(); drop(s); LL | let mut s: S<B> = S::new(); drop(s);
| ----- - value moved here | ----- - value moved here
@ -53,7 +69,7 @@ LL | s.x = 10;
| ^^^^^^^^ value partially assigned here after move | ^^^^^^^^ value partially assigned here after move
error[E0382]: assign to part of moved value: `t` error[E0382]: assign to part of moved value: `t`
--> $DIR/issue-21232-partial-init-and-use.rs:146:5 --> $DIR/issue-21232-partial-init-and-use.rs:142:5
| |
LL | let mut t: T = (0, Box::new(0)); drop(t); LL | let mut t: T = (0, Box::new(0)); drop(t);
| ----- - value moved here | ----- - value moved here
@ -62,32 +78,48 @@ LL | let mut t: T = (0, Box::new(0)); drop(t);
LL | t.0 = 10; LL | t.0 = 10;
| ^^^^^^^^ value partially assigned here after move | ^^^^^^^^ value partially assigned here after move
error[E0381]: assign to part of possibly-uninitialized variable: `s` error[E0381]: binding `s` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:153:5 --> $DIR/issue-21232-partial-init-and-use.rs:149:5
| |
LL | let s: S<Void>;
| - variable declared here
LL | s.x = 10; LL | s.x = 10;
| ^^^^^^^^ use of possibly-uninitialized `s` | ^^^^^^^^ `s` partially assigned here but it isn't fully initialized
error[E0381]: assign to part of possibly-uninitialized variable: `t`
--> $DIR/issue-21232-partial-init-and-use.rs:160:5
| |
LL | t.0 = 10; = help: partial initialization isn't supported, fully initialize the binding with a default value and mutate, or use `std::mem::MaybeUninit`
| ^^^^^^^^ use of possibly-uninitialized `t`
error[E0381]: assign to part of possibly-uninitialized variable: `q` error[E0381]: binding `t` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:155:5
|
LL | let t: Tvoid;
| - variable declared here
LL | t.0 = 10;
| ^^^^^^^^ `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, or use `std::mem::MaybeUninit`
error[E0381]: binding `q.r.f` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:170:5
|
LL | let q: Q<S<B>>;
| - variable declared here
LL | q.r.f.x = 10; q.r.f.y = Box::new(20);
| ^^^^^^^^^^^^ `q.r.f` 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, or use `std::mem::MaybeUninit`
error[E0381]: binding `q.r.f` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:176:5 --> $DIR/issue-21232-partial-init-and-use.rs:176:5
| |
LL | q.r.f.x = 10; q.r.f.y = Box::new(20); LL | let q: Q<T>;
| ^^^^^^^^^^^^ use of possibly-uninitialized `q.r.f` | - variable declared here
error[E0381]: assign to part of possibly-uninitialized variable: `q`
--> $DIR/issue-21232-partial-init-and-use.rs:183:5
|
LL | q.r.f.0 = 10; q.r.f.1 = Box::new(20); LL | q.r.f.0 = 10; q.r.f.1 = Box::new(20);
| ^^^^^^^^^^^^ use of possibly-uninitialized `q.r.f` | ^^^^^^^^^^^^ `q.r.f` 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, or use `std::mem::MaybeUninit`
error[E0382]: assign to part of moved value: `q.r` error[E0382]: assign to part of moved value: `q.r`
--> $DIR/issue-21232-partial-init-and-use.rs:190:5 --> $DIR/issue-21232-partial-init-and-use.rs:182:5
| |
LL | let mut q: Q<S<B>> = Q::new(S::new()); drop(q.r); LL | let mut q: Q<S<B>> = Q::new(S::new()); drop(q.r);
| --- value moved here | --- value moved here
@ -97,7 +129,7 @@ LL | q.r.f.x = 10; q.r.f.y = Box::new(20);
= note: move occurs because `q.r` has type `R<S<Box<u32>>>`, which does not implement the `Copy` trait = note: move occurs because `q.r` has type `R<S<Box<u32>>>`, which does not implement the `Copy` trait
error[E0382]: assign to part of moved value: `q.r` error[E0382]: assign to part of moved value: `q.r`
--> $DIR/issue-21232-partial-init-and-use.rs:197:5 --> $DIR/issue-21232-partial-init-and-use.rs:189:5
| |
LL | let mut q: Q<T> = Q::new((0, Box::new(0))); drop(q.r); LL | let mut q: Q<T> = Q::new((0, Box::new(0))); drop(q.r);
| --- value moved here | --- value moved here
@ -106,20 +138,28 @@ LL | q.r.f.0 = 10; q.r.f.1 = Box::new(20);
| |
= note: move occurs because `q.r` has type `R<(u32, Box<u32>)>`, which does not implement the `Copy` trait = note: move occurs because `q.r` has type `R<(u32, Box<u32>)>`, which does not implement the `Copy` trait
error[E0381]: assign to part of possibly-uninitialized variable: `q` error[E0381]: binding `q.r.f` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:204:5 --> $DIR/issue-21232-partial-init-and-use.rs:196:5
| |
LL | let q: Q<S<B>>;
| - variable declared here
LL | q.r.f.x = 10; LL | q.r.f.x = 10;
| ^^^^^^^^^^^^ use of possibly-uninitialized `q.r.f` | ^^^^^^^^^^^^ `q.r.f` partially assigned here but it isn't fully initialized
error[E0381]: assign to part of possibly-uninitialized variable: `q`
--> $DIR/issue-21232-partial-init-and-use.rs:211:5
| |
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate, or use `std::mem::MaybeUninit`
error[E0381]: binding `q.r.f` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:202:5
|
LL | let q: Q<T>;
| - variable declared here
LL | q.r.f.0 = 10; LL | q.r.f.0 = 10;
| ^^^^^^^^^^^^ use of possibly-uninitialized `q.r.f` | ^^^^^^^^^^^^ `q.r.f` 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, or use `std::mem::MaybeUninit`
error[E0382]: assign to part of moved value: `q.r` error[E0382]: assign to part of moved value: `q.r`
--> $DIR/issue-21232-partial-init-and-use.rs:218:5 --> $DIR/issue-21232-partial-init-and-use.rs:208:5
| |
LL | let mut q: Q<S<B>> = Q::new(S::new()); drop(q.r); LL | let mut q: Q<S<B>> = Q::new(S::new()); drop(q.r);
| --- value moved here | --- value moved here
@ -129,7 +169,7 @@ LL | q.r.f.x = 10;
= note: move occurs because `q.r` has type `R<S<Box<u32>>>`, which does not implement the `Copy` trait = note: move occurs because `q.r` has type `R<S<Box<u32>>>`, which does not implement the `Copy` trait
error[E0382]: assign to part of moved value: `q.r` error[E0382]: assign to part of moved value: `q.r`
--> $DIR/issue-21232-partial-init-and-use.rs:225:5 --> $DIR/issue-21232-partial-init-and-use.rs:215:5
| |
LL | let mut q: Q<T> = Q::new((0, Box::new(0))); drop(q.r); LL | let mut q: Q<T> = Q::new((0, Box::new(0))); drop(q.r);
| --- value moved here | --- value moved here
@ -138,20 +178,28 @@ LL | q.r.f.0 = 10;
| |
= note: move occurs because `q.r` has type `R<(u32, Box<u32>)>`, which does not implement the `Copy` trait = note: move occurs because `q.r` has type `R<(u32, Box<u32>)>`, which does not implement the `Copy` trait
error[E0381]: assign to part of possibly-uninitialized variable: `q` error[E0381]: binding `q.r.f` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:232:5 --> $DIR/issue-21232-partial-init-and-use.rs:222:5
| |
LL | let mut q: Q<S<Void>>;
| ----- variable declared here
LL | q.r.f.x = 10; LL | q.r.f.x = 10;
| ^^^^^^^^^^^^ use of possibly-uninitialized `q.r.f` | ^^^^^^^^^^^^ `q.r.f` partially assigned here but it isn't fully initialized
error[E0381]: assign to part of possibly-uninitialized variable: `q`
--> $DIR/issue-21232-partial-init-and-use.rs:239:5
| |
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate, or use `std::mem::MaybeUninit`
error[E0381]: binding `q.r.f` isn't fully initialized
--> $DIR/issue-21232-partial-init-and-use.rs:228:5
|
LL | let mut q: Q<Tvoid>;
| ----- variable declared here
LL | q.r.f.0 = 10; LL | q.r.f.0 = 10;
| ^^^^^^^^^^^^ use of possibly-uninitialized `q.r.f` | ^^^^^^^^^^^^ `q.r.f` 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, or use `std::mem::MaybeUninit`
error[E0382]: assign to part of moved value: `c` error[E0382]: assign to part of moved value: `c`
--> $DIR/issue-21232-partial-init-and-use.rs:257:13 --> $DIR/issue-21232-partial-init-and-use.rs:245:13
| |
LL | let mut c = (1, "".to_owned()); LL | let mut c = (1, "".to_owned());
| ----- move occurs because `c` has type `(i32, String)`, which does not implement the `Copy` trait | ----- move occurs because `c` has type `(i32, String)`, which does not implement the `Copy` trait
@ -162,7 +210,7 @@ LL | c.0 = 2;
| ^^^^^^^ value partially assigned here after move | ^^^^^^^ value partially assigned here after move
error[E0382]: assign to part of moved value: `c` error[E0382]: assign to part of moved value: `c`
--> $DIR/issue-21232-partial-init-and-use.rs:267:13 --> $DIR/issue-21232-partial-init-and-use.rs:255:13
| |
LL | let mut c = (1, (1, "".to_owned())); LL | let mut c = (1, (1, "".to_owned()));
| ----- move occurs because `c` has type `(i32, (i32, String))`, which does not implement the `Copy` trait | ----- move occurs because `c` has type `(i32, (i32, String))`, which does not implement the `Copy` trait
@ -173,7 +221,7 @@ LL | (c.1).0 = 2;
| ^^^^^^^^^^^ value partially assigned here after move | ^^^^^^^^^^^ value partially assigned here after move
error[E0382]: assign to part of moved value: `c.1` error[E0382]: assign to part of moved value: `c.1`
--> $DIR/issue-21232-partial-init-and-use.rs:275:13 --> $DIR/issue-21232-partial-init-and-use.rs:263:13
| |
LL | c2 => { LL | c2 => {
| -- value moved here | -- value moved here

View file

@ -18,7 +18,7 @@ fn guard_may_be_skipped(y: i32) {
match y { match y {
_ if { x = 2; true } => 1, _ if { x = 2; true } => 1,
_ if { _ if {
x; //~ ERROR use of possibly-uninitialized variable: `x` x; //~ ERROR E0381
false false
} => 2, } => 2,
_ => 3, _ => 3,

View file

@ -1,8 +1,13 @@
error[E0381]: use of possibly-uninitialized variable: `x` error[E0381]: binding `x` isn't initialized in all conditions
--> $DIR/match-cfg-fake-edges.rs:21:13 --> $DIR/match-cfg-fake-edges.rs:21:13
| |
LL | let x;
| - variable declared here
...
LL | _ if {
| - `x` is uninitialized if this pattern is matched
LL | x; LL | x;
| ^ use of possibly-uninitialized `x` | ^ `x` used here but it isn't initialized in all conditions
error[E0382]: use of moved value: `x` error[E0382]: use of moved value: `x`
--> $DIR/match-cfg-fake-edges.rs:35:13 --> $DIR/match-cfg-fake-edges.rs:35:13

View file

@ -33,11 +33,13 @@ LL | match t {
LL | x; LL | x;
| - borrow later used here | - borrow later used here
error[E0381]: use of possibly-uninitialized variable: `n` error[E0381]: binding `n` isn't initialized
--> $DIR/match-on-borrowed.rs:93:11 --> $DIR/match-on-borrowed.rs:93:11
| |
LL | let n: Never;
| - variable declared here
LL | match n {} LL | match n {}
| ^ use of possibly-uninitialized `n` | ^ `n` used here but it isn't initialized
error: aborting due to 4 previous errors error: aborting due to 4 previous errors

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