Skip to content

Commit 7ed0247

Browse files
Remove emit_err function from Stage
1 parent 7e0430f commit 7ed0247

3 files changed

Lines changed: 20 additions & 43 deletions

File tree

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_hir::attrs::AttributeKind;
1414
use rustc_hir::lints::AttributeLintKind;
1515
use rustc_hir::{AttrPath, HirId};
1616
use rustc_parse::parser::Recovery;
17-
use rustc_session::Session;
1817
use rustc_session::lint::{Lint, LintId};
1918
use rustc_span::{ErrorGuaranteed, Span, Symbol};
2019

@@ -357,12 +356,6 @@ pub trait Stage: Sized + 'static + Sealed {
357356

358357
fn parsers() -> &'static GroupType<Self>;
359358

360-
fn emit_err<'sess>(
361-
&self,
362-
sess: &'sess Session,
363-
diag: impl for<'x> Diagnostic<'x>,
364-
) -> ErrorGuaranteed;
365-
366359
fn should_emit(&self) -> ShouldEmit;
367360
}
368361

@@ -374,13 +367,6 @@ impl Stage for Early {
374367
fn parsers() -> &'static GroupType<Self> {
375368
&early::ATTRIBUTE_PARSERS
376369
}
377-
fn emit_err<'sess>(
378-
&self,
379-
sess: &'sess Session,
380-
diag: impl for<'x> Diagnostic<'x>,
381-
) -> ErrorGuaranteed {
382-
self.should_emit().emit_err(sess.dcx().create_err(diag))
383-
}
384370

385371
fn should_emit(&self) -> ShouldEmit {
386372
self.emit_errors
@@ -395,13 +381,6 @@ impl Stage for Late {
395381
fn parsers() -> &'static GroupType<Self> {
396382
&late::ATTRIBUTE_PARSERS
397383
}
398-
fn emit_err<'sess>(
399-
&self,
400-
tcx: &'sess Session,
401-
diag: impl for<'x> Diagnostic<'x>,
402-
) -> ErrorGuaranteed {
403-
tcx.dcx().emit_err(diag)
404-
}
405384

406385
fn should_emit(&self) -> ShouldEmit {
407386
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed }
@@ -458,7 +437,7 @@ pub struct AcceptContext<'f, 'sess, S: Stage> {
458437

459438
impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
460439
pub(crate) fn emit_err(&self, diag: impl for<'x> Diagnostic<'x>) -> ErrorGuaranteed {
461-
self.stage.emit_err(&self.sess, diag)
440+
self.cx.emit_err(diag)
462441
}
463442

464443
/// Emit a lint. This method is somewhat special, since lints emitted during attribute parsing

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use rustc_ast as ast;
44
use rustc_ast::token::DocFragmentKind;
55
use rustc_ast::{AttrItemKind, AttrStyle, CRATE_NODE_ID, NodeId, Safety};
66
use rustc_data_structures::sync::{DynSend, DynSync};
7-
use rustc_errors::{Diag, DiagCtxtHandle, Level, MultiSpan};
7+
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level, MultiSpan};
88
use rustc_feature::{AttributeTemplate, Features};
99
use rustc_hir::attrs::AttributeKind;
1010
use rustc_hir::lints::AttributeLintKind;
1111
use rustc_hir::{AttrArgs, AttrItem, AttrPath, Attribute, HashIgnoredAttrId, Target};
1212
use rustc_session::Session;
1313
use rustc_session::lint::LintId;
14-
use rustc_span::{DUMMY_SP, Span, Symbol, sym};
14+
use rustc_span::{DUMMY_SP, Span, Symbol, sym, ErrorGuaranteed};
1515

1616
use crate::attributes::AttributeSafety;
1717
use crate::context::{AcceptContext, FinalizeContext, FinalizeFn, SharedContext, Stage};
@@ -275,6 +275,10 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
275275
self.sess().dcx()
276276
}
277277

278+
pub(crate) fn emit_err(&self, diag: impl for<'x> Diagnostic<'x>) -> ErrorGuaranteed {
279+
self.stage.should_emit().emit_err(self.sess.dcx().create_err(diag))
280+
}
281+
278282
/// Parse a list of attributes.
279283
///
280284
/// `target_span` is the span of the thing this list of attributes is applied to,

compiler/rustc_attr_parsing/src/safety.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,15 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
6363
}
6464

6565
if emit_error {
66-
self.stage.emit_err(
67-
self.sess,
68-
crate::session_diagnostics::UnsafeAttrOutsideUnsafe {
69-
span: path_span,
70-
suggestion: not_from_proc_macro.then(|| {
71-
crate::session_diagnostics::UnsafeAttrOutsideUnsafeSuggestion {
72-
left: diag_span.shrink_to_lo(),
73-
right: diag_span.shrink_to_hi(),
74-
}
75-
}),
76-
},
77-
);
66+
self.emit_err(crate::session_diagnostics::UnsafeAttrOutsideUnsafe {
67+
span: path_span,
68+
suggestion: not_from_proc_macro.then(|| {
69+
crate::session_diagnostics::UnsafeAttrOutsideUnsafeSuggestion {
70+
left: diag_span.shrink_to_lo(),
71+
right: diag_span.shrink_to_hi(),
72+
}
73+
}),
74+
});
7875
} else {
7976
emit_lint(
8077
LintId::of(UNSAFE_ATTR_OUTSIDE_UNSAFE),
@@ -97,13 +94,10 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
9794
// - Normal builtin attribute
9895
// - Writing `#[unsafe(..)]` is not permitted on normal builtin attributes
9996
(AttributeSafety::Normal, Safety::Unsafe(unsafe_span)) => {
100-
self.stage.emit_err(
101-
self.sess,
102-
crate::session_diagnostics::InvalidAttrUnsafe {
103-
span: unsafe_span,
104-
name: attr_path.clone(),
105-
},
106-
);
97+
self.emit_err(crate::session_diagnostics::InvalidAttrUnsafe {
98+
span: unsafe_span,
99+
name: attr_path.clone(),
100+
});
107101
}
108102

109103
// - Normal builtin attribute

0 commit comments

Comments
 (0)