Skip to content

Commit 9be0441

Browse files
committed
borrowck_errors.rs init
1 parent 945b476 commit 9be0441

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

compiler/rustc_borrowck/src/borrowck_errors.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
3+
14
use rustc_errors::{
25
struct_span_err, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, ErrorGuaranteed, MultiSpan,
36
};
47
use rustc_middle::ty::{self, Ty, TyCtxt};
58
use rustc_span::Span;
69

10+
use crate::session_diagnostics::{TemporaryDroppedErr, ThreadLocalOutliveErr};
11+
712
impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
813
pub(crate) fn cannot_move_when_borrowed(
914
&self,
@@ -450,14 +455,14 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
450455
&self,
451456
span: Span,
452457
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
453-
struct_span_err!(self, span, E0712, "thread-local variable borrowed past end of function",)
458+
self.infcx.tcx.sess.create_err(ThreadLocalOutliveErr { span })
454459
}
455460

456461
pub(crate) fn temporary_value_borrowed_for_too_long(
457462
&self,
458463
span: Span,
459464
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
460-
struct_span_err!(self, span, E0716, "temporary value dropped while borrowed",)
465+
self.infcx.tcx.sess.create_err(TemporaryDroppedErr { span })
461466
}
462467

463468
#[rustc_lint_diagnostics]

compiler/rustc_borrowck/src/session_diagnostics.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,3 +589,17 @@ pub(crate) enum DefiningTypeNote<'a> {
589589
#[note(borrowck::define_inline_constant_type)]
590590
InlineConst { type_name: &'a str },
591591
}
592+
593+
#[derive(SessionDiagnostic)]
594+
#[diag(borrowck::borrowed_temporary_value_dropped, code = "E0716")]
595+
pub(crate) struct TemporaryDroppedErr {
596+
#[primary_span]
597+
pub span: Span,
598+
}
599+
600+
#[derive(SessionDiagnostic)]
601+
#[diag(borrowck::thread_local_outlive_function, code = "E0712")]
602+
pub(crate) struct ThreadLocalOutliveErr {
603+
#[primary_span]
604+
pub span: Span,
605+
}

compiler/rustc_error_messages/locales/en-US/borrowck.ftl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,9 @@ borrowck_define_type_with_generator_substs =
248248
249249
borrowck_define_type_with_closure_substs =
250250
defining type: {$type_name} with closure substs {$subsets}
251+
252+
borrowck_borrowed_temporary_value_dropped =
253+
temporary value dropped while borrowed
254+
255+
borrowck_thread_local_outlive_function =
256+
thread-local variable borrowed past end of function

0 commit comments

Comments
 (0)