Auto merge of #45484 - oli-obk:lint_names, r=nikomatsakis
Report lint names in json diagnostics This allows tools like `rustfix` to have whitelists for what to automatically apply and what not.
This commit is contained in:
commit
9f3b09116b
@ -33,7 +33,7 @@ pub use self::LintSource::*;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use errors::DiagnosticBuilder;
|
||||
use errors::{DiagnosticBuilder, DiagnosticId};
|
||||
use hir::def_id::{CrateNum, LOCAL_CRATE};
|
||||
use hir::intravisit::{self, FnKind};
|
||||
use hir;
|
||||
@ -463,6 +463,8 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
|
||||
}
|
||||
}
|
||||
|
||||
err.code(DiagnosticId::Lint(name));
|
||||
|
||||
// Check for future incompatibility lints and issue a stronger warning.
|
||||
let lints = sess.lint_store.borrow();
|
||||
if let Some(future_incompatible) = lints.future_incompatible(LintId::of(lint)) {
|
||||
|
@ -24,7 +24,7 @@ use util::nodemap::{FxHashMap, FxHashSet};
|
||||
use util::common::{duration_to_secs_str, ErrorReported};
|
||||
|
||||
use syntax::ast::NodeId;
|
||||
use errors::{self, DiagnosticBuilder};
|
||||
use errors::{self, DiagnosticBuilder, DiagnosticId};
|
||||
use errors::emitter::{Emitter, EmitterWriter};
|
||||
use syntax::json::JsonEmitter;
|
||||
use syntax::feature_gate;
|
||||
@ -187,7 +187,7 @@ impl Session {
|
||||
pub fn struct_span_warn_with_code<'a, S: Into<MultiSpan>>(&'a self,
|
||||
sp: S,
|
||||
msg: &str,
|
||||
code: &str)
|
||||
code: DiagnosticId)
|
||||
-> DiagnosticBuilder<'a> {
|
||||
self.diagnostic().struct_span_warn_with_code(sp, msg, code)
|
||||
}
|
||||
@ -203,7 +203,7 @@ impl Session {
|
||||
pub fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
|
||||
sp: S,
|
||||
msg: &str,
|
||||
code: &str)
|
||||
code: DiagnosticId)
|
||||
-> DiagnosticBuilder<'a> {
|
||||
self.diagnostic().struct_span_err_with_code(sp, msg, code)
|
||||
}
|
||||
@ -211,7 +211,11 @@ impl Session {
|
||||
pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
|
||||
self.diagnostic().struct_err(msg)
|
||||
}
|
||||
pub fn struct_err_with_code<'a>(&'a self, msg: &str, code: &str) -> DiagnosticBuilder<'a> {
|
||||
pub fn struct_err_with_code<'a>(
|
||||
&'a self,
|
||||
msg: &str,
|
||||
code: DiagnosticId,
|
||||
) -> DiagnosticBuilder<'a> {
|
||||
self.diagnostic().struct_err_with_code(msg, code)
|
||||
}
|
||||
pub fn struct_span_fatal<'a, S: Into<MultiSpan>>(&'a self,
|
||||
@ -223,7 +227,7 @@ impl Session {
|
||||
pub fn struct_span_fatal_with_code<'a, S: Into<MultiSpan>>(&'a self,
|
||||
sp: S,
|
||||
msg: &str,
|
||||
code: &str)
|
||||
code: DiagnosticId)
|
||||
-> DiagnosticBuilder<'a> {
|
||||
self.diagnostic().struct_span_fatal_with_code(sp, msg, code)
|
||||
}
|
||||
@ -234,7 +238,12 @@ impl Session {
|
||||
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
|
||||
panic!(self.diagnostic().span_fatal(sp, msg))
|
||||
}
|
||||
pub fn span_fatal_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: &str) -> ! {
|
||||
pub fn span_fatal_with_code<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
msg: &str,
|
||||
code: DiagnosticId,
|
||||
) -> ! {
|
||||
panic!(self.diagnostic().span_fatal_with_code(sp, msg, code))
|
||||
}
|
||||
pub fn fatal(&self, msg: &str) -> ! {
|
||||
@ -250,7 +259,7 @@ impl Session {
|
||||
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
|
||||
self.diagnostic().span_err(sp, msg)
|
||||
}
|
||||
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: &str) {
|
||||
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) {
|
||||
self.diagnostic().span_err_with_code(sp, &msg, code)
|
||||
}
|
||||
pub fn err(&self, msg: &str) {
|
||||
@ -283,7 +292,7 @@ impl Session {
|
||||
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
|
||||
self.diagnostic().span_warn(sp, msg)
|
||||
}
|
||||
pub fn span_warn_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: &str) {
|
||||
pub fn span_warn_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) {
|
||||
self.diagnostic().span_warn_with_code(sp, msg, code)
|
||||
}
|
||||
pub fn warn(&self, msg: &str) {
|
||||
|
@ -47,7 +47,7 @@ use std::rc::Rc;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use syntax::ast;
|
||||
use syntax_pos::{MultiSpan, Span};
|
||||
use errors::DiagnosticBuilder;
|
||||
use errors::{DiagnosticBuilder, DiagnosticId};
|
||||
|
||||
use rustc::hir;
|
||||
use rustc::hir::intravisit::{self, Visitor};
|
||||
@ -256,7 +256,7 @@ impl<'b, 'tcx: 'b> BorrowckErrors for BorrowckCtxt<'b, 'tcx> {
|
||||
fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
|
||||
sp: S,
|
||||
msg: &str,
|
||||
code: &str)
|
||||
code: DiagnosticId)
|
||||
-> DiagnosticBuilder<'a>
|
||||
{
|
||||
self.tcx.sess.struct_span_err_with_code(sp, msg, code)
|
||||
@ -755,12 +755,17 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||
pub fn struct_span_err_with_code<S: Into<MultiSpan>>(&self,
|
||||
s: S,
|
||||
msg: &str,
|
||||
code: &str)
|
||||
code: DiagnosticId)
|
||||
-> DiagnosticBuilder<'a> {
|
||||
self.tcx.sess.struct_span_err_with_code(s, msg, code)
|
||||
}
|
||||
|
||||
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, s: S, msg: &str, code: &str) {
|
||||
pub fn span_err_with_code<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
s: S,
|
||||
msg: &str,
|
||||
code: DiagnosticId,
|
||||
) {
|
||||
self.tcx.sess.span_err_with_code(s, msg, code);
|
||||
}
|
||||
|
||||
|
@ -21,12 +21,18 @@ use snippet::Style;
|
||||
pub struct Diagnostic {
|
||||
pub level: Level,
|
||||
pub message: Vec<(String, Style)>,
|
||||
pub code: Option<String>,
|
||||
pub code: Option<DiagnosticId>,
|
||||
pub span: MultiSpan,
|
||||
pub children: Vec<SubDiagnostic>,
|
||||
pub suggestions: Vec<CodeSuggestion>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub enum DiagnosticId {
|
||||
Error(String),
|
||||
Lint(String),
|
||||
}
|
||||
|
||||
/// For example a note attached to an error.
|
||||
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
|
||||
pub struct SubDiagnostic {
|
||||
@ -81,7 +87,7 @@ impl Diagnostic {
|
||||
Diagnostic::new_with_code(level, None, message)
|
||||
}
|
||||
|
||||
pub fn new_with_code(level: Level, code: Option<String>, message: &str) -> Self {
|
||||
pub fn new_with_code(level: Level, code: Option<DiagnosticId>, message: &str) -> Self {
|
||||
Diagnostic {
|
||||
level,
|
||||
message: vec![(message.to_owned(), Style::NoStyle)],
|
||||
@ -267,7 +273,7 @@ impl Diagnostic {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn code(&mut self, s: String) -> &mut Self {
|
||||
pub fn code(&mut self, s: DiagnosticId) -> &mut Self {
|
||||
self.code = Some(s);
|
||||
self
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
use Diagnostic;
|
||||
use DiagnosticId;
|
||||
use DiagnosticStyledString;
|
||||
|
||||
use Level;
|
||||
@ -192,7 +193,7 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||
suggestions: Vec<String>)
|
||||
-> &mut Self);
|
||||
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self);
|
||||
forward!(pub fn code(&mut self, s: String) -> &mut Self);
|
||||
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
|
||||
|
||||
/// Convenience function for internal use, clients should use one of the
|
||||
/// struct_* methods on Handler.
|
||||
@ -204,7 +205,7 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||
/// struct_* methods on Handler.
|
||||
pub fn new_with_code(handler: &'a Handler,
|
||||
level: Level,
|
||||
code: Option<String>,
|
||||
code: Option<DiagnosticId>,
|
||||
message: &str)
|
||||
-> DiagnosticBuilder<'a> {
|
||||
let diagnostic = Diagnostic::new_with_code(level, code, message);
|
||||
|
@ -12,7 +12,7 @@ use self::Destination::*;
|
||||
|
||||
use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan, CharPos};
|
||||
|
||||
use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapper};
|
||||
use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapper, DiagnosticId};
|
||||
use RenderSpan::*;
|
||||
use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
|
||||
use styled_buffer::StyledBuffer;
|
||||
@ -886,7 +886,7 @@ impl EmitterWriter {
|
||||
fn emit_message_default(&mut self,
|
||||
msp: &MultiSpan,
|
||||
msg: &Vec<(String, Style)>,
|
||||
code: &Option<String>,
|
||||
code: &Option<DiagnosticId>,
|
||||
level: &Level,
|
||||
max_line_num_len: usize,
|
||||
is_secondary: bool)
|
||||
@ -905,13 +905,11 @@ impl EmitterWriter {
|
||||
self.msg_to_buffer(&mut buffer, msg, max_line_num_len, "note", None);
|
||||
} else {
|
||||
buffer.append(0, &level.to_string(), Style::Level(level.clone()));
|
||||
match code {
|
||||
&Some(ref code) => {
|
||||
buffer.append(0, "[", Style::Level(level.clone()));
|
||||
buffer.append(0, &code, Style::Level(level.clone()));
|
||||
buffer.append(0, "]", Style::Level(level.clone()));
|
||||
}
|
||||
_ => {}
|
||||
// only render error codes, not lint codes
|
||||
if let Some(DiagnosticId::Error(ref code)) = *code {
|
||||
buffer.append(0, "[", Style::Level(level.clone()));
|
||||
buffer.append(0, &code, Style::Level(level.clone()));
|
||||
buffer.append(0, "]", Style::Level(level.clone()));
|
||||
}
|
||||
buffer.append(0, ": ", Style::HeaderMsg);
|
||||
for &(ref text, _) in msg.iter() {
|
||||
@ -1174,7 +1172,7 @@ impl EmitterWriter {
|
||||
fn emit_messages_default(&mut self,
|
||||
level: &Level,
|
||||
message: &Vec<(String, Style)>,
|
||||
code: &Option<String>,
|
||||
code: &Option<DiagnosticId>,
|
||||
span: &MultiSpan,
|
||||
children: &Vec<SubDiagnostic>) {
|
||||
let max_line_num = self.get_max_line_num(span, children);
|
||||
|
@ -262,7 +262,7 @@ impl error::Error for ExplicitBug {
|
||||
}
|
||||
}
|
||||
|
||||
pub use diagnostic::{Diagnostic, SubDiagnostic, DiagnosticStyledString};
|
||||
pub use diagnostic::{Diagnostic, SubDiagnostic, DiagnosticStyledString, DiagnosticId};
|
||||
pub use diagnostic_builder::DiagnosticBuilder;
|
||||
|
||||
/// A handler deals with errors; certain errors
|
||||
@ -337,11 +337,11 @@ impl Handler {
|
||||
pub fn struct_span_warn_with_code<'a, S: Into<MultiSpan>>(&'a self,
|
||||
sp: S,
|
||||
msg: &str,
|
||||
code: &str)
|
||||
code: DiagnosticId)
|
||||
-> DiagnosticBuilder<'a> {
|
||||
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
|
||||
result.set_span(sp);
|
||||
result.code(code.to_owned());
|
||||
result.code(code);
|
||||
if !self.can_emit_warnings {
|
||||
result.cancel();
|
||||
}
|
||||
@ -365,20 +365,24 @@ impl Handler {
|
||||
pub fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
|
||||
sp: S,
|
||||
msg: &str,
|
||||
code: &str)
|
||||
code: DiagnosticId)
|
||||
-> DiagnosticBuilder<'a> {
|
||||
let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
|
||||
result.set_span(sp);
|
||||
result.code(code.to_owned());
|
||||
result.code(code);
|
||||
result
|
||||
}
|
||||
// FIXME: This method should be removed (every error should have an associated error code).
|
||||
pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
|
||||
DiagnosticBuilder::new(self, Level::Error, msg)
|
||||
}
|
||||
pub fn struct_err_with_code<'a>(&'a self, msg: &str, code: &str) -> DiagnosticBuilder<'a> {
|
||||
pub fn struct_err_with_code<'a>(
|
||||
&'a self,
|
||||
msg: &str,
|
||||
code: DiagnosticId,
|
||||
) -> DiagnosticBuilder<'a> {
|
||||
let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
|
||||
result.code(code.to_owned());
|
||||
result.code(code);
|
||||
result
|
||||
}
|
||||
pub fn struct_span_fatal<'a, S: Into<MultiSpan>>(&'a self,
|
||||
@ -392,11 +396,11 @@ impl Handler {
|
||||
pub fn struct_span_fatal_with_code<'a, S: Into<MultiSpan>>(&'a self,
|
||||
sp: S,
|
||||
msg: &str,
|
||||
code: &str)
|
||||
code: DiagnosticId)
|
||||
-> DiagnosticBuilder<'a> {
|
||||
let mut result = DiagnosticBuilder::new(self, Level::Fatal, msg);
|
||||
result.set_span(sp);
|
||||
result.code(code.to_owned());
|
||||
result.code(code);
|
||||
result
|
||||
}
|
||||
pub fn struct_fatal<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
|
||||
@ -420,7 +424,7 @@ impl Handler {
|
||||
pub fn span_fatal_with_code<S: Into<MultiSpan>>(&self,
|
||||
sp: S,
|
||||
msg: &str,
|
||||
code: &str)
|
||||
code: DiagnosticId)
|
||||
-> FatalError {
|
||||
self.emit_with_code(&sp.into(), msg, code, Fatal);
|
||||
FatalError
|
||||
@ -436,13 +440,13 @@ impl Handler {
|
||||
result.set_span(sp);
|
||||
result
|
||||
}
|
||||
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: &str) {
|
||||
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) {
|
||||
self.emit_with_code(&sp.into(), msg, code, Error);
|
||||
}
|
||||
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
|
||||
self.emit(&sp.into(), msg, Warning);
|
||||
}
|
||||
pub fn span_warn_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: &str) {
|
||||
pub fn span_warn_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) {
|
||||
self.emit_with_code(&sp.into(), msg, code, Warning);
|
||||
}
|
||||
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
|
||||
@ -546,11 +550,11 @@ impl Handler {
|
||||
self.abort_if_errors();
|
||||
}
|
||||
}
|
||||
pub fn emit_with_code(&self, msp: &MultiSpan, msg: &str, code: &str, lvl: Level) {
|
||||
pub fn emit_with_code(&self, msp: &MultiSpan, msg: &str, code: DiagnosticId, lvl: Level) {
|
||||
if lvl == Warning && !self.can_emit_warnings {
|
||||
return;
|
||||
}
|
||||
let mut db = DiagnosticBuilder::new_with_code(self, lvl, Some(code.to_owned()), msg);
|
||||
let mut db = DiagnosticBuilder::new_with_code(self, lvl, Some(code), msg);
|
||||
db.set_span(msp.clone());
|
||||
db.emit();
|
||||
if !self.continue_after_error.get() {
|
||||
|
@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
use rustc::ty::{self, TyCtxt};
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use rustc_errors::{DiagnosticBuilder, DiagnosticId};
|
||||
use syntax_pos::{MultiSpan, Span};
|
||||
|
||||
use std::fmt;
|
||||
@ -41,7 +41,7 @@ pub trait BorrowckErrors {
|
||||
fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
|
||||
sp: S,
|
||||
msg: &str,
|
||||
code: &str)
|
||||
code: DiagnosticId)
|
||||
-> DiagnosticBuilder<'a>;
|
||||
|
||||
fn struct_span_err<'a, S: Into<MultiSpan>>(&'a self,
|
||||
@ -445,7 +445,7 @@ impl<'b, 'gcx, 'tcx> BorrowckErrors for TyCtxt<'b, 'gcx, 'tcx> {
|
||||
fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
|
||||
sp: S,
|
||||
msg: &str,
|
||||
code: &str)
|
||||
code: DiagnosticId)
|
||||
-> DiagnosticBuilder<'a>
|
||||
{
|
||||
self.sess.struct_span_err_with_code(sp, msg, code)
|
||||
|
@ -59,7 +59,7 @@ use syntax::ast::{QSelf, TraitItemKind, TraitRef, Ty, TyKind};
|
||||
use syntax::feature_gate::{feature_err, emit_feature_err, GateIssue};
|
||||
|
||||
use syntax_pos::{Span, DUMMY_SP, MultiSpan};
|
||||
use errors::DiagnosticBuilder;
|
||||
use errors::{DiagnosticBuilder, DiagnosticId};
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::cmp;
|
||||
@ -223,7 +223,11 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
|
||||
let target_sp = binding_error.target.iter().map(|x| *x).collect::<Vec<_>>();
|
||||
let msp = MultiSpan::from_spans(target_sp.clone());
|
||||
let msg = format!("variable `{}` is not bound in all patterns", binding_error.name);
|
||||
let mut err = resolver.session.struct_span_err_with_code(msp, &msg, "E0408");
|
||||
let mut err = resolver.session.struct_span_err_with_code(
|
||||
msp,
|
||||
&msg,
|
||||
DiagnosticId::Error("E0408".into()),
|
||||
);
|
||||
for sp in target_sp {
|
||||
err.span_label(sp, format!("pattern doesn't bind `{}`", binding_error.name));
|
||||
}
|
||||
@ -2490,18 +2494,19 @@ impl<'a> Resolver<'a> {
|
||||
(format!("cannot find {} `{}` in {}{}", expected, item_str, mod_prefix, mod_str),
|
||||
format!("not found in {}", mod_str), item_span)
|
||||
};
|
||||
let code = DiagnosticId::Error(code.into());
|
||||
let mut err = this.session.struct_span_err_with_code(base_span, &base_msg, code);
|
||||
|
||||
// Emit special messages for unresolved `Self` and `self`.
|
||||
if is_self_type(path, ns) {
|
||||
__diagnostic_used!(E0411);
|
||||
err.code("E0411".into());
|
||||
err.code(DiagnosticId::Error("E0411".into()));
|
||||
err.span_label(span, "`Self` is only available in traits and impls");
|
||||
return (err, Vec::new());
|
||||
}
|
||||
if is_self_value(path, ns) {
|
||||
__diagnostic_used!(E0424);
|
||||
err.code("E0424".into());
|
||||
err.code(DiagnosticId::Error("E0424".into()));
|
||||
err.span_label(span, format!("`self` value is only available in \
|
||||
methods with `self` parameter"));
|
||||
return (err, Vec::new());
|
||||
|
@ -32,7 +32,7 @@ use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
|
||||
use rustc::ty::TyCtxt;
|
||||
use rustc::util::common::{time, time_depth, set_time_depth, path2cstr, print_time_passes_entry};
|
||||
use rustc::util::fs::{link_or_copy, rename_or_copy_remove};
|
||||
use errors::{self, Handler, Level, DiagnosticBuilder, FatalError};
|
||||
use errors::{self, Handler, Level, DiagnosticBuilder, FatalError, DiagnosticId};
|
||||
use errors::emitter::{Emitter};
|
||||
use syntax::attr;
|
||||
use syntax::ext::hygiene::Mark;
|
||||
@ -1262,7 +1262,7 @@ enum Message {
|
||||
|
||||
struct Diagnostic {
|
||||
msg: String,
|
||||
code: Option<String>,
|
||||
code: Option<DiagnosticId>,
|
||||
lvl: Level,
|
||||
}
|
||||
|
||||
@ -2015,7 +2015,7 @@ impl SharedEmitterMain {
|
||||
Some(ref code) => {
|
||||
handler.emit_with_code(&MultiSpan::new(),
|
||||
&diag.msg,
|
||||
&code,
|
||||
code.clone(),
|
||||
diag.lvl);
|
||||
}
|
||||
None => {
|
||||
|
@ -100,7 +100,7 @@ use rustc::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
|
||||
use rustc::ty::fold::{BottomUpFolder, TypeFoldable};
|
||||
use rustc::ty::maps::Providers;
|
||||
use rustc::ty::util::{Representability, IntTypeExt};
|
||||
use errors::DiagnosticBuilder;
|
||||
use errors::{DiagnosticBuilder, DiagnosticId};
|
||||
use require_c_abi_if_variadic;
|
||||
use session::{CompileIncomplete, Session};
|
||||
use TypeAndSubsts;
|
||||
@ -2467,7 +2467,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
if expected_count == 1 {""} else {"s"},
|
||||
arg_count,
|
||||
if arg_count == 1 {" was"} else {"s were"}),
|
||||
error_code);
|
||||
DiagnosticId::Error(error_code.to_owned()));
|
||||
|
||||
if let Some(def_s) = def_span {
|
||||
err.span_label(def_s, "defined here");
|
||||
|
@ -18,7 +18,11 @@ macro_rules! register_diagnostic {
|
||||
macro_rules! span_fatal {
|
||||
($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
|
||||
__diagnostic_used!($code);
|
||||
$session.span_fatal_with_code($span, &format!($($message)*), stringify!($code))
|
||||
$session.span_fatal_with_code(
|
||||
$span,
|
||||
&format!($($message)*),
|
||||
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@ -26,7 +30,11 @@ macro_rules! span_fatal {
|
||||
macro_rules! span_err {
|
||||
($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
|
||||
__diagnostic_used!($code);
|
||||
$session.span_err_with_code($span, &format!($($message)*), stringify!($code))
|
||||
$session.span_err_with_code(
|
||||
$span,
|
||||
&format!($($message)*),
|
||||
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@ -34,7 +42,11 @@ macro_rules! span_err {
|
||||
macro_rules! span_warn {
|
||||
($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
|
||||
__diagnostic_used!($code);
|
||||
$session.span_warn_with_code($span, &format!($($message)*), stringify!($code))
|
||||
$session.span_warn_with_code(
|
||||
$span,
|
||||
&format!($($message)*),
|
||||
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@ -42,7 +54,10 @@ macro_rules! span_warn {
|
||||
macro_rules! struct_err {
|
||||
($session:expr, $code:ident, $($message:tt)*) => ({
|
||||
__diagnostic_used!($code);
|
||||
$session.struct_err_with_code(&format!($($message)*), stringify!($code))
|
||||
$session.struct_err_with_code(
|
||||
&format!($($message)*),
|
||||
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@ -51,9 +66,17 @@ macro_rules! span_err_or_warn {
|
||||
($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
|
||||
__diagnostic_used!($code);
|
||||
if $is_warning {
|
||||
$session.span_warn_with_code($span, &format!($($message)*), stringify!($code))
|
||||
$session.span_warn_with_code(
|
||||
$span,
|
||||
&format!($($message)*),
|
||||
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
|
||||
)
|
||||
} else {
|
||||
$session.span_err_with_code($span, &format!($($message)*), stringify!($code))
|
||||
$session.span_err_with_code(
|
||||
$span,
|
||||
&format!($($message)*),
|
||||
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -62,7 +85,11 @@ macro_rules! span_err_or_warn {
|
||||
macro_rules! struct_span_fatal {
|
||||
($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
|
||||
__diagnostic_used!($code);
|
||||
$session.struct_span_fatal_with_code($span, &format!($($message)*), stringify!($code))
|
||||
$session.struct_span_fatal_with_code(
|
||||
$span,
|
||||
&format!($($message)*),
|
||||
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@ -70,7 +97,11 @@ macro_rules! struct_span_fatal {
|
||||
macro_rules! struct_span_err {
|
||||
($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
|
||||
__diagnostic_used!($code);
|
||||
$session.struct_span_err_with_code($span, &format!($($message)*), stringify!($code))
|
||||
$session.struct_span_err_with_code(
|
||||
$span,
|
||||
&format!($($message)*),
|
||||
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@ -89,7 +120,11 @@ macro_rules! type_error_struct {
|
||||
macro_rules! struct_span_warn {
|
||||
($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
|
||||
__diagnostic_used!($code);
|
||||
$session.struct_span_warn_with_code($span, &format!($($message)*), stringify!($code))
|
||||
$session.struct_span_warn_with_code(
|
||||
$span,
|
||||
&format!($($message)*),
|
||||
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@ -98,9 +133,17 @@ macro_rules! struct_span_err_or_warn {
|
||||
($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
|
||||
__diagnostic_used!($code);
|
||||
if $is_warning {
|
||||
$session.struct_span_warn_with_code($span, &format!($($message)*), stringify!($code))
|
||||
$session.struct_span_warn_with_code(
|
||||
$span,
|
||||
&format!($($message)*),
|
||||
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
|
||||
)
|
||||
} else {
|
||||
$session.struct_span_err_with_code($span, &format!($($message)*), stringify!($code))
|
||||
$session.struct_span_err_with_code(
|
||||
$span,
|
||||
&format!($($message)*),
|
||||
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ use codemap::{CodeMap, FilePathMapping};
|
||||
use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan};
|
||||
use errors::registry::Registry;
|
||||
use errors::{DiagnosticBuilder, SubDiagnostic, RenderSpan, CodeSuggestion, CodeMapper};
|
||||
use errors::DiagnosticId;
|
||||
use errors::emitter::Emitter;
|
||||
|
||||
use std::rc::Rc;
|
||||
@ -340,9 +341,12 @@ impl DiagnosticSpanLine {
|
||||
}
|
||||
|
||||
impl DiagnosticCode {
|
||||
fn map_opt_string(s: Option<String>, je: &JsonEmitter) -> Option<DiagnosticCode> {
|
||||
fn map_opt_string(s: Option<DiagnosticId>, je: &JsonEmitter) -> Option<DiagnosticCode> {
|
||||
s.map(|s| {
|
||||
|
||||
let s = match s {
|
||||
DiagnosticId::Error(s) => s,
|
||||
DiagnosticId::Lint(s) => s,
|
||||
};
|
||||
let explanation = je.registry
|
||||
.as_ref()
|
||||
.and_then(|registry| registry.find_description(&s));
|
||||
|
@ -1 +1 @@
|
||||
{"message":"unnecessary parentheses around assigned value","code":null,"level":"warning","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":1001,"byte_end":1014,"line_start":24,"line_end":24,"column_start":14,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":27}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[{"message":"lint level defined here","code":null,"level":"note","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":847,"byte_end":860,"line_start":19,"line_end":19,"column_start":9,"column_end":22,"is_primary":true,"text":[{"text":"#![warn(unused_parens)]","highlight_start":9,"highlight_end":22}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[],"rendered":null},{"message":"remove these parentheses","code":null,"level":"help","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":1001,"byte_end":1014,"line_start":24,"line_end":24,"column_start":14,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":27}],"label":null,"suggested_replacement":"1 / (2 + 3)","expansion":null}],"children":[],"rendered":null}],"rendered":null}
|
||||
{"message":"unnecessary parentheses around assigned value","code":{"code":"unused_parens","explanation":null},"level":"warning","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":1001,"byte_end":1014,"line_start":24,"line_end":24,"column_start":14,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":27}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[{"message":"lint level defined here","code":null,"level":"note","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":847,"byte_end":860,"line_start":19,"line_end":19,"column_start":9,"column_end":22,"is_primary":true,"text":[{"text":"#![warn(unused_parens)]","highlight_start":9,"highlight_end":22}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[],"rendered":null},{"message":"remove these parentheses","code":null,"level":"help","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":1001,"byte_end":1014,"line_start":24,"line_end":24,"column_start":14,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":27}],"label":null,"suggested_replacement":"1 / (2 + 3)","expansion":null}],"children":[],"rendered":null}],"rendered":null}
|
||||
|
Loading…
Reference in New Issue
Block a user