File tree 5 files changed +57
-3
lines changed
compiler/rustc_borrowck/src
5 files changed +57
-3
lines changed Original file line number Diff line number Diff line change @@ -256,6 +256,6 @@ impl OutlivesSuggestionBuilder {
256
256
diag. sort_span = mir_span. shrink_to_hi ( ) ;
257
257
258
258
// Buffer the diagnostic
259
- mbcx. buffer_error ( diag) ;
259
+ mbcx. buffer_non_error_diag ( diag) ;
260
260
}
261
261
}
Original file line number Diff line number Diff line change @@ -398,7 +398,7 @@ fn do_mir_borrowck<'a, 'tcx>(
398
398
diag. message = initial_diag. styled_message ( ) . clone ( ) ;
399
399
diag. span = initial_diag. span . clone ( ) ;
400
400
401
- mbcx. buffer_error ( diag) ;
401
+ mbcx. buffer_non_error_diag ( diag) ;
402
402
} ,
403
403
) ;
404
404
initial_diag. cancel ( ) ;
@@ -2317,6 +2317,11 @@ mod error {
2317
2317
t. buffer ( & mut self . buffered ) ;
2318
2318
}
2319
2319
2320
+ // For diagnostics we must not set `tainted_by_errors`.
2321
+ pub fn buffer_non_error_diag ( & mut self , t : DiagnosticBuilder < ' _ > ) {
2322
+ t. buffer ( & mut self . buffered ) ;
2323
+ }
2324
+
2320
2325
pub fn set_tainted_by_errors ( & mut self ) {
2321
2326
self . tainted_by_errors = Some ( ErrorReported { } ) ;
2322
2327
}
@@ -2327,6 +2332,10 @@ mod error {
2327
2332
self . errors . buffer_error ( t) ;
2328
2333
}
2329
2334
2335
+ pub fn buffer_non_error_diag ( & mut self , t : DiagnosticBuilder < ' _ > ) {
2336
+ self . errors . buffer_non_error_diag ( t) ;
2337
+ }
2338
+
2330
2339
pub fn buffer_move_error (
2331
2340
& mut self ,
2332
2341
move_out_indices : Vec < MoveOutIndex > ,
Original file line number Diff line number Diff line change @@ -417,7 +417,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
417
417
err. note ( & format ! ( "Inferred opaque type values:\n {:#?}" , opaque_type_values) ) ;
418
418
}
419
419
420
- errors. buffer_error ( err) ;
420
+ errors. buffer_non_error_diag ( err) ;
421
421
}
422
422
423
423
fn for_each_region_constraint (
Original file line number Diff line number Diff line change
1
+ // check-pass
2
+
3
+ // mir borrowck previously incorrectly set `tainted_by_errors`
4
+ // when buffering lints, which resulted in ICE later on,
5
+ // see #94502.
6
+
7
+ // Errors with `nll` which is already tested in enough other tests,
8
+ // so we ignore it here.
9
+ //
10
+ // ignore-compare-mode-nll
11
+
12
+ struct Repro ;
13
+ impl Repro {
14
+ fn get ( & self ) -> & i32 {
15
+ & 3
16
+ }
17
+
18
+ fn insert ( & mut self , _: i32 ) { }
19
+ }
20
+
21
+ fn main ( ) {
22
+ let x = & 0 ;
23
+ let mut conflict = Repro ;
24
+ let prev = conflict. get ( ) ;
25
+ conflict. insert ( * prev + * x) ;
26
+ //~^ WARN cannot borrow `conflict` as mutable because it is also borrowed as immutable
27
+ //~| WARN this borrowing pattern was not meant to be accepted
28
+ }
Original file line number Diff line number Diff line change
1
+ warning: cannot borrow `conflict` as mutable because it is also borrowed as immutable
2
+ --> $DIR/lint-no-err.rs:25:5
3
+ |
4
+ LL | let prev = conflict.get();
5
+ | -------------- immutable borrow occurs here
6
+ LL | conflict.insert(*prev + *x);
7
+ | ^^^^^^^^^^^^^^^^-----^^^^^^
8
+ | | |
9
+ | | immutable borrow later used here
10
+ | mutable borrow occurs here
11
+ |
12
+ = note: `#[warn(mutable_borrow_reservation_conflict)]` on by default
13
+ = warning: this borrowing pattern was not meant to be accepted, and may become a hard error in the future
14
+ = note: for more information, see issue #59159 <https://github.com/rust-lang/rust/issues/59159>
15
+
16
+ warning: 1 warning emitted
17
+
You can’t perform that action at this time.
0 commit comments