lint: LintDiagnosticBuilder
into rustc_errors
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
84ec77769f
commit
2874f09534
10 changed files with 39 additions and 42 deletions
|
@ -589,3 +589,26 @@ macro_rules! struct_span_err {
|
||||||
macro_rules! error_code {
|
macro_rules! error_code {
|
||||||
($code:ident) => {{ $crate::DiagnosticId::Error(stringify!($code).to_owned()) }};
|
($code:ident) => {{ $crate::DiagnosticId::Error(stringify!($code).to_owned()) }};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Wrapper around a `DiagnosticBuilder` for creating lints.
|
||||||
|
pub struct LintDiagnosticBuilder<'a, G: EmissionGuarantee>(DiagnosticBuilder<'a, G>);
|
||||||
|
|
||||||
|
impl<'a, G: EmissionGuarantee> LintDiagnosticBuilder<'a, G> {
|
||||||
|
/// Return the inner `DiagnosticBuilder`, first setting the primary message to `msg`.
|
||||||
|
pub fn build(mut self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'a, G> {
|
||||||
|
self.0.set_primary_message(msg);
|
||||||
|
self.0.set_is_lint();
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a `LintDiagnosticBuilder` from some existing `DiagnosticBuilder`.
|
||||||
|
pub fn new(err: DiagnosticBuilder<'a, G>) -> LintDiagnosticBuilder<'a, G> {
|
||||||
|
LintDiagnosticBuilder(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> LintDiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||||
|
pub fn forget_guarantee(self) -> LintDiagnosticBuilder<'a, ()> {
|
||||||
|
LintDiagnosticBuilder(self.0.forget_guarantee())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -373,7 +373,7 @@ pub use diagnostic::{
|
||||||
AddSubdiagnostic, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
|
AddSubdiagnostic, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
|
||||||
DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
|
DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
|
||||||
};
|
};
|
||||||
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee};
|
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder};
|
||||||
use std::backtrace::Backtrace;
|
use std::backtrace::Backtrace;
|
||||||
|
|
||||||
/// A handler deals with errors and other compiler output.
|
/// A handler deals with errors and other compiler output.
|
||||||
|
|
|
@ -32,7 +32,8 @@ use rustc_ast_pretty::pprust::{self, expr_to_string};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
fluent, Applicability, Diagnostic, DiagnosticMessage, DiagnosticStyledString, MultiSpan,
|
fluent, Applicability, Diagnostic, DiagnosticMessage, DiagnosticStyledString,
|
||||||
|
LintDiagnosticBuilder, MultiSpan,
|
||||||
};
|
};
|
||||||
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
|
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
@ -40,7 +41,7 @@ use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
|
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
|
||||||
use rustc_hir::{ForeignItemKind, GenericParamKind, HirId, PatKind, PredicateOrigin};
|
use rustc_hir::{ForeignItemKind, GenericParamKind, HirId, PatKind, PredicateOrigin};
|
||||||
use rustc_index::vec::Idx;
|
use rustc_index::vec::Idx;
|
||||||
use rustc_middle::lint::{in_external_macro, LintDiagnosticBuilder};
|
use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_middle::ty::layout::{LayoutError, LayoutOf};
|
use rustc_middle::ty::layout::{LayoutError, LayoutOf};
|
||||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||||
use rustc_middle::ty::subst::GenericArgKind;
|
use rustc_middle::ty::subst::GenericArgKind;
|
||||||
|
|
|
@ -22,12 +22,11 @@ use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::sync;
|
use rustc_data_structures::sync;
|
||||||
use rustc_errors::{add_elided_lifetime_in_path_suggestion, struct_span_err};
|
use rustc_errors::{add_elided_lifetime_in_path_suggestion, struct_span_err};
|
||||||
use rustc_errors::{Applicability, MultiSpan, SuggestionStyle};
|
use rustc_errors::{Applicability, LintDiagnosticBuilder, MultiSpan, SuggestionStyle};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::Res;
|
use rustc_hir::def::Res;
|
||||||
use rustc_hir::def_id::{CrateNum, DefId};
|
use rustc_hir::def_id::{CrateNum, DefId};
|
||||||
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
|
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
|
||||||
use rustc_middle::lint::LintDiagnosticBuilder;
|
|
||||||
use rustc_middle::middle::privacy::AccessLevels;
|
use rustc_middle::middle::privacy::AccessLevels;
|
||||||
use rustc_middle::middle::stability;
|
use rustc_middle::middle::stability;
|
||||||
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
|
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
|
||||||
|
|
|
@ -3,13 +3,13 @@ use crate::late::unerased_lint_store;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::{struct_span_err, Applicability, Diagnostic, MultiSpan};
|
use rustc_errors::{struct_span_err, Applicability, Diagnostic, LintDiagnosticBuilder, MultiSpan};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::{intravisit, HirId};
|
use rustc_hir::{intravisit, HirId};
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
use rustc_middle::lint::{
|
use rustc_middle::lint::{
|
||||||
struct_lint_level, LevelAndSource, LintDiagnosticBuilder, LintExpectation, LintLevelMap,
|
struct_lint_level, LevelAndSource, LintExpectation, LintLevelMap, LintLevelSets,
|
||||||
LintLevelSets, LintLevelSource, LintSet, LintStackIndex, COMMAND_LINE,
|
LintLevelSource, LintSet, LintStackIndex, COMMAND_LINE,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::query::Providers;
|
use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::{RegisteredTools, TyCtxt};
|
use rustc_middle::ty::{RegisteredTools, TyCtxt};
|
||||||
|
|
|
@ -2,10 +2,7 @@ use std::cmp;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_errors::{
|
use rustc_errors::{Diagnostic, DiagnosticId, LintDiagnosticBuilder, MultiSpan};
|
||||||
Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, EmissionGuarantee,
|
|
||||||
ErrorGuaranteed, MultiSpan,
|
|
||||||
};
|
|
||||||
use rustc_hir::HirId;
|
use rustc_hir::HirId;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_query_system::ich::StableHashingContext;
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
|
@ -228,28 +225,6 @@ impl LintExpectation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LintDiagnosticBuilder<'a, G: EmissionGuarantee>(DiagnosticBuilder<'a, G>);
|
|
||||||
|
|
||||||
impl<'a, G: EmissionGuarantee> LintDiagnosticBuilder<'a, G> {
|
|
||||||
/// Return the inner `DiagnosticBuilder`, first setting the primary message to `msg`.
|
|
||||||
pub fn build(mut self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'a, G> {
|
|
||||||
self.0.set_primary_message(msg);
|
|
||||||
self.0.set_is_lint();
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a `LintDiagnosticBuilder` from some existing `DiagnosticBuilder`.
|
|
||||||
pub fn new(err: DiagnosticBuilder<'a, G>) -> LintDiagnosticBuilder<'a, G> {
|
|
||||||
LintDiagnosticBuilder(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> LintDiagnosticBuilder<'a, ErrorGuaranteed> {
|
|
||||||
pub fn forget_guarantee(self) -> LintDiagnosticBuilder<'a, ()> {
|
|
||||||
LintDiagnosticBuilder(self.0.forget_guarantee())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn explain_lint_level_source(
|
pub fn explain_lint_level_source(
|
||||||
lint: &'static Lint,
|
lint: &'static Lint,
|
||||||
level: Level,
|
level: Level,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::arena::Arena;
|
||||||
use crate::dep_graph::{DepGraph, DepKind, DepKindStruct};
|
use crate::dep_graph::{DepGraph, DepKind, DepKindStruct};
|
||||||
use crate::hir::place::Place as HirPlace;
|
use crate::hir::place::Place as HirPlace;
|
||||||
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
|
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
|
||||||
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
|
use crate::lint::{struct_lint_level, LintLevelSource};
|
||||||
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
|
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
|
||||||
use crate::middle::resolve_lifetime;
|
use crate::middle::resolve_lifetime;
|
||||||
use crate::middle::stability;
|
use crate::middle::stability;
|
||||||
|
@ -34,7 +34,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_data_structures::steal::Steal;
|
use rustc_data_structures::steal::Steal;
|
||||||
use rustc_data_structures::sync::{self, Lock, Lrc, WorkerLocal};
|
use rustc_data_structures::sync::{self, Lock, Lrc, WorkerLocal};
|
||||||
use rustc_data_structures::vec_map::VecMap;
|
use rustc_data_structures::vec_map::VecMap;
|
||||||
use rustc_errors::{ErrorGuaranteed, MultiSpan};
|
use rustc_errors::{ErrorGuaranteed, LintDiagnosticBuilder, MultiSpan};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::{DiagnosticBuilder, LintDiagnosticBuilder};
|
||||||
use rustc_middle::lint::LintDiagnosticBuilder;
|
|
||||||
use rustc_middle::mir::visit::Visitor;
|
use rustc_middle::mir::visit::Visitor;
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
|
|
@ -16,9 +16,8 @@ use crate::infer::{InferCtxt, InferOk, TyCtxtInferExt};
|
||||||
use crate::traits::select::IntercrateAmbiguityCause;
|
use crate::traits::select::IntercrateAmbiguityCause;
|
||||||
use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine};
|
use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine};
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::{struct_span_err, EmissionGuarantee};
|
use rustc_errors::{struct_span_err, EmissionGuarantee, LintDiagnosticBuilder};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_middle::lint::LintDiagnosticBuilder;
|
|
||||||
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
|
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
|
||||||
use rustc_middle::ty::{self, ImplSubject, TyCtxt};
|
use rustc_middle::ty::{self, ImplSubject, TyCtxt};
|
||||||
use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
|
use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
//! Validates syntax inside Rust code blocks (\`\`\`rust).
|
//! Validates syntax inside Rust code blocks (\`\`\`rust).
|
||||||
use rustc_data_structures::sync::{Lock, Lrc};
|
use rustc_data_structures::sync::{Lock, Lrc};
|
||||||
use rustc_errors::{emitter::Emitter, Applicability, Diagnostic, Handler, LazyFallbackBundle};
|
use rustc_errors::{
|
||||||
use rustc_middle::lint::LintDiagnosticBuilder;
|
emitter::Emitter, Applicability, Diagnostic, Handler, LazyFallbackBundle, LintDiagnosticBuilder,
|
||||||
|
};
|
||||||
use rustc_parse::parse_stream_from_source_str;
|
use rustc_parse::parse_stream_from_source_str;
|
||||||
use rustc_session::parse::ParseSess;
|
use rustc_session::parse::ParseSess;
|
||||||
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
|
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
|
||||||
|
|
Loading…
Add table
Reference in a new issue