Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #98494

Closed
wants to merge 30 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fd76552
std: use an event flag based thread parker on SOLID
joboet May 18, 2022
3b6ae15
std: fix deadlock in `Parker`
joboet May 19, 2022
b9660de
std: solve priority issue for Parker
joboet Jun 4, 2022
caff723
std: relax memory orderings in `Parker`
joboet Jun 7, 2022
c238582
On partial uninit error point at where we need init
estebank Jun 21, 2022
a944456
Tweak wording and spans
estebank Jun 21, 2022
328522e
Review comments: wording
estebank Jun 22, 2022
0e69340
Add test for `for` loop maybe initializing binding
estebank Jun 22, 2022
6eadf6e
Avoid misleading message/label in `match-cfg-fake-edges.rs` test
estebank Jun 22, 2022
cc4f804
Move help popup into a pocket menu as well
GuillaumeGomez Jun 20, 2022
3eb9e1a
Add/update GUI tests for help pocket menu
GuillaumeGomez Jun 20, 2022
e4b2b41
Merge all popover hide functions into one
GuillaumeGomez Jun 22, 2022
8495c64
Fix label on uninit binding field assignment
estebank Jun 22, 2022
6dd32f2
Wording tweak
estebank Jun 23, 2022
20cea3e
Fix printing impl trait under binders
compiler-errors Jun 22, 2022
e80cced
Use write! instead of p! to avoid having to use weird scoping
compiler-errors Jun 22, 2022
7475867
[rustc_parse] Forbid lets in certain places
c410-f3r Jun 25, 2022
51552e7
add codegen flag export symbols from executable
csmoe Aug 8, 2021
10ebfb7
add export executable symbols make run
csmoe Aug 22, 2021
557793c
Bump RLS to latest master on rust-lang/rls
Mark-Simulacrum Jun 25, 2022
7777dfd
fix: add compile target
csmoe Jun 25, 2022
50a46b9
Fix backtrace UI test when panic=abort is used
antoyo Jun 25, 2022
67053d1
Rollup merge of #85673 - csmoe:export-exe-sym, r=bjorn3
matthiaskrgr Jun 25, 2022
a336ba5
Rollup merge of #97140 - joboet:solid_parker, r=m-ou-se
matthiaskrgr Jun 25, 2022
72da786
Rollup merge of #97295 - c410-f3r:yet-another-let-chain, r=compiler-e…
matthiaskrgr Jun 25, 2022
5c31d40
Rollup merge of #98297 - GuillaumeGomez:help-pocket-menu, r=notriddle
matthiaskrgr Jun 25, 2022
308c8b8
Rollup merge of #98360 - estebank:uninit-binding, r=oli-obk
matthiaskrgr Jun 25, 2022
7097616
Rollup merge of #98371 - compiler-errors:better-opaque-printing, r=ol…
matthiaskrgr Jun 25, 2022
6bdce1d
Rollup merge of #98488 - Mark-Simulacrum:bump-rls, r=pietroalbini
matthiaskrgr Jun 25, 2022
3efe25f
Rollup merge of #98491 - antoyo:fix/ui-test-backtrace-panic-abort, r=…
matthiaskrgr Jun 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tweak wording and spans
estebank committed Jun 21, 2022
commit a944456d3a787524a2dd0e835f86f278fb2c337d
82 changes: 58 additions & 24 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ use rustc_middle::ty::{
self, subst::Subst, suggest_constraining_type_params, EarlyBinder, PredicateKind, Ty,
};
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
use rustc_span::hygiene::DesugaringKind;
use rustc_span::symbol::sym;
use rustc_span::{BytePos, Span};
use rustc_trait_selection::infer::InferCtxtExt;
@@ -331,7 +332,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
spans.push(span);
}

let (item_msg, name, desc) =
let (binding, name, desc) =
match self.describe_place_with_options(used_place, IncludingDowncast(true)) {
Some(name) => (format!("`{name}`"), format!("`{name}`"), format!("`{name}` ")),
None => ("value".to_string(), "the variable".to_string(), String::new()),
@@ -351,20 +352,21 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
} else {
"initialized in all conditions"
};
let mut err = struct_span_err!(self, span, E0381, "binding {desc}isn't {initialized}");
let used = desired_action.as_general_verb_in_past_tense();
let mut err =
struct_span_err!(self, span, E0381, "{used} 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`",
"partial initialization isn't supported, fully initialize the binding with a \
default value and mutate it, 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}",));
err.span_label(span, format!("{binding} {used} 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.
@@ -400,7 +402,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err.span_label(sp, &label);
}
}
err.span_label(decl_span, "variable declared here");
err.span_label(decl_span, "binding declared here but left uninitialized");
err
}

@@ -2559,10 +2561,10 @@ impl<'b, 'v> Visitor<'v> for ConditionVisitor<'b> {
v.visit_expr(body);
if v.1 {
self.errors.push((
cond.span,
ex.span.to(cond.span),
format!(
"this `if` expression might be missing an `else` arm where {} is \
initialized",
"this `if` expression might be missing an `else` arm that initializes \
{}",
self.name,
),
));
@@ -2578,10 +2580,24 @@ impl<'b, 'v> Visitor<'v> for ConditionVisitor<'b> {
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,),
));
if other.span.is_desugaring(DesugaringKind::WhileLoop) {
self.errors.push((
cond.span,
format!(
"{} is uninitialized if this condition isn't met and the \
`while` loop runs 0 times",
self.name
),
));
} else {
self.errors.push((
body.span.shrink_to_hi().until(other.span),
format!(
"{} is uninitialized if this `else` arm is executed",
self.name
),
));
}
}
(false, true) => {
self.errors.push((
@@ -2591,7 +2607,7 @@ impl<'b, 'v> Visitor<'v> for ConditionVisitor<'b> {
}
}
}
hir::ExprKind::Match(_, arms, _) => {
hir::ExprKind::Match(e, arms, loop_desugar) => {
// If the binding is initialized in one of the match arms, then the other match
// arms might be missing an initialization.
let results: Vec<bool> = arms
@@ -2605,22 +2621,40 @@ impl<'b, 'v> Visitor<'v> for ConditionVisitor<'b> {
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
),
));
if loop_desugar == hir::MatchSource::ForLoopDesugar {
self.errors.push((
e.span,
format!(
"{} is uninitialized if the `for` loop runs 0 times",
self.name
),
));
} else if let Some(guard) = &arm.guard {
self.errors.push((
arm.pat.span.to(guard.body().span),
format!(
"{} is uninitialized if this pattern and condition are \
matched",
self.name
),
));
} else {
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.
// *some* context.
_ => {}
}
walk_expr(self, ex);
10 changes: 10 additions & 0 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
@@ -905,6 +905,16 @@ impl InitializationRequiringAction {
InitializationRequiringAction::PartialAssignment => "partially assigned",
}
}

fn as_general_verb_in_past_tense(self) -> &'static str {
match self {
InitializationRequiringAction::Borrow
| InitializationRequiringAction::MatchOn
| InitializationRequiringAction::Use => "used",
InitializationRequiringAction::Assignment => "assigned",
InitializationRequiringAction::PartialAssignment => "partially assigned",
}
}
}

impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
8 changes: 4 additions & 4 deletions src/test/ui/asm/x86_64/type-check-5.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
error[E0381]: binding `x` isn't initialized
error[E0381]: used binding `x` isn't initialized
--> $DIR/type-check-5.rs:15:28
|
LL | let x: u64;
| - variable declared here
| - binding declared here but left uninitialized
LL | asm!("{}", in(reg) x);
| ^ `x` used here but it isn't initialized

error[E0381]: binding `y` isn't initialized
error[E0381]: used binding `y` isn't initialized
--> $DIR/type-check-5.rs:18:9
|
LL | let mut y: u64;
| ----- variable declared here
| ----- binding declared here but left uninitialized
LL | asm!("{}", inout(reg) y);
| ^^^^^^^^^^^^^^^^^^^^^^^^ `y` used here but it isn't initialized

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0381]: binding `y` isn't initialized in all conditions
error[E0381]: used binding `y` isn't initialized in all conditions
--> $DIR/no-non-guaranteed-initialization.rs:9:5
|
LL | let y;
| - variable declared here
| - binding declared here but left uninitialized
LL | if x > 5 {
| ----- this `if` expression might be missing an `else` arm where `y` is initialized
| ----- this `if` expression might be missing an `else` arm that initializes `y`
...
LL | y
| ^ `y` used here but it isn't initialized in all conditions
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
error[E0381]: binding `t` isn't fully initialized
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/partial-initialization-across-await.rs:13:5
|
LL | let mut t: (i32, i32);
| ----- variable declared here
| ----- binding declared here but left uninitialized
LL | t.0 = 42;
| ^^^^^^^^ `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`
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`

error[E0381]: binding `t` isn't fully initialized
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/partial-initialization-across-await.rs:21:5
|
LL | let mut t: T;
| ----- variable declared here
| ----- binding declared here but left uninitialized
LL | t.0 = 42;
| ^^^^^^^^ `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`
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`

error[E0381]: binding `t` isn't fully initialized
error[E0381]: partially assigned binding `t` isn't fully initialized
--> $DIR/partial-initialization-across-await.rs:29:5
|
LL | let mut t: S;
| ----- variable declared here
| ----- binding declared here but left uninitialized
LL | t.x = 42;
| ^^^^^^^^ `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`
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`

error: aborting due to 3 previous errors

12 changes: 6 additions & 6 deletions src/test/ui/borrowck/assign_mutable_fields.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
error[E0381]: binding `x` isn't fully initialized
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/assign_mutable_fields.rs:9:5
|
LL | let mut x: (u32, u32);
| ----- variable declared here
| ----- binding declared here but left uninitialized
LL | x.0 = 1;
| ^^^^^^^ `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`
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`

error[E0381]: binding `x` isn't fully initialized
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/assign_mutable_fields.rs:17:5
|
LL | let mut x: (u32, u32);
| ----- variable declared here
| ----- binding declared here but left uninitialized
LL | x.0 = 1;
| ^^^^^^^ `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`
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`

error: aborting due to 2 previous errors

6 changes: 3 additions & 3 deletions src/test/ui/borrowck/borrowck-and-init.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0381]: binding `i` isn't initialized in all conditions
error[E0381]: used binding `i` isn't initialized in all conditions
--> $DIR/borrowck-and-init.rs:5:20
|
LL | let i: isize;
| - variable declared here
| - binding declared here but left uninitialized
LL |
LL | println!("{}", false && { i = 5; true });
| ----- binding initialized here in some conditions
LL | println!("{}", i);
| ^ `i` borrowed here but it isn't initialized in all conditions
| ^ `i` used 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)

6 changes: 3 additions & 3 deletions src/test/ui/borrowck/borrowck-block-unint.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0381]: binding `x` isn't initialized
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-block-unint.rs:4:11
|
LL | let x: isize;
| - variable declared here
| - binding declared here but left uninitialized
LL | force(|| {
| ^^ `x` borrowed here but it isn't initialized
| ^^ `x` used here but it isn't initialized
LL | println!("{}", x);
| - borrow occurs due to use in closure

6 changes: 3 additions & 3 deletions src/test/ui/borrowck/borrowck-break-uninit-2.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0381]: binding `x` isn't initialized
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-break-uninit-2.rs:9:20
|
LL | let x: isize;
| - variable declared here
| - binding declared here but left uninitialized
...
LL | println!("{}", x);
| ^ `x` borrowed here but it isn't initialized
| ^ `x` used here but it isn't initialized
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

6 changes: 3 additions & 3 deletions src/test/ui/borrowck/borrowck-break-uninit.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0381]: binding `x` isn't initialized
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-break-uninit.rs:9:20
|
LL | let x: isize;
| - variable declared here
| - binding declared here but left uninitialized
...
LL | println!("{}", x);
| ^ `x` borrowed here but it isn't initialized
| ^ `x` used here but it isn't initialized
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

18 changes: 9 additions & 9 deletions src/test/ui/borrowck/borrowck-field-sensitivity.stderr
Original file line number Diff line number Diff line change
@@ -108,35 +108,35 @@ LL | let _z = A { a: 4, .. x };
|
= note: move occurs because `x.b` has type `Box<isize>`, which does not implement the `Copy` trait

error[E0381]: binding `x` isn't fully initialized
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/borrowck-field-sensitivity.rs:81:5
|
LL | let mut x: A;
| ----- variable declared here
| ----- binding declared here but left uninitialized
LL | x.a = 1;
| ^^^^^^^ `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`
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`

error[E0381]: binding `x` isn't fully initialized
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/borrowck-field-sensitivity.rs:87:5
|
LL | let mut x: A;
| ----- variable declared here
| ----- binding declared here but left uninitialized
LL | x.a = 1;
| ^^^^^^^ `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`
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`

error[E0381]: binding `x` isn't fully initialized
error[E0381]: partially assigned binding `x` isn't fully initialized
--> $DIR/borrowck-field-sensitivity.rs:94:5
|
LL | let mut x: A;
| ----- variable declared here
| ----- binding declared here but left uninitialized
LL | x.b = Box::new(1);
| ^^^ `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`
= help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`

error: aborting due to 14 previous errors

6 changes: 3 additions & 3 deletions src/test/ui/borrowck/borrowck-if-no-else.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0381]: binding `x` isn't initialized in all conditions
error[E0381]: used binding `x` isn't initialized in all conditions
--> $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
| - ----- this `if` expression might be missing an `else` arm that initializes `x`
| |
| variable declared here
| binding declared here but left uninitialized
LL | foo(x);
| ^ `x` used here but it isn't initialized in all conditions

Loading