From 969b74144641bf1c8ae5aba0581f4b52a4c15bac Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Wed, 13 Nov 2019 00:21:05 +0100 Subject: [PATCH 01/14] protect creation of destructors by a mutex add on HermizCore an additional lock to protect static data --- src/libstd/sys/hermit/thread_local.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libstd/sys/hermit/thread_local.rs b/src/libstd/sys/hermit/thread_local.rs index 4bc8c4d5883da..268fb770eae2c 100644 --- a/src/libstd/sys/hermit/thread_local.rs +++ b/src/libstd/sys/hermit/thread_local.rs @@ -3,6 +3,7 @@ use crate::collections::BTreeMap; use crate::ptr; use crate::sync::atomic::{AtomicUsize, Ordering}; +use crate::sys_common::mutex::Mutex; pub type Key = usize; @@ -11,6 +12,7 @@ type Dtor = unsafe extern fn(*mut u8); static NEXT_KEY: AtomicUsize = AtomicUsize::new(0); static mut KEYS: *mut BTreeMap> = ptr::null_mut(); +static KEYS_LOCK: Mutex = Mutex::new(); #[thread_local] static mut LOCALS: *mut BTreeMap = ptr::null_mut(); @@ -32,6 +34,7 @@ unsafe fn locals() -> &'static mut BTreeMap { #[inline] pub unsafe fn create(dtor: Option) -> Key { let key = NEXT_KEY.fetch_add(1, Ordering::SeqCst); + let _guard = KEYS_LOCK.lock(); keys().insert(key, dtor); key } From b6d93d9167ea4b8d28d27429a0c14e8dc0060d86 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 15 Nov 2019 11:52:46 +0100 Subject: [PATCH 02/14] libpanic_unwind for Miri: make sure we have the SEH lang items when needed --- src/libpanic_unwind/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs index d97a7a8a87d8d..c69399a87d969 100644 --- a/src/libpanic_unwind/lib.rs +++ b/src/libpanic_unwind/lib.rs @@ -39,6 +39,10 @@ cfg_if::cfg_if! { if #[cfg(miri)] { #[path = "miri.rs"] mod imp; + // On MSVC we need the SEH lang items as well... + #[cfg(all(target_env = "msvc", not(target_arch = "aarch64")))] + #[allow(unused)] + mod seh; } else if #[cfg(target_os = "emscripten")] { #[path = "emcc.rs"] mod imp; From e1a87ca17a60aadae36b6785b7204610e02ee994 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 14 Nov 2019 14:01:03 -0500 Subject: [PATCH 03/14] Move FatalError to syntax_pos This is a bit unfortunate, but code needs to be able to fatally error early on (in particular, syntax_pos after we move SourceMap there). It's also a tiny bit of code, which means it's ultimately not that bad. --- src/librustc_errors/lib.rs | 31 +------------------------------ src/libsyntax_pos/fatal_error.rs | 30 ++++++++++++++++++++++++++++++ src/libsyntax_pos/lib.rs | 1 + 3 files changed, 32 insertions(+), 30 deletions(-) create mode 100644 src/libsyntax_pos/fatal_error.rs diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 8ee28875c6259..ee35d23af34fd 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -259,36 +259,7 @@ impl CodeSuggestion { } } -/// Used as a return value to signify a fatal error occurred. (It is also -/// used as the argument to panic at the moment, but that will eventually -/// not be true.) -#[derive(Copy, Clone, Debug)] -#[must_use] -pub struct FatalError; - -pub struct FatalErrorMarker; - -// Don't implement Send on FatalError. This makes it impossible to panic!(FatalError). -// We don't want to invoke the panic handler and print a backtrace for fatal errors. -impl !Send for FatalError {} - -impl FatalError { - pub fn raise(self) -> ! { - panic::resume_unwind(Box::new(FatalErrorMarker)) - } -} - -impl fmt::Display for FatalError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "parser fatal error") - } -} - -impl error::Error for FatalError { - fn description(&self) -> &str { - "The parser has encountered a fatal error" - } -} +pub use syntax_pos::fatal_error::{FatalError, FatalErrorMarker}; /// Signifies that the compiler died with an explicit call to `.bug` /// or `.span_bug` rather than a failed assertion, etc. diff --git a/src/libsyntax_pos/fatal_error.rs b/src/libsyntax_pos/fatal_error.rs new file mode 100644 index 0000000000000..cf7c677d59d95 --- /dev/null +++ b/src/libsyntax_pos/fatal_error.rs @@ -0,0 +1,30 @@ +/// Used as a return value to signify a fatal error occurred. (It is also +/// used as the argument to panic at the moment, but that will eventually +/// not be true.) +#[derive(Copy, Clone, Debug)] +#[must_use] +pub struct FatalError; + +pub struct FatalErrorMarker; + +// Don't implement Send on FatalError. This makes it impossible to panic!(FatalError). +// We don't want to invoke the panic handler and print a backtrace for fatal errors. +impl !Send for FatalError {} + +impl FatalError { + pub fn raise(self) -> ! { + std::panic::resume_unwind(Box::new(FatalErrorMarker)) + } +} + +impl std::fmt::Display for FatalError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "parser fatal error") + } +} + +impl std::error::Error for FatalError { + fn description(&self) -> &str { + "The parser has encountered a fatal error" + } +} diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index a762d8af49a21..50839638bb4af 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -29,6 +29,7 @@ pub mod symbol; pub use symbol::{Symbol, sym}; mod analyze_source_file; +pub mod fatal_error; use rustc_data_structures::stable_hasher::StableHasher; use rustc_data_structures::sync::{Lrc, Lock}; From 942f0a6f7a82facc30501232e28759cab54a21b3 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 15 Nov 2019 08:27:09 -0500 Subject: [PATCH 04/14] Move SourceMap to syntax_pos This does not update the use sites or delete the now unnecessary SourceMapper trait, to allow git to interpret the file move as a rename rather than a new file. --- Cargo.lock | 1 + src/libsyntax/lib.rs | 2 +- src/libsyntax_pos/Cargo.toml | 1 + src/libsyntax_pos/lib.rs | 2 ++ src/{libsyntax => libsyntax_pos}/source_map.rs | 6 +++--- src/{libsyntax => libsyntax_pos}/source_map/tests.rs | 0 6 files changed, 8 insertions(+), 4 deletions(-) rename src/{libsyntax => libsyntax_pos}/source_map.rs (99%) rename src/{libsyntax => libsyntax_pos}/source_map/tests.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 781184af9a96c..51bdc06eee8d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4445,6 +4445,7 @@ version = "0.0.0" dependencies = [ "arena", "cfg-if", + "log", "rustc_data_structures", "rustc_index", "rustc_macros", diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 6290b2137ea9a..a1de0a2c9e461 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -92,7 +92,7 @@ pub mod json; pub mod ast; pub mod attr; pub mod expand; -pub mod source_map; +pub use syntax_pos::source_map; pub mod entry; pub mod feature_gate; pub mod mut_visit; diff --git a/src/libsyntax_pos/Cargo.toml b/src/libsyntax_pos/Cargo.toml index 378f7a955a36f..2cac76085d297 100644 --- a/src/libsyntax_pos/Cargo.toml +++ b/src/libsyntax_pos/Cargo.toml @@ -18,3 +18,4 @@ arena = { path = "../libarena" } scoped-tls = "1.0" unicode-width = "0.1.4" cfg-if = "0.1.2" +log = "0.4" diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 50839638bb4af..b88d6dbc3f379 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -16,6 +16,8 @@ use rustc_serialize::{Encodable, Decodable, Encoder, Decoder}; +pub mod source_map; + pub mod edition; use edition::Edition; pub mod hygiene; diff --git a/src/libsyntax/source_map.rs b/src/libsyntax_pos/source_map.rs similarity index 99% rename from src/libsyntax/source_map.rs rename to src/libsyntax_pos/source_map.rs index d9f618602a40b..035e61f9dea73 100644 --- a/src/libsyntax/source_map.rs +++ b/src/libsyntax_pos/source_map.rs @@ -7,8 +7,8 @@ //! within the `SourceMap`, which upon request can be converted to line and column //! information, source code snippets, etc. -pub use syntax_pos::*; -pub use syntax_pos::hygiene::{ExpnKind, ExpnData}; +pub use crate::*; +pub use crate::hygiene::{ExpnKind, ExpnData}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::StableHasher; @@ -216,7 +216,7 @@ impl SourceMap { self.try_new_source_file(filename, src) .unwrap_or_else(|OffsetOverflowError| { eprintln!("fatal error: rustc does not support files larger than 4GB"); - errors::FatalError.raise() + crate::fatal_error::FatalError.raise() }) } diff --git a/src/libsyntax/source_map/tests.rs b/src/libsyntax_pos/source_map/tests.rs similarity index 100% rename from src/libsyntax/source_map/tests.rs rename to src/libsyntax_pos/source_map/tests.rs From 3f93ffc3334b77cc9025f68dfcea92098987abf3 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 15 Nov 2019 08:32:31 -0500 Subject: [PATCH 05/14] Remove SourceMapper trait SourceMap is now in the root of all rustc-specific crates, syntax_pos, so there's no need for the trait object to decouple the dependencies between librustc_errors and libsyntax as was needed previously. --- src/librustc_codegen_ssa/back/write.rs | 5 ++- .../annotate_snippet_emitter_writer.rs | 11 ++--- src/librustc_errors/emitter.rs | 25 +++++------ src/librustc_errors/lib.rs | 33 +++------------ src/libsyntax/json.rs | 6 +-- src/libsyntax_pos/source_map.rs | 42 ++++--------------- 6 files changed, 38 insertions(+), 84 deletions(-) diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index ed901fa064a4e..f35a31d59fe62 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -23,7 +23,8 @@ use rustc_data_structures::profiling::SelfProfilerRef; use rustc_fs_util::link_or_copy; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::Lrc; -use rustc_errors::{Handler, Level, FatalError, DiagnosticId, SourceMapperDyn}; +use rustc_errors::{Handler, Level, FatalError, DiagnosticId}; +use syntax_pos::source_map::SourceMap; use rustc_errors::emitter::{Emitter}; use rustc_target::spec::MergeFunctions; use syntax::attr; @@ -1679,7 +1680,7 @@ impl Emitter for SharedEmitter { } drop(self.sender.send(SharedEmitterMessage::AbortIfErrors)); } - fn source_map(&self) -> Option<&Lrc> { + fn source_map(&self) -> Option<&Lrc> { None } } diff --git a/src/librustc_errors/annotate_snippet_emitter_writer.rs b/src/librustc_errors/annotate_snippet_emitter_writer.rs index 491bc2aa6a2eb..4c5d0178b2c64 100644 --- a/src/librustc_errors/annotate_snippet_emitter_writer.rs +++ b/src/librustc_errors/annotate_snippet_emitter_writer.rs @@ -6,9 +6,10 @@ //! [annotate_snippets]: https://docs.rs/crate/annotate-snippets/ use syntax_pos::{SourceFile, MultiSpan, Loc}; +use syntax_pos::source_map::SourceMap; use crate::{ Level, CodeSuggestion, Diagnostic, Emitter, - SourceMapperDyn, SubDiagnostic, DiagnosticId + SubDiagnostic, DiagnosticId }; use crate::emitter::FileWithAnnotatedLines; use rustc_data_structures::sync::Lrc; @@ -20,7 +21,7 @@ use annotate_snippets::formatter::DisplayListFormatter; /// Generates diagnostics using annotate-snippet pub struct AnnotateSnippetEmitterWriter { - source_map: Option>, + source_map: Option>, /// If true, hides the longer explanation text short_message: bool, /// If true, will normalize line numbers with `LL` to prevent noise in UI test diffs. @@ -49,7 +50,7 @@ impl Emitter for AnnotateSnippetEmitterWriter { &suggestions); } - fn source_map(&self) -> Option<&Lrc> { + fn source_map(&self) -> Option<&Lrc> { self.source_map.as_ref() } @@ -61,7 +62,7 @@ impl Emitter for AnnotateSnippetEmitterWriter { /// Collects all the data needed to generate the data structures needed for the /// `annotate-snippets` library. struct DiagnosticConverter<'a> { - source_map: Option>, + source_map: Option>, level: Level, message: String, code: Option, @@ -168,7 +169,7 @@ impl<'a> DiagnosticConverter<'a> { impl AnnotateSnippetEmitterWriter { pub fn new( - source_map: Option>, + source_map: Option>, short_message: bool, external_macro_backtrace: bool, ) -> Self { diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 291920f17f66d..ea779982ba961 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -10,10 +10,11 @@ use Destination::*; use syntax_pos::{SourceFile, Span, MultiSpan}; +use syntax_pos::source_map::SourceMap; use crate::{ Level, CodeSuggestion, Diagnostic, SubDiagnostic, pluralize, - SuggestionStyle, SourceMapper, SourceMapperDyn, DiagnosticId, + SuggestionStyle, DiagnosticId, }; use crate::Level::Error; use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style}; @@ -49,7 +50,7 @@ impl HumanReadableErrorType { pub fn new_emitter( self, dst: Box, - source_map: Option>, + source_map: Option>, teach: bool, terminal_width: Option, external_macro_backtrace: bool, @@ -192,7 +193,7 @@ pub trait Emitter { true } - fn source_map(&self) -> Option<&Lrc>; + fn source_map(&self) -> Option<&Lrc>; /// Formats the substitutions of the primary_span /// @@ -271,7 +272,7 @@ pub trait Emitter { // point directly at <*macros>. Since these are often difficult to read, this // will change the span to point at the use site. fn fix_multispans_in_std_macros(&self, - source_map: &Option>, + source_map: &Option>, span: &mut MultiSpan, children: &mut Vec, level: &Level, @@ -311,7 +312,7 @@ pub trait Emitter { // <*macros>. Since these locations are often difficult to read, we move these Spans from // <*macros> to their corresponding use site. fn fix_multispan_in_std_macros(&self, - source_map: &Option>, + source_map: &Option>, span: &mut MultiSpan, always_backtrace: bool) -> bool { let sm = match source_map { @@ -397,7 +398,7 @@ pub trait Emitter { } impl Emitter for EmitterWriter { - fn source_map(&self) -> Option<&Lrc> { + fn source_map(&self) -> Option<&Lrc> { self.sm.as_ref() } @@ -428,7 +429,7 @@ impl Emitter for EmitterWriter { pub struct SilentEmitter; impl Emitter for SilentEmitter { - fn source_map(&self) -> Option<&Lrc> { None } + fn source_map(&self) -> Option<&Lrc> { None } fn emit_diagnostic(&mut self, _: &Diagnostic) {} } @@ -476,7 +477,7 @@ impl ColorConfig { /// Handles the writing of `HumanReadableErrorType::Default` and `HumanReadableErrorType::Short` pub struct EmitterWriter { dst: Destination, - sm: Option>, + sm: Option>, short_message: bool, teach: bool, ui_testing: bool, @@ -495,7 +496,7 @@ pub struct FileWithAnnotatedLines { impl EmitterWriter { pub fn stderr( color_config: ColorConfig, - source_map: Option>, + source_map: Option>, short_message: bool, teach: bool, terminal_width: Option, @@ -515,7 +516,7 @@ impl EmitterWriter { pub fn new( dst: Box, - source_map: Option>, + source_map: Option>, short_message: bool, teach: bool, colored: bool, @@ -1685,7 +1686,7 @@ impl FileWithAnnotatedLines { /// This helps us quickly iterate over the whole message (including secondary file spans) pub fn collect_annotations( msp: &MultiSpan, - source_map: &Option> + source_map: &Option> ) -> Vec { fn add_annotation_to_file(file_vec: &mut Vec, file: Lrc, @@ -2067,7 +2068,7 @@ impl<'a> Drop for WritableDst<'a> { } /// Whether the original and suggested code are visually similar enough to warrant extra wording. -pub fn is_case_difference(sm: &dyn SourceMapper, suggested: &str, sp: Span) -> bool { +pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool { // FIXME: this should probably be extended to also account for `FO0` → `FOO` and unicode. let found = sm.span_to_snippet(sp).unwrap(); let ascii_confusables = &['c', 'f', 'i', 'k', 'o', 's', 'u', 'v', 'w', 'x', 'y', 'z']; diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index ee35d23af34fd..1a6ac328a47d4 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -18,6 +18,8 @@ use registry::Registry; use rustc_data_structures::sync::{self, Lrc, Lock}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::stable_hasher::StableHasher; +use syntax_pos::source_map::SourceMap; +use syntax_pos::{Loc, Span, MultiSpan}; use std::borrow::Cow; use std::cell::Cell; @@ -36,17 +38,6 @@ pub mod registry; mod styled_buffer; mod lock; -use syntax_pos::{ - BytePos, - FileLinesResult, - FileName, - Loc, - MultiSpan, - SourceFile, - Span, - SpanSnippetError, -}; - pub type PResult<'a, T> = Result>; // `PResult` is used a lot. Make sure it doesn't unintentionally get bigger. @@ -150,26 +141,12 @@ pub struct SubstitutionPart { pub snippet: String, } -pub type SourceMapperDyn = dyn SourceMapper + sync::Send + sync::Sync; - -pub trait SourceMapper { - fn lookup_char_pos(&self, pos: BytePos) -> Loc; - fn span_to_lines(&self, sp: Span) -> FileLinesResult; - fn span_to_string(&self, sp: Span) -> String; - fn span_to_snippet(&self, sp: Span) -> Result; - fn span_to_filename(&self, sp: Span) -> FileName; - fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option; - fn call_span_if_macro(&self, sp: Span) -> Span; - fn ensure_source_file_source_present(&self, source_file: Lrc) -> bool; - fn doctest_offset_line(&self, file: &FileName, line: usize) -> usize; -} - impl CodeSuggestion { /// Returns the assembled code suggestions, whether they should be shown with an underline /// and whether the substitution only differs in capitalization. pub fn splice_lines( &self, - cm: &SourceMapperDyn, + cm: &SourceMap, ) -> Vec<(String, Vec, bool)> { use syntax_pos::{CharPos, Pos}; @@ -376,7 +353,7 @@ impl Handler { color_config: ColorConfig, can_emit_warnings: bool, treat_err_as_bug: Option, - cm: Option>, + cm: Option>, ) -> Self { Self::with_tty_emitter_and_flags( color_config, @@ -391,7 +368,7 @@ impl Handler { pub fn with_tty_emitter_and_flags( color_config: ColorConfig, - cm: Option>, + cm: Option>, flags: HandlerFlags, ) -> Self { let emitter = Box::new(EmitterWriter::stderr( diff --git a/src/libsyntax/json.rs b/src/libsyntax/json.rs index 0b157938375e1..6096a930acfc4 100644 --- a/src/libsyntax/json.rs +++ b/src/libsyntax/json.rs @@ -12,7 +12,7 @@ use crate::source_map::{SourceMap, FilePathMapping}; use errors::registry::Registry; -use errors::{SubDiagnostic, CodeSuggestion, SourceMapper, SourceMapperDyn}; +use errors::{SubDiagnostic, CodeSuggestion}; use errors::{DiagnosticId, Applicability}; use errors::emitter::{Emitter, HumanReadableErrorType}; @@ -31,7 +31,7 @@ mod tests; pub struct JsonEmitter { dst: Box, registry: Option, - sm: Lrc, + sm: Lrc, pretty: bool, ui_testing: bool, json_rendered: HumanReadableErrorType, @@ -116,7 +116,7 @@ impl Emitter for JsonEmitter { } } - fn source_map(&self) -> Option<&Lrc> { + fn source_map(&self) -> Option<&Lrc> { Some(&self.sm) } diff --git a/src/libsyntax_pos/source_map.rs b/src/libsyntax_pos/source_map.rs index 035e61f9dea73..77d9807225ec8 100644 --- a/src/libsyntax_pos/source_map.rs +++ b/src/libsyntax_pos/source_map.rs @@ -22,8 +22,6 @@ use std::fs; use std::io; use log::debug; -use errors::SourceMapper; - #[cfg(test)] mod tests; @@ -956,28 +954,15 @@ impl SourceMap { None } -} - -impl SourceMapper for SourceMap { - fn lookup_char_pos(&self, pos: BytePos) -> Loc { - self.lookup_char_pos(pos) - } - fn span_to_lines(&self, sp: Span) -> FileLinesResult { - self.span_to_lines(sp) - } - fn span_to_string(&self, sp: Span) -> String { - self.span_to_string(sp) - } - fn span_to_snippet(&self, sp: Span) -> Result { - self.span_to_snippet(sp) - } - fn span_to_filename(&self, sp: Span) -> FileName { - self.span_to_filename(sp) - } - fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option { - self.merge_spans(sp_lhs, sp_rhs) + pub fn ensure_source_file_source_present(&self, source_file: Lrc) -> bool { + source_file.add_external_src( + || match source_file.name { + FileName::Real(ref name) => self.file_loader.read_file(name).ok(), + _ => None, + } + ) } - fn call_span_if_macro(&self, sp: Span) -> Span { + pub fn call_span_if_macro(&self, sp: Span) -> Span { if self.span_to_filename(sp.clone()).is_macros() { let v = sp.macro_backtrace(); if let Some(use_site) = v.last() { @@ -986,17 +971,6 @@ impl SourceMapper for SourceMap { } sp } - fn ensure_source_file_source_present(&self, source_file: Lrc) -> bool { - source_file.add_external_src( - || match source_file.name { - FileName::Real(ref name) => self.file_loader.read_file(name).ok(), - _ => None, - } - ) - } - fn doctest_offset_line(&self, file: &FileName, line: usize) -> usize { - self.doctest_offset_line(file, line) - } } #[derive(Clone)] From c31a8754e3f3a9274759cb429aad4ae594d39e29 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 14 Nov 2019 17:24:44 -0500 Subject: [PATCH 06/14] Move JSON emitter to rustc_errors --- src/librustc/session/mod.rs | 2 +- src/{libsyntax => librustc_errors}/json.rs | 16 ++++++++-------- src/{libsyntax => librustc_errors}/json/tests.rs | 14 ++++++++++---- src/librustc_errors/lib.rs | 1 + src/librustdoc/core.rs | 2 +- src/libsyntax/lib.rs | 2 -- src/tools/compiletest/src/json.rs | 2 +- 7 files changed, 22 insertions(+), 17 deletions(-) rename src/{libsyntax => librustc_errors}/json.rs (97%) rename src/{libsyntax => librustc_errors}/json/tests.rs (92%) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index a69584cb90ad1..4fbc8da9cbf02 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -22,7 +22,7 @@ use errors::emitter::HumanReadableErrorType; use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter}; use syntax::edition::Edition; use syntax::feature_gate::{self, AttributeType}; -use syntax::json::JsonEmitter; +use errors::json::JsonEmitter; use syntax::source_map; use syntax::sess::{ParseSess, ProcessCfgMod}; use syntax::symbol::Symbol; diff --git a/src/libsyntax/json.rs b/src/librustc_errors/json.rs similarity index 97% rename from src/libsyntax/json.rs rename to src/librustc_errors/json.rs index 6096a930acfc4..ebbd49bd84a73 100644 --- a/src/libsyntax/json.rs +++ b/src/librustc_errors/json.rs @@ -9,15 +9,15 @@ // FIXME: spec the JSON output properly. -use crate::source_map::{SourceMap, FilePathMapping}; +use syntax_pos::source_map::{SourceMap, FilePathMapping}; -use errors::registry::Registry; -use errors::{SubDiagnostic, CodeSuggestion}; -use errors::{DiagnosticId, Applicability}; -use errors::emitter::{Emitter, HumanReadableErrorType}; +use crate::registry::Registry; +use crate::{SubDiagnostic, CodeSuggestion}; +use crate::{DiagnosticId, Applicability}; +use crate::emitter::{Emitter, HumanReadableErrorType}; use syntax_pos::{MacroBacktrace, Span, SpanLabel, MultiSpan}; -use rustc_data_structures::sync::{self, Lrc}; +use rustc_data_structures::sync::Lrc; use std::io::{self, Write}; use std::path::Path; use std::vec; @@ -92,7 +92,7 @@ impl JsonEmitter { } impl Emitter for JsonEmitter { - fn emit_diagnostic(&mut self, diag: &errors::Diagnostic) { + fn emit_diagnostic(&mut self, diag: &crate::Diagnostic) { let data = Diagnostic::from_errors_diagnostic(diag, self); let result = if self.pretty { writeln!(&mut self.dst, "{}", as_pretty_json(&data)) @@ -212,7 +212,7 @@ struct ArtifactNotification<'a> { } impl Diagnostic { - fn from_errors_diagnostic(diag: &errors::Diagnostic, + fn from_errors_diagnostic(diag: &crate::Diagnostic, je: &JsonEmitter) -> Diagnostic { let sugg = diag.suggestions.iter().map(|sugg| { diff --git a/src/libsyntax/json/tests.rs b/src/librustc_errors/json/tests.rs similarity index 92% rename from src/libsyntax/json/tests.rs rename to src/librustc_errors/json/tests.rs index 1edefd5bc4bd8..4ab5cd21b0b00 100644 --- a/src/libsyntax/json/tests.rs +++ b/src/librustc_errors/json/tests.rs @@ -1,11 +1,10 @@ use super::*; use crate::json::JsonEmitter; -use crate::source_map::{FilePathMapping, SourceMap}; -use crate::with_default_globals; +use syntax_pos::source_map::{FilePathMapping, SourceMap}; -use errors::emitter::{ColorConfig, HumanReadableErrorType}; -use errors::Handler; +use crate::emitter::{ColorConfig, HumanReadableErrorType}; +use crate::Handler; use rustc_serialize::json::decode; use syntax_pos::{BytePos, Span}; @@ -40,6 +39,13 @@ impl Write for Shared { } } +fn with_default_globals(f: impl FnOnce()) { + let globals = syntax_pos::Globals::new(syntax_pos::edition::DEFAULT_EDITION); + syntax_pos::GLOBALS.set(&globals, || { + syntax_pos::GLOBALS.set(&globals, f) + }) +} + /// Test the span yields correct positions in JSON. fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) { let expected_output = TestData { spans: vec![expected_output] }; diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 1a6ac328a47d4..17765ef9deefa 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -37,6 +37,7 @@ mod snippet; pub mod registry; mod styled_buffer; mod lock; +pub mod json; pub type PResult<'a, T> = Result>; diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index a40325448b10b..507732a9107fb 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -18,7 +18,7 @@ use syntax::ast::CRATE_NODE_ID; use syntax::source_map; use syntax::attr; use syntax::feature_gate::UnstableFeatures; -use syntax::json::JsonEmitter; +use errors::json::JsonEmitter; use syntax::symbol::sym; use syntax_pos::DUMMY_SP; use errors; diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index a1de0a2c9e461..e3eca75dfe7e7 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -87,8 +87,6 @@ pub mod util { pub mod map_in_place; } -pub mod json; - pub mod ast; pub mod attr; pub mod expand; diff --git a/src/tools/compiletest/src/json.rs b/src/tools/compiletest/src/json.rs index 02b09e21ff022..7930d1249e7dc 100644 --- a/src/tools/compiletest/src/json.rs +++ b/src/tools/compiletest/src/json.rs @@ -1,4 +1,4 @@ -//! These structs are a subset of the ones found in `syntax::json`. +//! These structs are a subset of the ones found in `rustc_errors::json`. //! They are only used for deserialization of JSON output provided by libtest. use crate::errors::{Error, ErrorKind}; From b8dca6c82714d04a26071a48cd671ad707249950 Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Thu, 14 Nov 2019 07:26:22 -0800 Subject: [PATCH 07/14] Add --force-run-in-process unstable libtest option --- src/libtest/cli.rs | 4 ++++ src/libtest/lib.rs | 2 +- src/libtest/tests.rs | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libtest/cli.rs b/src/libtest/cli.rs index a34426305be2e..c97cb0e0605a2 100644 --- a/src/libtest/cli.rs +++ b/src/libtest/cli.rs @@ -13,6 +13,7 @@ pub struct TestOpts { pub list: bool, pub filter: Option, pub filter_exact: bool, + pub force_run_in_process: bool, pub exclude_should_panic: bool, pub run_ignored: RunIgnored, pub run_tests: bool, @@ -46,6 +47,7 @@ fn optgroups() -> getopts::Options { let mut opts = getopts::Options::new(); opts.optflag("", "include-ignored", "Run ignored and not ignored tests") .optflag("", "ignored", "Run only ignored tests") + .optflag("", "force-run-in-process", "Forces tests to run in-process when panic=abort") .optflag("", "exclude-should-panic", "Excludes tests marked as should_panic") .optflag("", "test", "Run tests and not benchmarks") .optflag("", "bench", "Run benchmarks instead of tests") @@ -233,6 +235,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes { let allow_unstable = get_allow_unstable(&matches)?; // Unstable flags + let force_run_in_process = unstable_optflag!(matches, allow_unstable, "force-run-in-process"); let exclude_should_panic = unstable_optflag!(matches, allow_unstable, "exclude-should-panic"); let include_ignored = unstable_optflag!(matches, allow_unstable, "include-ignored"); let time_options = get_time_options(&matches, allow_unstable)?; @@ -259,6 +262,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes { list, filter, filter_exact: exact, + force_run_in_process, exclude_should_panic, run_ignored, run_tests, diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 341a2e18db5fc..7647978b3d975 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -254,7 +254,7 @@ where let mut pending = 0; let (tx, rx) = channel::(); - let run_strategy = if opts.options.panic_abort { + let run_strategy = if opts.options.panic_abort && !opts.force_run_in_process { RunStrategy::SpawnPrimary } else { RunStrategy::InProcess diff --git a/src/libtest/tests.rs b/src/libtest/tests.rs index e0e211444cff5..5f55b647f5e78 100644 --- a/src/libtest/tests.rs +++ b/src/libtest/tests.rs @@ -24,6 +24,7 @@ impl TestOpts { list: false, filter: None, filter_exact: false, + force_run_in_process: false, exclude_should_panic: false, run_ignored: RunIgnored::No, run_tests: false, From d252ba35d490f16d2efefdedc581b1c9d6d64ecb Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Thu, 14 Nov 2019 07:26:41 -0800 Subject: [PATCH 08/14] Improve error message for tests with panic=abort --- src/libsyntax_ext/test_harness.rs | 3 ++- src/test/ui/test-panic-abort-disabled.rs | 2 +- src/test/ui/test-panic-abort-disabled.stderr | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libsyntax_ext/test_harness.rs b/src/libsyntax_ext/test_harness.rs index 1492f6f575ff7..659780d7a434b 100644 --- a/src/libsyntax_ext/test_harness.rs +++ b/src/libsyntax_ext/test_harness.rs @@ -67,7 +67,8 @@ pub fn inject( PanicStrategy::Unwind } (PanicStrategy::Abort, false) => { - span_diagnostic.err("building tests with panic=abort is not yet supported"); + span_diagnostic.err("building tests with panic=abort is not supported \ + without `-Zpanic_abort_tests`"); PanicStrategy::Unwind } (PanicStrategy::Unwind, _) => PanicStrategy::Unwind, diff --git a/src/test/ui/test-panic-abort-disabled.rs b/src/test/ui/test-panic-abort-disabled.rs index f24046ff0e8d2..4adb161d9ee4b 100644 --- a/src/test/ui/test-panic-abort-disabled.rs +++ b/src/test/ui/test-panic-abort-disabled.rs @@ -1,4 +1,4 @@ -// error-pattern:building tests with panic=abort is not yet supported +// error-pattern:building tests with panic=abort is not supported // no-prefer-dynamic // compile-flags: --test -Cpanic=abort // run-flags: --test-threads=1 diff --git a/src/test/ui/test-panic-abort-disabled.stderr b/src/test/ui/test-panic-abort-disabled.stderr index a8d9bad43ed3c..9c65c7360c108 100644 --- a/src/test/ui/test-panic-abort-disabled.stderr +++ b/src/test/ui/test-panic-abort-disabled.stderr @@ -1,4 +1,4 @@ -error: building tests with panic=abort is not yet supported +error: building tests with panic=abort is not supported without `-Zpanic_abort_tests` error: aborting due to previous error From 4e621a8b0cdb2a516e74d21c87aac7b75f6e5378 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 14 Nov 2019 16:50:32 +0900 Subject: [PATCH 09/14] Add test for issue-36122 --- .../ui/extern/issue-36122-accessing-externed-dst.rs | 6 ++++++ .../extern/issue-36122-accessing-externed-dst.stderr | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/test/ui/extern/issue-36122-accessing-externed-dst.rs create mode 100644 src/test/ui/extern/issue-36122-accessing-externed-dst.stderr diff --git a/src/test/ui/extern/issue-36122-accessing-externed-dst.rs b/src/test/ui/extern/issue-36122-accessing-externed-dst.rs new file mode 100644 index 0000000000000..22229db8000a8 --- /dev/null +++ b/src/test/ui/extern/issue-36122-accessing-externed-dst.rs @@ -0,0 +1,6 @@ +fn main() { + extern { + static symbol: [usize]; //~ ERROR: the size for values of type + } + println!("{}", symbol[0]); +} diff --git a/src/test/ui/extern/issue-36122-accessing-externed-dst.stderr b/src/test/ui/extern/issue-36122-accessing-externed-dst.stderr new file mode 100644 index 0000000000000..add3a8e79267d --- /dev/null +++ b/src/test/ui/extern/issue-36122-accessing-externed-dst.stderr @@ -0,0 +1,12 @@ +error[E0277]: the size for values of type `[usize]` cannot be known at compilation time + --> $DIR/issue-36122-accessing-externed-dst.rs:3:24 + | +LL | static symbol: [usize]; + | ^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `std::marker::Sized` is not implemented for `[usize]` + = note: to learn more, visit + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. From 74329bf619c65e99947535e2fc6f6612cae317ad Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 14 Nov 2019 16:51:11 +0900 Subject: [PATCH 10/14] Add test for issue-58094 --- .../issue-58094-missing-right-square-bracket.rs | 4 ++++ ...sue-58094-missing-right-square-bracket.stderr | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/test/ui/parser/issue-58094-missing-right-square-bracket.rs create mode 100644 src/test/ui/parser/issue-58094-missing-right-square-bracket.stderr diff --git a/src/test/ui/parser/issue-58094-missing-right-square-bracket.rs b/src/test/ui/parser/issue-58094-missing-right-square-bracket.rs new file mode 100644 index 0000000000000..173b988893f93 --- /dev/null +++ b/src/test/ui/parser/issue-58094-missing-right-square-bracket.rs @@ -0,0 +1,4 @@ +// https://github.com/rust-lang/rust/issues/58094 +// ignore-tidy-trailing-newlines +// error-pattern: aborting due to 2 previous errors +#[Ѕ \ No newline at end of file diff --git a/src/test/ui/parser/issue-58094-missing-right-square-bracket.stderr b/src/test/ui/parser/issue-58094-missing-right-square-bracket.stderr new file mode 100644 index 0000000000000..2c987da81d833 --- /dev/null +++ b/src/test/ui/parser/issue-58094-missing-right-square-bracket.stderr @@ -0,0 +1,16 @@ +error: this file contains an un-closed delimiter + --> $DIR/issue-58094-missing-right-square-bracket.rs:4:4 + | +LL | #[Ѕ + | - ^ + | | + | un-closed delimiter + +error: expected item after attributes + --> $DIR/issue-58094-missing-right-square-bracket.rs:4:4 + | +LL | #[Ѕ + | ^ + +error: aborting due to 2 previous errors + From 564c78a6981174b32079f576eb6e7f965a13945e Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 14 Nov 2019 17:56:36 +0900 Subject: [PATCH 11/14] Fix test case and issue number --- src/test/ui/unboxed-closures/issue-30904.rs | 36 ------------------- .../ui/unboxed-closures/issue-30904.stderr | 24 ------------- src/test/ui/unboxed-closures/issue-30906.rs | 18 ++++++++++ .../ui/unboxed-closures/issue-30906.stderr | 12 +++++++ 4 files changed, 30 insertions(+), 60 deletions(-) delete mode 100644 src/test/ui/unboxed-closures/issue-30904.rs delete mode 100644 src/test/ui/unboxed-closures/issue-30904.stderr create mode 100644 src/test/ui/unboxed-closures/issue-30906.rs create mode 100644 src/test/ui/unboxed-closures/issue-30906.stderr diff --git a/src/test/ui/unboxed-closures/issue-30904.rs b/src/test/ui/unboxed-closures/issue-30904.rs deleted file mode 100644 index eec5e962b431e..0000000000000 --- a/src/test/ui/unboxed-closures/issue-30904.rs +++ /dev/null @@ -1,36 +0,0 @@ -#![feature(fn_traits, unboxed_closures)] - -fn test FnOnce<(&'x str,)>>(_: F) {} - -struct Compose(F,G); -impl FnOnce<(T,)> for Compose -where F: FnOnce<(T,)>, G: FnOnce<(F::Output,)> { - type Output = G::Output; - extern "rust-call" fn call_once(self, (x,): (T,)) -> G::Output { - (self.1)((self.0)(x)) - } -} - -struct Str<'a>(&'a str); -fn mk_str<'a>(s: &'a str) -> Str<'a> { Str(s) } - -fn main() { - let _: for<'a> fn(&'a str) -> Str<'a> = mk_str; - // expected concrete lifetime, found bound lifetime parameter 'a - let _: for<'a> fn(&'a str) -> Str<'a> = Str; - //~^ ERROR: mismatched types - - test(|_: &str| {}); - test(mk_str); - // expected concrete lifetime, found bound lifetime parameter 'x - test(Str); //~ ERROR: type mismatch in function arguments - - test(Compose(|_: &str| {}, |_| {})); - test(Compose(mk_str, |_| {})); - // internal compiler error: cannot relate bound region: - // ReLateBound(DebruijnIndex { depth: 2 }, - // BrNamed(DefId { krate: 0, node: DefIndex(6) => test::'x }, 'x(65))) - //<= ReSkolemized(0, - // BrNamed(DefId { krate: 0, node: DefIndex(6) => test::'x }, 'x(65))) - test(Compose(Str, |_| {})); -} diff --git a/src/test/ui/unboxed-closures/issue-30904.stderr b/src/test/ui/unboxed-closures/issue-30904.stderr deleted file mode 100644 index 943cbe0ccc297..0000000000000 --- a/src/test/ui/unboxed-closures/issue-30904.stderr +++ /dev/null @@ -1,24 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/issue-30904.rs:20:45 - | -LL | let _: for<'a> fn(&'a str) -> Str<'a> = Str; - | ^^^ expected concrete lifetime, found bound lifetime parameter 'a - | - = note: expected type `for<'a> fn(&'a str) -> Str<'a>` - found type `fn(&str) -> Str<'_> {Str::<'_>}` - -error[E0631]: type mismatch in function arguments - --> $DIR/issue-30904.rs:26:10 - | -LL | fn test FnOnce<(&'x str,)>>(_: F) {} - | ---- -------------------------- required by this bound in `test` -... -LL | struct Str<'a>(&'a str); - | ------------------------ found signature of `fn(&str) -> _` -... -LL | test(Str); - | ^^^ expected signature of `for<'x> fn(&'x str) -> _` - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/unboxed-closures/issue-30906.rs b/src/test/ui/unboxed-closures/issue-30906.rs new file mode 100644 index 0000000000000..03cce83277515 --- /dev/null +++ b/src/test/ui/unboxed-closures/issue-30906.rs @@ -0,0 +1,18 @@ +#![feature(fn_traits, unboxed_closures)] + +fn test FnOnce<(&'x str,)>>(_: F) {} + +struct Compose(F,G); +impl FnOnce<(T,)> for Compose +where F: FnOnce<(T,)>, G: FnOnce<(F::Output,)> { + type Output = G::Output; + extern "rust-call" fn call_once(self, (x,): (T,)) -> G::Output { + (self.1)((self.0)(x)) + } +} + +fn bad(f: fn(&'static str) -> T) { + test(Compose(f, |_| {})); //~ ERROR: mismatched types +} + +fn main() {} diff --git a/src/test/ui/unboxed-closures/issue-30906.stderr b/src/test/ui/unboxed-closures/issue-30906.stderr new file mode 100644 index 0000000000000..5c3a1154e74c1 --- /dev/null +++ b/src/test/ui/unboxed-closures/issue-30906.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/issue-30906.rs:15:5 + | +LL | test(Compose(f, |_| {})); + | ^^^^ one type is more general than the other + | + = note: expected type `std::ops::FnOnce<(&'x str,)>` + found type `std::ops::FnOnce<(&str,)>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From 09f0ee51c972194a616194c3afb211cddcb157aa Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 14 Nov 2019 18:14:45 +0900 Subject: [PATCH 12/14] Apply suggestion from Centril Co-Authored-By: Mazdak Farrokhzad --- src/test/ui/parser/issue-58094-missing-right-square-bracket.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/parser/issue-58094-missing-right-square-bracket.rs b/src/test/ui/parser/issue-58094-missing-right-square-bracket.rs index 173b988893f93..25699f9fe111e 100644 --- a/src/test/ui/parser/issue-58094-missing-right-square-bracket.rs +++ b/src/test/ui/parser/issue-58094-missing-right-square-bracket.rs @@ -1,4 +1,4 @@ -// https://github.com/rust-lang/rust/issues/58094 +// Fixed in #66054. // ignore-tidy-trailing-newlines // error-pattern: aborting due to 2 previous errors #[Ѕ \ No newline at end of file From 065e1b8d8a68efeaaa4eb603e66fc937ae12b1b0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 15 Nov 2019 15:57:01 +0100 Subject: [PATCH 13/14] more comment --- src/libpanic_unwind/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs index c69399a87d969..5f345c2133f6b 100644 --- a/src/libpanic_unwind/lib.rs +++ b/src/libpanic_unwind/lib.rs @@ -40,6 +40,7 @@ cfg_if::cfg_if! { #[path = "miri.rs"] mod imp; // On MSVC we need the SEH lang items as well... + // This should match the conditions of the `seh.rs` import below. #[cfg(all(target_env = "msvc", not(target_arch = "aarch64")))] #[allow(unused)] mod seh; From 614abe48b0b9edc62a9455e27f64fa525c732aae Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 16 Nov 2019 01:40:59 +0900 Subject: [PATCH 14/14] Fix nll test --- src/test/ui/unboxed-closures/issue-30906.nll.stderr | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/test/ui/unboxed-closures/issue-30906.nll.stderr diff --git a/src/test/ui/unboxed-closures/issue-30906.nll.stderr b/src/test/ui/unboxed-closures/issue-30906.nll.stderr new file mode 100644 index 0000000000000..5a2cbab9a1500 --- /dev/null +++ b/src/test/ui/unboxed-closures/issue-30906.nll.stderr @@ -0,0 +1,8 @@ +error: higher-ranked subtype error + --> $DIR/issue-30906.rs:15:5 + | +LL | test(Compose(f, |_| {})); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error +