@@ -69,7 +69,7 @@ use rustc_macros::{Decodable, Encodable};
69
69
pub use rustc_span:: fatal_error:: { FatalError , FatalErrorMarker } ;
70
70
use rustc_span:: source_map:: SourceMap ;
71
71
pub use rustc_span:: ErrorGuaranteed ;
72
- use rustc_span:: { AttrId , Loc , Span , DUMMY_SP } ;
72
+ use rustc_span:: { Loc , Span , DUMMY_SP } ;
73
73
pub use snippet:: Style ;
74
74
// Used by external projects such as `rust-gpu`.
75
75
// See https://github.com/rust-lang/rust/pull/115393.
@@ -497,28 +497,18 @@ struct DiagCtxtInner {
497
497
498
498
future_breakage_diagnostics : Vec < DiagInner > ,
499
499
500
- /// The [`Self::unstable_expect_diagnostics`] should be empty when this struct is
501
- /// dropped. However, it can have values if the compilation is stopped early
502
- /// or is only partially executed. To avoid ICEs, like in rust#94953 we only
503
- /// check if [`Self::unstable_expect_diagnostics`] is empty, if the expectation ids
504
- /// have been converted.
505
- check_unstable_expect_diagnostics : bool ,
506
-
507
- /// Expected [`DiagInner`][struct@diagnostic::DiagInner]s store a [`LintExpectationId`] as part
508
- /// of the lint level. [`LintExpectationId`]s created early during the compilation
509
- /// (before `HirId`s have been defined) are not stable and can therefore not be
510
- /// stored on disk. This buffer stores these diagnostics until the ID has been
511
- /// replaced by a stable [`LintExpectationId`]. The [`DiagInner`][struct@diagnostic::DiagInner]s
512
- /// are submitted for storage and added to the list of fulfilled expectations.
513
- unstable_expect_diagnostics : Vec < DiagInner > ,
514
-
515
500
/// expected diagnostic will have the level `Expect` which additionally
516
501
/// carries the [`LintExpectationId`] of the expectation that can be
517
502
/// marked as fulfilled. This is a collection of all [`LintExpectationId`]s
518
503
/// that have been marked as fulfilled this way.
519
504
///
505
+ /// Emitting expectations after having stolen this field can happen. In particular, an
506
+ /// `#[expect(warnings)]` can easily make the `UNFULFILLED_LINT_EXPECTATIONS` lint expect
507
+ /// itself. To avoid needless complexity in this corner case, we tolerate failing to track
508
+ /// those expectations.
509
+ ///
520
510
/// [RFC-2383]: https://rust-lang.github.io/rfcs/2383-lint-reasons.html
521
- fulfilled_expectations : FxHashSet < LintExpectationId > ,
511
+ fulfilled_expectations : FxIndexSet < LintExpectationId > ,
522
512
523
513
/// The file where the ICE information is stored. This allows delayed_span_bug backtraces to be
524
514
/// stored along side the main panic backtrace.
@@ -605,13 +595,6 @@ impl Drop for DiagCtxtInner {
605
595
) ;
606
596
}
607
597
}
608
-
609
- if self . check_unstable_expect_diagnostics {
610
- assert ! (
611
- self . unstable_expect_diagnostics. is_empty( ) ,
612
- "all diagnostics with unstable expectations should have been converted" ,
613
- ) ;
614
- }
615
598
}
616
599
}
617
600
@@ -740,8 +723,6 @@ impl DiagCtxt {
740
723
emitted_diagnostics,
741
724
stashed_diagnostics,
742
725
future_breakage_diagnostics,
743
- check_unstable_expect_diagnostics,
744
- unstable_expect_diagnostics,
745
726
fulfilled_expectations,
746
727
ice_file : _,
747
728
} = inner. deref_mut ( ) ;
@@ -761,8 +742,6 @@ impl DiagCtxt {
761
742
* emitted_diagnostics = Default :: default ( ) ;
762
743
* stashed_diagnostics = Default :: default ( ) ;
763
744
* future_breakage_diagnostics = Default :: default ( ) ;
764
- * check_unstable_expect_diagnostics = false ;
765
- * unstable_expect_diagnostics = Default :: default ( ) ;
766
745
* fulfilled_expectations = Default :: default ( ) ;
767
746
}
768
747
@@ -1094,44 +1073,10 @@ impl<'a> DiagCtxtHandle<'a> {
1094
1073
inner. emitter . emit_unused_externs ( lint_level, unused_externs)
1095
1074
}
1096
1075
1097
- pub fn update_unstable_expectation_id (
1098
- & self ,
1099
- unstable_to_stable : FxIndexMap < AttrId , LintExpectationId > ,
1100
- ) {
1101
- let mut inner = self . inner . borrow_mut ( ) ;
1102
- let diags = std:: mem:: take ( & mut inner. unstable_expect_diagnostics ) ;
1103
- inner. check_unstable_expect_diagnostics = true ;
1104
-
1105
- if !diags. is_empty ( ) {
1106
- inner. suppressed_expected_diag = true ;
1107
- for mut diag in diags. into_iter ( ) {
1108
- diag. update_unstable_expectation_id ( & unstable_to_stable) ;
1109
-
1110
- // Here the diagnostic is given back to `emit_diagnostic` where it was first
1111
- // intercepted. Now it should be processed as usual, since the unstable expectation
1112
- // id is now stable.
1113
- inner. emit_diagnostic ( diag, self . tainted_with_errors ) ;
1114
- }
1115
- }
1116
-
1117
- inner
1118
- . stashed_diagnostics
1119
- . values_mut ( )
1120
- . for_each ( |( diag, _guar) | diag. update_unstable_expectation_id ( & unstable_to_stable) ) ;
1121
- inner
1122
- . future_breakage_diagnostics
1123
- . iter_mut ( )
1124
- . for_each ( |diag| diag. update_unstable_expectation_id ( & unstable_to_stable) ) ;
1125
- }
1126
-
1127
1076
/// This methods steals all [`LintExpectationId`]s that are stored inside
1128
1077
/// [`DiagCtxtInner`] and indicate that the linked expectation has been fulfilled.
1129
1078
#[ must_use]
1130
- pub fn steal_fulfilled_expectation_ids ( & self ) -> FxHashSet < LintExpectationId > {
1131
- assert ! (
1132
- self . inner. borrow( ) . unstable_expect_diagnostics. is_empty( ) ,
1133
- "`DiagCtxtInner::unstable_expect_diagnostics` should be empty at this point" ,
1134
- ) ;
1079
+ pub fn steal_fulfilled_expectation_ids ( & self ) -> FxIndexSet < LintExpectationId > {
1135
1080
std:: mem:: take ( & mut self . inner . borrow_mut ( ) . fulfilled_expectations )
1136
1081
}
1137
1082
@@ -1440,8 +1385,6 @@ impl DiagCtxtInner {
1440
1385
emitted_diagnostics : Default :: default ( ) ,
1441
1386
stashed_diagnostics : Default :: default ( ) ,
1442
1387
future_breakage_diagnostics : Vec :: new ( ) ,
1443
- check_unstable_expect_diagnostics : false ,
1444
- unstable_expect_diagnostics : Vec :: new ( ) ,
1445
1388
fulfilled_expectations : Default :: default ( ) ,
1446
1389
ice_file : None ,
1447
1390
}
@@ -1471,24 +1414,6 @@ impl DiagCtxtInner {
1471
1414
mut diagnostic : DiagInner ,
1472
1415
taint : Option < & Cell < Option < ErrorGuaranteed > > > ,
1473
1416
) -> Option < ErrorGuaranteed > {
1474
- match diagnostic. level {
1475
- Expect ( expect_id) | ForceWarning ( Some ( expect_id) ) => {
1476
- // The `LintExpectationId` can be stable or unstable depending on when it was
1477
- // created. Diagnostics created before the definition of `HirId`s are unstable and
1478
- // can not yet be stored. Instead, they are buffered until the `LintExpectationId`
1479
- // is replaced by a stable one by the `LintLevelsBuilder`.
1480
- if let LintExpectationId :: Unstable { .. } = expect_id {
1481
- // We don't call TRACK_DIAGNOSTIC because we wait for the
1482
- // unstable ID to be updated, whereupon the diagnostic will be
1483
- // passed into this method again.
1484
- self . unstable_expect_diagnostics . push ( diagnostic) ;
1485
- return None ;
1486
- }
1487
- // Continue through to the `Expect`/`ForceWarning` case below.
1488
- }
1489
- _ => { }
1490
- }
1491
-
1492
1417
if diagnostic. has_future_breakage ( ) {
1493
1418
// Future breakages aren't emitted if they're `Level::Allow` or
1494
1419
// `Level::Expect`, but they still need to be constructed and
@@ -1564,9 +1489,6 @@ impl DiagCtxtInner {
1564
1489
return None ;
1565
1490
}
1566
1491
Expect ( expect_id) | ForceWarning ( Some ( expect_id) ) => {
1567
- if let LintExpectationId :: Unstable { .. } = expect_id {
1568
- unreachable ! ( ) ; // this case was handled at the top of this function
1569
- }
1570
1492
self . fulfilled_expectations . insert ( expect_id) ;
1571
1493
if let Expect ( _) = diagnostic. level {
1572
1494
// Nothing emitted here for expected lints.
0 commit comments