Skip to content

Commit f835b13

Browse files
authored
Rollup merge of #111038 - tmiasko:untainted-promoteds, r=compiler-errors
Leave promoteds untainted by errors when borrowck fails Previously, when borrowck failed it would taint all promoteds within the MIR body. An attempt to evaluated the promoteds would subsequently fail with spurious "note: erroneous constant used". For example: ```console ... note: erroneous constant used --> tests/ui/borrowck/tainted-promoteds.rs:7:9 | 7 | a = &0 * &1 * &2 * &3; | ^^ note: erroneous constant used --> tests/ui/borrowck/tainted-promoteds.rs:7:14 | 7 | a = &0 * &1 * &2 * &3; | ^^ note: erroneous constant used --> tests/ui/borrowck/tainted-promoteds.rs:7:19 | 7 | a = &0 * &1 * &2 * &3; | ^^ note: erroneous constant used --> tests/ui/borrowck/tainted-promoteds.rs:7:24 | 7 | a = &0 * &1 * &2 * &3; | ^^ ``` Borrowck failure doesn't indicate that there is anything wrong with promoteds. Leave them untainted. Fixes #110856.
2 parents 8a9e696 + c678acd commit f835b13

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

compiler/rustc_mir_transform/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,10 @@ fn promoted_mir(tcx: TyCtxt<'_>, def: LocalDefId) -> &IndexVec<Promoted, Body<'_
616616
return tcx.arena.alloc(IndexVec::new());
617617
}
618618

619-
let tainted_by_errors = tcx.mir_borrowck(def).tainted_by_errors;
619+
tcx.ensure_with_value().mir_borrowck(def);
620620
let mut promoted = tcx.mir_promoted(def).1.steal();
621621

622622
for body in &mut promoted {
623-
if let Some(error_reported) = tainted_by_errors {
624-
body.tainted_by_errors = Some(error_reported);
625-
}
626623
run_analysis_to_runtime_passes(tcx, body);
627624
}
628625

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Regression test for issue #110856, where a borrowck error for a MIR tainted
2+
// all promoteds within. This in turn generated a spurious "erroneous constant
3+
// used" note when trying to evaluate a promoted.
4+
5+
pub fn f() -> u32 {
6+
let a = 0;
7+
a = &0 * &1 * &2 * &3;
8+
//~^ ERROR: cannot assign twice to immutable variable
9+
a
10+
}
11+
12+
fn main() {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0384]: cannot assign twice to immutable variable `a`
2+
--> $DIR/tainted-promoteds.rs:7:5
3+
|
4+
LL | let a = 0;
5+
| -
6+
| |
7+
| first assignment to `a`
8+
| help: consider making this binding mutable: `mut a`
9+
LL | a = &0 * &1 * &2 * &3;
10+
| ^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0384`.

0 commit comments

Comments
 (0)