Skip to content

Commit 6ab577a

Browse files
Ugly fix
1 parent c98094b commit 6ab577a

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ where
140140
}
141141

142142
#[derive(Clone, Debug, Encodable, Decodable)]
143-
pub(crate) struct DiagLocation {
143+
pub struct DiagLocation {
144144
file: Cow<'static, str>,
145145
line: u32,
146146
col: u32,
147147
}
148148

149149
impl DiagLocation {
150150
#[track_caller]
151-
fn caller() -> Self {
151+
pub fn caller() -> Self {
152152
let loc = panic::Location::caller();
153153
DiagLocation { file: loc.file().into(), line: loc.line(), col: loc.column() }
154154
}
@@ -249,7 +249,7 @@ pub struct DiagInner {
249249
pub long_ty_path: Option<PathBuf>,
250250
/// With `-Ztrack_diagnostics` enabled,
251251
/// we print where in rustc this error was emitted.
252-
pub(crate) emitted_at: DiagLocation,
252+
pub emitted_at: DiagLocation,
253253
}
254254

255255
impl DiagInner {

compiler/rustc_errors/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ pub use anstyle::{
3737
pub use codes::*;
3838
pub use decorate_diag::{BufferedEarlyLint, DecorateDiagCompat, LintBuffer};
3939
pub use diagnostic::{
40-
BugAbort, Diag, DiagInner, DiagStyledString, Diagnostic, EmissionGuarantee, FatalAbort,
41-
StringPart, Subdiag, Subdiagnostic,
40+
BugAbort, Diag, DiagInner, DiagLocation, DiagStyledString, Diagnostic, EmissionGuarantee,
41+
FatalAbort, StringPart, Subdiag, Subdiagnostic,
4242
};
4343
pub use diagnostic_impls::{
4444
DiagSymbolList, ElidedLifetimeInPathSubdiag, ExpectedLifetimeParameter,

compiler/rustc_middle/src/lint.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::cmp;
22

33
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_data_structures::sorted_map::SortedMap;
5-
use rustc_errors::{Diag, Diagnostic, MultiSpan};
5+
use rustc_errors::{Diag, DiagLocation, Diagnostic, MultiSpan};
66
use rustc_hir::{HirId, ItemLocalId};
77
use rustc_lint_defs::EditionFcw;
88
use rustc_macros::{Decodable, Encodable, HashStable};
@@ -502,6 +502,8 @@ pub fn diag_lint_level<'a, D: Diagnostic<'a, ()> + 'a>(
502502
span: Option<MultiSpan>,
503503
decorate: D,
504504
) {
505+
let caller = DiagLocation::caller();
506+
505507
// Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
506508
// the "real" work.
507509
#[track_caller]
@@ -513,6 +515,7 @@ pub fn diag_lint_level<'a, D: Diagnostic<'a, ()> + 'a>(
513515
decorate: Box<
514516
dyn FnOnce(rustc_errors::DiagCtxtHandle<'a>, rustc_errors::Level) -> Diag<'a, ()> + 'a,
515517
>,
518+
caller: DiagLocation,
516519
) {
517520
let LevelAndSource { level, lint_id, src } = level;
518521

@@ -602,6 +605,8 @@ pub fn diag_lint_level<'a, D: Diagnostic<'a, ()> + 'a>(
602605
} else {
603606
Diag::new(sess.dcx(), err_level, "")
604607
};
608+
err.emitted_at = caller;
609+
605610
if let Some(span) = span
606611
&& err.span.primary_span().is_none()
607612
{
@@ -692,5 +697,6 @@ pub fn diag_lint_level<'a, D: Diagnostic<'a, ()> + 'a>(
692697
level,
693698
span,
694699
Box::new(move |dcx, level| decorate.into_diag(dcx, level)),
700+
caller,
695701
);
696702
}

0 commit comments

Comments
 (0)