diff options
| author | Matthias Einwag <matthias.einwag@live.com> | 2019-02-12 22:46:14 -0800 |
|---|---|---|
| committer | Matthias Einwag <matthias.einwag@live.com> | 2019-02-12 22:46:14 -0800 |
| commit | 871338c3aed87cb84f02ebd7fd9b447966d5b05d (patch) | |
| tree | a2e1315d7d17d0b9f3463686ed2fbf36f3238ec4 /src/librustc_errors | |
| parent | 1ef34a5a39641846e824b6450a705d6031002beb (diff) | |
| parent | 0f949c2fcc696d0260a99196d5e5400c59a26a54 (diff) | |
| download | rust-871338c3aed87cb84f02ebd7fd9b447966d5b05d.tar.gz rust-871338c3aed87cb84f02ebd7fd9b447966d5b05d.zip | |
Merging master
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/librustc_errors/diagnostic.rs | 14 | ||||
| -rw-r--r-- | src/librustc_errors/diagnostic_builder.rs | 23 | ||||
| -rw-r--r-- | src/librustc_errors/emitter.rs | 26 | ||||
| -rw-r--r-- | src/librustc_errors/lib.rs | 35 | ||||
| -rw-r--r-- | src/librustc_errors/snippet.rs | 2 | ||||
| -rw-r--r-- | src/librustc_errors/styled_buffer.rs | 2 |
7 files changed, 47 insertions, 56 deletions
diff --git a/src/librustc_errors/Cargo.toml b/src/librustc_errors/Cargo.toml index b24f8ddf4d9..02c011857bd 100644 --- a/src/librustc_errors/Cargo.toml +++ b/src/librustc_errors/Cargo.toml @@ -2,6 +2,7 @@ authors = ["The Rust Project Developers"] name = "rustc_errors" version = "0.0.0" +edition = "2018" [lib] name = "rustc_errors" diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index 06a1761a1e7..2c410f69bfc 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -1,11 +1,11 @@ -use CodeSuggestion; -use SubstitutionPart; -use Substitution; -use Applicability; -use Level; +use crate::CodeSuggestion; +use crate::SubstitutionPart; +use crate::Substitution; +use crate::Applicability; +use crate::Level; +use crate::snippet::Style; use std::fmt; use syntax_pos::{MultiSpan, Span}; -use snippet::Style; #[must_use] #[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] @@ -118,7 +118,7 @@ impl Diagnostic { self.level == Level::Cancelled } - /// Add a span/label to be included in the resulting snippet. + /// Adds a span/label to be included in the resulting snippet. /// This is pushed onto the `MultiSpan` that was created when the /// diagnostic was first built. If you don't call this function at /// all, and you just supplied a `Span` to create the diagnostic, diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index f423a4cd1a7..9d5e8d10b17 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -1,14 +1,15 @@ -use Diagnostic; -use DiagnosticId; -use DiagnosticStyledString; -use Applicability; +use crate::Diagnostic; +use crate::DiagnosticId; +use crate::DiagnosticStyledString; +use crate::Applicability; -use Level; -use Handler; +use crate::Level; +use crate::Handler; use std::fmt::{self, Debug}; use std::ops::{Deref, DerefMut}; use std::thread::panicking; use syntax_pos::{MultiSpan, Span}; +use log::debug; /// Used for emitting structured error messages and other diagnostic information. /// @@ -25,7 +26,7 @@ pub struct DiagnosticBuilder<'a> { /// In general, the `DiagnosticBuilder` uses deref to allow access to /// the fields and methods of the embedded `diagnostic` in a -/// transparent way. *However,* many of the methods are intended to +/// transparent way. *However,* many of the methods are intended to /// be used in a chained way, and hence ought to return `self`. In /// that case, we can't just naively forward to the method on the /// `diagnostic`, because the return type would be a `&Diagnostic` @@ -111,8 +112,8 @@ impl<'a> DiagnosticBuilder<'a> { // implements `Drop`. let diagnostic; unsafe { - diagnostic = ::std::ptr::read(&self.diagnostic); - ::std::mem::forget(self); + diagnostic = std::ptr::read(&self.diagnostic); + std::mem::forget(self); }; // Logging here is useful to help track down where in logs an error was // actually emitted. @@ -149,7 +150,7 @@ impl<'a> DiagnosticBuilder<'a> { self.cancel(); } - /// Add a span/label to be included in the resulting snippet. + /// Adds a span/label to be included in the resulting snippet. /// This is pushed onto the `MultiSpan` that was created when the /// diagnostic was first built. If you don't call this function at /// all, and you just supplied a `Span` to create the diagnostic, @@ -298,7 +299,7 @@ impl<'a> 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) } } diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 25d09a33c15..1c0c9d137e4 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -1,37 +1,35 @@ -use self::Destination::*; +use Destination::*; use syntax_pos::{SourceFile, Span, MultiSpan}; -use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, SourceMapperDyn, DiagnosticId}; -use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style}; -use styled_buffer::StyledBuffer; +use crate::{Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, SourceMapperDyn, DiagnosticId}; +use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style}; +use crate::styled_buffer::StyledBuffer; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; -use atty; use std::borrow::Cow; use std::io::prelude::*; use std::io; use std::cmp::{min, Reverse}; use termcolor::{StandardStream, ColorChoice, ColorSpec, BufferWriter}; use termcolor::{WriteColor, Color, Buffer}; -use unicode_width; const ANONYMIZED_LINE_NUM: &str = "LL"; /// Emitter trait for emitting errors. pub trait Emitter { /// Emit a structured diagnostic. - fn emit(&mut self, db: &DiagnosticBuilder); + fn emit(&mut self, db: &DiagnosticBuilder<'_>); - /// Check if should show explanations about "rustc --explain" + /// Checks if should show explanations about "rustc --explain" fn should_show_explain(&self) -> bool { true } } 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 children = db.children.clone(); let mut suggestions: &[_] = &[]; @@ -674,8 +672,8 @@ impl EmitterWriter { // | | something about `foo` // | something about `fn foo()` annotations_position.sort_by(|a, b| { - // Decreasing order - a.1.len().cmp(&b.1.len()).reverse() + // Decreasing order. When `a` and `b` are the same length, prefer `Primary`. + (a.1.len(), !a.1.is_primary).cmp(&(b.1.len(), !b.1.is_primary)).reverse() }); // Write the underlines. @@ -870,7 +868,7 @@ impl EmitterWriter { } } - /// Add a left margin to every line but the first, given a padding length and the label being + /// Adds a left margin to every line but the first, given a padding length and the label being /// displayed, keeping the provided highlighting. fn msg_to_buffer(&self, buffer: &mut StyledBuffer, @@ -897,7 +895,7 @@ impl EmitterWriter { // `max_line_num_len` let padding = " ".repeat(padding + label.len() + 5); - /// Return whether `style`, or the override if present and the style is `NoStyle`. + /// Returns `true` if `style`, or the override if present and the style is `NoStyle`. fn style_or_override(style: Style, override_style: Option<Style>) -> Style { if let Some(o) = override_style { if style == Style::NoStyle { @@ -1431,7 +1429,7 @@ fn emit_to_destination(rendered_buffer: &[Vec<StyledString>], dst: &mut Destination, short_message: bool) -> io::Result<()> { - use lock; + use crate::lock; let mut dst = dst.writable(); diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 64d5ca0c2a7..93d33d99361 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -1,6 +1,4 @@ -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", - html_favicon_url = "https://doc.rust-lang.org/favicon.ico", - html_root_url = "https://doc.rust-lang.org/nightly/")] +#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![feature(custom_attribute)] #![allow(unused_attributes)] @@ -8,21 +6,14 @@ #![cfg_attr(unix, feature(libc))] #![feature(nll)] #![feature(optin_builtin_traits)] +#![deny(rust_2018_idioms)] -extern crate atty; -extern crate termcolor; -#[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; +#[allow(unused_extern_crates)] +extern crate serialize as rustc_serialize; // used by deriving pub use emitter::ColorConfig; -use self::Level::*; +use Level::*; use emitter::{Emitter, EmitterWriter}; @@ -144,7 +135,7 @@ impl CodeSuggestion { use syntax_pos::{CharPos, Loc, Pos}; fn push_trailing(buf: &mut String, - line_opt: Option<&Cow<str>>, + line_opt: Option<&Cow<'_, str>>, lo: &Loc, hi_opt: Option<&Loc>) { let (lo, hi_opt) = (lo.col.to_usize(), hi_opt.map(|hi| hi.col.to_usize())); @@ -247,7 +238,7 @@ impl 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") } } @@ -264,7 +255,7 @@ impl error::Error for FatalError { pub struct 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") } } @@ -399,7 +390,7 @@ impl Handler { /// Resets the diagnostic error count as well as the cached emitted diagnostics. /// - /// NOTE: DO NOT call this function from rustc. It is only meant to be called from external + /// NOTE: *do not* call this function from rustc. It is only meant to be called from external /// tools that want to reuse a `Parser` cleaning the previously emitted diagnostics as well as /// the overall count of emitted error diagnostics. pub fn reset_err_count(&self) { @@ -496,7 +487,7 @@ impl Handler { DiagnosticBuilder::new(self, Level::Fatal, msg) } - pub fn cancel(&self, err: &mut DiagnosticBuilder) { + pub fn cancel(&self, err: &mut DiagnosticBuilder<'_>) { err.cancel(); } @@ -698,12 +689,12 @@ impl Handler { 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); db.cancel(); } - fn emit_db(&self, db: &DiagnosticBuilder) { + fn emit_db(&self, db: &DiagnosticBuilder<'_>) { let diagnostic = &**db; TRACK_DIAGNOSTICS.with(|track_diagnostics| { @@ -749,7 +740,7 @@ pub enum 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) } } diff --git a/src/librustc_errors/snippet.rs b/src/librustc_errors/snippet.rs index da1da77f398..0c62ff0ff89 100644 --- a/src/librustc_errors/snippet.rs +++ b/src/librustc_errors/snippet.rs @@ -1,6 +1,6 @@ // Code for annotating snippets. -use Level; +use crate::Level; #[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct Line { diff --git a/src/librustc_errors/styled_buffer.rs b/src/librustc_errors/styled_buffer.rs index 880f09e75e3..6e03618d2b0 100644 --- a/src/librustc_errors/styled_buffer.rs +++ b/src/librustc_errors/styled_buffer.rs @@ -1,6 +1,6 @@ // Code for creating styled buffers -use snippet::{Style, StyledString}; +use crate::snippet::{Style, StyledString}; #[derive(Debug)] pub struct StyledBuffer { |
