lint: LintDiagnosticBuilder
into rustc_errors
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
84ec77769f
commit
2874f09534
@ -589,3 +589,26 @@ macro_rules! struct_span_err {
|
||||
macro_rules! error_code {
|
||||
($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 @@ impl error::Error for ExplicitBug {}
|
||||
AddSubdiagnostic, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
|
||||
DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
|
||||
};
|
||||
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee};
|
||||
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder};
|
||||
use std::backtrace::Backtrace;
|
||||
|
||||
/// A handler deals with errors and other compiler output.
|
||||
|
@ -32,7 +32,8 @@
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
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_hir as hir;
|
||||
@ -40,7 +41,7 @@
|
||||
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
|
||||
use rustc_hir::{ForeignItemKind, GenericParamKind, HirId, PatKind, PredicateOrigin};
|
||||
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::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
|
@ -22,12 +22,11 @@
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync;
|
||||
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::def::Res;
|
||||
use rustc_hir::def_id::{CrateNum, DefId};
|
||||
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
|
||||
use rustc_middle::lint::LintDiagnosticBuilder;
|
||||
use rustc_middle::middle::privacy::AccessLevels;
|
||||
use rustc_middle::middle::stability;
|
||||
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
|
||||
|
@ -3,13 +3,13 @@
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast_pretty::pprust;
|
||||
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::{intravisit, HirId};
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::lint::{
|
||||
struct_lint_level, LevelAndSource, LintDiagnosticBuilder, LintExpectation, LintLevelMap,
|
||||
LintLevelSets, LintLevelSource, LintSet, LintStackIndex, COMMAND_LINE,
|
||||
struct_lint_level, LevelAndSource, LintExpectation, LintLevelMap, LintLevelSets,
|
||||
LintLevelSource, LintSet, LintStackIndex, COMMAND_LINE,
|
||||
};
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{RegisteredTools, TyCtxt};
|
||||
|
@ -2,10 +2,7 @@
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_errors::{
|
||||
Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, EmissionGuarantee,
|
||||
ErrorGuaranteed, MultiSpan,
|
||||
};
|
||||
use rustc_errors::{Diagnostic, DiagnosticId, LintDiagnosticBuilder, MultiSpan};
|
||||
use rustc_hir::HirId;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
@ -228,28 +225,6 @@ pub fn new(
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
lint: &'static Lint,
|
||||
level: Level,
|
||||
|
@ -4,7 +4,7 @@
|
||||
use crate::dep_graph::{DepGraph, DepKind, DepKindStruct};
|
||||
use crate::hir::place::Place as HirPlace;
|
||||
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::resolve_lifetime;
|
||||
use crate::middle::stability;
|
||||
@ -34,7 +34,7 @@
|
||||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_data_structures::sync::{self, Lock, Lrc, WorkerLocal};
|
||||
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::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
|
||||
|
@ -1,5 +1,4 @@
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use rustc_middle::lint::LintDiagnosticBuilder;
|
||||
use rustc_errors::{DiagnosticBuilder, LintDiagnosticBuilder};
|
||||
use rustc_middle::mir::visit::Visitor;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
@ -16,9 +16,8 @@
|
||||
use crate::traits::select::IntercrateAmbiguityCause;
|
||||
use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine};
|
||||
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_middle::lint::LintDiagnosticBuilder;
|
||||
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
|
||||
use rustc_middle::ty::{self, ImplSubject, TyCtxt};
|
||||
use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
|
||||
|
@ -1,7 +1,8 @@
|
||||
//! Validates syntax inside Rust code blocks (\`\`\`rust).
|
||||
use rustc_data_structures::sync::{Lock, Lrc};
|
||||
use rustc_errors::{emitter::Emitter, Applicability, Diagnostic, Handler, LazyFallbackBundle};
|
||||
use rustc_middle::lint::LintDiagnosticBuilder;
|
||||
use rustc_errors::{
|
||||
emitter::Emitter, Applicability, Diagnostic, Handler, LazyFallbackBundle, LintDiagnosticBuilder,
|
||||
};
|
||||
use rustc_parse::parse_stream_from_source_str;
|
||||
use rustc_session::parse::ParseSess;
|
||||
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
|
||||
|
Loading…
Reference in New Issue
Block a user