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

Leave promoteds untainted by errors when borrowck fails #111038

Merged
merged 1 commit into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 1 addition & 4 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,10 @@ fn promoted_mir(tcx: TyCtxt<'_>, def: LocalDefId) -> &IndexVec<Promoted, Body<'_
return tcx.arena.alloc(IndexVec::new());
}

let tainted_by_errors = tcx.mir_borrowck(def).tainted_by_errors;
tcx.ensure_with_value().mir_borrowck(def);
let mut promoted = tcx.mir_promoted(def).1.steal();

for body in &mut promoted {
if let Some(error_reported) = tainted_by_errors {
body.tainted_by_errors = Some(error_reported);
}
run_analysis_to_runtime_passes(tcx, body);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/ui/borrowck/tainted-promoteds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Regression test for issue #110856, where a borrowck error for a MIR tainted
// all promoteds within. This in turn generated a spurious "erroneous constant
// used" note when trying to evaluate a promoted.

pub fn f() -> u32 {
let a = 0;
a = &0 * &1 * &2 * &3;
//~^ ERROR: cannot assign twice to immutable variable
a
}

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/borrowck/tainted-promoteds.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0384]: cannot assign twice to immutable variable `a`
--> $DIR/tainted-promoteds.rs:7:5
|
LL | let a = 0;
| -
| |
| first assignment to `a`
| help: consider making this binding mutable: `mut a`
LL | a = &0 * &1 * &2 * &3;
| ^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0384`.