librustc_errors => 2018
This commit is contained in:
parent
b139669f37
commit
950fe6686d
7 changed files with 37 additions and 45 deletions
|
@ -2,6 +2,7 @@
|
||||||
authors = ["The Rust Project Developers"]
|
authors = ["The Rust Project Developers"]
|
||||||
name = "rustc_errors"
|
name = "rustc_errors"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "rustc_errors"
|
name = "rustc_errors"
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use CodeSuggestion;
|
use crate::CodeSuggestion;
|
||||||
use SubstitutionPart;
|
use crate::SubstitutionPart;
|
||||||
use Substitution;
|
use crate::Substitution;
|
||||||
use Applicability;
|
use crate::Applicability;
|
||||||
use Level;
|
use crate::Level;
|
||||||
|
use crate::snippet::Style;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use syntax_pos::{MultiSpan, Span};
|
use syntax_pos::{MultiSpan, Span};
|
||||||
use snippet::Style;
|
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
|
#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
use Diagnostic;
|
use crate::Diagnostic;
|
||||||
use DiagnosticId;
|
use crate::DiagnosticId;
|
||||||
use DiagnosticStyledString;
|
use crate::DiagnosticStyledString;
|
||||||
use Applicability;
|
use crate::Applicability;
|
||||||
|
|
||||||
use Level;
|
use crate::Level;
|
||||||
use Handler;
|
use crate::Handler;
|
||||||
use std::fmt::{self, Debug};
|
use std::fmt::{self, Debug};
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::thread::panicking;
|
use std::thread::panicking;
|
||||||
use syntax_pos::{MultiSpan, Span};
|
use syntax_pos::{MultiSpan, Span};
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
/// Used for emitting structured error messages and other diagnostic information.
|
/// Used for emitting structured error messages and other diagnostic information.
|
||||||
///
|
///
|
||||||
|
@ -111,8 +112,8 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||||
// implements `Drop`.
|
// implements `Drop`.
|
||||||
let diagnostic;
|
let diagnostic;
|
||||||
unsafe {
|
unsafe {
|
||||||
diagnostic = ::std::ptr::read(&self.diagnostic);
|
diagnostic = std::ptr::read(&self.diagnostic);
|
||||||
::std::mem::forget(self);
|
std::mem::forget(self);
|
||||||
};
|
};
|
||||||
// Logging here is useful to help track down where in logs an error was
|
// Logging here is useful to help track down where in logs an error was
|
||||||
// actually emitted.
|
// actually emitted.
|
||||||
|
@ -298,7 +299,7 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Debug for DiagnosticBuilder<'a> {
|
impl<'a> Debug for DiagnosticBuilder<'a> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
self.diagnostic.fmt(f)
|
self.diagnostic.fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,26 @@
|
||||||
use self::Destination::*;
|
use Destination::*;
|
||||||
|
|
||||||
use syntax_pos::{SourceFile, Span, MultiSpan};
|
use syntax_pos::{SourceFile, Span, MultiSpan};
|
||||||
|
|
||||||
use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, SourceMapperDyn, DiagnosticId};
|
use crate::{Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, SourceMapperDyn, DiagnosticId};
|
||||||
use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
|
use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
|
||||||
use styled_buffer::StyledBuffer;
|
use crate::styled_buffer::StyledBuffer;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use atty;
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::cmp::{min, Reverse};
|
use std::cmp::{min, Reverse};
|
||||||
use termcolor::{StandardStream, ColorChoice, ColorSpec, BufferWriter};
|
use termcolor::{StandardStream, ColorChoice, ColorSpec, BufferWriter};
|
||||||
use termcolor::{WriteColor, Color, Buffer};
|
use termcolor::{WriteColor, Color, Buffer};
|
||||||
use unicode_width;
|
|
||||||
|
|
||||||
const ANONYMIZED_LINE_NUM: &str = "LL";
|
const ANONYMIZED_LINE_NUM: &str = "LL";
|
||||||
|
|
||||||
/// Emitter trait for emitting errors.
|
/// Emitter trait for emitting errors.
|
||||||
pub trait Emitter {
|
pub trait Emitter {
|
||||||
/// Emit a structured diagnostic.
|
/// Emit a structured diagnostic.
|
||||||
fn emit(&mut self, db: &DiagnosticBuilder);
|
fn emit(&mut self, db: &DiagnosticBuilder<'_>);
|
||||||
|
|
||||||
/// Check if should show explanations about "rustc --explain"
|
/// Check if should show explanations about "rustc --explain"
|
||||||
fn should_show_explain(&self) -> bool {
|
fn should_show_explain(&self) -> bool {
|
||||||
|
@ -31,7 +29,7 @@ pub trait Emitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emitter for EmitterWriter {
|
impl Emitter for EmitterWriter {
|
||||||
fn emit(&mut self, db: &DiagnosticBuilder) {
|
fn emit(&mut self, db: &DiagnosticBuilder<'_>) {
|
||||||
let mut primary_span = db.span.clone();
|
let mut primary_span = db.span.clone();
|
||||||
let mut children = db.children.clone();
|
let mut children = db.children.clone();
|
||||||
let mut suggestions: &[_] = &[];
|
let mut suggestions: &[_] = &[];
|
||||||
|
@ -1431,7 +1429,7 @@ fn emit_to_destination(rendered_buffer: &[Vec<StyledString>],
|
||||||
dst: &mut Destination,
|
dst: &mut Destination,
|
||||||
short_message: bool)
|
short_message: bool)
|
||||||
-> io::Result<()> {
|
-> io::Result<()> {
|
||||||
use lock;
|
use crate::lock;
|
||||||
|
|
||||||
let mut dst = dst.writable();
|
let mut dst = dst.writable();
|
||||||
|
|
||||||
|
|
|
@ -6,23 +6,15 @@
|
||||||
#![allow(unused_attributes)]
|
#![allow(unused_attributes)]
|
||||||
#![feature(range_contains)]
|
#![feature(range_contains)]
|
||||||
#![cfg_attr(unix, feature(libc))]
|
#![cfg_attr(unix, feature(libc))]
|
||||||
#![feature(nll)]
|
|
||||||
#![feature(optin_builtin_traits)]
|
#![feature(optin_builtin_traits)]
|
||||||
|
#![deny(rust_2018_idioms)]
|
||||||
|
|
||||||
extern crate atty;
|
#[allow(unused_extern_crates)]
|
||||||
extern crate termcolor;
|
extern crate serialize as rustc_serialize; // used by deriving
|
||||||
#[cfg(unix)]
|
|
||||||
extern crate libc;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
extern crate rustc_data_structures;
|
|
||||||
extern crate serialize as rustc_serialize;
|
|
||||||
extern crate syntax_pos;
|
|
||||||
extern crate unicode_width;
|
|
||||||
|
|
||||||
pub use emitter::ColorConfig;
|
pub use emitter::ColorConfig;
|
||||||
|
|
||||||
use self::Level::*;
|
use Level::*;
|
||||||
|
|
||||||
use emitter::{Emitter, EmitterWriter};
|
use emitter::{Emitter, EmitterWriter};
|
||||||
|
|
||||||
|
@ -144,7 +136,7 @@ impl CodeSuggestion {
|
||||||
use syntax_pos::{CharPos, Loc, Pos};
|
use syntax_pos::{CharPos, Loc, Pos};
|
||||||
|
|
||||||
fn push_trailing(buf: &mut String,
|
fn push_trailing(buf: &mut String,
|
||||||
line_opt: Option<&Cow<str>>,
|
line_opt: Option<&Cow<'_, str>>,
|
||||||
lo: &Loc,
|
lo: &Loc,
|
||||||
hi_opt: Option<&Loc>) {
|
hi_opt: Option<&Loc>) {
|
||||||
let (lo, hi_opt) = (lo.col.to_usize(), hi_opt.map(|hi| hi.col.to_usize()));
|
let (lo, hi_opt) = (lo.col.to_usize(), hi_opt.map(|hi| hi.col.to_usize()));
|
||||||
|
@ -247,7 +239,7 @@ impl FatalError {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for FatalError {
|
impl fmt::Display for FatalError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "parser fatal error")
|
write!(f, "parser fatal error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,7 +256,7 @@ impl error::Error for FatalError {
|
||||||
pub struct ExplicitBug;
|
pub struct ExplicitBug;
|
||||||
|
|
||||||
impl fmt::Display for ExplicitBug {
|
impl fmt::Display for ExplicitBug {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "parser internal bug")
|
write!(f, "parser internal bug")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -496,7 +488,7 @@ impl Handler {
|
||||||
DiagnosticBuilder::new(self, Level::Fatal, msg)
|
DiagnosticBuilder::new(self, Level::Fatal, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cancel(&self, err: &mut DiagnosticBuilder) {
|
pub fn cancel(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||||
err.cancel();
|
err.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,12 +690,12 @@ impl Handler {
|
||||||
self.taught_diagnostics.borrow_mut().insert(code.clone())
|
self.taught_diagnostics.borrow_mut().insert(code.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn force_print_db(&self, mut db: DiagnosticBuilder) {
|
pub fn force_print_db(&self, mut db: DiagnosticBuilder<'_>) {
|
||||||
self.emitter.borrow_mut().emit(&db);
|
self.emitter.borrow_mut().emit(&db);
|
||||||
db.cancel();
|
db.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_db(&self, db: &DiagnosticBuilder) {
|
fn emit_db(&self, db: &DiagnosticBuilder<'_>) {
|
||||||
let diagnostic = &**db;
|
let diagnostic = &**db;
|
||||||
|
|
||||||
TRACK_DIAGNOSTICS.with(|track_diagnostics| {
|
TRACK_DIAGNOSTICS.with(|track_diagnostics| {
|
||||||
|
@ -749,7 +741,7 @@ pub enum Level {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Level {
|
impl fmt::Display for Level {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
self.to_str().fmt(f)
|
self.to_str().fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Code for annotating snippets.
|
// Code for annotating snippets.
|
||||||
|
|
||||||
use Level;
|
use crate::Level;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
|
||||||
pub struct Line {
|
pub struct Line {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Code for creating styled buffers
|
// Code for creating styled buffers
|
||||||
|
|
||||||
use snippet::{Style, StyledString};
|
use crate::snippet::{Style, StyledString};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct StyledBuffer {
|
pub struct StyledBuffer {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue