Skip to content

Commit 9cdefd7

Browse files
committed
Auto merge of rust-lang#93691 - compiler-errors:mir-tainted-by-errors, r=oli-obk
Implement `tainted_by_errors` in MIR borrowck, use it to skip CTFE Putting this up for initial review. The issue that I found is when we're evaluating a const, we're doing borrowck, but doing nothing with the fact that borrowck fails. This implements a `tainted_by_errors` field for MIR borrowck like we have in infcx, so we can use that information to return an `Err` during const eval if our const fails to borrowck. This PR needs some cleaning up. I should probably just use `Result` in more places, instead of `.expect`ing in the places I am, but I just wanted it to compile so I could see if it worked! Fixes rust-lang#93646 r? `@oli-obk` feel free to reassign
2 parents fc32303 + 67ad0ff commit 9cdefd7

32 files changed

+255
-213
lines changed

compiler/rustc_borrowck/src/borrowck_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
327327
verb: &str,
328328
optional_adverb_for_moved: &str,
329329
moved_path: Option<String>,
330-
) -> DiagnosticBuilder<'cx> {
330+
) -> DiagnosticBuilder<'tcx> {
331331
let moved_path = moved_path.map(|mp| format!(": `{}`", mp)).unwrap_or_default();
332332

333333
struct_span_err!(

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'tcx> UniverseInfo<'tcx> {
5555
found,
5656
TypeError::RegionsPlaceholderMismatch,
5757
);
58-
err.buffer(&mut mbcx.errors_buffer);
58+
mbcx.buffer_error(err);
5959
}
6060
UniverseInfoInner::TypeOp(ref type_op_info) => {
6161
type_op_info.report_error(mbcx, placeholder, error_element, cause);
@@ -64,11 +64,9 @@ impl<'tcx> UniverseInfo<'tcx> {
6464
// FIXME: This error message isn't great, but it doesn't show
6565
// up in the existing UI tests. Consider investigating this
6666
// some more.
67-
mbcx.infcx
68-
.tcx
69-
.sess
70-
.struct_span_err(cause.span, "higher-ranked subtype error")
71-
.buffer(&mut mbcx.errors_buffer);
67+
mbcx.buffer_error(
68+
mbcx.infcx.tcx.sess.struct_span_err(cause.span, "higher-ranked subtype error"),
69+
);
7270
}
7371
}
7472
}
@@ -149,7 +147,7 @@ trait TypeOpInfo<'tcx> {
149147
{
150148
adjusted
151149
} else {
152-
self.fallback_error(tcx, cause.span).buffer(&mut mbcx.errors_buffer);
150+
mbcx.buffer_error(self.fallback_error(tcx, cause.span));
153151
return;
154152
};
155153

@@ -178,9 +176,9 @@ trait TypeOpInfo<'tcx> {
178176
let nice_error = self.nice_error(tcx, cause, placeholder_region, error_region);
179177

180178
if let Some(nice_error) = nice_error {
181-
nice_error.buffer(&mut mbcx.errors_buffer);
179+
mbcx.buffer_error(nice_error);
182180
} else {
183-
self.fallback_error(tcx, span).buffer(&mut mbcx.errors_buffer);
181+
mbcx.buffer_error(self.fallback_error(tcx, span));
184182
}
185183
}
186184
}

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
104104
format!("{} occurs due to use{}", desired_action.as_noun(), use_spans.describe()),
105105
);
106106

107-
err.buffer(&mut self.errors_buffer);
107+
self.buffer_error(err);
108108
} else {
109-
if let Some((reported_place, _)) = self.move_error_reported.get(&move_out_indices) {
109+
if let Some((reported_place, _)) = self.has_move_error(&move_out_indices) {
110110
if self.prefixes(*reported_place, PrefixSet::All).any(|p| p == used_place) {
111111
debug!(
112112
"report_use_of_moved_or_uninitialized place: error suppressed \
@@ -449,12 +449,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
449449
}
450450
}
451451

452-
if let Some((_, mut old_err)) =
453-
self.move_error_reported.insert(move_out_indices, (used_place, err))
454-
{
455-
// Cancel the old error so it doesn't ICE.
456-
old_err.cancel();
457-
}
452+
self.buffer_move_error(move_out_indices, (used_place, err));
458453
}
459454
}
460455

@@ -503,7 +498,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
503498
Some(borrow_span),
504499
None,
505500
);
506-
err.buffer(&mut self.errors_buffer);
501+
self.buffer_error(err);
507502
}
508503

509504
pub(crate) fn report_use_while_mutably_borrowed(
@@ -1021,7 +1016,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10211016
if self.body.local_decls[borrowed_local].is_ref_to_thread_local() {
10221017
let err =
10231018
self.report_thread_local_value_does_not_live_long_enough(drop_span, borrow_span);
1024-
err.buffer(&mut self.errors_buffer);
1019+
self.buffer_error(err);
10251020
return;
10261021
}
10271022

@@ -1113,7 +1108,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11131108
),
11141109
};
11151110

1116-
err.buffer(&mut self.errors_buffer);
1111+
self.buffer_error(err);
11171112
}
11181113

11191114
fn report_local_value_does_not_live_long_enough(
@@ -1295,7 +1290,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12951290
None,
12961291
);
12971292

1298-
err.buffer(&mut self.errors_buffer);
1293+
self.buffer_error(err);
12991294
}
13001295

13011296
fn report_thread_local_value_does_not_live_long_enough(
@@ -1810,7 +1805,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
18101805
loan.kind.describe_mutability(),
18111806
);
18121807

1813-
err.buffer(&mut self.errors_buffer);
1808+
self.buffer_error(err);
18141809

18151810
return;
18161811
}
@@ -1836,7 +1831,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
18361831

18371832
self.explain_deref_coercion(loan, &mut err);
18381833

1839-
err.buffer(&mut self.errors_buffer);
1834+
self.buffer_error(err);
18401835
}
18411836

18421837
fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut DiagnosticBuilder<'_>) {
@@ -1938,7 +1933,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19381933
}
19391934
}
19401935
err.span_label(span, msg);
1941-
err.buffer(&mut self.errors_buffer);
1936+
self.buffer_error(err);
19421937
}
19431938

19441939
fn classify_drop_access_kind(&self, place: PlaceRef<'tcx>) -> StorageDeadOrDrop<'tcx> {

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
264264
};
265265

266266
self.add_move_hints(error, &mut err, err_span);
267-
err.buffer(&mut self.errors_buffer);
267+
self.buffer_error(err);
268268
}
269269

270270
fn report_cannot_move_from_static(

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
626626
}
627627
}
628628

629-
err.buffer(&mut self.errors_buffer);
629+
self.buffer_error(err);
630630
}
631631

632632
/// User cannot make signature of a trait mutable without changing the

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,6 @@ impl OutlivesSuggestionBuilder {
256256
diag.sort_span = mir_span.shrink_to_hi();
257257

258258
// Buffer the diagnostic
259-
diag.buffer(&mut mbcx.errors_buffer);
259+
mbcx.buffer_error(diag);
260260
}
261261
}

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+14-21
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
168168
let type_test_span = type_test.locations.span(&self.body);
169169

170170
if let Some(lower_bound_region) = lower_bound_region {
171-
self.infcx
172-
.construct_generic_bound_failure(
173-
type_test_span,
174-
None,
175-
type_test.generic_kind,
176-
lower_bound_region,
177-
)
178-
.buffer(&mut self.errors_buffer);
171+
self.buffer_error(self.infcx.construct_generic_bound_failure(
172+
type_test_span,
173+
None,
174+
type_test.generic_kind,
175+
lower_bound_region,
176+
));
179177
} else {
180178
// FIXME. We should handle this case better. It
181179
// indicates that we have e.g., some region variable
@@ -186,27 +184,22 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
186184
// to report it; we could probably handle it by
187185
// iterating over the universal regions and reporting
188186
// an error that multiple bounds are required.
189-
self.infcx
190-
.tcx
191-
.sess
192-
.struct_span_err(
193-
type_test_span,
194-
&format!("`{}` does not live long enough", type_test.generic_kind),
195-
)
196-
.buffer(&mut self.errors_buffer);
187+
self.buffer_error(self.infcx.tcx.sess.struct_span_err(
188+
type_test_span,
189+
&format!("`{}` does not live long enough", type_test.generic_kind),
190+
));
197191
}
198192
}
199193

200194
RegionErrorKind::UnexpectedHiddenRegion { span, hidden_ty, member_region } => {
201195
let named_ty = self.regioncx.name_regions(self.infcx.tcx, hidden_ty);
202196
let named_region = self.regioncx.name_regions(self.infcx.tcx, member_region);
203-
unexpected_hidden_region_diagnostic(
197+
self.buffer_error(unexpected_hidden_region_diagnostic(
204198
self.infcx.tcx,
205199
span,
206200
named_ty,
207201
named_region,
208-
)
209-
.buffer(&mut self.errors_buffer);
202+
));
210203
}
211204

212205
RegionErrorKind::BoundUniversalRegionError {
@@ -285,7 +278,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
285278
if let (Some(f), Some(o)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) {
286279
let nice = NiceRegionError::new_from_span(self.infcx, cause.span, o, f);
287280
if let Some(diag) = nice.try_report_from_nll() {
288-
diag.buffer(&mut self.errors_buffer);
281+
self.buffer_error(diag);
289282
return;
290283
}
291284
}
@@ -375,7 +368,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
375368
}
376369
}
377370

378-
diag.buffer(&mut self.errors_buffer);
371+
self.buffer_error(diag);
379372
}
380373

381374
/// Report a specialized error when `FnMut` closures return a reference to a captured variable.

0 commit comments

Comments
 (0)