Skip to content

Commit 5b81528

Browse files
committed
UPDATE - move SessionDiagnostic from rustc_session to rustc_errors
1 parent b79b7d8 commit 5b81528

File tree

16 files changed

+33
-30
lines changed

16 files changed

+33
-30
lines changed

compiler/rustc_attr/src/session_diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::num::IntErrorKind;
22

33
use rustc_ast as ast;
4+
use rustc_errors::SessionDiagnostic;
45
use rustc_errors::{
56
error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler,
67
};
78
use rustc_macros::SessionDiagnostic;
8-
use rustc_session::SessionDiagnostic;
99
use rustc_span::{Span, Symbol};
1010

1111
use crate::UnsupportedLiteralReason;

compiler/rustc_errors/src/diagnostic_builder.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ use std::marker::PhantomData;
1313
use std::ops::{Deref, DerefMut};
1414
use std::thread::panicking;
1515

16+
/// Trait implemented by error types. This should not be implemented manually. Instead, use
17+
/// `#[derive(SessionDiagnostic)]` -- see [rustc_macros::SessionDiagnostic].
18+
#[rustc_diagnostic_item = "SessionDiagnostic"]
19+
pub trait SessionDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> {
20+
/// Write out as a diagnostic out of `Handler`.
21+
#[must_use]
22+
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, T>;
23+
}
24+
1625
/// Used for emitting structured error messages and other diagnostic information.
1726
///
1827
/// If there is some state in a downstream crate you would like to

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ mod snippet;
6060
mod styled_buffer;
6161
pub mod translation;
6262

63+
pub use diagnostic_builder::SessionDiagnostic;
6364
pub use snippet::Style;
6465

6566
pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a, ErrorGuaranteed>>;

compiler/rustc_expand/src/base.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, Item, NodeId, PatKind
1010
use rustc_attr::{self as attr, Deprecation, Stability};
1111
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
1212
use rustc_data_structures::sync::{self, Lrc};
13-
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, PResult};
13+
use rustc_errors::{
14+
Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, PResult, SessionDiagnostic,
15+
};
1416
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
1517
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics};
1618
use rustc_parse::{self, parser, MACRO_ARGUMENTS};
17-
use rustc_session::{parse::ParseSess, Limit, Session, SessionDiagnostic};
19+
use rustc_session::{parse::ParseSess, Limit, Session};
1820
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
1921
use rustc_span::edition::Edition;
2022
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::errors::{
44
};
55
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
66
use crate::infer::InferCtxt;
7+
use rustc_errors::SessionDiagnostic;
78
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, IntoDiagnosticArg};
89
use rustc_hir as hir;
910
use rustc_hir::def::Res;
@@ -18,7 +19,6 @@ use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
1819
use rustc_middle::ty::{self, DefIdTree, InferConst};
1920
use rustc_middle::ty::{GenericArg, GenericArgKind, SubstsRef};
2021
use rustc_middle::ty::{IsSuggestable, Ty, TyCtxt, TypeckResults};
21-
use rustc_session::SessionDiagnostic;
2222
use rustc_span::symbol::{kw, Ident};
2323
use rustc_span::{BytePos, Span};
2424
use std::borrow::Cow;

compiler/rustc_lint/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use rustc_errors::{fluent, AddSubdiagnostic, ErrorGuaranteed, Handler};
1+
use rustc_errors::{fluent, AddSubdiagnostic, ErrorGuaranteed, Handler, SessionDiagnostic};
22
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
3-
use rustc_session::{lint::Level, SessionDiagnostic};
3+
use rustc_session::lint::Level;
44
use rustc_span::{Span, Symbol};
55

66
#[derive(SessionDiagnostic)]

compiler/rustc_macros/src/diagnostics/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'a> SessionDiagnosticDerive<'a> {
8282

8383
structure.gen_impl(quote! {
8484
gen impl<'__session_diagnostic_sess, G>
85-
rustc_session::SessionDiagnostic<'__session_diagnostic_sess, G>
85+
rustc_errors::SessionDiagnostic<'__session_diagnostic_sess, G>
8686
for @Self
8787
where G: rustc_errors::EmissionGuarantee
8888
{

compiler/rustc_metadata/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use std::{
33
path::{Path, PathBuf},
44
};
55

6-
use rustc_errors::{error_code, ErrorGuaranteed};
6+
use rustc_errors::{error_code, ErrorGuaranteed, SessionDiagnostic};
77
use rustc_macros::SessionDiagnostic;
8-
use rustc_session::{config, SessionDiagnostic};
8+
use rustc_session::config;
99
use rustc_span::{sym, Span, Symbol};
1010
use rustc_target::spec::{PanicStrategy, TargetTriple};
1111

compiler/rustc_monomorphize/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::path::PathBuf;
22

33
use rustc_errors::ErrorGuaranteed;
4+
use rustc_errors::SessionDiagnostic;
45
use rustc_macros::{LintDiagnostic, SessionDiagnostic};
5-
use rustc_session::SessionDiagnostic;
66
use rustc_span::Span;
77

88
#[derive(SessionDiagnostic)]

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ use rustc_ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, MacCall, Param, Ty
3636
use rustc_ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits};
3737
use rustc_ast::{ClosureBinder, StmtKind};
3838
use rustc_ast_pretty::pprust;
39+
use rustc_errors::SessionDiagnostic;
3940
use rustc_errors::{Applicability, Diagnostic, PResult};
4041
use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP;
4142
use rustc_session::lint::BuiltinLintDiagnostics;
42-
use rustc_session::SessionDiagnostic;
4343
use rustc_span::source_map::{self, Span, Spanned};
4444
use rustc_span::symbol::{kw, sym, Ident, Symbol};
4545
use rustc_span::{BytePos, Pos};

compiler/rustc_query_system/src/query/job.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ use crate::query::plumbing::CycleError;
33
use crate::query::{QueryContext, QueryStackFrame};
44

55
use rustc_data_structures::fx::FxHashMap;
6-
use rustc_errors::{Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, Level};
6+
use rustc_errors::{
7+
Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, Level, SessionDiagnostic,
8+
};
79
use rustc_hir::def::DefKind;
8-
use rustc_session::{Session, SessionDiagnostic};
10+
use rustc_session::Session;
911
use rustc_span::Span;
1012

1113
use std::hash::Hash;

compiler/rustc_session/src/parse.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ use crate::errors::{FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGat
66
use crate::lint::{
77
builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
88
};
9-
use crate::SessionDiagnostic;
109
use rustc_ast::node_id::NodeId;
1110
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
1211
use rustc_data_structures::sync::{Lock, Lrc};
1312
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
1413
use rustc_errors::{
1514
fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId,
16-
DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, StashKey,
15+
DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, SessionDiagnostic, StashKey,
1716
};
1817
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
1918
use rustc_span::edition::Edition;

compiler/rustc_session/src/session.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_errors::json::JsonEmitter;
2828
use rustc_errors::registry::Registry;
2929
use rustc_errors::{
3030
error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
31-
EmissionGuarantee, ErrorGuaranteed, FluentBundle, Handler, LazyFallbackBundle, MultiSpan,
31+
ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan, SessionDiagnostic,
3232
};
3333
use rustc_macros::HashStable_Generic;
3434
pub use rustc_span::def_id::StableCrateId;
@@ -223,15 +223,6 @@ pub struct PerfStats {
223223
pub normalize_projection_ty: AtomicUsize,
224224
}
225225

226-
/// Trait implemented by error types. This should not be implemented manually. Instead, use
227-
/// `#[derive(SessionDiagnostic)]` -- see [rustc_macros::SessionDiagnostic].
228-
#[rustc_diagnostic_item = "SessionDiagnostic"]
229-
pub trait SessionDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> {
230-
/// Write out as a diagnostic out of `Handler`.
231-
#[must_use]
232-
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, T>;
233-
}
234-
235226
impl Session {
236227
pub fn miri_unleashed_feature(&self, span: Span, feature_gate: Option<Symbol>) {
237228
self.miri_unleashed_features.lock().push((span, feature_gate));

compiler/rustc_trait_selection/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use rustc_errors::{fluent, ErrorGuaranteed, Handler};
1+
use rustc_errors::{fluent, ErrorGuaranteed, Handler, SessionDiagnostic};
22
use rustc_macros::SessionDiagnostic;
33
use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated};
4-
use rustc_session::{Limit, SessionDiagnostic};
4+
use rustc_session::Limit;
55
use rustc_span::{Span, Symbol};
66

77
#[derive(SessionDiagnostic)]

compiler/rustc_typeck/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Errors emitted by typeck.
2+
use rustc_errors::SessionDiagnostic;
23
use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler};
34
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
45
use rustc_middle::ty::Ty;
5-
use rustc_session::SessionDiagnostic;
66
use rustc_span::{symbol::Ident, Span, Symbol};
77

88
#[derive(SessionDiagnostic)]

src/test/ui-fulldeps/internal-lints/diagnostics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ extern crate rustc_session;
1212
extern crate rustc_span;
1313

1414
use rustc_errors::{
15-
AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent
15+
AddSubdiagnostic, SessionDiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent
1616
};
1717
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
18-
use rustc_session::SessionDiagnostic;
1918
use rustc_span::Span;
2019

2120
#[derive(SessionDiagnostic)]

0 commit comments

Comments
 (0)