@@ -338,7 +338,13 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
338
338
// downgrade all the buffered MIR-borrowck errors
339
339
// to warnings.
340
340
for err in & mut mbcx. errors_buffer {
341
- if err. is_error ( ) { err. level = Level :: Warning ; }
341
+ if err. is_error ( ) {
342
+ err. level = Level :: Warning ;
343
+ err. warn ( "This error has been downgraded to a warning \
344
+ for backwards compatibility with previous releases.\n \
345
+ It represents potential unsoundness in your code.\n \
346
+ This warning will become a hard error in the future.") ;
347
+ }
342
348
}
343
349
}
344
350
SignalledError :: SawSomeError => {
@@ -1768,20 +1774,44 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1768
1774
}
1769
1775
}
1770
1776
1771
- Reservation ( WriteKind :: Move )
1772
- | Write ( WriteKind :: Move )
1773
- | Reservation ( WriteKind :: StorageDeadOrDrop )
1774
- | Reservation ( WriteKind :: MutableBorrow ( BorrowKind :: Shared ) )
1775
- | Write ( WriteKind :: StorageDeadOrDrop )
1776
- | Write ( WriteKind :: MutableBorrow ( BorrowKind :: Shared ) ) => {
1777
+ Reservation ( wk @ WriteKind :: Move )
1778
+ | Write ( wk @ WriteKind :: Move )
1779
+ | Reservation ( wk @ WriteKind :: StorageDeadOrDrop )
1780
+ | Reservation ( wk @ WriteKind :: MutableBorrow ( BorrowKind :: Shared ) )
1781
+ | Write ( wk @ WriteKind :: StorageDeadOrDrop )
1782
+ | Write ( wk @ WriteKind :: MutableBorrow ( BorrowKind :: Shared ) ) => {
1777
1783
if let Err ( _place_err) = self . is_mutable ( place, is_local_mutation_allowed) {
1778
- self . tcx . sess . delay_span_bug (
1779
- span,
1780
- & format ! (
1781
- "Accessing `{:?}` with the kind `{:?}` shouldn't be possible" ,
1782
- place, kind
1783
- ) ,
1784
- ) ;
1784
+ if self . tcx . migrate_borrowck ( ) {
1785
+ // rust-lang/rust#46908: In pure NLL mode this
1786
+ // code path should be unreachable (and thus
1787
+ // we signal an ICE in the else branch
1788
+ // here). But we can legitimately get here
1789
+ // under borrowck=migrate mode, so instead of
1790
+ // ICE'ing we instead report a legitimate
1791
+ // error (which will then be downgraded to a
1792
+ // warning by the migrate machinery).
1793
+ error_access = match wk {
1794
+ WriteKind :: MutableBorrow ( _) => AccessKind :: MutableBorrow ,
1795
+ WriteKind :: Move => AccessKind :: Move ,
1796
+ WriteKind :: StorageDeadOrDrop |
1797
+ WriteKind :: Mutate => AccessKind :: Mutate ,
1798
+ } ;
1799
+ self . report_mutability_error (
1800
+ place,
1801
+ span,
1802
+ _place_err,
1803
+ error_access,
1804
+ location,
1805
+ ) ;
1806
+ } else {
1807
+ self . tcx . sess . delay_span_bug (
1808
+ span,
1809
+ & format ! (
1810
+ "Accessing `{:?}` with the kind `{:?}` shouldn't be possible" ,
1811
+ place, kind
1812
+ ) ,
1813
+ ) ;
1814
+ }
1785
1815
}
1786
1816
return false ;
1787
1817
}
0 commit comments