diff --git a/Cargo.lock b/Cargo.lock index 2a2223814918a..40dad13df6b21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3653,6 +3653,7 @@ dependencies = [ "log", "rustc", "rustc_data_structures", + "rustc_errors", "rustc_feature", "rustc_hir", "rustc_index", diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 8cd7fc2c17257..a87b44c79897f 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -49,7 +49,7 @@ macro_rules! book { builder.ensure(RustbookSrc { target: self.target, name: INTERNER.intern_str($book_name), - src: doc_src(builder), + src: INTERNER.intern_path(builder.src.join($path)), }) } } @@ -60,6 +60,7 @@ macro_rules! book { // NOTE: When adding a book here, make sure to ALSO build the book by // adding a build step in `src/bootstrap/builder.rs`! book!( + CargoBook, "src/tools/cargo/src/doc", "cargo"; EditionGuide, "src/doc/edition-guide", "edition-guide"; EmbeddedBook, "src/doc/embedded-book", "embedded-book"; Nomicon, "src/doc/nomicon", "nomicon"; @@ -69,10 +70,6 @@ book!( RustdocBook, "src/doc/rustdoc", "rustdoc"; ); -fn doc_src(builder: &Builder<'_>) -> Interned { - INTERNER.intern_path(builder.src.join("src/doc")) -} - #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct UnstableBook { target: Interned, @@ -96,48 +93,11 @@ impl Step for UnstableBook { builder.ensure(RustbookSrc { target: self.target, name: INTERNER.intern_str("unstable-book"), - src: builder.md_doc_out(self.target), + src: INTERNER.intern_path(builder.md_doc_out(self.target).join("unstable-book")), }) } } -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct CargoBook { - target: Interned, - name: Interned, -} - -impl Step for CargoBook { - type Output = (); - const DEFAULT: bool = true; - - fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - let builder = run.builder; - run.path("src/tools/cargo/src/doc/book").default_condition(builder.config.docs) - } - - fn make_run(run: RunConfig<'_>) { - run.builder.ensure(CargoBook { target: run.target, name: INTERNER.intern_str("cargo") }); - } - - fn run(self, builder: &Builder<'_>) { - let target = self.target; - let name = self.name; - let src = builder.src.join("src/tools/cargo/src/doc"); - - let out = builder.doc_out(target); - t!(fs::create_dir_all(&out)); - - let out = out.join(name); - - builder.info(&format!("Cargo Book ({}) - {}", target, name)); - - let _ = fs::remove_dir_all(&out); - - builder.run(builder.tool_cmd(Tool::Rustbook).arg("build").arg(&src).arg("-d").arg(out)); - } -} - #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] struct RustbookSrc { target: Interned, @@ -164,7 +124,6 @@ impl Step for RustbookSrc { t!(fs::create_dir_all(&out)); let out = out.join(name); - let src = src.join(name); let index = out.join("index.html"); let rustbook = builder.tool_exe(Tool::Rustbook); let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook); @@ -182,7 +141,6 @@ impl Step for RustbookSrc { pub struct TheBook { compiler: Compiler, target: Interned, - name: &'static str, } impl Step for TheBook { @@ -198,7 +156,6 @@ impl Step for TheBook { run.builder.ensure(TheBook { compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build), target: run.target, - name: "book", }); } @@ -206,45 +163,30 @@ impl Step for TheBook { /// /// We need to build: /// - /// * Book (first edition) - /// * Book (second edition) + /// * Book + /// * Older edition redirects /// * Version info and CSS /// * Index page /// * Redirect pages fn run(self, builder: &Builder<'_>) { let compiler = self.compiler; let target = self.target; - let name = self.name; // build book builder.ensure(RustbookSrc { target, - name: INTERNER.intern_string(name.to_string()), - src: doc_src(builder), + name: INTERNER.intern_str("book"), + src: INTERNER.intern_path(builder.src.join("src/doc/book")), }); // building older edition redirects - - let source_name = format!("{}/first-edition", name); - builder.ensure(RustbookSrc { - target, - name: INTERNER.intern_string(source_name), - src: doc_src(builder), - }); - - let source_name = format!("{}/second-edition", name); - builder.ensure(RustbookSrc { - target, - name: INTERNER.intern_string(source_name), - src: doc_src(builder), - }); - - let source_name = format!("{}/2018-edition", name); - builder.ensure(RustbookSrc { - target, - name: INTERNER.intern_string(source_name), - src: doc_src(builder), - }); + for edition in &["first-edition", "second-edition", "2018-edition"] { + builder.ensure(RustbookSrc { + target, + name: INTERNER.intern_string(format!("book/{}", edition)), + src: INTERNER.intern_path(builder.src.join("src/doc/book").join(edition)), + }); + } // build the version info page and CSS builder.ensure(Standalone { compiler, target }); @@ -531,7 +473,7 @@ impl Step for Rustc { // Build cargo command. let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "doc"); - cargo.env("RUSTDOCFLAGS", "--document-private-items --passes strip-hidden"); + cargo.env("RUSTDOCFLAGS", "--document-private-items"); compile::rustc_cargo(builder, &mut cargo, target); // Only include compiler crates, no dependencies of those, such as `libc`. diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 9fd20386e367b..7f24768a4f10e 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -289,8 +289,8 @@ fn rustbook_features() -> Vec { macro_rules! bootstrap_tool { ($( $name:ident, $path:expr, $tool_name:expr - $(,llvm_tools = $llvm:expr)* $(,is_external_tool = $external:expr)* + $(,is_unstable_tool = $unstable:expr)* $(,features = $features:expr)* ; )+) => { @@ -301,15 +301,6 @@ macro_rules! bootstrap_tool { )+ } - impl Tool { - /// Whether this tool requires LLVM to run - pub fn uses_llvm_tools(&self) -> bool { - match self { - $(Tool::$name => false $(|| $llvm)*,)+ - } - } - } - impl<'a> Builder<'a> { pub fn tool_exe(&self, tool: Tool) -> PathBuf { match tool { @@ -350,7 +341,12 @@ macro_rules! bootstrap_tool { compiler: self.compiler, target: self.target, tool: $tool_name, - mode: Mode::ToolBootstrap, + mode: if false $(|| $unstable)* { + // use in-tree libraries for unstable features + Mode::ToolStd + } else { + Mode::ToolBootstrap + }, path: $path, is_optional_tool: false, source_type: if false $(|| $external)* { @@ -377,7 +373,7 @@ bootstrap_tool!( Tidy, "src/tools/tidy", "tidy"; Linkchecker, "src/tools/linkchecker", "linkchecker"; CargoTest, "src/tools/cargotest", "cargotest"; - Compiletest, "src/tools/compiletest", "compiletest", llvm_tools = true; + Compiletest, "src/tools/compiletest", "compiletest", is_unstable_tool = true; BuildManifest, "src/tools/build-manifest", "build-manifest"; RemoteTestClient, "src/tools/remote-test-client", "remote-test-client"; RustInstaller, "src/tools/rust-installer", "fabricate", is_external_tool = true; diff --git a/src/libpanic_unwind/emcc.rs b/src/libpanic_unwind/emcc.rs index 2098404ee1b9d..9d3fe5254f8a9 100644 --- a/src/libpanic_unwind/emcc.rs +++ b/src/libpanic_unwind/emcc.rs @@ -63,7 +63,7 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box { pub unsafe fn panic(data: Box) -> u32 { let sz = mem::size_of_val(&data); let exception = __cxa_allocate_exception(sz); - if exception == ptr::null_mut() { + if exception.is_null() { return uw::_URC_FATAL_PHASE1_ERROR as u32; } ptr::write(exception as *mut _, data); diff --git a/src/librustc/Cargo.toml b/src/librustc/Cargo.toml index 1a04a9d86b58b..21ab5c75c026d 100644 --- a/src/librustc/Cargo.toml +++ b/src/librustc/Cargo.toml @@ -26,8 +26,8 @@ rustc_hir = { path = "../librustc_hir" } rustc_target = { path = "../librustc_target" } rustc_macros = { path = "../librustc_macros" } rustc_data_structures = { path = "../librustc_data_structures" } +rustc_errors = { path = "../librustc_errors" } rustc_index = { path = "../librustc_index" } -errors = { path = "../librustc_errors", package = "rustc_errors" } rustc_serialize = { path = "../libserialize", package = "serialize" } syntax = { path = "../libsyntax" } rustc_span = { path = "../librustc_span" } diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs index 0d03c834e0f7b..78895340b07c3 100644 --- a/src/librustc/dep_graph/graph.rs +++ b/src/librustc/dep_graph/graph.rs @@ -1,10 +1,10 @@ use crate::ty::{self, TyCtxt}; -use errors::Diagnostic; use parking_lot::{Condvar, Mutex}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sharded::{self, Sharded}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering}; +use rustc_errors::Diagnostic; use rustc_index::vec::{Idx, IndexVec}; use smallvec::SmallVec; use std::collections::hash_map::Entry; diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 06b7b3194defd..c6a996f84f461 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -9,8 +9,8 @@ use crate::lint::builtin::UNUSED_ATTRIBUTES; use crate::ty::query::Providers; use crate::ty::TyCtxt; -use errors::struct_span_err; use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 5e5f39e6c7a22..c52d4335ea184 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -64,15 +64,13 @@ use crate::ty::{ subst::{Subst, SubstsRef}, Region, Ty, TyCtxt, TypeFoldable, }; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_error_codes::*; +use rustc_errors::{pluralize, struct_span_err}; +use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::Node; - -use errors::{ - pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticStyledString, -}; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_error_codes::*; use rustc_span::{DesugaringKind, Pos, Span}; use rustc_target::spec::abi; use std::{cmp, fmt}; diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 16cfaec5ee91b..70f7987faf4cc 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -3,7 +3,7 @@ use crate::infer::type_variable::TypeVariableOriginKind; use crate::infer::InferCtxt; use crate::ty::print::Print; use crate::ty::{self, DefIdTree, Infer, Ty, TyVar}; -use errors::{struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Namespace}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; @@ -151,12 +151,12 @@ pub enum TypeAnnotationNeeded { E0284, } -impl Into for TypeAnnotationNeeded { - fn into(self) -> errors::DiagnosticId { +impl Into for TypeAnnotationNeeded { + fn into(self) -> rustc_errors::DiagnosticId { match self { - Self::E0282 => errors::error_code!(E0282), - Self::E0283 => errors::error_code!(E0283), - Self::E0284 => errors::error_code!(E0284), + Self::E0282 => rustc_errors::error_code!(E0282), + Self::E0283 => rustc_errors::error_code!(E0283), + Self::E0284 => rustc_errors::error_code!(E0284), } } } diff --git a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs index b73fb40f637ed..d6e50209f72dd 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -5,8 +5,8 @@ use crate::infer::error_reporting::nice_region_error::util::AnonymousParamInfo; use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::util::common::ErrorReported; -use errors::struct_span_err; use rustc_error_codes::*; +use rustc_errors::struct_span_err; impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// Print the error message for lifetime errors when both the concerned regions are anonymous. diff --git a/src/librustc/infer/error_reporting/nice_region_error/mod.rs b/src/librustc/infer/error_reporting/nice_region_error/mod.rs index 5da65a3019395..8749d6cd34bed 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/mod.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/mod.rs @@ -3,7 +3,7 @@ use crate::infer::lexical_region_resolve::RegionResolutionError::*; use crate::infer::InferCtxt; use crate::ty::{self, TyCtxt}; use crate::util::common::ErrorReported; -use errors::DiagnosticBuilder; +use rustc_errors::DiagnosticBuilder; use rustc_span::source_map::Span; mod different_lifetimes; diff --git a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs index dacd2025da53b..2344d408a43a5 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs @@ -2,7 +2,7 @@ //! where one region is named and the other is anonymous. use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::ty; -use errors::{struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir::{FunctionRetTy, TyKind}; use rustc_error_codes::*; diff --git a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs index f276dab5000bc..7b31fe7cd7e4d 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -7,7 +7,7 @@ use crate::ty::error::ExpectedFound; use crate::ty::print::{FmtPrinter, Print, RegionHighlightMode}; use crate::ty::subst::SubstsRef; use crate::ty::{self, TyCtxt}; -use errors::DiagnosticBuilder; +use rustc_errors::DiagnosticBuilder; use rustc_hir::def::Namespace; use rustc_hir::def_id::DefId; diff --git a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs index 6c78e70a4444d..c6fc4cd3c15f7 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -5,7 +5,7 @@ use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::infer::lexical_region_resolve::RegionResolutionError; use crate::ty::{BoundRegion, FreeRegion, RegionKind}; use crate::util::common::ErrorReported; -use errors::Applicability; +use rustc_errors::Applicability; impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// Print the error message for lifetime errors when the return type is a static impl Trait. diff --git a/src/librustc/infer/error_reporting/note.rs b/src/librustc/infer/error_reporting/note.rs index a3fdcb44f996f..6303104e39dd3 100644 --- a/src/librustc/infer/error_reporting/note.rs +++ b/src/librustc/infer/error_reporting/note.rs @@ -3,7 +3,7 @@ use crate::infer::{self, InferCtxt, SubregionOrigin}; use crate::middle::region; use crate::ty::error::TypeError; use crate::ty::{self, Region}; -use errors::{struct_span_err, DiagnosticBuilder}; +use rustc_errors::{struct_span_err, DiagnosticBuilder}; use rustc_error_codes::*; diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 4eb8d79a067ef..f67669e367f00 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -21,10 +21,10 @@ use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef}; use crate::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt}; use crate::ty::{ConstVid, FloatVid, IntVid, TyVid}; -use errors::DiagnosticBuilder; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::Lrc; use rustc_data_structures::unify as ut; +use rustc_errors::DiagnosticBuilder; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_span::symbol::Symbol; diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 839e8588ff090..a1afb1a86be44 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -6,10 +6,10 @@ use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor}; use crate::ty::free_region_map::FreeRegionRelations; use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef}; use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt}; -use errors::{struct_span_err, DiagnosticBuilder}; use rustc::session::config::nightly_options; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; +use rustc_errors::{struct_span_err, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, DefIdMap}; use rustc_hir::Node; diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 3726e6ace54b1..f5845dcae1288 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -7,7 +7,7 @@ use crate::lint::{FutureIncompatibleInfo, LateLintPass, LintArray, LintPass}; use crate::middle::stability; use crate::session::Session; -use errors::{pluralize, Applicability, DiagnosticBuilder}; +use rustc_errors::{pluralize, Applicability, DiagnosticBuilder}; use rustc_session::declare_lint; use rustc_span::edition::Edition; use rustc_span::source_map::Span; diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index ea96b15a162aa..bd561b41c57f5 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -25,10 +25,10 @@ use crate::middle::privacy::AccessLevels; use crate::session::Session; use crate::ty::layout::{LayoutError, LayoutOf, TyLayout}; use crate::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt}; -use errors::{struct_span_err, DiagnosticBuilder}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync; use rustc_error_codes::*; +use rustc_errors::{struct_span_err, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP}; diff --git a/src/librustc/lint/internal.rs b/src/librustc/lint/internal.rs index 69f212a9a3098..7b99b4af4f9ab 100644 --- a/src/librustc/lint/internal.rs +++ b/src/librustc/lint/internal.rs @@ -4,8 +4,8 @@ use crate::lint::{ EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass, }; -use errors::Applicability; use rustc_data_structures::fx::FxHashMap; +use rustc_errors::Applicability; use rustc_hir::{GenericArg, HirId, MutTy, Mutability, Path, PathSegment, QPath, Ty, TyKind}; use rustc_session::declare_tool_lint; use rustc_span::symbol::{sym, Symbol}; diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index abd52a9de50d5..6ca98b44bf80c 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -5,9 +5,9 @@ use crate::lint::builtin; use crate::lint::context::{CheckLintNameResult, LintStore}; use crate::lint::{self, Level, Lint, LintId, LintSource}; use crate::session::Session; -use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir::HirId; use rustc_span::source_map::MultiSpan; use rustc_span::symbol::{sym, Symbol}; diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 3f43800590353..a8c1f9a664f18 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -23,8 +23,8 @@ pub use self::LintSource::*; use crate::lint::builtin::BuiltinLintDiagnostics; use crate::ty::TyCtxt; -use errors::{DiagnosticBuilder, DiagnosticId}; use rustc_data_structures::sync; +use rustc_errors::{DiagnosticBuilder, DiagnosticId}; use rustc_hir as hir; use rustc_session::node_id::NodeMap; use rustc_session::{DiagnosticMessageId, Session}; diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 6f59df01a5205..42fc3e030e7bb 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -14,8 +14,8 @@ use crate::middle::cstore::ExternCrate; use crate::middle::weak_lang_items; use crate::ty::{self, TyCtxt}; -use errors::struct_span_err; use rustc_data_structures::fx::FxHashMap; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::itemlikevisit::ItemLikeVisitor; diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index f2474faa75e44..93c23e40d2e2b 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -7,8 +7,8 @@ use crate::lint::builtin::BuiltinLintDiagnostics; use crate::lint::{self, in_derive_expansion, Lint}; use crate::session::{DiagnosticMessageId, Session}; use crate::ty::{self, TyCtxt}; -use errors::DiagnosticBuilder; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_feature::GateIssue; use rustc_hir as hir; use rustc_hir::def::DefKind; @@ -18,7 +18,6 @@ use rustc_span::symbol::{sym, Symbol}; use rustc_span::{MultiSpan, Span}; use syntax::ast::CRATE_NODE_ID; use syntax::attr::{self, ConstStability, Deprecation, RustcDeprecation, Stability}; -use syntax::errors::Applicability; use syntax::feature_gate::feature_err_issue; use std::num::NonZeroU32; diff --git a/src/librustc/middle/weak_lang_items.rs b/src/librustc/middle/weak_lang_items.rs index 89f385a51bc6a..fdffd1251ce8f 100644 --- a/src/librustc/middle/weak_lang_items.rs +++ b/src/librustc/middle/weak_lang_items.rs @@ -5,8 +5,8 @@ use crate::session::config; use crate::hir::map::Map; use crate::ty::TyCtxt; -use errors::struct_span_err; use rustc_data_structures::fx::FxHashSet; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index cb11ac49cec35..ed61534d54519 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -7,8 +7,8 @@ use crate::ty::query::TyCtxtAt; use crate::ty::{self, layout, Ty}; use backtrace::Backtrace; -use errors::{struct_span_err, DiagnosticBuilder}; use hir::GeneratorKind; +use rustc_errors::{struct_span_err, DiagnosticBuilder}; use rustc_hir as hir; use rustc_macros::HashStable; use rustc_span::symbol::Symbol; diff --git a/src/librustc/traits/coherence.rs b/src/librustc/traits/coherence.rs index db7cda3b95bb2..29ea47809a077 100644 --- a/src/librustc/traits/coherence.rs +++ b/src/librustc/traits/coherence.rs @@ -38,7 +38,7 @@ pub struct OverlapResult<'tcx> { pub involves_placeholder: bool, } -pub fn add_placeholder_note(err: &mut errors::DiagnosticBuilder<'_>) { +pub fn add_placeholder_note(err: &mut rustc_errors::DiagnosticBuilder<'_>) { err.note(&format!( "this behavior recently changed as a result of a bug fix; \ see rust-lang/rust#56105 for details" diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index b9bb68798e588..0c9a73d78a5eb 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -21,8 +21,8 @@ use crate::ty::SubtypePredicate; use crate::ty::TypeckTables; use crate::ty::{self, AdtKind, DefIdTree, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable}; -use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, Style}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, Style}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::Node; diff --git a/src/librustc/traits/on_unimplemented.rs b/src/librustc/traits/on_unimplemented.rs index f1b830e43fc1d..1afe153bb1361 100644 --- a/src/librustc/traits/on_unimplemented.rs +++ b/src/librustc/traits/on_unimplemented.rs @@ -3,8 +3,8 @@ use fmt_macros::{Parser, Piece, Position}; use crate::ty::{self, GenericParamDefKind, TyCtxt}; use crate::util::common::ErrorReported; -use errors::struct_span_err; use rustc_data_structures::fx::FxHashMap; +use rustc_errors::struct_span_err; use rustc_hir::def_id::DefId; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; diff --git a/src/librustc/traits/query/dropck_outlives.rs b/src/librustc/traits/query/dropck_outlives.rs index 370acb53896d3..34866b684de01 100644 --- a/src/librustc/traits/query/dropck_outlives.rs +++ b/src/librustc/traits/query/dropck_outlives.rs @@ -76,7 +76,7 @@ pub struct DropckOutlivesResult<'tcx> { impl<'tcx> DropckOutlivesResult<'tcx> { pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) { if let Some(overflow_ty) = self.overflows.iter().next() { - errors::struct_span_err!( + rustc_errors::struct_span_err!( tcx.sess, span, E0320, diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 1b1cb1b36e09a..8b66f4926e0c8 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -102,7 +102,7 @@ pub enum IntercrateAmbiguityCause { impl IntercrateAmbiguityCause { /// Emits notes when the overlap is caused by complex intercrate ambiguities. /// See #23980 for details. - pub fn add_intercrate_ambiguity_hint(&self, err: &mut errors::DiagnosticBuilder<'_>) { + pub fn add_intercrate_ambiguity_hint(&self, err: &mut rustc_errors::DiagnosticBuilder<'_>) { err.note(&self.intercrate_ambiguity_hint()); } diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index d189714883845..7b66341ef1c96 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -17,8 +17,8 @@ use crate::traits::select::IntercrateAmbiguityCause; use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine}; use crate::ty::subst::{InternalSubsts, Subst, SubstsRef}; use crate::ty::{self, TyCtxt, TypeFoldable}; -use errors::struct_span_err; use rustc_data_structures::fx::FxHashSet; +use rustc_errors::struct_span_err; use rustc_hir::def_id::DefId; use rustc_span::DUMMY_SP; diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 8355239af87a4..65fd809657bd0 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -1,4 +1,4 @@ -use errors::DiagnosticBuilder; +use rustc_errors::DiagnosticBuilder; use rustc_span::Span; use smallvec::SmallVec; diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 17f5b98ab208b..1b0b5fc4d078d 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -51,7 +51,6 @@ use rustc_hir::{HirId, Node, TraitCandidate}; use rustc_hir::{ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet}; use arena::SyncDroplessArena; -use errors::DiagnosticBuilder; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::sharded::ShardedHashMap; @@ -59,6 +58,7 @@ use rustc_data_structures::stable_hasher::{ hash_stable_hashmap, HashStable, StableHasher, StableVec, }; use rustc_data_structures::sync::{Lock, Lrc, WorkerLocal}; +use rustc_errors::DiagnosticBuilder; use rustc_index::vec::{Idx, IndexVec}; use rustc_macros::HashStable; use rustc_session::node_id::NodeMap; @@ -1613,10 +1613,10 @@ pub mod tls { use crate::dep_graph::TaskDeps; use crate::ty::query; - use errors::Diagnostic; use rustc_data_structures::sync::{self, Lock, Lrc}; use rustc_data_structures::thin_vec::ThinVec; use rustc_data_structures::OnDrop; + use rustc_errors::Diagnostic; use std::mem; #[cfg(not(parallel_compiler))] diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 25fc484cd5301..f7612874e05b6 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -1,12 +1,10 @@ use crate::ty::{self, BoundRegion, Region, Ty, TyCtxt}; +use rustc_errors::{pluralize, Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def_id::DefId; - -use errors::{Applicability, DiagnosticBuilder}; use rustc_span::Span; use rustc_target::spec::abi; use syntax::ast; -use syntax::errors::pluralize; use std::borrow::Cow; use std::fmt; diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 5d968811addd8..a81fe33831c96 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -7,10 +7,10 @@ use crate::session::{CrateDisambiguator, Session}; use crate::ty::codec::{self as ty_codec, TyDecoder, TyEncoder}; use crate::ty::context::TyCtxt; use crate::ty::{self, Ty}; -use errors::Diagnostic; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::{HashMapExt, Lock, Lrc, Once}; use rustc_data_structures::thin_vec::ThinVec; +use rustc_errors::Diagnostic; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, LOCAL_CRATE}; use rustc_index::vec::{Idx, IndexVec}; diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 35608540383b0..49028107df758 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -9,13 +9,13 @@ use crate::ty::query::Query; use crate::ty::tls; use crate::ty::{self, TyCtxt}; -use errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, Handler, Level}; #[cfg(not(parallel_compiler))] use rustc_data_structures::cold_path; use rustc_data_structures::fx::{FxHashMap, FxHasher}; use rustc_data_structures::sharded::Sharded; use rustc_data_structures::sync::{Lock, Lrc}; use rustc_data_structures::thin_vec::ThinVec; +use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, Handler, Level}; use rustc_span::source_map::DUMMY_SP; use rustc_span::Span; use std::collections::hash_map::Entry; diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index ddff8258c6d8f..8d22ac9dbbe97 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -3,18 +3,18 @@ use crate::hir::map::DefPathData; use crate::ich::NodeIdHashingMode; use crate::mir::interpret::{sign_extend, truncate}; -use crate::ty::layout::{Integer, IntegerExt}; +use crate::ty::layout::{Integer, IntegerExt, Size}; use crate::ty::query::TyCtxtAt; use crate::ty::subst::{GenericArgKind, InternalSubsts, Subst, SubstsRef}; use crate::ty::TyKind::*; use crate::ty::{self, DefIdTree, GenericParamDefKind, Ty, TyCtxt, TypeFoldable}; use crate::util::common::ErrorReported; +use rustc_apfloat::Float as _; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; - -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_macros::HashStable; use rustc_span::Span; use std::{cmp, fmt}; @@ -43,26 +43,38 @@ impl<'tcx> fmt::Display for Discr<'tcx> { } } +fn signed_min(size: Size) -> i128 { + sign_extend(1_u128 << (size.bits() - 1), size) as i128 +} + +fn signed_max(size: Size) -> i128 { + i128::max_value() >> (128 - size.bits()) +} + +fn unsigned_max(size: Size) -> u128 { + u128::max_value() >> (128 - size.bits()) +} + +fn int_size_and_signed<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> (Size, bool) { + let (int, signed) = match ty.kind { + Int(ity) => (Integer::from_attr(&tcx, SignedInt(ity)), true), + Uint(uty) => (Integer::from_attr(&tcx, UnsignedInt(uty)), false), + _ => bug!("non integer discriminant"), + }; + (int.size(), signed) +} + impl<'tcx> Discr<'tcx> { /// Adds `1` to the value and wraps around if the maximum for the type is reached. pub fn wrap_incr(self, tcx: TyCtxt<'tcx>) -> Self { self.checked_add(tcx, 1).0 } pub fn checked_add(self, tcx: TyCtxt<'tcx>, n: u128) -> (Self, bool) { - let (int, signed) = match self.ty.kind { - Int(ity) => (Integer::from_attr(&tcx, SignedInt(ity)), true), - Uint(uty) => (Integer::from_attr(&tcx, UnsignedInt(uty)), false), - _ => bug!("non integer discriminant"), - }; - - let size = int.size(); - let bit_size = int.size().bits(); - let shift = 128 - bit_size; - if signed { - let sext = |u| sign_extend(u, size) as i128; - let min = sext(1_u128 << (bit_size - 1)); - let max = i128::max_value() >> shift; - let val = sext(self.val); + let (size, signed) = int_size_and_signed(tcx, self.ty); + let (val, oflo) = if signed { + let min = signed_min(size); + let max = signed_max(size); + let val = sign_extend(self.val, size) as i128; assert!(n < (i128::max_value() as u128)); let n = n as i128; let oflo = val > max - n; @@ -70,14 +82,15 @@ impl<'tcx> Discr<'tcx> { // zero the upper bits let val = val as u128; let val = truncate(val, size); - (Self { val: val as u128, ty: self.ty }, oflo) + (val, oflo) } else { - let max = u128::max_value() >> shift; + let max = unsigned_max(size); let val = self.val; let oflo = val > max - n; let val = if oflo { n - (max - val) - 1 } else { val + n }; - (Self { val: val, ty: self.ty }, oflo) - } + (val, oflo) + }; + (Self { val, ty: self.ty }, oflo) } } @@ -621,6 +634,44 @@ impl<'tcx> TyCtxt<'tcx> { } impl<'tcx> ty::TyS<'tcx> { + /// Returns the maximum value for the given numeric type (including `char`s) + /// or returns `None` if the type is not numeric. + pub fn numeric_max_val(&'tcx self, tcx: TyCtxt<'tcx>) -> Option<&'tcx ty::Const<'tcx>> { + let val = match self.kind { + ty::Int(_) | ty::Uint(_) => { + let (size, signed) = int_size_and_signed(tcx, self); + let val = if signed { signed_max(size) as u128 } else { unsigned_max(size) }; + Some(val) + } + ty::Char => Some(std::char::MAX as u128), + ty::Float(fty) => Some(match fty { + ast::FloatTy::F32 => ::rustc_apfloat::ieee::Single::INFINITY.to_bits(), + ast::FloatTy::F64 => ::rustc_apfloat::ieee::Double::INFINITY.to_bits(), + }), + _ => None, + }; + val.map(|v| ty::Const::from_bits(tcx, v, ty::ParamEnv::empty().and(self))) + } + + /// Returns the minimum value for the given numeric type (including `char`s) + /// or returns `None` if the type is not numeric. + pub fn numeric_min_val(&'tcx self, tcx: TyCtxt<'tcx>) -> Option<&'tcx ty::Const<'tcx>> { + let val = match self.kind { + ty::Int(_) | ty::Uint(_) => { + let (size, signed) = int_size_and_signed(tcx, self); + let val = if signed { truncate(signed_min(size) as u128, size) } else { 0 }; + Some(val) + } + ty::Char => Some(0), + ty::Float(fty) => Some(match fty { + ast::FloatTy::F32 => (-::rustc_apfloat::ieee::Single::INFINITY).to_bits(), + ast::FloatTy::F64 => (-::rustc_apfloat::ieee::Double::INFINITY).to_bits(), + }), + _ => None, + }; + val.map(|v| ty::Const::from_bits(tcx, v, ty::ParamEnv::empty().and(self))) + } + /// Checks whether values of this type `T` are *moved* or *copied* /// when referenced -- this amounts to a check for whether `T: /// Copy`, but note that we **don't** consider lifetimes when diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 9324b26a09b6f..19b43bfd16241 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -8,7 +8,7 @@ use std::time::{Duration, Instant}; #[cfg(test)] mod tests; -pub use errors::ErrorReported; +pub use rustc_errors::ErrorReported; pub fn to_readable_str(mut val: usize) -> String { let mut groups = vec![]; diff --git a/src/librustc_ast_lowering/pat.rs b/src/librustc_ast_lowering/pat.rs index cd69646d0c53a..6cf640a0e98a2 100644 --- a/src/librustc_ast_lowering/pat.rs +++ b/src/librustc_ast_lowering/pat.rs @@ -65,9 +65,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { PatKind::Box(ref inner) => hir::PatKind::Box(self.lower_pat(inner)), PatKind::Ref(ref inner, mutbl) => hir::PatKind::Ref(self.lower_pat(inner), mutbl), PatKind::Range(ref e1, ref e2, Spanned { node: ref end, .. }) => hir::PatKind::Range( - self.lower_expr(e1), - self.lower_expr(e2), - self.lower_range_end(end), + e1.as_deref().map(|e| self.lower_expr(e)), + e2.as_deref().map(|e| self.lower_expr(e)), + self.lower_range_end(end, e2.is_some()), ), PatKind::Slice(ref pats) => self.lower_pat_slice(pats), PatKind::Rest => { @@ -253,10 +253,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hir::PatKind::Wild } - fn lower_range_end(&mut self, e: &RangeEnd) -> hir::RangeEnd { + fn lower_range_end(&mut self, e: &RangeEnd, has_end: bool) -> hir::RangeEnd { match *e { - RangeEnd::Included(_) => hir::RangeEnd::Included, - RangeEnd::Excluded => hir::RangeEnd::Excluded, + RangeEnd::Excluded if has_end => hir::RangeEnd::Excluded, + // No end; so `X..` behaves like `RangeFrom`. + RangeEnd::Excluded | RangeEnd::Included(_) => hir::RangeEnd::Included, } } } diff --git a/src/librustc_builtin_macros/Cargo.toml b/src/librustc_builtin_macros/Cargo.toml index f56cc938f4a2f..ca57068fb9a33 100644 --- a/src/librustc_builtin_macros/Cargo.toml +++ b/src/librustc_builtin_macros/Cargo.toml @@ -10,10 +10,10 @@ path = "lib.rs" doctest = false [dependencies] -errors = { path = "../librustc_errors", package = "rustc_errors" } fmt_macros = { path = "../libfmt_macros" } log = "0.4" rustc_data_structures = { path = "../librustc_data_structures" } +rustc_errors = { path = "../librustc_errors" } rustc_feature = { path = "../librustc_feature" } rustc_parse = { path = "../librustc_parse" } rustc_target = { path = "../librustc_target" } diff --git a/src/librustc_builtin_macros/asm.rs b/src/librustc_builtin_macros/asm.rs index 78d2d37ef56d3..a6b45e0567c72 100644 --- a/src/librustc_builtin_macros/asm.rs +++ b/src/librustc_builtin_macros/asm.rs @@ -2,7 +2,7 @@ // use State::*; -use errors::{struct_span_err, DiagnosticBuilder, PResult}; +use rustc_errors::{struct_span_err, DiagnosticBuilder, PResult}; use rustc_expand::base::*; use rustc_parse::parser::Parser; use rustc_span::symbol::{kw, sym, Symbol}; diff --git a/src/librustc_builtin_macros/assert.rs b/src/librustc_builtin_macros/assert.rs index 9043db4742bf7..c96ba516f0ced 100644 --- a/src/librustc_builtin_macros/assert.rs +++ b/src/librustc_builtin_macros/assert.rs @@ -1,4 +1,4 @@ -use errors::{Applicability, DiagnosticBuilder}; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_expand::base::*; use rustc_parse::parser::Parser; diff --git a/src/librustc_builtin_macros/cfg.rs b/src/librustc_builtin_macros/cfg.rs index 62a4dc06b1fe2..cee62a54f0088 100644 --- a/src/librustc_builtin_macros/cfg.rs +++ b/src/librustc_builtin_macros/cfg.rs @@ -1,8 +1,8 @@ -/// The compiler code necessary to support the cfg! extension, which expands to -/// a literal `true` or `false` based on whether the given cfg matches the -/// current compilation environment. -use errors::DiagnosticBuilder; +//! The compiler code necessary to support the cfg! extension, which expands to +//! a literal `true` or `false` based on whether the given cfg matches the +//! current compilation environment. +use rustc_errors::DiagnosticBuilder; use rustc_expand::base::{self, *}; use rustc_span::Span; use syntax::ast; diff --git a/src/librustc_builtin_macros/deriving/default.rs b/src/librustc_builtin_macros/deriving/default.rs index 8d3f195137375..72c41ad9745c1 100644 --- a/src/librustc_builtin_macros/deriving/default.rs +++ b/src/librustc_builtin_macros/deriving/default.rs @@ -2,7 +2,7 @@ use crate::deriving::generic::ty::*; use crate::deriving::generic::*; use crate::deriving::path_std; -use errors::struct_span_err; +use rustc_errors::struct_span_err; use rustc_expand::base::{Annotatable, DummyResult, ExtCtxt}; use rustc_span::symbol::{kw, sym}; use rustc_span::Span; diff --git a/src/librustc_builtin_macros/format.rs b/src/librustc_builtin_macros/format.rs index e2662faab6cb5..6fca74e223944 100644 --- a/src/librustc_builtin_macros/format.rs +++ b/src/librustc_builtin_macros/format.rs @@ -3,10 +3,8 @@ use Position::*; use fmt_macros as parse; -use errors::pluralize; -use errors::Applicability; -use errors::DiagnosticBuilder; - +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::{pluralize, Applicability, DiagnosticBuilder}; use rustc_expand::base::{self, *}; use rustc_span::symbol::{sym, Symbol}; use rustc_span::{MultiSpan, Span}; @@ -15,7 +13,6 @@ use syntax::ptr::P; use syntax::token; use syntax::tokenstream::TokenStream; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use std::borrow::Cow; use std::collections::hash_map::Entry; diff --git a/src/librustc_builtin_macros/global_asm.rs b/src/librustc_builtin_macros/global_asm.rs index 2bcd76e669971..052e62ee9ffd3 100644 --- a/src/librustc_builtin_macros/global_asm.rs +++ b/src/librustc_builtin_macros/global_asm.rs @@ -1,14 +1,14 @@ -/// Module-level assembly support. -/// -/// The macro defined here allows you to specify "top-level", -/// "file-scoped", or "module-level" assembly. These synonyms -/// all correspond to LLVM's module-level inline assembly instruction. -/// -/// For example, `global_asm!("some assembly here")` codegens to -/// LLVM's `module asm "some assembly here"`. All of LLVM's caveats -/// therefore apply. -use errors::DiagnosticBuilder; +//! Module-level assembly support. +//! +//! The macro defined here allows you to specify "top-level", +//! "file-scoped", or "module-level" assembly. These synonyms +//! all correspond to LLVM's module-level inline assembly instruction. +//! +//! For example, `global_asm!("some assembly here")` codegens to +//! LLVM's `module asm "some assembly here"`. All of LLVM's caveats +//! therefore apply. +use rustc_errors::DiagnosticBuilder; use rustc_expand::base::{self, *}; use rustc_span::source_map::respan; use rustc_span::Span; diff --git a/src/librustc_builtin_macros/proc_macro_harness.rs b/src/librustc_builtin_macros/proc_macro_harness.rs index 44968d6df9693..ae70608505130 100644 --- a/src/librustc_builtin_macros/proc_macro_harness.rs +++ b/src/librustc_builtin_macros/proc_macro_harness.rs @@ -40,7 +40,7 @@ enum ProcMacro { struct CollectProcMacros<'a> { macros: Vec, in_root: bool, - handler: &'a errors::Handler, + handler: &'a rustc_errors::Handler, is_proc_macro_crate: bool, is_test_crate: bool, } @@ -53,7 +53,7 @@ pub fn inject( has_proc_macro_decls: bool, is_test_crate: bool, num_crate_types: usize, - handler: &errors::Handler, + handler: &rustc_errors::Handler, ) -> ast::Crate { let ecfg = ExpansionConfig::default("proc_macro".to_string()); let mut cx = ExtCtxt::new(sess, ecfg, resolver); diff --git a/src/librustc_builtin_macros/test_harness.rs b/src/librustc_builtin_macros/test_harness.rs index eddf492720336..17d180da6bfda 100644 --- a/src/librustc_builtin_macros/test_harness.rs +++ b/src/librustc_builtin_macros/test_harness.rs @@ -40,7 +40,7 @@ pub fn inject( resolver: &mut dyn Resolver, should_test: bool, krate: &mut ast::Crate, - span_diagnostic: &errors::Handler, + span_diagnostic: &rustc_errors::Handler, features: &Features, panic_strategy: PanicStrategy, platform_panic_strategy: PanicStrategy, @@ -351,7 +351,7 @@ fn is_test_case(i: &ast::Item) -> bool { attr::contains_name(&i.attrs, sym::rustc_test_marker) } -fn get_test_runner(sd: &errors::Handler, krate: &ast::Crate) -> Option { +fn get_test_runner(sd: &rustc_errors::Handler, krate: &ast::Crate) -> Option { let test_attr = attr::find_by_name(&krate.attrs, sym::test_runner)?; test_attr.meta_item_list().map(|meta_list| { if meta_list.len() != 1 { diff --git a/src/librustc_driver/Cargo.toml b/src/librustc_driver/Cargo.toml index 5e0c853ed2473..37449f9402eff 100644 --- a/src/librustc_driver/Cargo.toml +++ b/src/librustc_driver/Cargo.toml @@ -17,7 +17,7 @@ rustc = { path = "../librustc" } rustc_target = { path = "../librustc_target" } rustc_lint = { path = "../librustc_lint" } rustc_data_structures = { path = "../librustc_data_structures" } -errors = { path = "../librustc_errors", package = "rustc_errors" } +rustc_errors = { path = "../librustc_errors" } rustc_feature = { path = "../librustc_feature" } rustc_hir = { path = "../librustc_hir" } rustc_metadata = { path = "../librustc_metadata" } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index a5277bcd120ed..a1318d3506711 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -24,7 +24,6 @@ extern crate lazy_static; pub extern crate rustc_plugin_impl as plugin; //use rustc_resolve as resolve; -use errors::{registry::Registry, PResult}; use rustc::lint; use rustc::lint::Lint; use rustc::middle::cstore::MetadataLoader; @@ -37,6 +36,7 @@ use rustc::util::common::ErrorReported; use rustc_codegen_utils::codegen_backend::CodegenBackend; use rustc_data_structures::profiling::print_time_passes_entry; use rustc_data_structures::sync::SeqCst; +use rustc_errors::{registry::Registry, PResult}; use rustc_feature::{find_gated_cfg, UnstableFeatures}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_interface::util::get_builtin_codegen_backend; @@ -1134,7 +1134,7 @@ fn extra_compiler_flags() -> Option<(Vec, bool)> { /// the panic into a `Result` instead. pub fn catch_fatal_errors R, R>(f: F) -> Result { catch_unwind(panic::AssertUnwindSafe(f)).map_err(|value| { - if value.is::() { + if value.is::() { ErrorReported } else { panic::resume_unwind(value); @@ -1163,20 +1163,20 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { // Separate the output with an empty line eprintln!(); - let emitter = Box::new(errors::emitter::EmitterWriter::stderr( - errors::ColorConfig::Auto, + let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr( + rustc_errors::ColorConfig::Auto, None, false, false, None, false, )); - let handler = errors::Handler::with_emitter(true, None, emitter); + let handler = rustc_errors::Handler::with_emitter(true, None, emitter); // a .span_bug or .bug call has already printed what // it wants to print. - if !info.payload().is::() { - let d = errors::Diagnostic::new(errors::Level::Bug, "unexpected panic"); + if !info.payload().is::() { + let d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic"); handler.emit_diagnostic(&d); } diff --git a/src/librustc_expand/Cargo.toml b/src/librustc_expand/Cargo.toml index f9c15fbed362f..c23846063c1dc 100644 --- a/src/librustc_expand/Cargo.toml +++ b/src/librustc_expand/Cargo.toml @@ -14,8 +14,8 @@ doctest = false rustc_serialize = { path = "../libserialize", package = "serialize" } log = "0.4" rustc_span = { path = "../librustc_span" } -errors = { path = "../librustc_errors", package = "rustc_errors" } rustc_data_structures = { path = "../librustc_data_structures" } +rustc_errors = { path = "../librustc_errors" } rustc_feature = { path = "../librustc_feature" } rustc_lexer = { path = "../librustc_lexer" } rustc_parse = { path = "../librustc_parse" } diff --git a/src/librustc_expand/base.rs b/src/librustc_expand/base.rs index fe08c85249a2e..52ba14dbc3df0 100644 --- a/src/librustc_expand/base.rs +++ b/src/librustc_expand/base.rs @@ -1,9 +1,15 @@ use crate::expand::{self, AstFragment, Invocation}; +use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::sync::{self, Lrc}; +use rustc_errors::{DiagnosticBuilder, DiagnosticId}; use rustc_parse::{self, parser, DirectoryOwnership, MACRO_ARGUMENTS}; use rustc_span::edition::Edition; +use rustc_span::hygiene::{AstPass, ExpnData, ExpnId, ExpnKind}; use rustc_span::source_map::SourceMap; use rustc_span::symbol::{kw, sym, Ident, Symbol}; +use rustc_span::{FileName, MultiSpan, Span, DUMMY_SP}; +use smallvec::{smallvec, SmallVec}; use syntax::ast::{self, Attribute, Name, NodeId, PatKind}; use syntax::attr::{self, Deprecation, HasAttrs, Stability}; use syntax::mut_visit::{self, MutVisitor}; @@ -13,13 +19,6 @@ use syntax::token; use syntax::tokenstream::{self, TokenStream}; use syntax::visit::Visitor; -use errors::{DiagnosticBuilder, DiagnosticId}; -use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::sync::{self, Lrc}; -use rustc_span::hygiene::{AstPass, ExpnData, ExpnId, ExpnKind}; -use rustc_span::{FileName, MultiSpan, Span, DUMMY_SP}; -use smallvec::{smallvec, SmallVec}; - use std::default::Default; use std::iter; use std::path::PathBuf; diff --git a/src/librustc_expand/expand.rs b/src/librustc_expand/expand.rs index 6eead11ccb7ba..8426391a2f389 100644 --- a/src/librustc_expand/expand.rs +++ b/src/librustc_expand/expand.rs @@ -5,6 +5,8 @@ use crate::mbe::macro_rules::annotate_err_with_kind; use crate::placeholders::{placeholder, PlaceholderExpander}; use crate::proc_macro::collect_derives; +use rustc_data_structures::sync::Lrc; +use rustc_errors::{Applicability, FatalError, PResult}; use rustc_feature::Features; use rustc_parse::configure; use rustc_parse::parser::Parser; @@ -26,10 +28,7 @@ use syntax::tokenstream::{TokenStream, TokenTree}; use syntax::util::map_in_place::MapInPlace; use syntax::visit::{self, Visitor}; -use errors::{Applicability, FatalError, PResult}; use smallvec::{smallvec, SmallVec}; - -use rustc_data_structures::sync::Lrc; use std::io::ErrorKind; use std::ops::DerefMut; use std::path::PathBuf; diff --git a/src/librustc_expand/lib.rs b/src/librustc_expand/lib.rs index feba7f633ed80..4fe7c268c4f0b 100644 --- a/src/librustc_expand/lib.rs +++ b/src/librustc_expand/lib.rs @@ -13,7 +13,7 @@ extern crate proc_macro as pm; #[macro_export] macro_rules! panictry { ($e:expr) => {{ - use errors::FatalError; + use rustc_errors::FatalError; use std::result::Result::{Err, Ok}; match $e { Ok(e) => e, diff --git a/src/librustc_expand/mbe/macro_parser.rs b/src/librustc_expand/mbe/macro_parser.rs index c0e34a30c54e9..441c1b75a7c73 100644 --- a/src/librustc_expand/mbe/macro_parser.rs +++ b/src/librustc_expand/mbe/macro_parser.rs @@ -85,7 +85,7 @@ use syntax::sess::ParseSess; use syntax::token::{self, DocComment, Nonterminal, Token}; use syntax::tokenstream::TokenStream; -use errors::{FatalError, PResult}; +use rustc_errors::{FatalError, PResult}; use rustc_span::Span; use smallvec::{smallvec, SmallVec}; diff --git a/src/librustc_expand/mbe/macro_rules.rs b/src/librustc_expand/mbe/macro_rules.rs index 6e965346d30e9..d72317af9eb67 100644 --- a/src/librustc_expand/mbe/macro_rules.rs +++ b/src/librustc_expand/mbe/macro_rules.rs @@ -8,6 +8,9 @@ use crate::mbe::macro_parser::{Error, Failure, Success}; use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, NamedParseResult}; use crate::mbe::transcribe::transcribe; +use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::sync::Lrc; +use rustc_errors::{Applicability, DiagnosticBuilder, FatalError}; use rustc_feature::Features; use rustc_parse::parser::Parser; use rustc_parse::Directory; @@ -22,17 +25,11 @@ use syntax::sess::ParseSess; use syntax::token::{self, NtTT, Token, TokenKind::*}; use syntax::tokenstream::{DelimSpan, TokenStream}; -use errors::{DiagnosticBuilder, FatalError}; use log::debug; - -use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::sync::Lrc; use std::borrow::Cow; use std::collections::hash_map::Entry; use std::{mem, slice}; -use errors::Applicability; - const VALID_FRAGMENT_NAMES_MSG: &str = "valid fragment specifiers are \ `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, \ `literal`, `path`, `meta`, `tt`, `item` and `vis`"; diff --git a/src/librustc_expand/mbe/transcribe.rs b/src/librustc_expand/mbe/transcribe.rs index 4fd68a80de81d..104a5233c9d8c 100644 --- a/src/librustc_expand/mbe/transcribe.rs +++ b/src/librustc_expand/mbe/transcribe.rs @@ -2,19 +2,17 @@ use crate::base::ExtCtxt; use crate::mbe; use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, NamedMatch}; +use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::sync::Lrc; +use rustc_errors::pluralize; +use rustc_span::hygiene::{ExpnId, Transparency}; +use rustc_span::Span; use syntax::ast::{Ident, Mac}; use syntax::mut_visit::{self, MutVisitor}; use syntax::token::{self, NtTT, Token}; use syntax::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint}; use smallvec::{smallvec, SmallVec}; - -use errors::pluralize; -use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::sync::Lrc; -use rustc_span::hygiene::{ExpnId, Transparency}; -use rustc_span::Span; - use std::mem; // A Marker adds the given mark to the syntax context. diff --git a/src/librustc_expand/parse/lexer/tests.rs b/src/librustc_expand/parse/lexer/tests.rs index 835f0b0108ead..2ef81d80a1412 100644 --- a/src/librustc_expand/parse/lexer/tests.rs +++ b/src/librustc_expand/parse/lexer/tests.rs @@ -1,4 +1,5 @@ use rustc_data_structures::sync::Lrc; +use rustc_errors::{emitter::EmitterWriter, Handler}; use rustc_parse::lexer::StringReader; use rustc_span::source_map::{FilePathMapping, SourceMap}; use rustc_span::symbol::Symbol; @@ -8,7 +9,6 @@ use syntax::token::{self, Token, TokenKind}; use syntax::util::comments::is_doc_comment; use syntax::with_default_globals; -use errors::{emitter::EmitterWriter, Handler}; use std::io; use std::path::PathBuf; diff --git a/src/librustc_expand/parse/tests.rs b/src/librustc_expand/parse/tests.rs index 25cd5dabe57ec..b79e2894126dd 100644 --- a/src/librustc_expand/parse/tests.rs +++ b/src/librustc_expand/parse/tests.rs @@ -1,6 +1,6 @@ use crate::tests::{matches_codepattern, string_to_stream, with_error_checking_parse}; -use errors::PResult; +use rustc_errors::PResult; use rustc_parse::new_parser_from_source_str; use rustc_span::source_map::FilePathMapping; use rustc_span::symbol::{kw, sym, Symbol}; diff --git a/src/librustc_expand/proc_macro.rs b/src/librustc_expand/proc_macro.rs index 25e2bbb34678e..cb6249e936976 100644 --- a/src/librustc_expand/proc_macro.rs +++ b/src/librustc_expand/proc_macro.rs @@ -1,15 +1,14 @@ use crate::base::{self, *}; use crate::proc_macro_server; +use rustc_data_structures::sync::Lrc; +use rustc_errors::{Applicability, FatalError}; use rustc_span::symbol::sym; +use rustc_span::{Span, DUMMY_SP}; use syntax::ast::{self, ItemKind, MetaItemKind, NestedMetaItem}; -use syntax::errors::{Applicability, FatalError}; use syntax::token; use syntax::tokenstream::{self, TokenStream}; -use rustc_data_structures::sync::Lrc; -use rustc_span::{Span, DUMMY_SP}; - const EXEC_STRATEGY: pm::bridge::server::SameThread = pm::bridge::server::SameThread; pub struct BangProcMacro { diff --git a/src/librustc_expand/proc_macro_server.rs b/src/librustc_expand/proc_macro_server.rs index cf5749f506856..d441613ac58f4 100644 --- a/src/librustc_expand/proc_macro_server.rs +++ b/src/librustc_expand/proc_macro_server.rs @@ -1,5 +1,7 @@ use crate::base::ExtCtxt; +use rustc_data_structures::sync::Lrc; +use rustc_errors::Diagnostic; use rustc_parse::lexer::nfc_normalize; use rustc_parse::{nt_to_tokenstream, parse_stream_from_source_str}; use rustc_span::symbol::{kw, sym, Symbol}; @@ -11,9 +13,6 @@ use syntax::token; use syntax::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint}; use syntax::util::comments; -use errors::Diagnostic; -use rustc_data_structures::sync::Lrc; - use pm::bridge::{server, TokenTree}; use pm::{Delimiter, Level, LineColumn, Spacing}; use std::ops::Bound; @@ -265,13 +264,13 @@ impl ToInternal for TokenTree { } } -impl ToInternal for Level { - fn to_internal(self) -> errors::Level { +impl ToInternal for Level { + fn to_internal(self) -> rustc_errors::Level { match self { - Level::Error => errors::Level::Error, - Level::Warning => errors::Level::Warning, - Level::Note => errors::Level::Note, - Level::Help => errors::Level::Help, + Level::Error => rustc_errors::Level::Error, + Level::Warning => rustc_errors::Level::Warning, + Level::Note => rustc_errors::Level::Note, + Level::Help => rustc_errors::Level::Help, _ => unreachable!("unknown proc_macro::Level variant: {:?}", self), } } diff --git a/src/librustc_expand/tests.rs b/src/librustc_expand/tests.rs index 18dc605c9e754..82ab74ac15004 100644 --- a/src/librustc_expand/tests.rs +++ b/src/librustc_expand/tests.rs @@ -6,9 +6,9 @@ use syntax::sess::ParseSess; use syntax::tokenstream::TokenStream; use syntax::with_default_globals; -use errors::emitter::EmitterWriter; -use errors::{Handler, PResult}; use rustc_data_structures::sync::Lrc; +use rustc_errors::emitter::EmitterWriter; +use rustc_errors::{Handler, PResult}; use std::io; use std::io::prelude::*; diff --git a/src/librustc_feature/active.rs b/src/librustc_feature/active.rs index 6a15cc5cb0fce..d3876ecc7c3ad 100644 --- a/src/librustc_feature/active.rs +++ b/src/librustc_feature/active.rs @@ -534,6 +534,9 @@ declare_features! ( /// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used. (active, cfg_sanitize, "1.41.0", Some(39699), None), + /// Allows using `..X`, `..=X`, `...X`, and `X..` as a pattern. + (active, half_open_range_patterns, "1.41.0", Some(67264), None), + /// Allows using `&mut` in constant functions. (active, const_mut_refs, "1.41.0", Some(57349), None), diff --git a/src/librustc_hir/hir.rs b/src/librustc_hir/hir.rs index 603c21188e3ac..550e3654d0800 100644 --- a/src/librustc_hir/hir.rs +++ b/src/librustc_hir/hir.rs @@ -905,7 +905,7 @@ pub enum PatKind<'hir> { Lit(&'hir Expr<'hir>), /// A range pattern (e.g., `1..=2` or `1..2`). - Range(&'hir Expr<'hir>, &'hir Expr<'hir>, RangeEnd), + Range(Option<&'hir Expr<'hir>>, Option<&'hir Expr<'hir>>, RangeEnd), /// A slice pattern, `[before_0, ..., before_n, (slice, after_0, ..., after_n)?]`. /// diff --git a/src/librustc_hir/intravisit.rs b/src/librustc_hir/intravisit.rs index 4664340b15fb7..3dbc5253a9abf 100644 --- a/src/librustc_hir/intravisit.rs +++ b/src/librustc_hir/intravisit.rs @@ -766,8 +766,8 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) { } PatKind::Lit(ref expression) => visitor.visit_expr(expression), PatKind::Range(ref lower_bound, ref upper_bound, _) => { - visitor.visit_expr(lower_bound); - visitor.visit_expr(upper_bound) + walk_list!(visitor, visit_expr, lower_bound); + walk_list!(visitor, visit_expr, upper_bound); } PatKind::Wild => (), PatKind::Slice(prepatterns, ref slice_pattern, postpatterns) => { diff --git a/src/librustc_hir/print.rs b/src/librustc_hir/print.rs index 571bab2cb83f2..759f423070aa0 100644 --- a/src/librustc_hir/print.rs +++ b/src/librustc_hir/print.rs @@ -1767,13 +1767,17 @@ impl<'a> State<'a> { } PatKind::Lit(ref e) => self.print_expr(&e), PatKind::Range(ref begin, ref end, ref end_kind) => { - self.print_expr(&begin); - self.s.space(); + if let Some(expr) = begin { + self.print_expr(expr); + self.s.space(); + } match *end_kind { RangeEnd::Included => self.s.word("..."), RangeEnd::Excluded => self.s.word(".."), } - self.print_expr(&end); + if let Some(expr) = end { + self.print_expr(expr); + } } PatKind::Slice(ref before, ref slice, ref after) => { self.s.word("["); diff --git a/src/librustc_lint/Cargo.toml b/src/librustc_lint/Cargo.toml index 5ca8fc97ac422..7e23e70577975 100644 --- a/src/librustc_lint/Cargo.toml +++ b/src/librustc_lint/Cargo.toml @@ -12,6 +12,7 @@ path = "lib.rs" log = "0.4" unicode-security = "0.0.2" rustc = { path = "../librustc" } +rustc_errors = { path = "../librustc_errors" } rustc_hir = { path = "../librustc_hir" } rustc_target = { path = "../librustc_target" } syntax = { path = "../libsyntax" } diff --git a/src/librustc_lint/array_into_iter.rs b/src/librustc_lint/array_into_iter.rs index 46202cda16d50..d8ddf7435b458 100644 --- a/src/librustc_lint/array_into_iter.rs +++ b/src/librustc_lint/array_into_iter.rs @@ -2,9 +2,9 @@ use crate::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc::lint::FutureIncompatibleInfo; use rustc::ty; use rustc::ty::adjustment::{Adjust, Adjustment}; +use rustc_errors::Applicability; use rustc_hir as hir; use rustc_span::symbol::sym; -use syntax::errors::Applicability; declare_lint! { pub ARRAY_INTO_ITER, diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 23740af525971..25f6361e0507d 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -31,6 +31,7 @@ use rustc::lint::FutureIncompatibleInfo; use rustc::traits::misc::can_type_implement_copy; use rustc::ty::{self, layout::VariantIdx, Ty, TyCtxt}; use rustc_data_structures::fx::FxHashSet; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_feature::Stability; use rustc_feature::{deprecated_attributes, AttributeGate, AttributeTemplate, AttributeType}; use rustc_hir as hir; @@ -44,9 +45,7 @@ use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::{BytePos, Span}; use syntax::ast::{self, Expr}; use syntax::attr::{self, HasAttrs}; -use syntax::errors::{Applicability, DiagnosticBuilder}; use syntax::print::pprust::{self, expr_to_string}; -use syntax::ptr::P; use syntax::tokenstream::{TokenStream, TokenTree}; use syntax::visit::FnKind; @@ -1309,11 +1308,13 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns { /// If `pat` is a `...` pattern, return the start and end of the range, as well as the span /// corresponding to the ellipsis. - fn matches_ellipsis_pat(pat: &ast::Pat) -> Option<(&P, &P, Span)> { + fn matches_ellipsis_pat(pat: &ast::Pat) -> Option<(Option<&Expr>, &Expr, Span)> { match &pat.kind { - PatKind::Range(a, b, Spanned { span, node: RangeEnd::Included(DotDotDot), .. }) => { - Some((a, b, *span)) - } + PatKind::Range( + a, + Some(b), + Spanned { span, node: RangeEnd::Included(DotDotDot) }, + ) => Some((a.as_deref(), b, *span)), _ => None, } } @@ -1328,11 +1329,16 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns { let suggestion = "use `..=` for an inclusive range"; if parenthesise { self.node_id = Some(pat.id); + let end = expr_to_string(&end); + let replace = match start { + Some(start) => format!("&({}..={})", expr_to_string(&start), end), + None => format!("&(..={})", end), + }; let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, pat.span, msg); err.span_suggestion( pat.span, suggestion, - format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)), + replace, Applicability::MachineApplicable, ); err.emit(); diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 13e57ecf1469c..7e5ad0976989e 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -2,6 +2,7 @@ use lint::{EarlyContext, LateContext, LintArray, LintContext}; use lint::{EarlyLintPass, LateLintPass, LintPass}; use rustc::lint; use rustc::ty; +use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::FnKind; @@ -11,7 +12,6 @@ use rustc_span::{symbol::Ident, BytePos, Span}; use rustc_target::spec::abi::Abi; use syntax::ast; use syntax::attr; -use syntax::errors::Applicability; #[derive(PartialEq)] pub enum MethodLateContext { diff --git a/src/librustc_lint/redundant_semicolon.rs b/src/librustc_lint/redundant_semicolon.rs index 8dbf96a155825..9fc147f2a0c5a 100644 --- a/src/librustc_lint/redundant_semicolon.rs +++ b/src/librustc_lint/redundant_semicolon.rs @@ -1,6 +1,6 @@ use crate::lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass}; +use rustc_errors::Applicability; use syntax::ast::{ExprKind, Stmt, StmtKind}; -use syntax::errors::Applicability; declare_lint! { pub REDUNDANT_SEMICOLON, diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index f740bdb271619..f128e25f35bf2 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -9,6 +9,7 @@ use rustc::ty::layout::{self, IntegerExt, LayoutOf, SizeSkeleton, VariantIdx}; use rustc::ty::subst::SubstsRef; use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt}; use rustc_data_structures::fx::FxHashSet; +use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::{is_range_literal, ExprKind, Node}; use rustc_index::vec::Idx; @@ -16,7 +17,6 @@ use rustc_span::source_map; use rustc_span::symbol::sym; use rustc_span::Span; use rustc_target::spec::abi::Abi; -use syntax::errors::Applicability; use syntax::{ast, attr}; use log::debug; diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 184651e3ad564..d57f565d919be 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -5,17 +5,16 @@ use rustc::lint::builtin::UNUSED_ATTRIBUTES; use rustc::ty::adjustment; use rustc::ty::{self, Ty}; use rustc_data_structures::fx::FxHashMap; +use rustc_errors::{pluralize, Applicability}; use rustc_feature::{AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; - use rustc_span::symbol::Symbol; use rustc_span::symbol::{kw, sym}; use rustc_span::{BytePos, Span}; use syntax::ast; use syntax::attr; -use syntax::errors::{pluralize, Applicability}; use syntax::print::pprust; use syntax::util::parser; diff --git a/src/librustc_metadata/Cargo.toml b/src/librustc_metadata/Cargo.toml index d998e82d4890b..48767c377a94c 100644 --- a/src/librustc_metadata/Cargo.toml +++ b/src/librustc_metadata/Cargo.toml @@ -16,8 +16,8 @@ memmap = "0.7" smallvec = { version = "1.0", features = ["union", "may_dangle"] } rustc = { path = "../librustc" } rustc_data_structures = { path = "../librustc_data_structures" } +rustc_errors = { path = "../librustc_errors" } rustc_hir = { path = "../librustc_hir" } -errors = { path = "../librustc_errors", package = "rustc_errors" } rustc_target = { path = "../librustc_target" } rustc_index = { path = "../librustc_index" } rustc_serialize = { path = "../libserialize", package = "serialize" } diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 30d049d143eab..17c2e3303cb56 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -12,25 +12,23 @@ use rustc::session::{CrateDisambiguator, Session}; use rustc::ty::TyCtxt; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::Lrc; +use rustc_error_codes::*; +use rustc_errors::struct_span_err; +use rustc_expand::base::SyntaxExtension; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc_index::vec::IndexVec; -use rustc_target::spec::{PanicStrategy, TargetTriple}; - -use std::path::Path; -use std::{cmp, fs}; - -use errors::struct_span_err; -use log::{debug, info, log_enabled}; -use proc_macro::bridge::client::ProcMacro; -use rustc_expand::base::SyntaxExtension; use rustc_span::edition::Edition; use rustc_span::symbol::{sym, Symbol}; use rustc_span::{Span, DUMMY_SP}; +use rustc_target::spec::{PanicStrategy, TargetTriple}; use syntax::ast; use syntax::attr; use syntax::expand::allocator::{global_allocator_spans, AllocatorKind}; -use rustc_error_codes::*; +use log::{debug, info, log_enabled}; +use proc_macro::bridge::client::ProcMacro; +use std::path::Path; +use std::{cmp, fs}; #[derive(Clone)] pub struct CStore { diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index 9f9a2187eced8..4745ad02a3aa4 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -215,7 +215,6 @@ use crate::creader::Library; use crate::rmeta::{rustc_version, MetadataBlob, METADATA_HEADER}; -use errors::{struct_span_err, DiagnosticBuilder}; use rustc::middle::cstore::{CrateSource, MetadataLoader}; use rustc::session::filesearch::{FileDoesntMatch, FileMatches, FileSearch}; use rustc::session::search_paths::PathKind; @@ -223,6 +222,7 @@ use rustc::session::{config, CrateDisambiguator, Session}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::MetadataRef; +use rustc_errors::{struct_span_err, DiagnosticBuilder}; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; use rustc_target::spec::{Target, TargetTriple}; diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index c9f47475af851..ae67efb966c96 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -1,9 +1,9 @@ -use errors::struct_span_err; use rustc::middle::cstore::{self, NativeLibrary}; use rustc::session::Session; use rustc::ty::TyCtxt; use rustc_data_structures::fx::FxHashSet; use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_span::source_map::Span; diff --git a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs index 9a301a6ad32a8..dc63fa80275e1 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs @@ -6,13 +6,12 @@ use rustc::infer::{ }; use rustc::mir::{Body, ConstraintCategory, Location}; use rustc::ty::{self, RegionVid, Ty}; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir::def_id::DefId; use rustc_index::vec::IndexVec; use rustc_span::symbol::kw; use rustc_span::Span; use std::collections::VecDeque; -use syntax::errors::Applicability; use crate::util::borrowck_errors; diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 611d3f5b832dc..2598ce2391fb3 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -429,14 +429,87 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { expr: &'tcx hir::Expr<'tcx>, ) -> (PatKind<'tcx>, Option>) { match self.lower_lit(expr) { - PatKind::AscribeUserType { - ascription: lo_ascription, - subpattern: Pat { kind: box kind, .. }, - } => (kind, Some(lo_ascription)), + PatKind::AscribeUserType { ascription, subpattern: Pat { kind: box kind, .. } } => { + (kind, Some(ascription)) + } kind => (kind, None), } } + fn lower_pattern_range( + &mut self, + ty: Ty<'tcx>, + lo: &'tcx ty::Const<'tcx>, + hi: &'tcx ty::Const<'tcx>, + end: RangeEnd, + span: Span, + ) -> PatKind<'tcx> { + assert_eq!(lo.ty, ty); + assert_eq!(hi.ty, ty); + let cmp = compare_const_vals(self.tcx, lo, hi, self.param_env, ty); + match (end, cmp) { + // `x..y` where `x < y`. + // Non-empty because the range includes at least `x`. + (RangeEnd::Excluded, Some(Ordering::Less)) => PatKind::Range(PatRange { lo, hi, end }), + // `x..y` where `x >= y`. The range is empty => error. + (RangeEnd::Excluded, _) => { + struct_span_err!( + self.tcx.sess, + span, + E0579, + "lower range bound must be less than upper" + ) + .emit(); + PatKind::Wild + } + // `x..=y` where `x == y`. + (RangeEnd::Included, Some(Ordering::Equal)) => PatKind::Constant { value: lo }, + // `x..=y` where `x < y`. + (RangeEnd::Included, Some(Ordering::Less)) => PatKind::Range(PatRange { lo, hi, end }), + // `x..=y` where `x > y` hence the range is empty => error. + (RangeEnd::Included, _) => { + let mut err = struct_span_err!( + self.tcx.sess, + span, + E0030, + "lower range bound must be less than or equal to upper" + ); + err.span_label(span, "lower bound larger than upper bound"); + if self.tcx.sess.teach(&err.get_code().unwrap()) { + err.note( + "When matching against a range, the compiler \ + verifies that the range is non-empty. Range \ + patterns include both end-points, so this is \ + equivalent to requiring the start of the range \ + to be less than or equal to the end of the range.", + ); + } + err.emit(); + PatKind::Wild + } + } + } + + fn normalize_range_pattern_ends( + &self, + ty: Ty<'tcx>, + lo: Option<&PatKind<'tcx>>, + hi: Option<&PatKind<'tcx>>, + ) -> Option<(&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>)> { + match (lo, hi) { + (Some(PatKind::Constant { value: lo }), Some(PatKind::Constant { value: hi })) => { + Some((lo, hi)) + } + (Some(PatKind::Constant { value: lo }), None) => { + Some((lo, ty.numeric_max_val(self.tcx)?)) + } + (None, Some(PatKind::Constant { value: hi })) => { + Some((ty.numeric_min_val(self.tcx)?, hi)) + } + _ => None, + } + } + fn lower_pattern_unadjusted(&mut self, pat: &'tcx hir::Pat<'tcx>) -> Pat<'tcx> { let mut ty = self.tables.node_type(pat.hir_id); @@ -451,65 +524,20 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { hir::PatKind::Lit(ref value) => self.lower_lit(value), hir::PatKind::Range(ref lo_expr, ref hi_expr, end) => { - let (lo, lo_ascription) = self.lower_range_expr(lo_expr); - let (hi, hi_ascription) = self.lower_range_expr(hi_expr); - - let mut kind = match (lo, hi) { - (PatKind::Constant { value: lo }, PatKind::Constant { value: hi }) => { - assert_eq!(lo.ty, ty); - assert_eq!(hi.ty, ty); - let cmp = compare_const_vals(self.tcx, lo, hi, self.param_env, ty); - match (end, cmp) { - (RangeEnd::Excluded, Some(Ordering::Less)) => { - PatKind::Range(PatRange { lo, hi, end }) - } - (RangeEnd::Excluded, _) => { - struct_span_err!( - self.tcx.sess, - lo_expr.span, - E0579, - "lower range bound must be less than upper", - ) - .emit(); - PatKind::Wild - } - (RangeEnd::Included, Some(Ordering::Equal)) => { - PatKind::Constant { value: lo } - } - (RangeEnd::Included, Some(Ordering::Less)) => { - PatKind::Range(PatRange { lo, hi, end }) - } - (RangeEnd::Included, _) => { - let mut err = struct_span_err!( - self.tcx.sess, - lo_expr.span, - E0030, - "lower range bound must be less than or equal to upper" - ); - err.span_label(lo_expr.span, "lower bound larger than upper bound"); - if self.tcx.sess.teach(&err.get_code().unwrap()) { - err.note( - "When matching against a range, the compiler \ - verifies that the range is non-empty. Range \ - patterns include both end-points, so this is \ - equivalent to requiring the start of the range \ - to be less than or equal to the end of the range.", - ); - } - err.emit(); - PatKind::Wild - } - } - } - ref pats => { - self.tcx.sess.delay_span_bug( - pat.span, - &format!( - "found bad range pattern `{:?}` outside of error recovery", - pats, - ), + let (lo_expr, hi_expr) = (lo_expr.as_deref(), hi_expr.as_deref()); + let lo_span = lo_expr.map_or(pat.span, |e| e.span); + let lo = lo_expr.map(|e| self.lower_range_expr(e)); + let hi = hi_expr.map(|e| self.lower_range_expr(e)); + + let (lp, hp) = (lo.as_ref().map(|x| &x.0), hi.as_ref().map(|x| &x.0)); + let mut kind = match self.normalize_range_pattern_ends(ty, lp, hp) { + Some((lc, hc)) => self.lower_pattern_range(ty, lc, hc, end, lo_span), + None => { + let msg = &format!( + "found bad range pattern `{:?}` outside of error recovery", + (&lo, &hi), ); - + self.tcx.sess.delay_span_bug(pat.span, msg); PatKind::Wild } }; @@ -517,12 +545,10 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { // If we are handling a range with associated constants (e.g. // `Foo::<'a>::A..=Foo::B`), we need to put the ascriptions for the associated // constants somewhere. Have them on the range pattern. - for ascription in &[lo_ascription, hi_ascription] { - if let Some(ascription) = ascription { - kind = PatKind::AscribeUserType { - ascription: *ascription, - subpattern: Pat { span: pat.span, ty, kind: Box::new(kind) }, - }; + for end in &[lo, hi] { + if let Some((_, Some(ascription))) = end { + let subpattern = Pat { span: pat.span, ty, kind: Box::new(kind) }; + kind = PatKind::AscribeUserType { ascription: *ascription, subpattern }; } } diff --git a/src/librustc_parse/lexer/unescape_error_reporting.rs b/src/librustc_parse/lexer/unescape_error_reporting.rs index 151c63a49b57c..88762dabd8a29 100644 --- a/src/librustc_parse/lexer/unescape_error_reporting.rs +++ b/src/librustc_parse/lexer/unescape_error_reporting.rs @@ -3,11 +3,10 @@ use std::iter::once; use std::ops::Range; +use rustc_errors::{Applicability, Handler}; use rustc_lexer::unescape::{EscapeError, Mode}; use rustc_span::{BytePos, Span}; -use syntax::errors::{Applicability, Handler}; - pub(crate) fn emit_unescape_error( handler: &Handler, // interior part of the literal, without quotes diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index 9abfbc698c5cf..d321383424cab 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -51,7 +51,6 @@ pub enum Error { secondary_path: String, }, UselessDocComment, - InclusiveRangeWithNoEnd, } impl Error { @@ -102,11 +101,6 @@ impl Error { ); err } - Error::InclusiveRangeWithNoEnd => { - let mut err = struct_span_err!(handler, sp, E0586, "inclusive range with no end",); - err.help("inclusive ranges must be bounded at the end (`..=b` or `a..=b`)"); - err - } } } } diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index 90f15375aec42..2d6a94ce620cf 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -1,4 +1,3 @@ -use super::diagnostics::Error; use super::pat::{GateOr, PARAM_EXPECTED}; use super::{BlockMode, Parser, PathStyle, PrevTokenKind, Restrictions, TokenType}; use super::{SemiColonMode, SeqSep, TokenExpectType}; @@ -1967,7 +1966,8 @@ impl<'a> Parser<'a> { limits: RangeLimits, ) -> PResult<'a, ExprKind> { if end.is_none() && limits == RangeLimits::Closed { - Err(self.span_fatal_err(self.token.span, Error::InclusiveRangeWithNoEnd)) + self.error_inclusive_range_with_no_end(self.token.span); + Ok(ExprKind::Err) } else { Ok(ExprKind::Range(start, end, limits)) } diff --git a/src/librustc_parse/parser/pat.rs b/src/librustc_parse/parser/pat.rs index bf7f5735f134b..50756ddec9f2d 100644 --- a/src/librustc_parse/parser/pat.rs +++ b/src/librustc_parse/parser/pat.rs @@ -1,6 +1,6 @@ use super::{Parser, PathStyle}; use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole}; -use rustc_errors::{Applicability, DiagnosticBuilder, PResult}; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, PResult}; use rustc_span::source_map::{respan, Span, Spanned}; use rustc_span::symbol::{kw, sym}; use syntax::ast::{self, AttrVec, Attribute, FieldPat, Mac, Pat, PatKind, RangeEnd, RangeSyntax}; @@ -281,91 +281,73 @@ impl<'a> Parser<'a> { maybe_whole!(self, NtPat, |x| x); let lo = self.token.span; - let pat = match self.token.kind { - token::BinOp(token::And) | token::AndAnd => self.parse_pat_deref(expected)?, - token::OpenDelim(token::Paren) => self.parse_pat_tuple_or_parens()?, - token::OpenDelim(token::Bracket) => { - // Parse `[pat, pat,...]` as a slice pattern. - let (pats, _) = - self.parse_delim_comma_seq(token::Bracket, |p| p.parse_pat_with_or_inner())?; - PatKind::Slice(pats) - } - token::DotDot => { - self.bump(); - if self.is_pat_range_end_start() { - // Parse `..42` for recovery. - self.parse_pat_range_to(RangeEnd::Excluded, "..")? - } else { - // A rest pattern `..`. - PatKind::Rest - } - } - token::DotDotEq => { - // Parse `..=42` for recovery. - self.bump(); - self.parse_pat_range_to(RangeEnd::Included(RangeSyntax::DotDotEq), "..=")? - } - token::DotDotDot => { - // Parse `...42` for recovery. - self.bump(); - self.parse_pat_range_to(RangeEnd::Included(RangeSyntax::DotDotDot), "...")? + + let pat = if self.check(&token::BinOp(token::And)) || self.token.kind == token::AndAnd { + self.parse_pat_deref(expected)? + } else if self.check(&token::OpenDelim(token::Paren)) { + self.parse_pat_tuple_or_parens()? + } else if self.check(&token::OpenDelim(token::Bracket)) { + // Parse `[pat, pat,...]` as a slice pattern. + let (pats, _) = + self.parse_delim_comma_seq(token::Bracket, |p| p.parse_pat_with_or_inner())?; + PatKind::Slice(pats) + } else if self.check(&token::DotDot) && !self.is_pat_range_end_start(1) { + // A rest pattern `..`. + self.bump(); // `..` + PatKind::Rest + } else if let Some(form) = self.parse_range_end() { + self.parse_pat_range_to(form)? // `..=X`, `...X`, or `..X`. + } else if self.eat_keyword(kw::Underscore) { + // Parse _ + PatKind::Wild + } else if self.eat_keyword(kw::Mut) { + self.parse_pat_ident_mut()? + } else if self.eat_keyword(kw::Ref) { + // Parse ref ident @ pat / ref mut ident @ pat + let mutbl = self.parse_mutability(); + self.parse_pat_ident(BindingMode::ByRef(mutbl))? + } else if self.eat_keyword(kw::Box) { + // Parse `box pat` + let pat = self.parse_pat_with_range_pat(false, None)?; + self.sess.gated_spans.gate(sym::box_patterns, lo.to(self.prev_span)); + PatKind::Box(pat) + } else if self.can_be_ident_pat() { + // Parse `ident @ pat` + // This can give false positives and parse nullary enums, + // they are dealt with later in resolve. + self.parse_pat_ident(BindingMode::ByValue(Mutability::Not))? + } else if self.is_start_of_pat_with_path() { + // Parse pattern starting with a path + let (qself, path) = if self.eat_lt() { + // Parse a qualified path + let (qself, path) = self.parse_qpath(PathStyle::Expr)?; + (Some(qself), path) + } else { + // Parse an unqualified path + (None, self.parse_path(PathStyle::Expr)?) + }; + let span = lo.to(self.prev_span); + + if qself.is_none() && self.check(&token::Not) { + self.parse_pat_mac_invoc(path)? + } else if let Some(form) = self.parse_range_end() { + let begin = self.mk_expr(span, ExprKind::Path(qself, path), AttrVec::new()); + self.parse_pat_range_begin_with(begin, form)? + } else if self.check(&token::OpenDelim(token::Brace)) { + self.parse_pat_struct(qself, path)? + } else if self.check(&token::OpenDelim(token::Paren)) { + self.parse_pat_tuple_struct(qself, path)? + } else { + PatKind::Path(qself, path) } - // At this point, token != `&`, `&&`, `(`, `[`, `..`, `..=`, or `...`. - _ => { - if self.eat_keyword(kw::Underscore) { - // Parse _ - PatKind::Wild - } else if self.eat_keyword(kw::Mut) { - self.parse_pat_ident_mut()? - } else if self.eat_keyword(kw::Ref) { - // Parse ref ident @ pat / ref mut ident @ pat - let mutbl = self.parse_mutability(); - self.parse_pat_ident(BindingMode::ByRef(mutbl))? - } else if self.eat_keyword(kw::Box) { - // Parse `box pat` - let pat = self.parse_pat_with_range_pat(false, None)?; - self.sess.gated_spans.gate(sym::box_patterns, lo.to(self.prev_span)); - PatKind::Box(pat) - } else if self.can_be_ident_pat() { - // Parse `ident @ pat` - // This can give false positives and parse nullary enums, - // they are dealt with later in resolve. - self.parse_pat_ident(BindingMode::ByValue(Mutability::Not))? - } else if self.is_start_of_pat_with_path() { - // Parse pattern starting with a path - let (qself, path) = if self.eat_lt() { - // Parse a qualified path - let (qself, path) = self.parse_qpath(PathStyle::Expr)?; - (Some(qself), path) - } else { - // Parse an unqualified path - (None, self.parse_path(PathStyle::Expr)?) - }; - match self.token.kind { - token::Not if qself.is_none() => self.parse_pat_mac_invoc(path)?, - token::DotDotDot | token::DotDotEq | token::DotDot => { - self.parse_pat_range_starting_with_path(lo, qself, path)? - } - token::OpenDelim(token::Brace) => self.parse_pat_struct(qself, path)?, - token::OpenDelim(token::Paren) => { - self.parse_pat_tuple_struct(qself, path)? - } - _ => PatKind::Path(qself, path), - } - } else { - // Try to parse everything else as literal with optional minus - match self.parse_literal_maybe_minus() { - Ok(begin) - if self.check(&token::DotDot) - || self.check(&token::DotDotEq) - || self.check(&token::DotDotDot) => - { - self.parse_pat_range_starting_with_lit(begin)? - } - Ok(begin) => PatKind::Lit(begin), - Err(err) => return self.fatal_unexpected_non_pat(err, expected), - } - } + } else { + // Try to parse everything else as literal with optional minus + match self.parse_literal_maybe_minus() { + Ok(begin) => match self.parse_range_end() { + Some(form) => self.parse_pat_range_begin_with(begin, form)?, + None => PatKind::Lit(begin), + }, + Err(err) => return self.fatal_unexpected_non_pat(err, expected), } }; @@ -374,7 +356,7 @@ impl<'a> Parser<'a> { let pat = self.recover_intersection_pat(pat)?; if !allow_range_pat { - self.ban_pat_range_if_ambiguous(&pat)? + self.ban_pat_range_if_ambiguous(&pat) } Ok(pat) @@ -441,26 +423,25 @@ impl<'a> Parser<'a> { } /// Ban a range pattern if it has an ambiguous interpretation. - fn ban_pat_range_if_ambiguous(&self, pat: &Pat) -> PResult<'a, ()> { + fn ban_pat_range_if_ambiguous(&self, pat: &Pat) { match pat.kind { PatKind::Range( .., Spanned { node: RangeEnd::Included(RangeSyntax::DotDotDot), .. }, - ) => return Ok(()), + ) => return, PatKind::Range(..) => {} - _ => return Ok(()), + _ => return, } - let mut err = - self.struct_span_err(pat.span, "the range pattern here has ambiguous interpretation"); - err.span_suggestion( - pat.span, - "add parentheses to clarify the precedence", - format!("({})", pprust::pat_to_string(&pat)), - // "ambiguous interpretation" implies that we have to be guessing - Applicability::MaybeIncorrect, - ); - Err(err) + self.struct_span_err(pat.span, "the range pattern here has ambiguous interpretation") + .span_suggestion( + pat.span, + "add parentheses to clarify the precedence", + format!("({})", pprust::pat_to_string(&pat)), + // "ambiguous interpretation" implies that we have to be guessing + Applicability::MaybeIncorrect, + ) + .emit(); } /// Parse `&pat` / `&mut pat`. @@ -618,51 +599,6 @@ impl<'a> Parser<'a> { Ok(PatKind::Mac(mac)) } - fn excluded_range_end(&self, span: Span) -> RangeEnd { - self.sess.gated_spans.gate(sym::exclusive_range_pattern, span); - RangeEnd::Excluded - } - - /// Parse a range pattern `$path $form $end?` where `$form = ".." | "..." | "..=" ;`. - /// The `$path` has already been parsed and the next token is the `$form`. - fn parse_pat_range_starting_with_path( - &mut self, - lo: Span, - qself: Option, - path: Path, - ) -> PResult<'a, PatKind> { - let (end_kind, form) = match self.token.kind { - token::DotDot => (self.excluded_range_end(self.token.span), ".."), - token::DotDotDot => (RangeEnd::Included(RangeSyntax::DotDotDot), "..."), - token::DotDotEq => (RangeEnd::Included(RangeSyntax::DotDotEq), "..="), - _ => panic!("can only parse `..`/`...`/`..=` for ranges (checked above)"), - }; - let op_span = self.token.span; - // Parse range - let span = lo.to(self.prev_span); - let begin = self.mk_expr(span, ExprKind::Path(qself, path), AttrVec::new()); - self.bump(); - let end = self.parse_pat_range_end_opt(&begin, form)?; - Ok(PatKind::Range(begin, end, respan(op_span, end_kind))) - } - - /// Parse a range pattern `$literal $form $end?` where `$form = ".." | "..." | "..=" ;`. - /// The `$path` has already been parsed and the next token is the `$form`. - fn parse_pat_range_starting_with_lit(&mut self, begin: P) -> PResult<'a, PatKind> { - let op_span = self.token.span; - let (end_kind, form) = if self.eat(&token::DotDotDot) { - (RangeEnd::Included(RangeSyntax::DotDotDot), "...") - } else if self.eat(&token::DotDotEq) { - (RangeEnd::Included(RangeSyntax::DotDotEq), "..=") - } else if self.eat(&token::DotDot) { - (self.excluded_range_end(op_span), "..") - } else { - panic!("impossible case: we already matched on a range-operator token") - }; - let end = self.parse_pat_range_end_opt(&begin, form)?; - Ok(PatKind::Range(begin, end, respan(op_span, end_kind))) - } - fn fatal_unexpected_non_pat( &mut self, mut err: DiagnosticBuilder<'a>, @@ -684,57 +620,66 @@ impl<'a> Parser<'a> { Err(err) } - /// Is the current token suitable as the start of a range patterns end? - fn is_pat_range_end_start(&self) -> bool { - self.token.is_path_start() // e.g. `MY_CONST`; - || self.token == token::Dot // e.g. `.5` for recovery; - || self.token.can_begin_literal_or_bool() // e.g. `42`. - || self.token.is_whole_expr() - } - - /// Parse a range-to pattern, e.g. `..X` and `..=X` for recovery. - fn parse_pat_range_to(&mut self, re: RangeEnd, form: &str) -> PResult<'a, PatKind> { - let lo = self.prev_span; - let end = self.parse_pat_range_end()?; - let range_span = lo.to(end.span); - let begin = self.mk_expr(range_span, ExprKind::Err, AttrVec::new()); - - self.struct_span_err(range_span, &format!("`{}X` range patterns are not supported", form)) - .span_suggestion( - range_span, - "try using the minimum value for the type", - format!("MIN{}{}", form, pprust::expr_to_string(&end)), - Applicability::HasPlaceholders, - ) - .emit(); - - Ok(PatKind::Range(begin, end, respan(lo, re))) + /// Parses the range pattern end form `".." | "..." | "..=" ;`. + fn parse_range_end(&mut self) -> Option> { + let re = if self.eat(&token::DotDotDot) { + RangeEnd::Included(RangeSyntax::DotDotDot) + } else if self.eat(&token::DotDotEq) { + RangeEnd::Included(RangeSyntax::DotDotEq) + } else if self.eat(&token::DotDot) { + self.sess.gated_spans.gate(sym::exclusive_range_pattern, self.prev_span); + RangeEnd::Excluded + } else { + return None; + }; + Some(respan(self.prev_span, re)) } - /// Parse the end of a `X..Y`, `X..=Y`, or `X...Y` range pattern or recover - /// if that end is missing treating it as `X..`, `X..=`, or `X...` respectively. - fn parse_pat_range_end_opt(&mut self, begin: &Expr, form: &str) -> PResult<'a, P> { - if self.is_pat_range_end_start() { + /// Parse a range pattern `$begin $form $end?` where `$form = ".." | "..." | "..=" ;`. + /// `$begin $form` has already been parsed. + fn parse_pat_range_begin_with( + &mut self, + begin: P, + re: Spanned, + ) -> PResult<'a, PatKind> { + let end = if self.is_pat_range_end_start(0) { // Parsing e.g. `X..=Y`. - self.parse_pat_range_end() + Some(self.parse_pat_range_end()?) } else { // Parsing e.g. `X..`. - let range_span = begin.span.to(self.prev_span); + self.sess.gated_spans.gate(sym::half_open_range_patterns, begin.span.to(re.span)); + if let RangeEnd::Included(_) = re.node { + // FIXME(Centril): Consider semantic errors instead in `ast_validation`. + // Possibly also do this for `X..=` in *expression* contexts. + self.error_inclusive_range_with_no_end(re.span); + } + None + }; + Ok(PatKind::Range(Some(begin), end, re)) + } - self.struct_span_err( - range_span, - &format!("`X{}` range patterns are not supported", form), - ) - .span_suggestion( - range_span, - "try using the maximum value for the type", - format!("{}{}MAX", pprust::expr_to_string(&begin), form), - Applicability::HasPlaceholders, - ) + pub(super) fn error_inclusive_range_with_no_end(&self, span: Span) { + use rustc_error_codes::E0586; + struct_span_err!(self.sess.span_diagnostic, span, E0586, "inclusive range with no end") + .help("inclusive ranges must be bounded at the end (`..=b` or `a..=b`)") .emit(); + } - Ok(self.mk_expr(range_span, ExprKind::Err, AttrVec::new())) - } + /// Parse a range-to pattern, e.g. `..X` and `..=X` where `X` remains to be parsed. + fn parse_pat_range_to(&mut self, re: Spanned) -> PResult<'a, PatKind> { + let end = self.parse_pat_range_end()?; + self.sess.gated_spans.gate(sym::half_open_range_patterns, re.span.to(self.prev_span)); + Ok(PatKind::Range(None, Some(end), re)) + } + + /// Is the token `dist` away from the current suitable as the start of a range patterns end? + fn is_pat_range_end_start(&self, dist: usize) -> bool { + self.look_ahead(dist, |t| { + t.is_path_start() // e.g. `MY_CONST`; + || t.kind == token::Dot // e.g. `.5` for recovery; + || t.can_begin_literal_or_bool() // e.g. `42`. + || t.is_whole_expr() + }) } fn parse_pat_range_end(&mut self) -> PResult<'a, P> { diff --git a/src/librustc_passes/Cargo.toml b/src/librustc_passes/Cargo.toml index ced933ba3ee42..4adc6dabb9fdb 100644 --- a/src/librustc_passes/Cargo.toml +++ b/src/librustc_passes/Cargo.toml @@ -12,6 +12,7 @@ path = "lib.rs" log = "0.4" rustc = { path = "../librustc" } rustc_data_structures = { path = "../librustc_data_structures" } +rustc_errors = { path = "../librustc_errors" } rustc_feature = { path = "../librustc_feature" } rustc_hir = { path = "../librustc_hir" } rustc_index = { path = "../librustc_index" } @@ -19,5 +20,4 @@ rustc_parse = { path = "../librustc_parse" } rustc_target = { path = "../librustc_target" } syntax = { path = "../libsyntax" } rustc_span = { path = "../librustc_span" } -errors = { path = "../librustc_errors", package = "rustc_errors" } rustc_error_codes = { path = "../librustc_error_codes" } diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 724d717304c20..be58a790fa878 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -6,10 +6,10 @@ // This pass is supposed to perform only simple checks not requiring name resolution // or type checking or some other kind of complex analysis. -use errors::{struct_span_err, Applicability, FatalError}; use rustc::lint; use rustc::session::Session; use rustc_data_structures::fx::FxHashMap; +use rustc_errors::{struct_span_err, Applicability, FatalError}; use rustc_parse::validate_attr; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym}; @@ -158,7 +158,7 @@ impl<'a> AstValidator<'a> { } } - fn err_handler(&self) -> &errors::Handler { + fn err_handler(&self) -> &rustc_errors::Handler { &self.session.diagnostic() } @@ -409,7 +409,7 @@ enum GenericPosition { fn validate_generics_order<'a>( sess: &Session, - handler: &errors::Handler, + handler: &rustc_errors::Handler, generics: impl Iterator, Span, Option)>, pos: GenericPosition, span: Span, @@ -920,8 +920,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> { self.check_expr_within_pat(expr, false); } PatKind::Range(ref start, ref end, _) => { - self.check_expr_within_pat(start, true); - self.check_expr_within_pat(end, true); + if let Some(expr) = start { + self.check_expr_within_pat(expr, true); + } + if let Some(expr) = end { + self.check_expr_within_pat(expr, true); + } } _ => {} } diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index 47e6e5ccc24fe..a2944918a4748 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -7,12 +7,12 @@ //! errors. We still look for those primitives in the MIR const-checker to ensure nothing slips //! through, but errors for structured control flow in a `const` should be emitted here. -use errors::struct_span_err; use rustc::hir::map::Map; use rustc::session::config::nightly_options; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; diff --git a/src/librustc_passes/entry.rs b/src/librustc_passes/entry.rs index 8273504715dba..028d7c662758a 100644 --- a/src/librustc_passes/entry.rs +++ b/src/librustc_passes/entry.rs @@ -1,9 +1,9 @@ -use errors::struct_span_err; use rustc::hir::map as hir_map; use rustc::session::config::EntryFnType; use rustc::session::{config, Session}; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; +use rustc_errors::struct_span_err; use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::{HirId, ImplItem, Item, ItemKind, TraitItem}; diff --git a/src/librustc_passes/intrinsicck.rs b/src/librustc_passes/intrinsicck.rs index ae8ac2e2c2e35..2c26707a51850 100644 --- a/src/librustc_passes/intrinsicck.rs +++ b/src/librustc_passes/intrinsicck.rs @@ -1,8 +1,8 @@ -use errors::struct_span_err; use rustc::hir::map::Map; use rustc::ty::layout::{LayoutError, Pointer, SizeSkeleton, VariantIdx}; use rustc::ty::query::Providers; use rustc::ty::{self, Ty, TyCtxt}; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; diff --git a/src/librustc_passes/lib_features.rs b/src/librustc_passes/lib_features.rs index e7d490d6d8ddb..8ae7291289786 100644 --- a/src/librustc_passes/lib_features.rs +++ b/src/librustc_passes/lib_features.rs @@ -4,11 +4,11 @@ // and `#[unstable (..)]`), but are not declared in one single location // (unlike lang features), which means we need to collect them instead. -use errors::struct_span_err; use rustc::hir::map::Map; use rustc::middle::lib_features::LibFeatures; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; +use rustc_errors::struct_span_err; use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_span::symbol::Symbol; diff --git a/src/librustc_passes/liveness.rs b/src/librustc_passes/liveness.rs index 5c1bc4d1eaa87..0426f3fbea236 100644 --- a/src/librustc_passes/liveness.rs +++ b/src/librustc_passes/liveness.rs @@ -96,12 +96,12 @@ use self::LiveNodeKind::*; use self::VarKind::*; -use errors::Applicability; use rustc::hir::map::Map; use rustc::lint; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt}; use rustc_data_structures::fx::FxIndexMap; +use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::*; use rustc_hir::def_id::DefId; @@ -1064,7 +1064,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { .sess .struct_span_err(expr.span, "`break` to unknown label") .emit(); - errors::FatalError.raise() + rustc_errors::FatalError.raise() } } } diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index 333b39c3bb302..5ad5795c777d4 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -2,10 +2,10 @@ use Context::*; use rustc::session::Session; -use errors::{struct_span_err, Applicability}; use rustc::hir::map::Map; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; +use rustc_errors::{struct_span_err, Applicability}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; diff --git a/src/librustc_passes/stability.rs b/src/librustc_passes/stability.rs index be098543a2ff2..588386e6f8d69 100644 --- a/src/librustc_passes/stability.rs +++ b/src/librustc_passes/stability.rs @@ -1,7 +1,6 @@ //! A pass that annotates every item and method with its stability level, //! propagating default levels lexically from parent to children ast nodes. -use errors::struct_span_err; use rustc::hir::map::Map; use rustc::lint; use rustc::middle::privacy::AccessLevels; @@ -11,6 +10,7 @@ use rustc::traits::misc::can_type_implement_copy; use rustc::ty::query::Providers; use rustc::ty::TyCtxt; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; diff --git a/src/librustc_resolve/Cargo.toml b/src/librustc_resolve/Cargo.toml index 01e5d75d2b57d..af37e7b5b76ac 100644 --- a/src/librustc_resolve/Cargo.toml +++ b/src/librustc_resolve/Cargo.toml @@ -14,16 +14,16 @@ doctest = false bitflags = "1.2.1" log = "0.4" syntax = { path = "../libsyntax" } -rustc_expand = { path = "../librustc_expand" } arena = { path = "../libarena" } -errors = { path = "../librustc_errors", package = "rustc_errors" } -rustc_span = { path = "../librustc_span" } rustc = { path = "../librustc" } rustc_ast_lowering = { path = "../librustc_ast_lowering" } rustc_data_structures = { path = "../librustc_data_structures" } +rustc_errors = { path = "../librustc_errors" } +rustc_expand = { path = "../librustc_expand" } rustc_feature = { path = "../librustc_feature" } rustc_hir = { path = "../librustc_hir" } rustc_metadata = { path = "../librustc_metadata" } rustc_error_codes = { path = "../librustc_error_codes" } rustc_session = { path = "../librustc_session" } +rustc_span = { path = "../librustc_span" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 6472f39e844a1..291386413d647 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -20,18 +20,14 @@ use rustc::bug; use rustc::hir::exports::Export; use rustc::middle::cstore::CrateStore; use rustc::ty; -use rustc_hir::def::{self, *}; -use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; -use rustc_metadata::creader::LoadedMacro; - use rustc_data_structures::sync::Lrc; -use std::cell::Cell; -use std::ptr; - -use errors::{struct_span_err, Applicability}; - +use rustc_error_codes::*; +use rustc_errors::{struct_span_err, Applicability}; use rustc_expand::base::SyntaxExtension; use rustc_expand::expand::AstFragment; +use rustc_hir::def::{self, *}; +use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_metadata::creader::LoadedMacro; use rustc_span::hygiene::{ExpnId, MacroKind}; use rustc_span::source_map::{respan, Spanned}; use rustc_span::symbol::{kw, sym}; @@ -44,8 +40,8 @@ use syntax::token::{self, Token}; use syntax::visit::{self, Visitor}; use log::debug; - -use rustc_error_codes::*; +use std::cell::Cell; +use std::ptr; type Res = def::Res; diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs index 6561072a21bce..d6f365fce7929 100644 --- a/src/librustc_resolve/check_unused.rs +++ b/src/librustc_resolve/check_unused.rs @@ -26,9 +26,9 @@ use crate::imports::ImportDirectiveSubclass; use crate::Resolver; -use errors::pluralize; use rustc::{lint, ty}; use rustc_data_structures::fx::FxHashSet; +use rustc_errors::pluralize; use rustc_session::node_id::NodeMap; use rustc_span::{MultiSpan, Span, DUMMY_SP}; use syntax::ast; diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index b81e71f0acfd7..9942804909380 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -1,11 +1,11 @@ use std::cmp::Reverse; -use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use log::debug; use rustc::bug; use rustc::session::Session; use rustc::ty::{self, DefIdTree}; use rustc_data_structures::fx::FxHashSet; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_feature::BUILTIN_ATTRIBUTES; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, DefKind, NonMacroAttrKind}; diff --git a/src/librustc_resolve/imports.rs b/src/librustc_resolve/imports.rs index 72de895f350f8..813e6ac96911e 100644 --- a/src/librustc_resolve/imports.rs +++ b/src/librustc_resolve/imports.rs @@ -11,7 +11,6 @@ use crate::{BindingKey, ModuleKind, ResolutionError, Resolver, Segment}; use crate::{CrateLint, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet, Weak}; use crate::{NameBinding, NameBindingKind, PathResult, PrivacyError, ToNameBinding}; -use errors::{pluralize, struct_span_err, Applicability}; use rustc::hir::exports::Export; use rustc::lint::builtin::BuiltinLintDiagnostics; use rustc::lint::builtin::{PUB_USE_OF_PRIVATE_EXTERN_CRATE, UNUSED_IMPORTS}; @@ -20,6 +19,7 @@ use rustc::ty; use rustc::{bug, span_bug}; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::ptr_key::PtrKey; +use rustc_errors::{pluralize, struct_span_err, Applicability}; use rustc_hir::def::{self, PartialRes}; use rustc_hir::def_id::DefId; use rustc_span::hygiene::ExpnId; diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 29a1be6bb7461..defca4944bcd8 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -11,10 +11,9 @@ use crate::{path_names_to_string, BindingError, CrateLint, LexicalScopeBinding}; use crate::{Module, ModuleOrUniformRoot, NameBindingKind, ParentScope, PathResult}; use crate::{ResolutionError, Resolver, Segment, UseError}; -use errors::DiagnosticId; -use log::debug; use rustc::{bug, lint, span_bug}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::DiagnosticId; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, DefKind, PartialRes, PerNS}; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX}; @@ -28,6 +27,7 @@ use syntax::util::lev_distance::find_best_match_for_name; use syntax::visit::{self, FnKind, Visitor}; use syntax::{unwrap_or, walk_list}; +use log::debug; use std::collections::BTreeSet; use std::mem::replace; @@ -306,7 +306,7 @@ impl<'a> PathSource<'a> { } fn error_code(self, has_unexpected_resolution: bool) -> DiagnosticId { - use errors::error_code; + use rustc_errors::error_code; match (self, has_unexpected_resolution) { (PathSource::Trait(_), true) => error_code!(E0404), (PathSource::Trait(_), false) => error_code!(E0405), diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index 029f8421475e5..151f3e834e5de 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -4,10 +4,10 @@ use crate::path_names_to_string; use crate::{CrateLint, Module, ModuleKind, ModuleOrUniformRoot}; use crate::{PathResult, PathSource, Segment}; -use errors::{Applicability, DiagnosticBuilder}; -use log::debug; use rustc::session::config::nightly_options; use rustc_data_structures::fx::FxHashSet; +use rustc_error_codes::*; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, DefKind}; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX}; @@ -18,7 +18,7 @@ use rustc_span::Span; use syntax::ast::{self, Expr, ExprKind, Ident, NodeId, Path, Ty, TyKind}; use syntax::util::lev_distance::find_best_match_for_name; -use rustc_error_codes::*; +use log::debug; type Res = def::Res; @@ -139,7 +139,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { // Emit special messages for unresolved `Self` and `self`. if is_self_type(path, ns) { - err.code(errors::error_code!(E0411)); + err.code(rustc_errors::error_code!(E0411)); err.span_label( span, format!("`Self` is only available in impls, traits, and type definitions"), @@ -149,7 +149,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { if is_self_value(path, ns) { debug!("smart_resolve_path_fragment: E0424, source={:?}", source); - err.code(errors::error_code!(E0424)); + err.code(rustc_errors::error_code!(E0424)); err.span_label(span, match source { PathSource::Pat => format!( "`self` value is a keyword and may not be bound to variables or shadowed", diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 9e4486e16f2cc..e6be9f6d328c0 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -20,7 +20,6 @@ pub use rustc_hir::def::{Namespace, PerNS}; use Determinacy::*; -use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc::hir::exports::ExportMap; use rustc::hir::map::{DefKey, Definitions}; use rustc::lint; @@ -32,6 +31,7 @@ use rustc::ty::{self, DefIdTree, ResolverOutputs}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::ptr_key::PtrKey; use rustc_data_structures::sync::Lrc; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_expand::base::SyntaxExtension; use rustc_hir::def::Namespace::*; use rustc_hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, PartialRes}; diff --git a/src/librustc_resolve/lifetimes.rs b/src/librustc_resolve/lifetimes.rs index 469e1b9aa6207..d6143eec73c00 100644 --- a/src/librustc_resolve/lifetimes.rs +++ b/src/librustc_resolve/lifetimes.rs @@ -5,7 +5,6 @@ //! used between functions, and they operate in a purely top-down //! way. Therefore, we break lifetime name resolution into a separate pass. -use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc::hir::map::Map; use rustc::lint; use rustc::middle::resolve_lifetime::*; @@ -13,6 +12,7 @@ use rustc::session::Session; use rustc::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt}; use rustc::{bug, span_bug}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE}; diff --git a/src/librustc_span/symbol.rs b/src/librustc_span/symbol.rs index d9f4b72560ceb..a8b2db300a478 100644 --- a/src/librustc_span/symbol.rs +++ b/src/librustc_span/symbol.rs @@ -343,6 +343,7 @@ symbols! { global_allocator, global_asm, globs, + half_open_range_patterns, hash, Hash, HashSet, diff --git a/src/librustc_typeck/Cargo.toml b/src/librustc_typeck/Cargo.toml index a489d0cd02b40..84e5f56d9c208 100644 --- a/src/librustc_typeck/Cargo.toml +++ b/src/librustc_typeck/Cargo.toml @@ -15,8 +15,8 @@ arena = { path = "../libarena" } log = "0.4" rustc = { path = "../librustc" } rustc_data_structures = { path = "../librustc_data_structures" } +rustc_errors = { path = "../librustc_errors" } rustc_hir = { path = "../librustc_hir" } -errors = { path = "../librustc_errors", package = "rustc_errors" } rustc_target = { path = "../librustc_target" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } syntax = { path = "../libsyntax" } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 7c7480339a5ee..c6f36c66a3aa4 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -9,7 +9,6 @@ use crate::middle::resolve_lifetime as rl; use crate::namespace::Namespace; use crate::require_c_abi_if_c_variadic; use crate::util::common::ErrorReported; -use errors::{struct_span_err, Applicability, DiagnosticId}; use rustc::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS; use rustc::traits; use rustc::traits::astconv_object_safety_violations; @@ -19,6 +18,7 @@ use rustc::ty::subst::{self, InternalSubsts, Subst, SubstsRef}; use rustc::ty::{self, Const, DefIdTree, ToPredicate, Ty, TyCtxt, TypeFoldable}; use rustc::ty::{GenericParamDef, GenericParamDefKind}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; @@ -30,7 +30,6 @@ use rustc_span::{MultiSpan, Span, DUMMY_SP}; use rustc_target::spec::abi; use smallvec::SmallVec; use syntax::ast; -use syntax::errors::pluralize; use syntax::feature_gate::feature_err; use syntax::util::lev_distance::find_best_match_for_name; diff --git a/src/librustc_typeck/check/autoderef.rs b/src/librustc_typeck/check/autoderef.rs index 3d02889d2ddd3..8d6b74c3015c9 100644 --- a/src/librustc_typeck/check/autoderef.rs +++ b/src/librustc_typeck/check/autoderef.rs @@ -1,13 +1,13 @@ use super::method::MethodCallee; use super::{FnCtxt, Needs, PlaceOp}; -use errors::struct_span_err; use rustc::infer::{InferCtxt, InferOk}; use rustc::session::DiagnosticMessageId; use rustc::traits::{self, TraitEngine}; use rustc::ty::adjustment::{Adjust, Adjustment, OverloadedDeref}; use rustc::ty::{self, TraitRef, Ty, TyCtxt}; use rustc::ty::{ToPredicate, TypeFoldable}; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_span::Span; diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index a1915bc025f79..bff6765314ab8 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -3,22 +3,20 @@ use super::method::MethodCallee; use super::{Expectation, FnCtxt, Needs, TupleArgumentsFlag}; use crate::type_error_struct; -use errors::{struct_span_err, Applicability, DiagnosticBuilder}; -use hir::def::Res; -use hir::def_id::{DefId, LOCAL_CRATE}; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; use rustc::ty::subst::SubstsRef; use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc::{infer, traits}; +use rustc_error_codes::*; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; +use rustc_hir as hir; +use rustc_hir::def::Res; +use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_span::Span; use rustc_target::spec::abi; use syntax::ast::Ident; -use rustc_hir as hir; - -use rustc_error_codes::*; - /// Checks that it is legal to call methods of the trait corresponding /// to `trait_id` (this only cares about the trait, not the specific /// method that is called). diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 9dbf55c494831..ba5e5fd8ac188 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -34,7 +34,6 @@ use crate::hir::def_id::DefId; use crate::lint; use crate::type_error_struct; use crate::util::common::ErrorReported; -use errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc::middle::lang_items; use rustc::session::Session; use rustc::traits; @@ -45,6 +44,7 @@ use rustc::ty::cast::{CastKind, CastTy}; use rustc::ty::error::TypeError; use rustc::ty::subst::SubstsRef; use rustc::ty::{self, Ty, TypeAndMut, TypeFoldable}; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_span::Span; use syntax::ast; diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index ec298ca697183..feab31523f265 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -51,7 +51,6 @@ //! we may want to adjust precisely when coercions occur. use crate::check::{FnCtxt, Needs}; -use errors::{struct_span_err, DiagnosticBuilder}; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::infer::{Coercion, InferOk, InferResult}; use rustc::traits::{self, ObligationCause, ObligationCauseCode}; @@ -63,6 +62,7 @@ use rustc::ty::fold::TypeFoldable; use rustc::ty::relate::RelateResult; use rustc::ty::subst::SubstsRef; use rustc::ty::{self, Ty, TypeAndMut}; +use rustc_errors::{struct_span_err, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_span; diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 449c2e90ff202..c35661ac649fc 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -1,4 +1,3 @@ -use errors::{pluralize, struct_span_err, Applicability, DiagnosticId}; use rustc::hir::map::Map; use rustc::infer::{self, InferOk}; use rustc::traits::{self, ObligationCause, ObligationCauseCode, Reveal}; @@ -7,6 +6,7 @@ use rustc::ty::subst::{InternalSubsts, Subst}; use rustc::ty::util::ExplicitSelf; use rustc::ty::{self, GenericParamDefKind, TyCtxt}; use rustc::util::common::ErrorReported; +use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit; diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 1be65b5f1894b..e0f9fcc69325c 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -2,9 +2,9 @@ use crate::check::FnCtxt; use rustc::infer::InferOk; use rustc::traits::{self, ObligationCause}; -use errors::{Applicability, DiagnosticBuilder}; use rustc::ty::adjustment::AllowTwoPhase; use rustc::ty::{self, AssocItem, Ty}; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::{is_range_literal, print, Node}; use rustc_span::symbol::sym; diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 33a07423c2502..88e7a265ebbcf 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -2,7 +2,6 @@ use crate::check::regionck::RegionCtxt; use crate::hir; use crate::hir::def_id::DefId; use crate::util::common::ErrorReported; -use errors::struct_span_err; use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::{InferOk, SuppressRegionErrors}; use rustc::middle::region; @@ -11,6 +10,7 @@ use rustc::ty::error::TypeError; use rustc::ty::relate::{Relate, RelateResult, TypeRelation}; use rustc::ty::subst::{Subst, SubstsRef}; use rustc::ty::{self, Predicate, Ty, TyCtxt}; +use rustc_errors::struct_span_err; use rustc_span::Span; diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 01795ef39665f..35342de59a082 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -17,7 +17,6 @@ use crate::check::TupleArgumentsFlag::DontTupleArguments; use crate::type_error_struct; use crate::util::common::ErrorReported; -use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc::infer; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::middle::lang_items; @@ -28,6 +27,7 @@ use rustc::ty::Ty; use rustc::ty::TypeFoldable; use rustc::ty::{AdtKind, Visibility}; use rustc_data_structures::fx::FxHashMap; +use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::DefId; diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 2b731947aa0fa..0441514c83c9d 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -3,11 +3,11 @@ use crate::require_same_types; -use errors::struct_span_err; use rustc::traits::{ObligationCause, ObligationCauseCode}; use rustc::ty::subst::Subst; use rustc::ty::{self, Ty, TyCtxt}; use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_span::symbol::Symbol; use rustc_target::spec::abi::Abi; diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index e9356a04c01d4..711c285d17e88 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -12,7 +12,6 @@ pub use self::MethodError::*; use crate::check::FnCtxt; use crate::namespace::Namespace; -use errors::{Applicability, DiagnosticBuilder}; use rustc::infer::{self, InferOk}; use rustc::traits; use rustc::ty::subst::Subst; @@ -20,6 +19,7 @@ use rustc::ty::subst::{InternalSubsts, SubstsRef}; use rustc::ty::GenericParamDefKind; use rustc::ty::{self, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TypeFoldable}; use rustc_data_structures::sync::Lrc; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind}; use rustc_hir::def_id::DefId; diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 4f0467b78b252..b2542cc27a551 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -9,7 +9,6 @@ use crate::hir::def::DefKind; use crate::hir::def_id::DefId; use crate::namespace::Namespace; -use errors::struct_span_err; use rustc::infer::canonical::OriginalQueryValues; use rustc::infer::canonical::{Canonical, QueryResponse}; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; @@ -29,6 +28,7 @@ use rustc::ty::{ }; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_span::{symbol::Symbol, Span, DUMMY_SP}; use std::cmp::max; diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 4f55d9ab70ede..97f652383fb6e 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -4,7 +4,6 @@ use crate::check::FnCtxt; use crate::middle::lang_items::FnOnceTraitLangItem; use crate::namespace::Namespace; -use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc::hir::map as hir_map; use rustc::hir::map::Map; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; @@ -12,6 +11,7 @@ use rustc::traits::Obligation; use rustc::ty::print::with_crate_prefix; use rustc::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable}; use rustc_data_structures::fx::FxHashSet; +use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 5e73f8e3e128f..32225cd417f2d 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -90,7 +90,6 @@ pub mod writeback; use crate::astconv::{AstConv, PathSeg}; use crate::middle::lang_items; use crate::namespace::Namespace; -use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc::hir::map::Map; use rustc::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse}; use rustc::infer::error_reporting::TypeAnnotationNeeded::E0282; @@ -116,6 +115,7 @@ use rustc::ty::{ }; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LOCAL_CRATE}; @@ -164,7 +164,7 @@ macro_rules! type_error_struct { if $typ.references_error() { $session.diagnostic().struct_dummy() } else { - errors::struct_span_err!($session, $span, $code, $($message)*) + rustc_errors::struct_span_err!($session, $span, $code, $($message)*) } }) } diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index d746b97472735..edf9d19dea377 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -2,11 +2,11 @@ use super::method::MethodCallee; use super::{FnCtxt, Needs}; -use errors::{self, struct_span_err, Applicability}; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; use rustc::ty::TyKind::{Adt, Array, Char, FnDef, Never, Ref, Str, Tuple, Uint}; use rustc::ty::{self, Ty, TypeFoldable}; +use rustc_errors::{self, struct_span_err, Applicability}; use rustc_hir as hir; use rustc_span::Span; use syntax::ast::Ident; @@ -279,7 +279,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { lhs_expr.span, msg, format!("*{}", lstring), - errors::Applicability::MachineApplicable, + rustc_errors::Applicability::MachineApplicable, ); suggested_deref = true; } @@ -482,7 +482,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// suggest calling the function. Returns wether a suggestion was given. fn add_type_neq_err_label( &self, - err: &mut errors::DiagnosticBuilder<'_>, + err: &mut rustc_errors::DiagnosticBuilder<'_>, span: Span, ty: Ty<'tcx>, other_ty: Ty<'tcx>, @@ -565,7 +565,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { rhs_expr: &'tcx hir::Expr<'tcx>, lhs_ty: Ty<'tcx>, rhs_ty: Ty<'tcx>, - err: &mut errors::DiagnosticBuilder<'_>, + err: &mut rustc_errors::DiagnosticBuilder<'_>, is_assign: bool, op: hir::BinOp, ) -> bool { diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index 58c722f1da6f4..1478b35a25ddc 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -1,11 +1,11 @@ use crate::check::FnCtxt; -use errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc::infer; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc::traits::Pattern; use rustc::ty::subst::GenericArg; use rustc::ty::{self, BindingMode, Ty, TypeFoldable}; use rustc_data_structures::fx::FxHashMap; +use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::pat_util::EnumerateAndAdjustIterator; @@ -135,12 +135,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = match pat.kind { PatKind::Wild => expected, PatKind::Lit(lt) => self.check_pat_lit(pat.span, lt, expected, ti), - PatKind::Range(begin, end, _) => { - match self.check_pat_range(pat.span, begin, end, expected, ti) { - None => return, - Some(ty) => ty, - } - } + PatKind::Range(lhs, rhs, _) => self.check_pat_range(pat.span, lhs, rhs, expected, ti), PatKind::Binding(ba, var_id, _, sub) => { self.check_pat_ident(pat, ba, var_id, sub, expected, def_bm, ti) } @@ -395,39 +390,49 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn check_pat_range( &self, span: Span, - lhs: &'tcx hir::Expr<'tcx>, - rhs: &'tcx hir::Expr<'tcx>, + lhs: Option<&'tcx hir::Expr<'tcx>>, + rhs: Option<&'tcx hir::Expr<'tcx>>, expected: Ty<'tcx>, ti: TopInfo<'tcx>, - ) -> Option> { - let lhs_ty = self.check_expr(lhs); - let rhs_ty = self.check_expr(rhs); - - // Check that both end-points are of numeric or char type. - let numeric_or_char = |ty: Ty<'_>| ty.is_numeric() || ty.is_char() || ty.references_error(); - let lhs_fail = !numeric_or_char(lhs_ty); - let rhs_fail = !numeric_or_char(rhs_ty); - - if lhs_fail || rhs_fail { - self.emit_err_pat_range(span, lhs.span, rhs.span, lhs_fail, rhs_fail, lhs_ty, rhs_ty); - return None; + ) -> Ty<'tcx> { + let calc_side = |opt_expr: Option<&'tcx hir::Expr<'tcx>>| match opt_expr { + None => (None, None), + Some(expr) => { + let ty = self.check_expr(expr); + // Check that the end-point is of numeric or char type. + let fail = !(ty.is_numeric() || ty.is_char() || ty.references_error()); + (Some(ty), Some((fail, ty, expr.span))) + } + }; + let (lhs_ty, lhs) = calc_side(lhs); + let (rhs_ty, rhs) = calc_side(rhs); + + if let (Some((true, ..)), _) | (_, Some((true, ..))) = (lhs, rhs) { + // There exists a side that didn't meet our criteria that the end-point + // be of a numeric or char type, as checked in `calc_side` above. + self.emit_err_pat_range(span, lhs, rhs); + return self.tcx.types.err; } - // Now that we know the types can be unified we find the unified type and use - // it to type the entire expression. - let common_type = self.resolve_vars_if_possible(&lhs_ty); + // Now that we know the types can be unified we find the unified type + // and use it to type the entire expression. + let common_type = self.resolve_vars_if_possible(&lhs_ty.or(rhs_ty).unwrap_or(expected)); // Subtyping doesn't matter here, as the value is some kind of scalar. - let demand_eqtype = |x_span, y_span, x_ty, y_ty| { - self.demand_eqtype_pat_diag(x_span, expected, x_ty, ti).map(|mut err| { - self.endpoint_has_type(&mut err, y_span, y_ty); - err.emit(); - }); + let demand_eqtype = |x, y| { + if let Some((_, x_ty, x_span)) = x { + self.demand_eqtype_pat_diag(x_span, expected, x_ty, ti).map(|mut err| { + if let Some((_, y_ty, y_span)) = y { + self.endpoint_has_type(&mut err, y_span, y_ty); + } + err.emit(); + }); + } }; - demand_eqtype(lhs.span, rhs.span, lhs_ty, rhs_ty); - demand_eqtype(rhs.span, lhs.span, rhs_ty, lhs_ty); + demand_eqtype(lhs, rhs); + demand_eqtype(rhs, lhs); - Some(common_type) + common_type } fn endpoint_has_type(&self, err: &mut DiagnosticBuilder<'_>, span: Span, ty: Ty<'_>) { @@ -439,21 +444,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn emit_err_pat_range( &self, span: Span, - begin_span: Span, - end_span: Span, - lhs_fail: bool, - rhs_fail: bool, - lhs_ty: Ty<'tcx>, - rhs_ty: Ty<'tcx>, + lhs: Option<(bool, Ty<'tcx>, Span)>, + rhs: Option<(bool, Ty<'tcx>, Span)>, ) { - let span = if lhs_fail && rhs_fail { - span - } else if lhs_fail { - begin_span - } else { - end_span + let span = match (lhs, rhs) { + (Some((true, ..)), Some((true, ..))) => span, + (Some((true, _, sp)), _) => sp, + (_, Some((true, _, sp))) => sp, + _ => span_bug!(span, "emit_err_pat_range: no side failed or exists but still error?"), }; - let mut err = struct_span_err!( self.tcx.sess, span, @@ -461,17 +460,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { "only char and numeric types are allowed in range patterns" ); let msg = |ty| format!("this is of type `{}` but it should be `char` or numeric", ty); - let mut one_side_err = |first_span, first_ty, second_span, second_ty: Ty<'_>| { + let mut one_side_err = |first_span, first_ty, second: Option<(bool, Ty<'tcx>, Span)>| { err.span_label(first_span, &msg(first_ty)); - self.endpoint_has_type(&mut err, second_span, second_ty); + if let Some((_, ty, sp)) = second { + self.endpoint_has_type(&mut err, sp, ty); + } }; - if lhs_fail && rhs_fail { - err.span_label(begin_span, &msg(lhs_ty)); - err.span_label(end_span, &msg(rhs_ty)); - } else if lhs_fail { - one_side_err(begin_span, lhs_ty, end_span, rhs_ty); - } else { - one_side_err(end_span, rhs_ty, begin_span, lhs_ty); + match (lhs, rhs) { + (Some((true, lhs_ty, lhs_sp)), Some((true, rhs_ty, rhs_sp))) => { + err.span_label(lhs_sp, &msg(lhs_ty)); + err.span_label(rhs_sp, &msg(rhs_ty)); + } + (Some((true, lhs_ty, lhs_sp)), rhs) => one_side_err(lhs_sp, lhs_ty, rhs), + (lhs, Some((true, rhs_ty, rhs_sp))) => one_side_err(rhs_sp, rhs_ty, lhs), + _ => span_bug!(span, "Impossible, verified above."), } if self.tcx.sess.teach(&err.get_code().unwrap()) { err.note( diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index c57eb67218964..df1eecdcfa8c5 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -1,13 +1,13 @@ use crate::check::{FnCtxt, Inherited}; use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter}; -use errors::{struct_span_err, DiagnosticBuilder}; use rustc::infer::opaque_types::may_define_opaque_type; use rustc::middle::lang_items; use rustc::traits::{self, ObligationCause, ObligationCauseCode}; use rustc::ty::subst::{InternalSubsts, Subst}; use rustc::ty::{self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::{struct_span_err, DiagnosticBuilder}; use rustc_hir::def_id::DefId; use rustc_hir::ItemKind; use rustc_span::symbol::sym; diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index ab8e4ce6975a9..ec098c1d89679 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -1,15 +1,13 @@ use crate::lint; use rustc::ty::TyCtxt; - -use errors::Applicability; -use rustc_span::Span; -use syntax::ast; - use rustc_data_structures::fx::FxHashMap; +use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def_id::{DefId, DefIdSet, LOCAL_CRATE}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::print::visibility_qualified; +use rustc_span::Span; +use syntax::ast; pub fn check_crate(tcx: TyCtxt<'_>) { let mut used_trait_imports = DefIdSet::default(); diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 5af5acda14379..8b3db15c02b4e 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -1,7 +1,6 @@ //! Check properties that are required by built-in traits and set //! up data structures required by type-checking/codegen. -use errors::struct_span_err; use rustc::infer; use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::SuppressRegionErrors; @@ -14,6 +13,7 @@ use rustc::ty::adjustment::CoerceUnsizedInfo; use rustc::ty::TypeFoldable; use rustc::ty::{self, Ty, TyCtxt}; use rustc_error_codes::*; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::ItemKind; diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 73d03f9244721..673c1bd9fd831 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -7,8 +7,8 @@ //! `tcx.inherent_impls(def_id)`). That value, however, //! is computed by selecting an idea from this table. -use errors::struct_span_err; use rustc::ty::{self, CrateInherentImpls, TyCtxt}; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::itemlikevisit::ItemLikeVisitor; diff --git a/src/librustc_typeck/coherence/inherent_impls_overlap.rs b/src/librustc_typeck/coherence/inherent_impls_overlap.rs index 01d2f528d4563..a9228c7f6bb4c 100644 --- a/src/librustc_typeck/coherence/inherent_impls_overlap.rs +++ b/src/librustc_typeck/coherence/inherent_impls_overlap.rs @@ -1,7 +1,7 @@ use crate::namespace::Namespace; -use errors::struct_span_err; use rustc::traits::{self, IntercrateMode}; use rustc::ty::TyCtxt; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::itemlikevisit::ItemLikeVisitor; diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index ca10601f4135b..fd685e77b418c 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -5,14 +5,13 @@ // done by the orphan and overlap modules. Then we build up various // mappings. That mapping code resides here. -use crate::hir::def_id::{DefId, LOCAL_CRATE}; -use crate::hir::HirId; -use errors::struct_span_err; use rustc::traits; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt, TypeFoldable}; - use rustc_error_codes::*; +use rustc_errors::struct_span_err; +use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_hir::HirId; mod builtin; mod inherent_impls; diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index cf9935143b2d7..1878f9385a891 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -1,9 +1,9 @@ //! Orphan checker: every impl either implements a trait defined in this //! crate or pertains to a type defined in this crate. -use errors::struct_span_err; use rustc::traits; use rustc::ty::{self, TyCtxt}; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::itemlikevisit::ItemLikeVisitor; diff --git a/src/librustc_typeck/coherence/unsafety.rs b/src/librustc_typeck/coherence/unsafety.rs index 9257aa759b4cf..3f4035b0998d6 100644 --- a/src/librustc_typeck/coherence/unsafety.rs +++ b/src/librustc_typeck/coherence/unsafety.rs @@ -1,8 +1,8 @@ //! Unsafety checker: every impl either implements a trait defined in this //! crate or pertains to a type defined in this crate. -use errors::struct_span_err; use rustc::ty::TyCtxt; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::Unsafety; diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 3bb06d7634983..64e71cc42e0ca 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -20,7 +20,6 @@ use crate::constrained_generic_params as cgp; use crate::lint; use crate::middle::resolve_lifetime as rl; use crate::middle::weak_lang_items; -use errors::{struct_span_err, Applicability, StashKey}; use rustc::hir::map::Map; use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc::mir::mono::Linkage; @@ -34,6 +33,7 @@ use rustc::ty::{self, AdtKind, Const, DefIdTree, ToPolyTraitRef, Ty, TyCtxt}; use rustc::ty::{ReprOptions, ToPredicate}; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxHashMap; +use rustc_errors::{struct_span_err, Applicability, StashKey}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; @@ -255,7 +255,7 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { fn bad_placeholder_type( tcx: TyCtxt<'tcx>, mut spans: Vec, -) -> errors::DiagnosticBuilder<'tcx> { +) -> rustc_errors::DiagnosticBuilder<'tcx> { spans.sort(); let mut err = struct_span_err!( tcx.sess, diff --git a/src/librustc_typeck/impl_wf_check.rs b/src/librustc_typeck/impl_wf_check.rs index e3e61ebb93607..fb87b285fa29f 100644 --- a/src/librustc_typeck/impl_wf_check.rs +++ b/src/librustc_typeck/impl_wf_check.rs @@ -9,10 +9,10 @@ //! fixed, but for the moment it's easier to do these checks early. use crate::constrained_generic_params as cgp; -use errors::struct_span_err; use rustc::ty::query::Providers; use rustc::ty::{self, TyCtxt, TypeFoldable}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::itemlikevisit::ItemLikeVisitor; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 0d9940cbf92c7..b951883ac195a 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -91,7 +91,6 @@ mod outlives; mod structured_errors; mod variance; -use errors::struct_span_err; use rustc::infer::InferOk; use rustc::lint; use rustc::middle; @@ -103,6 +102,7 @@ use rustc::ty::subst::SubstsRef; use rustc::ty::{self, Ty, TyCtxt}; use rustc::util; use rustc::util::common::ErrorReported; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::Node; diff --git a/src/librustc_typeck/outlives/test.rs b/src/librustc_typeck/outlives/test.rs index b693743e47496..908429c8dc48a 100644 --- a/src/librustc_typeck/outlives/test.rs +++ b/src/librustc_typeck/outlives/test.rs @@ -1,5 +1,5 @@ -use errors::struct_span_err; use rustc::ty::TyCtxt; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_span::symbol::sym; diff --git a/src/librustc_typeck/structured_errors.rs b/src/librustc_typeck/structured_errors.rs index dc6c45b41842c..068814723f52d 100644 --- a/src/librustc_typeck/structured_errors.rs +++ b/src/librustc_typeck/structured_errors.rs @@ -1,6 +1,6 @@ -use errors::{Applicability, DiagnosticBuilder, DiagnosticId}; use rustc::session::Session; use rustc::ty::{Ty, TypeFoldable}; +use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId}; use rustc_span::Span; use rustc_error_codes::*; @@ -50,7 +50,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for VariadicError<'tcx> { } fn code(&self) -> DiagnosticId { - errors::error_code!(E0617) + rustc_errors::error_code!(E0617) } fn common(&self) -> DiagnosticBuilder<'tcx> { @@ -111,7 +111,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCastError<'tcx> { } fn code(&self) -> DiagnosticId { - errors::error_code!(E0607) + rustc_errors::error_code!(E0607) } fn common(&self) -> DiagnosticBuilder<'tcx> { diff --git a/src/librustc_typeck/variance/test.rs b/src/librustc_typeck/variance/test.rs index 860bfe79395ff..2f41bee1819cd 100644 --- a/src/librustc_typeck/variance/test.rs +++ b/src/librustc_typeck/variance/test.rs @@ -1,5 +1,5 @@ -use errors::struct_span_err; use rustc::ty::TyCtxt; +use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_span::symbol::sym; diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index c8f1dff703fb4..5d8e27ecadb82 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -497,7 +497,7 @@ impl Attributes { false } - pub fn from_ast(diagnostic: &::errors::Handler, attrs: &[ast::Attribute]) -> Attributes { + pub fn from_ast(diagnostic: &::rustc_errors::Handler, attrs: &[ast::Attribute]) -> Attributes { let mut doc_strings = vec![]; let mut sp = None; let mut cfg = Cfg::True; diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 26b49d2f9624e..22f5d0dc2c078 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -3,7 +3,6 @@ use std::ffi::OsStr; use std::fmt; use std::path::PathBuf; -use errors; use getopts; use rustc::lint::Level; use rustc::session; @@ -566,7 +565,7 @@ impl Options { } /// Prints deprecation warnings for deprecated options -fn check_deprecated_options(matches: &getopts::Matches, diag: &errors::Handler) { +fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Handler) { let deprecated_flags = ["input-format", "output-format", "no-defaults", "passes"]; for flag in deprecated_flags.iter() { diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index be7f7ea364f47..3cda1b3be75f1 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -15,8 +15,8 @@ use rustc_interface::interface; use rustc_lint; use rustc_resolve as resolve; -use errors::emitter::{Emitter, EmitterWriter}; -use errors::json::JsonEmitter; +use rustc_errors::emitter::{Emitter, EmitterWriter}; +use rustc_errors::json::JsonEmitter; use rustc_span::source_map; use rustc_span::symbol::sym; use rustc_span::DUMMY_SP; @@ -171,7 +171,7 @@ pub fn new_handler( error_format: ErrorOutputType, source_map: Option>, debugging_opts: &DebuggingOptions, -) -> errors::Handler { +) -> rustc_errors::Handler { let emitter: Box = match error_format { ErrorOutputType::HumanReadable(kind) => { let (short, color_config) = kind.unzip(); @@ -198,7 +198,10 @@ pub fn new_handler( } }; - errors::Handler::with_emitter_and_flags(emitter, debugging_opts.diagnostic_handler_flags(true)) + rustc_errors::Handler::with_emitter_and_flags( + emitter, + debugging_opts.diagnostic_handler_flags(true), + ) } pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOptions) { @@ -409,7 +412,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt let mut krate = clean::krate(&mut ctxt); - fn report_deprecated_attr(name: &str, diag: &errors::Handler) { + fn report_deprecated_attr(name: &str, diag: &rustc_errors::Handler) { let mut msg = diag.struct_warn(&format!( "the `#![doc({})]` attribute is \ considered deprecated", diff --git a/src/librustdoc/docfs.rs b/src/librustdoc/docfs.rs index 2a107e828f75f..ecc394a2bc992 100644 --- a/src/librustdoc/docfs.rs +++ b/src/librustdoc/docfs.rs @@ -9,8 +9,6 @@ //! needs to read-after-write from a file, then it would be added to this //! abstraction. -use errors; - use std::fs; use std::io; use std::path::Path; @@ -42,7 +40,7 @@ impl ErrorStorage { } /// Prints all stored errors. Returns the number of printed errors. - pub fn write_errors(&mut self, diag: &errors::Handler) -> usize { + pub fn write_errors(&mut self, diag: &rustc_errors::Handler) -> usize { let mut printed = 0; // In order to drop the sender part of the channel. self.sender = None; diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index e0ed02c11c71a..8b5a3a2ba6131 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -1,6 +1,5 @@ use crate::html::markdown::{ErrorCodes, IdMap, Markdown, Playground}; use crate::rustc_span::edition::Edition; -use errors; use rustc_feature::UnstableFeatures; use std::fs; use std::path::Path; @@ -26,7 +25,7 @@ impl ExternalHtml { after_content: &[String], md_before_content: &[String], md_after_content: &[String], - diag: &errors::Handler, + diag: &rustc_errors::Handler, id_map: &mut IdMap, edition: Edition, playground: &Option, @@ -58,7 +57,7 @@ pub enum LoadStringError { pub fn load_string>( file_path: P, - diag: &errors::Handler, + diag: &rustc_errors::Handler, ) -> Result { let file_path = file_path.as_ref(); let contents = match fs::read(file_path) { @@ -77,7 +76,7 @@ pub fn load_string>( } } -fn load_external_files(names: &[String], diag: &errors::Handler) -> Option { +fn load_external_files(names: &[String], diag: &rustc_errors::Handler) -> Option { let mut out = String::new(); for name in names { let s = match load_string(name, diag) { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index a01e2f793948e..2d932eb7668c4 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -42,7 +42,6 @@ use std::rc::Rc; use std::str; use std::sync::Arc; -use errors; use rustc::middle::privacy::AccessLevels; use rustc::middle::stability; use rustc_data_structures::flock; @@ -394,7 +393,7 @@ pub fn run( mut krate: clean::Crate, options: RenderOptions, renderinfo: RenderInfo, - diag: &errors::Handler, + diag: &rustc_errors::Handler, edition: Edition, ) -> Result<(), Error> { // need to save a copy of the options for rendering the index page @@ -528,7 +527,7 @@ fn write_shared( krate: &clean::Crate, search_index: String, options: &RenderOptions, - diag: &errors::Handler, + diag: &rustc_errors::Handler, ) -> Result<(), Error> { // Write out the shared files. Note that these are shared among all rustdoc // docs placed in the output directory, so this needs to be a synchronized diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 91150899877fe..b15dae452ff05 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -24,6 +24,7 @@ extern crate rustc; extern crate rustc_data_structures; extern crate rustc_driver; extern crate rustc_error_codes; +extern crate rustc_errors; extern crate rustc_expand; extern crate rustc_feature; extern crate rustc_hir; @@ -42,7 +43,6 @@ extern crate syntax; extern crate test as testing; #[macro_use] extern crate log; -extern crate rustc_errors as errors; use std::default::Default; use std::env; @@ -518,6 +518,6 @@ where match result { Ok(output) => output, - Err(_) => panic::resume_unwind(Box::new(errors::FatalErrorMarker)), + Err(_) => panic::resume_unwind(Box::new(rustc_errors::FatalErrorMarker)), } } diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 69aa248aa8e98..912a40722b8af 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -2,7 +2,6 @@ use std::fs::File; use std::io::prelude::*; use std::path::PathBuf; -use errors; use rustc_feature::UnstableFeatures; use rustc_span::edition::Edition; use rustc_span::source_map::DUMMY_SP; @@ -39,7 +38,7 @@ fn extract_leading_metadata(s: &str) -> (Vec<&str>, &str) { pub fn render( input: PathBuf, options: RenderOptions, - diag: &errors::Handler, + diag: &rustc_errors::Handler, edition: Edition, ) -> i32 { let mut output = options.output; @@ -128,7 +127,7 @@ pub fn render( } /// Runs any tests/code examples in the markdown file `input`. -pub fn test(mut options: Options, diag: &errors::Handler) -> i32 { +pub fn test(mut options: Options, diag: &rustc_errors::Handler) -> i32 { let input_str = match load_string(&options.input, diag) { Ok(s) => s, Err(LoadStringError::ReadFail) => return 1, diff --git a/src/librustdoc/passes/check_code_block_syntax.rs b/src/librustdoc/passes/check_code_block_syntax.rs index 79548eb6d647a..0bab4423b3dfd 100644 --- a/src/librustdoc/passes/check_code_block_syntax.rs +++ b/src/librustdoc/passes/check_code_block_syntax.rs @@ -1,5 +1,5 @@ -use errors::{emitter::Emitter, Applicability, Diagnostic, Handler}; use rustc_data_structures::sync::{Lock, Lrc}; +use rustc_errors::{emitter::Emitter, Applicability, Diagnostic, Handler}; use rustc_parse::lexer::StringReader as Lexer; use rustc_span::source_map::{FilePathMapping, SourceMap}; use rustc_span::{FileName, InnerSpan}; diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index b1cd3deecb479..50d5f70f4889a 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -1,6 +1,6 @@ -use errors::Applicability; use rustc::lint; use rustc::ty; +use rustc_errors::Applicability; use rustc_expand::base::SyntaxExtensionKind; use rustc_feature::UnstableFeatures; use rustc_hir as hir; diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 94e31108901ea..cc5359b53d17c 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -389,8 +389,8 @@ pub fn make_test( // crate already is included. let result = rustc_driver::catch_fatal_errors(|| { with_globals(edition, || { - use errors::emitter::EmitterWriter; - use errors::Handler; + use rustc_errors::emitter::EmitterWriter; + use rustc_errors::Handler; use rustc_parse::maybe_new_parser_from_source_str; use rustc_span::source_map::FilePathMapping; use syntax::sess::ParseSess; diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index b45531d7252a1..af1c50acb0a35 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -3,7 +3,7 @@ use std::fs; use std::hash::{Hash, Hasher}; use std::path::Path; -use errors::Handler; +use rustc_errors::Handler; #[cfg(test)] mod tests; diff --git a/src/libstd/sys/hermit/os.rs b/src/libstd/sys/hermit/os.rs index 5999fdd4f8d58..5a5808f07e956 100644 --- a/src/libstd/sys/hermit/os.rs +++ b/src/libstd/sys/hermit/os.rs @@ -77,13 +77,17 @@ pub fn init_environment(env: *const *const i8) { unsafe { ENV = Some(Mutex::new(HashMap::new())); + if env.is_null() { + return; + } + let mut guard = ENV.as_ref().unwrap().lock().unwrap(); let mut environ = env; - while environ != ptr::null() && *environ != ptr::null() { + while !(*environ).is_null() { if let Some((key, value)) = parse(CStr::from_ptr(*environ).to_bytes()) { guard.insert(key, value); } - environ = environ.offset(1); + environ = environ.add(1); } } diff --git a/src/libstd/sys/hermit/thread_local.rs b/src/libstd/sys/hermit/thread_local.rs index ba967c7676c3f..c6f8adb21623a 100644 --- a/src/libstd/sys/hermit/thread_local.rs +++ b/src/libstd/sys/hermit/thread_local.rs @@ -18,14 +18,14 @@ static KEYS_LOCK: Mutex = Mutex::new(); static mut LOCALS: *mut BTreeMap = ptr::null_mut(); unsafe fn keys() -> &'static mut BTreeMap> { - if KEYS == ptr::null_mut() { + if KEYS.is_null() { KEYS = Box::into_raw(Box::new(BTreeMap::new())); } &mut *KEYS } unsafe fn locals() -> &'static mut BTreeMap { - if LOCALS == ptr::null_mut() { + if LOCALS.is_null() { LOCALS = Box::into_raw(Box::new(BTreeMap::new())); } &mut *LOCALS diff --git a/src/libstd/sys/sgx/abi/tls.rs b/src/libstd/sys/sgx/abi/tls.rs index 81a766e367d6e..2b0485c4f0363 100644 --- a/src/libstd/sys/sgx/abi/tls.rs +++ b/src/libstd/sys/sgx/abi/tls.rs @@ -70,7 +70,7 @@ impl<'a> Drop for ActiveTls<'a> { any_non_null_dtor = false; for (value, dtor) in TLS_KEY_IN_USE.iter().filter_map(&value_with_destructor) { let value = value.replace(ptr::null_mut()); - if value != ptr::null_mut() { + if !value.is_null() { any_non_null_dtor = true; unsafe { dtor(value) } } diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index b277b3d5899b8..91f7d1524ccef 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -480,11 +480,13 @@ pub fn env() -> Env { let _guard = env_lock(); let mut environ = *environ(); let mut result = Vec::new(); - while environ != ptr::null() && *environ != ptr::null() { - if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { - result.push(key_value); + if !environ.is_null() { + while !(*environ).is_null() { + if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { + result.push(key_value); + } + environ = environ.add(1); } - environ = environ.offset(1); } return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData }; } diff --git a/src/libstd/sys/vxworks/os.rs b/src/libstd/sys/vxworks/os.rs index d421915449944..f1e759f8e764d 100644 --- a/src/libstd/sys/vxworks/os.rs +++ b/src/libstd/sys/vxworks/os.rs @@ -226,15 +226,15 @@ pub fn env() -> Env { unsafe { let _guard = env_lock(); let mut environ = *environ(); - if environ == ptr::null() { + if environ.is_null() { panic!("os::env() failure getting env string from OS: {}", io::Error::last_os_error()); } let mut result = Vec::new(); - while *environ != ptr::null() { + while !(*environ).is_null() { if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { result.push(key_value); } - environ = environ.offset(1); + environ = environ.add(1); } return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData }; } diff --git a/src/libstd/sys/wasi/os.rs b/src/libstd/sys/wasi/os.rs index 3baec6bf09924..2d1fc53e32f91 100644 --- a/src/libstd/sys/wasi/os.rs +++ b/src/libstd/sys/wasi/os.rs @@ -107,11 +107,13 @@ pub fn env() -> Env { let _guard = env_lock(); let mut environ = libc::environ; let mut result = Vec::new(); - while environ != ptr::null_mut() && *environ != ptr::null_mut() { - if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { - result.push(key_value); + if !environ.is_null() { + while !(*environ).is_null() { + if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { + result.push(key_value); + } + environ = environ.add(1); } - environ = environ.offset(1); } return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData }; } diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index c5354671c9843..cc4ae40590693 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -43,7 +43,7 @@ pub fn error_string(mut errnum: i32) -> String { ]; module = c::GetModuleHandleW(NTDLL_DLL.as_ptr()); - if module != ptr::null_mut() { + if !module.is_null() { errnum ^= c::FACILITY_NT_BIT as i32; flags = c::FORMAT_MESSAGE_FROM_HMODULE; } diff --git a/src/libsyntax/Cargo.toml b/src/libsyntax/Cargo.toml index e4f0398fb42d2..7d9f715e9feb8 100644 --- a/src/libsyntax/Cargo.toml +++ b/src/libsyntax/Cargo.toml @@ -13,8 +13,8 @@ doctest = false rustc_serialize = { path = "../libserialize", package = "serialize" } log = "0.4" scoped-tls = "1.0" +rustc_errors = { path = "../librustc_errors" } rustc_span = { path = "../librustc_span" } -errors = { path = "../librustc_errors", package = "rustc_errors" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_feature = { path = "../librustc_feature" } rustc_index = { path = "../librustc_index" } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 1d3bb7d87686c..33acba8eba010 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -649,7 +649,7 @@ pub enum PatKind { Lit(P), /// A range pattern (e.g., `1...2`, `1..=2` or `1..2`). - Range(P, P, Spanned), + Range(Option>, Option>, Spanned), /// A slice pattern `[a, b, c]`. Slice(Vec>), diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index b308d479545be..958e4373cc0ed 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -6,7 +6,7 @@ use crate::feature_gate::feature_err; use crate::print::pprust; use crate::sess::ParseSess; -use errors::{struct_span_err, Applicability, Handler}; +use rustc_errors::{struct_span_err, Applicability, Handler}; use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg}; use rustc_macros::HashStable_Generic; use rustc_span::hygiene::Transparency; diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 8449b61f7b0bb..ec05dab451af8 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -384,7 +384,7 @@ pub fn find_by_name(attrs: &[Attribute], name: Symbol) -> Option<&Attribute> { pub fn allow_internal_unstable<'a>( attrs: &[Attribute], - span_diagnostic: &'a errors::Handler, + span_diagnostic: &'a rustc_errors::Handler, ) -> Option + 'a> { find_by_name(attrs, sym::allow_internal_unstable).and_then(|attr| { attr.meta_item_list() diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 52eb20d320f7b..4eee4e943c2cd 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -4,9 +4,9 @@ use crate::attr; use crate::sess::ParseSess; use crate::visit::{self, FnKind, Visitor}; -use errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder, Handler}; use rustc_data_structures::fx::FxHashMap; use rustc_error_codes::*; +use rustc_errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder, Handler}; use rustc_feature::{find_feature_issue, GateIssue}; use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP}; use rustc_feature::{Feature, Features, State as FeatureState, UnstableFeatures}; @@ -911,6 +911,7 @@ pub fn check_crate( gate_all!(raw_ref_op, "raw address of syntax is experimental"); gate_all!(const_trait_bound_opt_out, "`?const` on trait bounds is experimental"); gate_all!(const_trait_impl, "const trait impls are experimental"); + gate_all!(half_open_range_patterns, "half-open range patterns are unstable"); // All uses of `gate_all!` below this point were added in #65742, // and subsequently disabled (with the non-early gating readded). diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index b197eab739427..7ee4ca4603c9c 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -18,7 +18,6 @@ #![recursion_limit = "256"] use ast::AttrId; -pub use errors; use rustc_data_structures::sync::Lock; use rustc_index::bit_set::GrowableBitSet; use rustc_span::edition::{Edition, DEFAULT_EDITION}; diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index 264ba25cedecc..58d4e46111b83 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -1075,8 +1075,8 @@ pub fn noop_visit_pat(pat: &mut P, vis: &mut T) { PatKind::Box(inner) => vis.visit_pat(inner), PatKind::Ref(inner, _mutbl) => vis.visit_pat(inner), PatKind::Range(e1, e2, Spanned { span: _, node: _ }) => { - vis.visit_expr(e1); - vis.visit_expr(e2); + visit_opt(e1, |e| vis.visit_expr(e)); + visit_opt(e2, |e| vis.visit_expr(e)); vis.visit_span(span); } PatKind::Tuple(elems) | PatKind::Slice(elems) | PatKind::Or(elems) => { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index dd9976510dccf..11c8cb8ef7500 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2329,14 +2329,18 @@ impl<'a> State<'a> { } PatKind::Lit(ref e) => self.print_expr(&**e), PatKind::Range(ref begin, ref end, Spanned { node: ref end_kind, .. }) => { - self.print_expr(begin); - self.s.space(); + if let Some(e) = begin { + self.print_expr(e); + self.s.space(); + } match *end_kind { RangeEnd::Included(RangeSyntax::DotDotDot) => self.s.word("..."), RangeEnd::Included(RangeSyntax::DotDotEq) => self.s.word("..="), RangeEnd::Excluded => self.s.word(".."), } - self.print_expr(end); + if let Some(e) = end { + self.print_expr(e); + } } PatKind::Slice(ref elts) => { self.s.word("["); diff --git a/src/libsyntax/show_span.rs b/src/libsyntax/show_span.rs index fb641239dfa4f..b70e2ce0d3eb7 100644 --- a/src/libsyntax/show_span.rs +++ b/src/libsyntax/show_span.rs @@ -29,7 +29,7 @@ impl FromStr for Mode { } struct ShowSpanVisitor<'a> { - span_diagnostic: &'a errors::Handler, + span_diagnostic: &'a rustc_errors::Handler, mode: Mode, } @@ -60,7 +60,7 @@ impl<'a> Visitor<'a> for ShowSpanVisitor<'a> { } } -pub fn run(span_diagnostic: &errors::Handler, mode: &str, krate: &ast::Crate) { +pub fn run(span_diagnostic: &rustc_errors::Handler, mode: &str, krate: &ast::Crate) { let mode = match mode.parse().ok() { Some(mode) => mode, None => return, diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index ebb49abebb01e..3c2ebacbc4e34 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -492,8 +492,8 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) { } PatKind::Lit(ref expression) => visitor.visit_expr(expression), PatKind::Range(ref lower_bound, ref upper_bound, _) => { - visitor.visit_expr(lower_bound); - visitor.visit_expr(upper_bound); + walk_list!(visitor, visit_expr, lower_bound); + walk_list!(visitor, visit_expr, upper_bound); } PatKind::Wild | PatKind::Rest => {} PatKind::Tuple(ref elems) | PatKind::Slice(ref elems) | PatKind::Or(ref elems) => { diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.rs b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.rs similarity index 59% rename from src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.rs rename to src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.rs index d97b693f52098..3f4c17836c4fc 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.rs +++ b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.rs @@ -1,10 +1,10 @@ +#![feature(half_open_range_patterns)] #![feature(exclusive_range_pattern)] fn main() { match [5..4, 99..105, 43..44] { [_, 99.., _] => {}, - //~^ ERROR `X..` range patterns are not supported - //~| ERROR mismatched types + //~^ ERROR mismatched types _ => {}, } } diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.stderr b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.stderr similarity index 57% rename from src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.stderr rename to src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.stderr index 76ae7241ff277..a6f8563a04785 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.stderr +++ b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.stderr @@ -1,11 +1,5 @@ -error: `X..` range patterns are not supported - --> $DIR/exclusive_range_pattern_syntax_collision.rs:5:13 - | -LL | [_, 99.., _] => {}, - | ^^^^ help: try using the maximum value for the type: `99..MAX` - error[E0308]: mismatched types - --> $DIR/exclusive_range_pattern_syntax_collision.rs:5:13 + --> $DIR/exclusive_range_pattern_syntax_collision.rs:6:13 | LL | match [5..4, 99..105, 43..44] { | ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]` @@ -15,6 +9,6 @@ LL | [_, 99.., _] => {}, = note: expected struct `std::ops::Range<{integer}>` found type `{integer}` -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.rs b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.rs similarity index 58% rename from src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.rs rename to src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.rs index 09f459c9862ee..dedc85491b4a9 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.rs +++ b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.rs @@ -1,10 +1,10 @@ +#![feature(half_open_range_patterns)] #![feature(exclusive_range_pattern)] fn main() { match [5..4, 99..105, 43..44] { [_, 99..] => {}, - //~^ ERROR `X..` range patterns are not supported - //~| ERROR pattern requires 2 elements but array has 3 + //~^ ERROR pattern requires 2 elements but array has 3 //~| ERROR mismatched types _ => {}, } diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.stderr b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.stderr similarity index 62% rename from src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.stderr rename to src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.stderr index 5c96f8041feb2..4e0102c930da8 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.stderr +++ b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.stderr @@ -1,17 +1,11 @@ -error: `X..` range patterns are not supported - --> $DIR/exclusive_range_pattern_syntax_collision2.rs:5:13 - | -LL | [_, 99..] => {}, - | ^^^^ help: try using the maximum value for the type: `99..MAX` - error[E0527]: pattern requires 2 elements but array has 3 - --> $DIR/exclusive_range_pattern_syntax_collision2.rs:5:9 + --> $DIR/exclusive_range_pattern_syntax_collision2.rs:6:9 | LL | [_, 99..] => {}, | ^^^^^^^^^ expected 3 elements error[E0308]: mismatched types - --> $DIR/exclusive_range_pattern_syntax_collision2.rs:5:13 + --> $DIR/exclusive_range_pattern_syntax_collision2.rs:6:13 | LL | match [5..4, 99..105, 43..44] { | ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]` @@ -21,7 +15,7 @@ LL | [_, 99..] => {}, = note: expected struct `std::ops::Range<{integer}>` found type `{integer}` -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0308, E0527. For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.rs b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.rs similarity index 69% rename from src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.rs rename to src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.rs index 1557f592b2a9b..6a9b562cc3a3b 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.rs +++ b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.rs @@ -1,10 +1,10 @@ +#![feature(half_open_range_patterns)] #![feature(exclusive_range_pattern)] fn main() { match [5..4, 99..105, 43..44] { [..9, 99..100, _] => {}, - //~^ ERROR `..X` range patterns are not supported - //~| ERROR mismatched types + //~^ ERROR mismatched types //~| ERROR mismatched types //~| ERROR mismatched types _ => {}, diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.stderr b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.stderr similarity index 75% rename from src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.stderr rename to src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.stderr index 17e10324db181..665eef2fcb96c 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.stderr +++ b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.stderr @@ -1,11 +1,5 @@ -error: `..X` range patterns are not supported - --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:10 - | -LL | [..9, 99..100, _] => {}, - | ^^^ help: try using the minimum value for the type: `MIN..9` - error[E0308]: mismatched types - --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:12 + --> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:12 | LL | match [5..4, 99..105, 43..44] { | ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]` @@ -16,7 +10,7 @@ LL | [..9, 99..100, _] => {}, found type `{integer}` error[E0308]: mismatched types - --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:15 + --> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:15 | LL | match [5..4, 99..105, 43..44] { | ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]` @@ -29,7 +23,7 @@ LL | [..9, 99..100, _] => {}, found type `{integer}` error[E0308]: mismatched types - --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:19 + --> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:19 | LL | match [5..4, 99..105, 43..44] { | ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]` @@ -41,6 +35,6 @@ LL | [..9, 99..100, _] => {}, = note: expected struct `std::ops::Range<{integer}>` found type `{integer}` -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.rs b/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.rs new file mode 100644 index 0000000000000..4cb8230a7b620 --- /dev/null +++ b/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.rs @@ -0,0 +1,21 @@ +#![feature(exclusive_range_pattern)] + +fn main() {} + +#[cfg(FALSE)] +fn foo() { + if let ..=5 = 0 {} + //~^ ERROR half-open range patterns are unstable + if let ...5 = 0 {} + //~^ ERROR half-open range patterns are unstable + if let ..5 = 0 {} + //~^ ERROR half-open range patterns are unstable + if let 5.. = 0 {} + //~^ ERROR half-open range patterns are unstable + if let 5..= = 0 {} + //~^ ERROR half-open range patterns are unstable + //~| ERROR inclusive range with no end + if let 5... = 0 {} + //~^ ERROR half-open range patterns are unstable + //~| ERROR inclusive range with no end +} diff --git a/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.stderr b/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.stderr new file mode 100644 index 0000000000000..68ba654de76da --- /dev/null +++ b/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.stderr @@ -0,0 +1,74 @@ +error[E0586]: inclusive range with no end + --> $DIR/feature-gate-half-open-range-patterns.rs:15:13 + | +LL | if let 5..= = 0 {} + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) + +error[E0586]: inclusive range with no end + --> $DIR/feature-gate-half-open-range-patterns.rs:18:13 + | +LL | if let 5... = 0 {} + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) + +error[E0658]: half-open range patterns are unstable + --> $DIR/feature-gate-half-open-range-patterns.rs:7:12 + | +LL | if let ..=5 = 0 {} + | ^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/67264 + = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable + +error[E0658]: half-open range patterns are unstable + --> $DIR/feature-gate-half-open-range-patterns.rs:9:12 + | +LL | if let ...5 = 0 {} + | ^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/67264 + = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable + +error[E0658]: half-open range patterns are unstable + --> $DIR/feature-gate-half-open-range-patterns.rs:11:12 + | +LL | if let ..5 = 0 {} + | ^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/67264 + = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable + +error[E0658]: half-open range patterns are unstable + --> $DIR/feature-gate-half-open-range-patterns.rs:13:12 + | +LL | if let 5.. = 0 {} + | ^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/67264 + = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable + +error[E0658]: half-open range patterns are unstable + --> $DIR/feature-gate-half-open-range-patterns.rs:15:12 + | +LL | if let 5..= = 0 {} + | ^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/67264 + = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable + +error[E0658]: half-open range patterns are unstable + --> $DIR/feature-gate-half-open-range-patterns.rs:18:12 + | +LL | if let 5... = 0 {} + | ^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/67264 + = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable + +error: aborting due to 8 previous errors + +Some errors have detailed explanations: E0586, E0658. +For more information about an error, try `rustc --explain E0586`. diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.rs new file mode 100644 index 0000000000000..7cddf5f652a31 --- /dev/null +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.rs @@ -0,0 +1,8 @@ +#![feature(half_open_range_patterns)] +#![feature(exclusive_range_pattern)] + +fn main() { + let "a".. = "a"; //~ ERROR only char and numeric types are allowed in range patterns + let .."a" = "a"; //~ ERROR only char and numeric types are allowed in range patterns + let ..="a" = "a"; //~ ERROR only char and numeric types are allowed in range patterns +} diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.stderr new file mode 100644 index 0000000000000..68ca3637150d3 --- /dev/null +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.stderr @@ -0,0 +1,21 @@ +error[E0029]: only char and numeric types are allowed in range patterns + --> $DIR/half-open-range-pats-bad-types.rs:5:9 + | +LL | let "a".. = "a"; + | ^^^ this is of type `&'static str` but it should be `char` or numeric + +error[E0029]: only char and numeric types are allowed in range patterns + --> $DIR/half-open-range-pats-bad-types.rs:6:11 + | +LL | let .."a" = "a"; + | ^^^ this is of type `&'static str` but it should be `char` or numeric + +error[E0029]: only char and numeric types are allowed in range patterns + --> $DIR/half-open-range-pats-bad-types.rs:7:12 + | +LL | let ..="a" = "a"; + | ^^^ this is of type `&'static str` but it should be `char` or numeric + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0029`. diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.rs new file mode 100644 index 0000000000000..b135891d0b82f --- /dev/null +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.rs @@ -0,0 +1,168 @@ +// Test various non-exhaustive matches for `X..`, `..=X` and `..X` ranges. + +#![feature(half_open_range_patterns)] +#![feature(exclusive_range_pattern)] +#![allow(illegal_floating_point_literal_pattern)] + +fn main() {} + +macro_rules! m { + ($s:expr, $($t:tt)+) => { + match $s { $($t)+ => {} } + } +} + +fn floats() { + m!(0f32, core::f32::NEG_INFINITY..); //~ ERROR non-exhaustive patterns: `_` not covered + m!(0f32, ..core::f32::INFINITY); //~ ERROR non-exhaustive patterns: `_` not covered +} + +fn khar() { + const ALMOST_MAX: char = '\u{10fffe}'; + const ALMOST_MIN: char = '\u{1}'; + const VAL: char = 'a'; + const VAL_1: char = 'b'; + const VAL_2: char = 'c'; + m!('a', ..core::char::MAX); //~ ERROR non-exhaustive patterns + m!('a', ..ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!('a', ALMOST_MIN..); //~ ERROR non-exhaustive patterns + m!('a', ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!('a', ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns + m!('a', ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns +} + +mod unsigned { + fn u8() { + const ALMOST_MAX: u8 = core::u8::MAX - 1; + const ALMOST_MIN: u8 = core::u8::MIN + 1; + const VAL: u8 = 42; + const VAL_1: u8 = VAL + 1; + const VAL_2: u8 = VAL + 2; + m!(0, ..core::u8::MAX); //~ ERROR non-exhaustive patterns + m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns + m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns + m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns + } + fn u16() { + const ALMOST_MAX: u16 = core::u16::MAX - 1; + const ALMOST_MIN: u16 = core::u16::MIN + 1; + const VAL: u16 = 42; + const VAL_1: u16 = VAL + 1; + const VAL_2: u16 = VAL + 2; + m!(0, ..core::u16::MAX); //~ ERROR non-exhaustive patterns + m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns + m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns + m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns + } + fn u32() { + const ALMOST_MAX: u32 = core::u32::MAX - 1; + const ALMOST_MIN: u32 = core::u32::MIN + 1; + const VAL: u32 = 42; + const VAL_1: u32 = VAL + 1; + const VAL_2: u32 = VAL + 2; + m!(0, ..core::u32::MAX); //~ ERROR non-exhaustive patterns + m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns + m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns + m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns + } + fn u64() { + const ALMOST_MAX: u64 = core::u64::MAX - 1; + const ALMOST_MIN: u64 = core::u64::MIN + 1; + const VAL: u64 = 42; + const VAL_1: u64 = VAL + 1; + const VAL_2: u64 = VAL + 2; + m!(0, ..core::u64::MAX); //~ ERROR non-exhaustive patterns + m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns + m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns + m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns + } + fn u128() { + const ALMOST_MAX: u128 = core::u128::MAX - 1; + const ALMOST_MIN: u128 = core::u128::MIN + 1; + const VAL: u128 = 42; + const VAL_1: u128 = VAL + 1; + const VAL_2: u128 = VAL + 2; + m!(0, ..core::u128::MAX); //~ ERROR non-exhaustive patterns + m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns + m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns + m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns + } +} + +mod signed { + fn i8() { + const ALMOST_MAX: i8 = core::i8::MAX - 1; + const ALMOST_MIN: i8 = core::i8::MIN + 1; + const VAL: i8 = 42; + const VAL_1: i8 = VAL + 1; + const VAL_2: i8 = VAL + 2; + m!(0, ..core::i8::MAX); //~ ERROR non-exhaustive patterns + m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns + m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns + m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns + } + fn i16() { + const ALMOST_MAX: i16 = core::i16::MAX - 1; + const ALMOST_MIN: i16 = core::i16::MIN + 1; + const VAL: i16 = 42; + const VAL_1: i16 = VAL + 1; + const VAL_2: i16 = VAL + 2; + m!(0, ..core::i16::MAX); //~ ERROR non-exhaustive patterns + m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns + m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns + m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns + } + fn i32() { + const ALMOST_MAX: i32 = core::i32::MAX - 1; + const ALMOST_MIN: i32 = core::i32::MIN + 1; + const VAL: i32 = 42; + const VAL_1: i32 = VAL + 1; + const VAL_2: i32 = VAL + 2; + m!(0, ..core::i32::MAX); //~ ERROR non-exhaustive patterns + m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns + m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns + m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns + } + fn i64() { + const ALMOST_MAX: i64 = core::i64::MAX - 1; + const ALMOST_MIN: i64 = core::i64::MIN + 1; + const VAL: i64 = 42; + const VAL_1: i64 = VAL + 1; + const VAL_2: i64 = VAL + 2; + m!(0, ..core::i64::MAX); //~ ERROR non-exhaustive patterns + m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns + m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns + m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns + } + fn i128() { + const ALMOST_MAX: i128 = core::i128::MAX - 1; + const ALMOST_MIN: i128 = core::i128::MIN + 1; + const VAL: i128 = 42; + const VAL_1: i128 = VAL + 1; + const VAL_2: i128 = VAL + 2; + m!(0, ..core::i128::MAX); //~ ERROR non-exhaustive patterns + m!(0, ..ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ALMOST_MIN..); //~ ERROR non-exhaustive patterns + m!(0, ..=ALMOST_MAX); //~ ERROR non-exhaustive patterns + m!(0, ..=VAL | VAL_2..); //~ ERROR non-exhaustive patterns + m!(0, ..VAL_1 | VAL_2..); //~ ERROR non-exhaustive patterns + } +} diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.stderr new file mode 100644 index 0000000000000..26d0cf9e9ecba --- /dev/null +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.stderr @@ -0,0 +1,547 @@ +error[E0004]: non-exhaustive patterns: `_` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:16:8 + | +LL | m!(0f32, core::f32::NEG_INFINITY..); + | ^^^^ pattern `_` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `_` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:17:8 + | +LL | m!(0f32, ..core::f32::INFINITY); + | ^^^^ pattern `_` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `'\u{10ffff}'` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:26:8 + | +LL | m!('a', ..core::char::MAX); + | ^^^ pattern `'\u{10ffff}'` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `'\u{10fffe}'..='\u{10ffff}'` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:27:8 + | +LL | m!('a', ..ALMOST_MAX); + | ^^^ pattern `'\u{10fffe}'..='\u{10ffff}'` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `'\u{0}'` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:28:8 + | +LL | m!('a', ALMOST_MIN..); + | ^^^ pattern `'\u{0}'` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `'\u{10ffff}'` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:29:8 + | +LL | m!('a', ..=ALMOST_MAX); + | ^^^ pattern `'\u{10ffff}'` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `'b'` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:30:8 + | +LL | m!('a', ..=VAL | VAL_2..); + | ^^^ pattern `'b'` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `'b'` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:31:8 + | +LL | m!('a', ..VAL_1 | VAL_2..); + | ^^^ pattern `'b'` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::u8::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:41:12 + | +LL | m!(0, ..core::u8::MAX); + | ^ pattern `std::u8::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `254u8..=std::u8::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:42:12 + | +LL | m!(0, ..ALMOST_MAX); + | ^ pattern `254u8..=std::u8::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `0u8` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:43:12 + | +LL | m!(0, ALMOST_MIN..); + | ^ pattern `0u8` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::u8::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:44:12 + | +LL | m!(0, ..=ALMOST_MAX); + | ^ pattern `std::u8::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43u8` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:45:12 + | +LL | m!(0, ..=VAL | VAL_2..); + | ^ pattern `43u8` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43u8` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:46:12 + | +LL | m!(0, ..VAL_1 | VAL_2..); + | ^ pattern `43u8` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::u16::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:54:12 + | +LL | m!(0, ..core::u16::MAX); + | ^ pattern `std::u16::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `65534u16..=std::u16::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:55:12 + | +LL | m!(0, ..ALMOST_MAX); + | ^ pattern `65534u16..=std::u16::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `0u16` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:56:12 + | +LL | m!(0, ALMOST_MIN..); + | ^ pattern `0u16` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::u16::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:57:12 + | +LL | m!(0, ..=ALMOST_MAX); + | ^ pattern `std::u16::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43u16` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:58:12 + | +LL | m!(0, ..=VAL | VAL_2..); + | ^ pattern `43u16` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43u16` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:59:12 + | +LL | m!(0, ..VAL_1 | VAL_2..); + | ^ pattern `43u16` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::u32::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:67:12 + | +LL | m!(0, ..core::u32::MAX); + | ^ pattern `std::u32::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `4294967294u32..=std::u32::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:68:12 + | +LL | m!(0, ..ALMOST_MAX); + | ^ pattern `4294967294u32..=std::u32::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `0u32` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:69:12 + | +LL | m!(0, ALMOST_MIN..); + | ^ pattern `0u32` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::u32::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:70:12 + | +LL | m!(0, ..=ALMOST_MAX); + | ^ pattern `std::u32::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43u32` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:71:12 + | +LL | m!(0, ..=VAL | VAL_2..); + | ^ pattern `43u32` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43u32` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:72:12 + | +LL | m!(0, ..VAL_1 | VAL_2..); + | ^ pattern `43u32` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::u64::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:80:12 + | +LL | m!(0, ..core::u64::MAX); + | ^ pattern `std::u64::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `18446744073709551614u64..=std::u64::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:81:12 + | +LL | m!(0, ..ALMOST_MAX); + | ^ pattern `18446744073709551614u64..=std::u64::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `0u64` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:82:12 + | +LL | m!(0, ALMOST_MIN..); + | ^ pattern `0u64` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::u64::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:83:12 + | +LL | m!(0, ..=ALMOST_MAX); + | ^ pattern `std::u64::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43u64` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:84:12 + | +LL | m!(0, ..=VAL | VAL_2..); + | ^ pattern `43u64` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43u64` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:85:12 + | +LL | m!(0, ..VAL_1 | VAL_2..); + | ^ pattern `43u64` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::u128::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:93:12 + | +LL | m!(0, ..core::u128::MAX); + | ^ pattern `std::u128::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `340282366920938463463374607431768211454u128..=std::u128::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:94:12 + | +LL | m!(0, ..ALMOST_MAX); + | ^ pattern `340282366920938463463374607431768211454u128..=std::u128::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `0u128` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:95:12 + | +LL | m!(0, ALMOST_MIN..); + | ^ pattern `0u128` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::u128::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:96:12 + | +LL | m!(0, ..=ALMOST_MAX); + | ^ pattern `std::u128::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43u128` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:97:12 + | +LL | m!(0, ..=VAL | VAL_2..); + | ^ pattern `43u128` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43u128` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:98:12 + | +LL | m!(0, ..VAL_1 | VAL_2..); + | ^ pattern `43u128` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i8::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:109:12 + | +LL | m!(0, ..core::i8::MAX); + | ^ pattern `std::i8::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `126i8..=std::i8::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:110:12 + | +LL | m!(0, ..ALMOST_MAX); + | ^ pattern `126i8..=std::i8::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i8::MIN` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:111:12 + | +LL | m!(0, ALMOST_MIN..); + | ^ pattern `std::i8::MIN` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i8::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:112:12 + | +LL | m!(0, ..=ALMOST_MAX); + | ^ pattern `std::i8::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43i8` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:113:12 + | +LL | m!(0, ..=VAL | VAL_2..); + | ^ pattern `43i8` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43i8` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:114:12 + | +LL | m!(0, ..VAL_1 | VAL_2..); + | ^ pattern `43i8` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i16::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:122:12 + | +LL | m!(0, ..core::i16::MAX); + | ^ pattern `std::i16::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `32766i16..=std::i16::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:123:12 + | +LL | m!(0, ..ALMOST_MAX); + | ^ pattern `32766i16..=std::i16::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i16::MIN` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:124:12 + | +LL | m!(0, ALMOST_MIN..); + | ^ pattern `std::i16::MIN` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i16::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:125:12 + | +LL | m!(0, ..=ALMOST_MAX); + | ^ pattern `std::i16::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43i16` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:126:12 + | +LL | m!(0, ..=VAL | VAL_2..); + | ^ pattern `43i16` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43i16` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:127:12 + | +LL | m!(0, ..VAL_1 | VAL_2..); + | ^ pattern `43i16` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i32::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:135:12 + | +LL | m!(0, ..core::i32::MAX); + | ^ pattern `std::i32::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `2147483646i32..=std::i32::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:136:12 + | +LL | m!(0, ..ALMOST_MAX); + | ^ pattern `2147483646i32..=std::i32::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i32::MIN` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:137:12 + | +LL | m!(0, ALMOST_MIN..); + | ^ pattern `std::i32::MIN` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i32::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:138:12 + | +LL | m!(0, ..=ALMOST_MAX); + | ^ pattern `std::i32::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43i32` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:139:12 + | +LL | m!(0, ..=VAL | VAL_2..); + | ^ pattern `43i32` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43i32` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:140:12 + | +LL | m!(0, ..VAL_1 | VAL_2..); + | ^ pattern `43i32` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i64::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:148:12 + | +LL | m!(0, ..core::i64::MAX); + | ^ pattern `std::i64::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `9223372036854775806i64..=std::i64::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:149:12 + | +LL | m!(0, ..ALMOST_MAX); + | ^ pattern `9223372036854775806i64..=std::i64::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i64::MIN` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:150:12 + | +LL | m!(0, ALMOST_MIN..); + | ^ pattern `std::i64::MIN` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i64::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:151:12 + | +LL | m!(0, ..=ALMOST_MAX); + | ^ pattern `std::i64::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43i64` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:152:12 + | +LL | m!(0, ..=VAL | VAL_2..); + | ^ pattern `43i64` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43i64` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:153:12 + | +LL | m!(0, ..VAL_1 | VAL_2..); + | ^ pattern `43i64` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i128::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:161:12 + | +LL | m!(0, ..core::i128::MAX); + | ^ pattern `std::i128::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `170141183460469231731687303715884105726i128..=std::i128::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:162:12 + | +LL | m!(0, ..ALMOST_MAX); + | ^ pattern `170141183460469231731687303715884105726i128..=std::i128::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i128::MIN` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:163:12 + | +LL | m!(0, ALMOST_MIN..); + | ^ pattern `std::i128::MIN` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `std::i128::MAX` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:164:12 + | +LL | m!(0, ..=ALMOST_MAX); + | ^ pattern `std::i128::MAX` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43i128` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:165:12 + | +LL | m!(0, ..=VAL | VAL_2..); + | ^ pattern `43i128` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error[E0004]: non-exhaustive patterns: `43i128` not covered + --> $DIR/half-open-range-pats-exhaustive-fail.rs:166:12 + | +LL | m!(0, ..VAL_1 | VAL_2..); + | ^ pattern `43i128` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + +error: aborting due to 68 previous errors + +For more information about this error, try `rustc --explain E0004`. diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-pass.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-pass.rs new file mode 100644 index 0000000000000..efac0df2a430d --- /dev/null +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-pass.rs @@ -0,0 +1,49 @@ +// check-pass + +// Test various exhaustive matches for `X..`, `..=X` and `..X` ranges. + +#![feature(half_open_range_patterns)] +#![feature(exclusive_range_pattern)] + +fn main() {} + +macro_rules! m { + ($s:expr, $($t:tt)+) => { + match $s { $($t)+ => {} } + } +} + +macro_rules! test_int { + ($s:expr, $min:path, $max:path) => { + m!($s, $min..); + m!($s, $min..5 | 5..); + m!($s, ..5 | 5..); + m!($s, ..=4 | 5..); + m!($s, ..=$max); + m!($s, ..$max | $max); + m!(($s, true), (..5, true) | (5.., true) | ($min.., false)); + } +} + +fn unsigned_int() { + test_int!(0u8, core::u8::MIN, core::u8::MAX); + test_int!(0u16, core::u16::MIN, core::u16::MAX); + test_int!(0u32, core::u32::MIN, core::u32::MAX); + test_int!(0u64, core::u64::MIN, core::u64::MAX); + test_int!(0u128, core::u128::MIN, core::u128::MAX); +} + +fn signed_int() { + test_int!(0i8, core::i8::MIN, core::i8::MAX); + test_int!(0i16, core::i16::MIN, core::i16::MAX); + test_int!(0i32, core::i32::MIN, core::i32::MAX); + test_int!(0i64, core::i64::MIN, core::i64::MAX); + test_int!(0i128, core::i128::MIN, core::i128::MAX); +} + +fn khar() { + m!('a', ..=core::char::MAX); + m!('a', '\u{0}'..); + m!('a', ..='\u{D7FF}' | '\u{E000}'..); + m!('a', ..'\u{D7FF}' | '\u{D7FF}' | '\u{E000}'..); +} diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-hair-lower-empty.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-hair-lower-empty.rs new file mode 100644 index 0000000000000..904efda903c69 --- /dev/null +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-hair-lower-empty.rs @@ -0,0 +1,54 @@ +#![feature(half_open_range_patterns)] +#![feature(exclusive_range_pattern)] +#![allow(illegal_floating_point_literal_pattern)] + +macro_rules! m { + ($s:expr, $($t:tt)+) => { + match $s { $($t)+ => {} } + } +} + +fn main() { + m!(0, ..core::u8::MIN); + //~^ ERROR lower range bound must be less than upper + //~| ERROR lower range bound must be less than upper + m!(0, ..core::u16::MIN); + //~^ ERROR lower range bound must be less than upper + //~| ERROR lower range bound must be less than upper + m!(0, ..core::u32::MIN); + //~^ ERROR lower range bound must be less than upper + //~| ERROR lower range bound must be less than upper + m!(0, ..core::u64::MIN); + //~^ ERROR lower range bound must be less than upper + //~| ERROR lower range bound must be less than upper + m!(0, ..core::u128::MIN); + //~^ ERROR lower range bound must be less than upper + //~| ERROR lower range bound must be less than upper + + m!(0, ..core::i8::MIN); + //~^ ERROR lower range bound must be less than upper + //~| ERROR lower range bound must be less than upper + m!(0, ..core::i16::MIN); + //~^ ERROR lower range bound must be less than upper + //~| ERROR lower range bound must be less than upper + m!(0, ..core::i32::MIN); + //~^ ERROR lower range bound must be less than upper + //~| ERROR lower range bound must be less than upper + m!(0, ..core::i64::MIN); + //~^ ERROR lower range bound must be less than upper + //~| ERROR lower range bound must be less than upper + m!(0, ..core::i128::MIN); + //~^ ERROR lower range bound must be less than upper + //~| ERROR lower range bound must be less than upper + + m!(0f32, ..core::f32::NEG_INFINITY); + //~^ ERROR lower range bound must be less than upper + //~| ERROR lower range bound must be less than upper + m!(0f64, ..core::f64::NEG_INFINITY); + //~^ ERROR lower range bound must be less than upper + //~| ERROR lower range bound must be less than upper + + m!('a', ..'\u{0}'); + //~^ ERROR lower range bound must be less than upper + //~| ERROR lower range bound must be less than upper +} diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-hair-lower-empty.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-hair-lower-empty.stderr new file mode 100644 index 0000000000000..b536e1b5548d0 --- /dev/null +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-hair-lower-empty.stderr @@ -0,0 +1,159 @@ +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:12:11 + | +LL | m!(0, ..core::u8::MIN); + | ^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:15:11 + | +LL | m!(0, ..core::u16::MIN); + | ^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:18:11 + | +LL | m!(0, ..core::u32::MIN); + | ^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:21:11 + | +LL | m!(0, ..core::u64::MIN); + | ^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:24:11 + | +LL | m!(0, ..core::u128::MIN); + | ^^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:28:11 + | +LL | m!(0, ..core::i8::MIN); + | ^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:31:11 + | +LL | m!(0, ..core::i16::MIN); + | ^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:34:11 + | +LL | m!(0, ..core::i32::MIN); + | ^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:37:11 + | +LL | m!(0, ..core::i64::MIN); + | ^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:40:11 + | +LL | m!(0, ..core::i128::MIN); + | ^^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:44:14 + | +LL | m!(0f32, ..core::f32::NEG_INFINITY); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:47:14 + | +LL | m!(0f64, ..core::f64::NEG_INFINITY); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:51:13 + | +LL | m!('a', ..'\u{0}'); + | ^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:12:11 + | +LL | m!(0, ..core::u8::MIN); + | ^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:15:11 + | +LL | m!(0, ..core::u16::MIN); + | ^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:18:11 + | +LL | m!(0, ..core::u32::MIN); + | ^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:21:11 + | +LL | m!(0, ..core::u64::MIN); + | ^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:24:11 + | +LL | m!(0, ..core::u128::MIN); + | ^^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:28:11 + | +LL | m!(0, ..core::i8::MIN); + | ^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:31:11 + | +LL | m!(0, ..core::i16::MIN); + | ^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:34:11 + | +LL | m!(0, ..core::i32::MIN); + | ^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:37:11 + | +LL | m!(0, ..core::i64::MIN); + | ^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:40:11 + | +LL | m!(0, ..core::i128::MIN); + | ^^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:44:14 + | +LL | m!(0f32, ..core::f32::NEG_INFINITY); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:47:14 + | +LL | m!(0f64, ..core::f64::NEG_INFINITY); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0579]: lower range bound must be less than upper + --> $DIR/half-open-range-pats-hair-lower-empty.rs:51:13 + | +LL | m!('a', ..'\u{0}'); + | ^^^^^^^^^ + +error: aborting due to 26 previous errors + +For more information about this error, try `rustc --explain E0579`. diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.rs new file mode 100644 index 0000000000000..03166e3675571 --- /dev/null +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.rs @@ -0,0 +1,15 @@ +// Test `X...` and `X..=` range patterns not being allowed syntactically. +// FIXME(Centril): perhaps these should be semantic restrictions. + +#![feature(half_open_range_patterns)] + +fn main() {} + +#[cfg(FALSE)] +fn foo() { + if let 0... = 1 {} //~ ERROR inclusive range with no end + if let 0..= = 1 {} //~ ERROR inclusive range with no end + const X: u8 = 0; + if let X... = 1 {} //~ ERROR inclusive range with no end + if let X..= = 1 {} //~ ERROR inclusive range with no end +} diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr new file mode 100644 index 0000000000000..2b4d95f684284 --- /dev/null +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr @@ -0,0 +1,35 @@ +error[E0586]: inclusive range with no end + --> $DIR/half-open-range-pats-inclusive-no-end.rs:10:13 + | +LL | if let 0... = 1 {} + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) + +error[E0586]: inclusive range with no end + --> $DIR/half-open-range-pats-inclusive-no-end.rs:11:13 + | +LL | if let 0..= = 1 {} + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) + +error[E0586]: inclusive range with no end + --> $DIR/half-open-range-pats-inclusive-no-end.rs:13:13 + | +LL | if let X... = 1 {} + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) + +error[E0586]: inclusive range with no end + --> $DIR/half-open-range-pats-inclusive-no-end.rs:14:13 + | +LL | if let X..= = 1 {} + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0586`. diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.rs new file mode 100644 index 0000000000000..e9a5361e63d27 --- /dev/null +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.rs @@ -0,0 +1,24 @@ +#![feature(half_open_range_patterns)] + +fn main() {} + +#[cfg(FALSE)] +fn syntax() { + match &0 { + &0.. | _ => {} + //~^ ERROR the range pattern here has ambiguous interpretation + &0..= | _ => {} + //~^ ERROR the range pattern here has ambiguous interpretation + //~| ERROR inclusive range with no end + &0... | _ => {} + //~^ ERROR inclusive range with no end + } + + match &0 { + &..0 | _ => {} + //~^ ERROR the range pattern here has ambiguous interpretation + &..=0 | _ => {} + //~^ ERROR the range pattern here has ambiguous interpretation + &...0 | _ => {} + } +} diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.stderr new file mode 100644 index 0000000000000..5d3aded022224 --- /dev/null +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.stderr @@ -0,0 +1,43 @@ +error: the range pattern here has ambiguous interpretation + --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:8:10 + | +LL | &0.. | _ => {} + | ^^^ help: add parentheses to clarify the precedence: `(0 ..)` + +error[E0586]: inclusive range with no end + --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:10:11 + | +LL | &0..= | _ => {} + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) + +error: the range pattern here has ambiguous interpretation + --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:10:10 + | +LL | &0..= | _ => {} + | ^^^^ help: add parentheses to clarify the precedence: `(0 ..=)` + +error[E0586]: inclusive range with no end + --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:13:11 + | +LL | &0... | _ => {} + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) + +error: the range pattern here has ambiguous interpretation + --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:18:10 + | +LL | &..0 | _ => {} + | ^^^ help: add parentheses to clarify the precedence: `(..0)` + +error: the range pattern here has ambiguous interpretation + --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:20:10 + | +LL | &..=0 | _ => {} + | ^^^^ help: add parentheses to clarify the precedence: `(..=0)` + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0586`. diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-semantics.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-semantics.rs new file mode 100644 index 0000000000000..416c59af3fd3e --- /dev/null +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-semantics.rs @@ -0,0 +1,160 @@ +// run-pass + +// Test half-open range patterns against their expression equivalents +// via `.contains(...)` and make sure the dynamic semantics match. + +#![feature(half_open_range_patterns)] +#![feature(exclusive_range_pattern)] +#![allow(illegal_floating_point_literal_pattern)] +#![allow(unreachable_patterns)] + +macro_rules! yes { + ($scrutinee:expr, $($t:tt)+) => { + { + let m = match $scrutinee { $($t)+ => true, _ => false, }; + let c = ($($t)+).contains(&$scrutinee); + assert_eq!(m, c); + m + } + } +} + +fn range_to_inclusive() { + // `..=X` (`RangeToInclusive`-equivalent): + //--------------------------------------- + + // u8; `..=X` + assert!(yes!(core::u8::MIN, ..=core::u8::MIN)); + assert!(yes!(core::u8::MIN, ..=5)); + assert!(yes!(5u8, ..=5)); + assert!(!yes!(6u8, ..=5)); + + // i16; `..=X` + assert!(yes!(core::i16::MIN, ..=core::i16::MIN)); + assert!(yes!(core::i16::MIN, ..=0)); + assert!(yes!(core::i16::MIN, ..=-5)); + assert!(yes!(-5, ..=-5)); + assert!(!yes!(-4, ..=-5)); + + // char; `..=X` + assert!(yes!('\u{0}', ..='\u{0}')); + assert!(yes!('\u{0}', ..='a')); + assert!(yes!('a', ..='a')); + assert!(!yes!('b', ..='a')); + + // f32; `..=X` + assert!(yes!(core::f32::NEG_INFINITY, ..=core::f32::NEG_INFINITY)); + assert!(yes!(core::f32::NEG_INFINITY, ..=1.0f32)); + assert!(yes!(1.5f32, ..=1.5f32)); + assert!(!yes!(1.6f32, ..=-1.5f32)); + + // f64; `..=X` + assert!(yes!(core::f64::NEG_INFINITY, ..=core::f64::NEG_INFINITY)); + assert!(yes!(core::f64::NEG_INFINITY, ..=1.0f64)); + assert!(yes!(1.5f64, ..=1.5f64)); + assert!(!yes!(1.6f64, ..=-1.5f64)); +} + +fn range_to() { + // `..X` (`RangeTo`-equivalent): + //----------------------------- + + // u8; `..X` + assert!(yes!(0u8, ..1)); + assert!(yes!(0u8, ..5)); + assert!(!yes!(5u8, ..5)); + assert!(!yes!(6u8, ..5)); + + // u8; `..X` + const NU8: u8 = core::u8::MIN + 1; + assert!(yes!(core::u8::MIN, ..NU8)); + assert!(yes!(0u8, ..5)); + assert!(!yes!(5u8, ..5)); + assert!(!yes!(6u8, ..5)); + + // i16; `..X` + const NI16: i16 = core::i16::MIN + 1; + assert!(yes!(core::i16::MIN, ..NI16)); + assert!(yes!(core::i16::MIN, ..5)); + assert!(yes!(-6, ..-5)); + assert!(!yes!(-5, ..-5)); + + // char; `..X` + assert!(yes!('\u{0}', ..'\u{1}')); + assert!(yes!('\u{0}', ..'a')); + assert!(yes!('a', ..'b')); + assert!(!yes!('a', ..'a')); + assert!(!yes!('b', ..'a')); + + // f32; `..X` + assert!(yes!(core::f32::NEG_INFINITY, ..1.0f32)); + assert!(!yes!(1.5f32, ..1.5f32)); + const E32: f32 = 1.5f32 + core::f32::EPSILON; + assert!(yes!(1.5f32, ..E32)); + assert!(!yes!(1.6f32, ..1.5f32)); + + // f64; `..X` + assert!(yes!(core::f64::NEG_INFINITY, ..1.0f64)); + assert!(!yes!(1.5f64, ..1.5f64)); + const E64: f64 = 1.5f64 + core::f64::EPSILON; + assert!(yes!(1.5f64, ..E64)); + assert!(!yes!(1.6f64, ..1.5f64)); +} + +fn range_from() { + // `X..` (`RangeFrom`-equivalent): + //-------------------------------- + + // u8; `X..` + assert!(yes!(core::u8::MIN, core::u8::MIN..)); + assert!(yes!(core::u8::MAX, core::u8::MIN..)); + assert!(!yes!(core::u8::MIN, 1..)); + assert!(!yes!(4, 5..)); + assert!(yes!(5, 5..)); + assert!(yes!(6, 5..)); + assert!(yes!(core::u8::MAX, core::u8::MAX..)); + + // i16; `X..` + assert!(yes!(core::i16::MIN, core::i16::MIN..)); + assert!(yes!(core::i16::MAX, core::i16::MIN..)); + const NI16: i16 = core::i16::MIN + 1; + assert!(!yes!(core::i16::MIN, NI16..)); + assert!(!yes!(-4, 5..)); + assert!(yes!(-4, -4..)); + assert!(yes!(-3, -4..)); + assert!(yes!(core::i16::MAX, core::i16::MAX..)); + + // char; `X..` + assert!(yes!('\u{0}', '\u{0}'..)); + assert!(yes!(core::char::MAX, '\u{0}'..)); + assert!(yes!('a', 'a'..)); + assert!(yes!('b', 'a'..)); + assert!(!yes!('a', 'b'..)); + assert!(yes!(core::char::MAX, core::char::MAX..)); + + // f32; `X..` + assert!(yes!(core::f32::NEG_INFINITY, core::f32::NEG_INFINITY..)); + assert!(yes!(core::f32::INFINITY, core::f32::NEG_INFINITY..)); + assert!(!yes!(core::f32::NEG_INFINITY, 1.0f32..)); + assert!(yes!(core::f32::INFINITY, 1.0f32..)); + assert!(!yes!(1.0f32 - core::f32::EPSILON, 1.0f32..)); + assert!(yes!(1.0f32, 1.0f32..)); + assert!(yes!(core::f32::INFINITY, 1.0f32..)); + assert!(yes!(core::f32::INFINITY, core::f32::INFINITY..)); + + // f64; `X..` + assert!(yes!(core::f64::NEG_INFINITY, core::f64::NEG_INFINITY..)); + assert!(yes!(core::f64::INFINITY, core::f64::NEG_INFINITY..)); + assert!(!yes!(core::f64::NEG_INFINITY, 1.0f64..)); + assert!(yes!(core::f64::INFINITY, 1.0f64..)); + assert!(!yes!(1.0f64 - core::f64::EPSILON, 1.0f64..)); + assert!(yes!(1.0f64, 1.0f64..)); + assert!(yes!(core::f64::INFINITY, 1.0f64..)); + assert!(yes!(core::f64::INFINITY, core::f64::INFINITY..)); +} + +fn main() { + range_to_inclusive(); + range_to(); + range_from(); +} diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-syntactic-pass.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-syntactic-pass.rs new file mode 100644 index 0000000000000..a663acd2d191c --- /dev/null +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-syntactic-pass.rs @@ -0,0 +1,32 @@ +// check-pass + +// Test the parsing of half-open ranges. + +#![feature(exclusive_range_pattern)] +#![feature(half_open_range_patterns)] + +fn main() {} + +#[cfg(FALSE)] +fn syntax() { + match scrutinee { + X.. | 0.. | 'a'.. | 0.0f32.. => {} + ..=X | ...X | ..X => {} + ..=0 | ...0 | ..0 => {} + ..='a' | ...'a' | ..'a' => {} + ..=0.0f32 | ...0.0f32 | ..0.0f32 => {} + } + + macro_rules! mac { + ($e:expr) => { + let ..$e; + let ...$e; + let ..=$e; + let $e..; + let $e...; + let $e..=; + } + } + + mac!(0); +} diff --git a/src/test/ui/half-open-range-patterns/pat-tuple-4.rs b/src/test/ui/half-open-range-patterns/pat-tuple-4.rs new file mode 100644 index 0000000000000..bd795368205fc --- /dev/null +++ b/src/test/ui/half-open-range-patterns/pat-tuple-4.rs @@ -0,0 +1,13 @@ +// check-pass + +#![feature(half_open_range_patterns)] +#![feature(exclusive_range_pattern)] + +fn main() { + const PAT: u8 = 1; + + match 0 { + (.. PAT) => {} + _ => {} + } +} diff --git a/src/test/ui/half-open-range-patterns/pat-tuple-5.rs b/src/test/ui/half-open-range-patterns/pat-tuple-5.rs new file mode 100644 index 0000000000000..613d907cfe329 --- /dev/null +++ b/src/test/ui/half-open-range-patterns/pat-tuple-5.rs @@ -0,0 +1,10 @@ +#![feature(half_open_range_patterns)] +#![feature(exclusive_range_pattern)] + +fn main() { + const PAT: u8 = 1; + + match (0, 1) { + (PAT ..) => {} //~ ERROR mismatched types + } +} diff --git a/src/test/ui/half-open-range-patterns/pat-tuple-5.stderr b/src/test/ui/half-open-range-patterns/pat-tuple-5.stderr new file mode 100644 index 0000000000000..307ad711b74d9 --- /dev/null +++ b/src/test/ui/half-open-range-patterns/pat-tuple-5.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/pat-tuple-5.rs:8:10 + | +LL | match (0, 1) { + | ------ this expression has type `({integer}, {integer})` +LL | (PAT ..) => {} + | ^^^ expected tuple, found `u8` + | + = note: expected tuple `({integer}, {integer})` + found type `u8` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/issues/issue-41255.rs b/src/test/ui/issues/issue-41255.rs index 478e13bb177f6..5b95a73791355 100644 --- a/src/test/ui/issues/issue-41255.rs +++ b/src/test/ui/issues/issue-41255.rs @@ -1,6 +1,7 @@ // Matching against float literals should result in a linter error #![feature(exclusive_range_pattern)] +#![feature(half_open_range_patterns)] #![allow(unused)] #![forbid(illegal_floating_point_literal_pattern)] @@ -35,6 +36,22 @@ fn main() { //~| WARNING hard error //~| WARNING hard error //~| WARNING hard error + + ..71.0 => {} + //~^ ERROR floating-point types cannot be used in patterns + //~| ERROR floating-point types cannot be used in patterns + //~| WARNING hard error + //~| WARNING this was previously accepted by the compiler + ..=72.0 => {} + //~^ ERROR floating-point types cannot be used in patterns + //~| ERROR floating-point types cannot be used in patterns + //~| WARNING hard error + //~| WARNING this was previously accepted by the compiler + 71.0.. => {} + //~^ ERROR floating-point types cannot be used in patterns + //~| ERROR floating-point types cannot be used in patterns + //~| WARNING hard error + //~| WARNING this was previously accepted by the compiler _ => {}, }; let y = 5.0; diff --git a/src/test/ui/issues/issue-41255.stderr b/src/test/ui/issues/issue-41255.stderr index 4f24456c169b8..1ff58153c8864 100644 --- a/src/test/ui/issues/issue-41255.stderr +++ b/src/test/ui/issues/issue-41255.stderr @@ -1,11 +1,11 @@ error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:10:9 + --> $DIR/issue-41255.rs:11:9 | LL | 5.0 => {}, | ^^^ | note: lint level defined here - --> $DIR/issue-41255.rs:5:11 + --> $DIR/issue-41255.rs:6:11 | LL | #![forbid(illegal_floating_point_literal_pattern)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL | #![forbid(illegal_floating_point_literal_pattern)] = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:14:9 + --> $DIR/issue-41255.rs:15:9 | LL | 5.0f32 => {}, | ^^^^^^ @@ -22,7 +22,7 @@ LL | 5.0f32 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:18:10 + --> $DIR/issue-41255.rs:19:10 | LL | -5.0 => {}, | ^^^ @@ -31,7 +31,7 @@ LL | -5.0 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:22:9 + --> $DIR/issue-41255.rs:23:9 | LL | 1.0 .. 33.0 => {}, | ^^^ @@ -40,7 +40,7 @@ LL | 1.0 .. 33.0 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:22:16 + --> $DIR/issue-41255.rs:23:16 | LL | 1.0 .. 33.0 => {}, | ^^^^ @@ -49,7 +49,7 @@ LL | 1.0 .. 33.0 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:30:9 + --> $DIR/issue-41255.rs:31:9 | LL | 39.0 ..= 70.0 => {}, | ^^^^ @@ -58,7 +58,7 @@ LL | 39.0 ..= 70.0 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:30:18 + --> $DIR/issue-41255.rs:31:18 | LL | 39.0 ..= 70.0 => {}, | ^^^^ @@ -67,7 +67,34 @@ LL | 39.0 ..= 70.0 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:43:10 + --> $DIR/issue-41255.rs:40:11 + | +LL | ..71.0 => {} + | ^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #41620 + +error: floating-point types cannot be used in patterns + --> $DIR/issue-41255.rs:45:12 + | +LL | ..=72.0 => {} + | ^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #41620 + +error: floating-point types cannot be used in patterns + --> $DIR/issue-41255.rs:50:9 + | +LL | 71.0.. => {} + | ^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #41620 + +error: floating-point types cannot be used in patterns + --> $DIR/issue-41255.rs:60:10 | LL | (3.14, 1) => {}, | ^^^^ @@ -76,7 +103,7 @@ LL | (3.14, 1) => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:52:18 + --> $DIR/issue-41255.rs:69:18 | LL | Foo { x: 2.0 } => {}, | ^^^ @@ -85,7 +112,7 @@ LL | Foo { x: 2.0 } => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:10:9 + --> $DIR/issue-41255.rs:11:9 | LL | 5.0 => {}, | ^^^ @@ -94,7 +121,7 @@ LL | 5.0 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:14:9 + --> $DIR/issue-41255.rs:15:9 | LL | 5.0f32 => {}, | ^^^^^^ @@ -103,7 +130,7 @@ LL | 5.0f32 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:18:10 + --> $DIR/issue-41255.rs:19:10 | LL | -5.0 => {}, | ^^^ @@ -112,7 +139,7 @@ LL | -5.0 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:22:9 + --> $DIR/issue-41255.rs:23:9 | LL | 1.0 .. 33.0 => {}, | ^^^ @@ -121,7 +148,7 @@ LL | 1.0 .. 33.0 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:22:16 + --> $DIR/issue-41255.rs:23:16 | LL | 1.0 .. 33.0 => {}, | ^^^^ @@ -130,7 +157,7 @@ LL | 1.0 .. 33.0 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:30:9 + --> $DIR/issue-41255.rs:31:9 | LL | 39.0 ..= 70.0 => {}, | ^^^^ @@ -139,7 +166,7 @@ LL | 39.0 ..= 70.0 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:30:18 + --> $DIR/issue-41255.rs:31:18 | LL | 39.0 ..= 70.0 => {}, | ^^^^ @@ -148,7 +175,34 @@ LL | 39.0 ..= 70.0 => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:43:10 + --> $DIR/issue-41255.rs:40:11 + | +LL | ..71.0 => {} + | ^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #41620 + +error: floating-point types cannot be used in patterns + --> $DIR/issue-41255.rs:45:12 + | +LL | ..=72.0 => {} + | ^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #41620 + +error: floating-point types cannot be used in patterns + --> $DIR/issue-41255.rs:50:9 + | +LL | 71.0.. => {} + | ^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #41620 + +error: floating-point types cannot be used in patterns + --> $DIR/issue-41255.rs:60:10 | LL | (3.14, 1) => {}, | ^^^^ @@ -157,7 +211,7 @@ LL | (3.14, 1) => {}, = note: for more information, see issue #41620 error: floating-point types cannot be used in patterns - --> $DIR/issue-41255.rs:52:18 + --> $DIR/issue-41255.rs:69:18 | LL | Foo { x: 2.0 } => {}, | ^^^ @@ -165,5 +219,5 @@ LL | Foo { x: 2.0 } => {}, = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #41620 -error: aborting due to 18 previous errors +error: aborting due to 24 previous errors diff --git a/src/test/ui/parser/attr-stmt-expr-attr-bad.rs b/src/test/ui/parser/attr-stmt-expr-attr-bad.rs index f6d2bee0e1560..118bff8144c7f 100644 --- a/src/test/ui/parser/attr-stmt-expr-attr-bad.rs +++ b/src/test/ui/parser/attr-stmt-expr-attr-bad.rs @@ -1,3 +1,5 @@ +#![feature(half_open_range_patterns)] + fn main() {} #[cfg(FALSE)] fn e() { let _ = box #![attr] 0; } @@ -90,15 +92,15 @@ fn main() {} // note: requires parens in patterns to allow disambiguation #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] 10 => () } } -//~^ ERROR `X..=` range patterns are not supported +//~^ ERROR inclusive range with no end //~| ERROR expected one of `=>`, `if`, or `|`, found `#` #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] -10 => () } } -//~^ ERROR `X..=` range patterns are not supported +//~^ ERROR inclusive range with no end //~| ERROR expected one of `=>`, `if`, or `|`, found `#` #[cfg(FALSE)] fn e() { match 0 { 0..=-#[attr] 10 => () } } //~^ ERROR unexpected token: `#` #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] FOO => () } } -//~^ ERROR `X..=` range patterns are not supported +//~^ ERROR inclusive range with no end //~| ERROR expected one of `=>`, `if`, or `|`, found `#` #[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); } diff --git a/src/test/ui/parser/attr-stmt-expr-attr-bad.stderr b/src/test/ui/parser/attr-stmt-expr-attr-bad.stderr index 0123006418a3a..654b49ab62022 100644 --- a/src/test/ui/parser/attr-stmt-expr-attr-bad.stderr +++ b/src/test/ui/parser/attr-stmt-expr-attr-bad.stderr @@ -1,5 +1,5 @@ error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:3:36 + --> $DIR/attr-stmt-expr-attr-bad.rs:5:36 | LL | #[cfg(FALSE)] fn e() { let _ = box #![attr] 0; } | ^^^^^^^^ @@ -7,19 +7,19 @@ LL | #[cfg(FALSE)] fn e() { let _ = box #![attr] 0; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: expected expression, found `]` - --> $DIR/attr-stmt-expr-attr-bad.rs:5:40 + --> $DIR/attr-stmt-expr-attr-bad.rs:7:40 | LL | #[cfg(FALSE)] fn e() { let _ = [#[attr]]; } | ^ expected expression error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, or an operator, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:7:35 + --> $DIR/attr-stmt-expr-attr-bad.rs:9:35 | LL | #[cfg(FALSE)] fn e() { let _ = foo#[attr](); } | ^ expected one of 7 possible tokens error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:9:36 + --> $DIR/attr-stmt-expr-attr-bad.rs:11:36 | LL | #[cfg(FALSE)] fn e() { let _ = foo(#![attr]); } | ^^^^^^^^ @@ -27,13 +27,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = foo(#![attr]); } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: expected expression, found `)` - --> $DIR/attr-stmt-expr-attr-bad.rs:9:44 + --> $DIR/attr-stmt-expr-attr-bad.rs:11:44 | LL | #[cfg(FALSE)] fn e() { let _ = foo(#![attr]); } | ^ expected expression error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:12:38 + --> $DIR/attr-stmt-expr-attr-bad.rs:14:38 | LL | #[cfg(FALSE)] fn e() { let _ = x.foo(#![attr]); } | ^^^^^^^^ @@ -41,13 +41,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = x.foo(#![attr]); } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: expected expression, found `)` - --> $DIR/attr-stmt-expr-attr-bad.rs:12:46 + --> $DIR/attr-stmt-expr-attr-bad.rs:14:46 | LL | #[cfg(FALSE)] fn e() { let _ = x.foo(#![attr]); } | ^ expected expression error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:15:36 + --> $DIR/attr-stmt-expr-attr-bad.rs:17:36 | LL | #[cfg(FALSE)] fn e() { let _ = 0 + #![attr] 0; } | ^^^^^^^^ @@ -55,7 +55,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = 0 + #![attr] 0; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:17:33 + --> $DIR/attr-stmt-expr-attr-bad.rs:19:33 | LL | #[cfg(FALSE)] fn e() { let _ = !#![attr] 0; } | ^^^^^^^^ @@ -63,7 +63,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = !#![attr] 0; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:19:33 + --> $DIR/attr-stmt-expr-attr-bad.rs:21:33 | LL | #[cfg(FALSE)] fn e() { let _ = -#![attr] 0; } | ^^^^^^^^ @@ -71,13 +71,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = -#![attr] 0; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, or an operator, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:21:34 + --> $DIR/attr-stmt-expr-attr-bad.rs:23:34 | LL | #[cfg(FALSE)] fn e() { let _ = x #![attr] as Y; } | ^ expected one of 7 possible tokens error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:23:35 + --> $DIR/attr-stmt-expr-attr-bad.rs:25:35 | LL | #[cfg(FALSE)] fn e() { let _ = || #![attr] foo; } | ^^^^^^^^ @@ -85,7 +85,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = || #![attr] foo; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:25:40 + --> $DIR/attr-stmt-expr-attr-bad.rs:27:40 | LL | #[cfg(FALSE)] fn e() { let _ = move || #![attr] foo; } | ^^^^^^^^ @@ -93,7 +93,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = move || #![attr] foo; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:27:35 + --> $DIR/attr-stmt-expr-attr-bad.rs:29:35 | LL | #[cfg(FALSE)] fn e() { let _ = || #![attr] {foo}; } | ^^^^^^^^ @@ -101,7 +101,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = || #![attr] {foo}; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:29:40 + --> $DIR/attr-stmt-expr-attr-bad.rs:31:40 | LL | #[cfg(FALSE)] fn e() { let _ = move || #![attr] {foo}; } | ^^^^^^^^ @@ -109,19 +109,19 @@ LL | #[cfg(FALSE)] fn e() { let _ = move || #![attr] {foo}; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: expected expression, found `..` - --> $DIR/attr-stmt-expr-attr-bad.rs:31:40 + --> $DIR/attr-stmt-expr-attr-bad.rs:33:40 | LL | #[cfg(FALSE)] fn e() { let _ = #[attr] ..#[attr] 0; } | ^^ expected expression error: expected expression, found `..` - --> $DIR/attr-stmt-expr-attr-bad.rs:33:40 + --> $DIR/attr-stmt-expr-attr-bad.rs:35:40 | LL | #[cfg(FALSE)] fn e() { let _ = #[attr] ..; } | ^^ expected expression error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:35:41 + --> $DIR/attr-stmt-expr-attr-bad.rs:37:41 | LL | #[cfg(FALSE)] fn e() { let _ = #[attr] &#![attr] 0; } | ^^^^^^^^ @@ -129,7 +129,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = #[attr] &#![attr] 0; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:37:45 + --> $DIR/attr-stmt-expr-attr-bad.rs:39:45 | LL | #[cfg(FALSE)] fn e() { let _ = #[attr] &mut #![attr] 0; } | ^^^^^^^^ @@ -137,13 +137,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = #[attr] &mut #![attr] 0; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: attributes are not yet allowed on `if` expressions - --> $DIR/attr-stmt-expr-attr-bad.rs:39:32 + --> $DIR/attr-stmt-expr-attr-bad.rs:41:32 | LL | #[cfg(FALSE)] fn e() { let _ = #[attr] if 0 {}; } | ^^^^^^^ error: expected `{`, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:41:37 + --> $DIR/attr-stmt-expr-attr-bad.rs:43:37 | LL | #[cfg(FALSE)] fn e() { let _ = if 0 #[attr] {}; } | -- ^ --- help: try placing this code inside a block: `{ {}; }` @@ -152,7 +152,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 #[attr] {}; } | this `if` expression has a condition, but no block error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:43:38 + --> $DIR/attr-stmt-expr-attr-bad.rs:45:38 | LL | #[cfg(FALSE)] fn e() { let _ = if 0 {#![attr]}; } | ^^^^^^^^ @@ -160,13 +160,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 {#![attr]}; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: expected one of `.`, `;`, `?`, `else`, or an operator, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:45:40 + --> $DIR/attr-stmt-expr-attr-bad.rs:47:40 | LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} #[attr] else {}; } | ^ expected one of `.`, `;`, `?`, `else`, or an operator error: expected `{`, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:47:45 + --> $DIR/attr-stmt-expr-attr-bad.rs:49:45 | LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else #[attr] {}; } | ^ --- help: try placing this code inside a block: `{ {}; }` @@ -174,7 +174,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else #[attr] {}; } | expected `{` error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:49:46 + --> $DIR/attr-stmt-expr-attr-bad.rs:51:46 | LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else {#![attr]}; } | ^^^^^^^^ @@ -182,13 +182,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else {#![attr]}; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: attributes are not yet allowed on `if` expressions - --> $DIR/attr-stmt-expr-attr-bad.rs:51:45 + --> $DIR/attr-stmt-expr-attr-bad.rs:53:45 | LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else #[attr] if 0 {}; } | ^^^^^^^ error: expected `{`, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:51:45 + --> $DIR/attr-stmt-expr-attr-bad.rs:53:45 | LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else #[attr] if 0 {}; } | ^ -------- help: try placing this code inside a block: `{ if 0 {}; }` @@ -196,7 +196,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else #[attr] if 0 {}; } | expected `{` error: expected `{`, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:54:50 + --> $DIR/attr-stmt-expr-attr-bad.rs:56:50 | LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else if 0 #[attr] {}; } | -- ^ --- help: try placing this code inside a block: `{ {}; }` @@ -205,7 +205,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else if 0 #[attr] {}; } | this `if` expression has a condition, but no block error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:56:51 + --> $DIR/attr-stmt-expr-attr-bad.rs:58:51 | LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else if 0 {#![attr]}; } | ^^^^^^^^ @@ -213,13 +213,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else if 0 {#![attr]}; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: attributes are not yet allowed on `if` expressions - --> $DIR/attr-stmt-expr-attr-bad.rs:58:32 + --> $DIR/attr-stmt-expr-attr-bad.rs:60:32 | LL | #[cfg(FALSE)] fn e() { let _ = #[attr] if let _ = 0 {}; } | ^^^^^^^ error: expected `{`, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:60:45 + --> $DIR/attr-stmt-expr-attr-bad.rs:62:45 | LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 #[attr] {}; } | -- ^ --- help: try placing this code inside a block: `{ {}; }` @@ -228,7 +228,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 #[attr] {}; } | this `if` expression has a condition, but no block error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:62:46 + --> $DIR/attr-stmt-expr-attr-bad.rs:64:46 | LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {#![attr]}; } | ^^^^^^^^ @@ -236,13 +236,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {#![attr]}; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: expected one of `.`, `;`, `?`, `else`, or an operator, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:64:48 + --> $DIR/attr-stmt-expr-attr-bad.rs:66:48 | LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} #[attr] else {}; } | ^ expected one of `.`, `;`, `?`, `else`, or an operator error: expected `{`, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:66:53 + --> $DIR/attr-stmt-expr-attr-bad.rs:68:53 | LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else #[attr] {}; } | ^ --- help: try placing this code inside a block: `{ {}; }` @@ -250,7 +250,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else #[attr] {}; } | expected `{` error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:68:54 + --> $DIR/attr-stmt-expr-attr-bad.rs:70:54 | LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else {#![attr]}; } | ^^^^^^^^ @@ -258,13 +258,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else {#![attr]}; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: attributes are not yet allowed on `if` expressions - --> $DIR/attr-stmt-expr-attr-bad.rs:70:53 + --> $DIR/attr-stmt-expr-attr-bad.rs:72:53 | LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else #[attr] if let _ = 0 {}; } | ^^^^^^^ error: expected `{`, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:70:53 + --> $DIR/attr-stmt-expr-attr-bad.rs:72:53 | LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else #[attr] if let _ = 0 {}; } | ^ ---------------- help: try placing this code inside a block: `{ if let _ = 0 {}; }` @@ -272,7 +272,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else #[attr] if let _ = 0 {} | expected `{` error: expected `{`, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:73:66 + --> $DIR/attr-stmt-expr-attr-bad.rs:75:66 | LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else if let _ = 0 #[attr] {}; } | -- ^ --- help: try placing this code inside a block: `{ {}; }` @@ -281,7 +281,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else if let _ = 0 #[attr] {} | this `if` expression has a condition, but no block error: an inner attribute is not permitted in this context - --> $DIR/attr-stmt-expr-attr-bad.rs:75:67 + --> $DIR/attr-stmt-expr-attr-bad.rs:77:67 | LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else if let _ = 0 {#![attr]}; } | ^^^^^^^^ @@ -289,7 +289,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else if let _ = 0 {#![attr]} = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: an inner attribute is not permitted following an outer attribute - --> $DIR/attr-stmt-expr-attr-bad.rs:78:32 + --> $DIR/attr-stmt-expr-attr-bad.rs:80:32 | LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] let _ = 0; } | ------- ^^^^^^^^ not permitted following an outer attibute @@ -299,7 +299,7 @@ LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] let _ = 0; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: an inner attribute is not permitted following an outer attribute - --> $DIR/attr-stmt-expr-attr-bad.rs:80:32 + --> $DIR/attr-stmt-expr-attr-bad.rs:82:32 | LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] 0; } | ------- ^^^^^^^^ not permitted following an outer attibute @@ -309,7 +309,7 @@ LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] 0; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: an inner attribute is not permitted following an outer attribute - --> $DIR/attr-stmt-expr-attr-bad.rs:82:32 + --> $DIR/attr-stmt-expr-attr-bad.rs:84:32 | LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] foo!(); } | ------- ^^^^^^^^ not permitted following an outer attibute @@ -319,7 +319,7 @@ LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] foo!(); } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: an inner attribute is not permitted following an outer attribute - --> $DIR/attr-stmt-expr-attr-bad.rs:84:32 + --> $DIR/attr-stmt-expr-attr-bad.rs:86:32 | LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] foo![]; } | ------- ^^^^^^^^ not permitted following an outer attibute @@ -329,7 +329,7 @@ LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] foo![]; } = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. error: an inner attribute is not permitted following an outer attribute - --> $DIR/attr-stmt-expr-attr-bad.rs:86:32 + --> $DIR/attr-stmt-expr-attr-bad.rs:88:32 | LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] foo!{}; } | ------- ^^^^^^^^ not permitted following an outer attibute @@ -338,83 +338,90 @@ LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] foo!{}; } | = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them. -error: `X..=` range patterns are not supported - --> $DIR/attr-stmt-expr-attr-bad.rs:92:34 +error[E0586]: inclusive range with no end + --> $DIR/attr-stmt-expr-attr-bad.rs:94:35 | LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] 10 => () } } - | ^^^^ help: try using the maximum value for the type: `0..=MAX` + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) error: expected one of `=>`, `if`, or `|`, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:92:38 + --> $DIR/attr-stmt-expr-attr-bad.rs:94:38 | LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] 10 => () } } | ^ expected one of `=>`, `if`, or `|` -error: `X..=` range patterns are not supported - --> $DIR/attr-stmt-expr-attr-bad.rs:95:34 +error[E0586]: inclusive range with no end + --> $DIR/attr-stmt-expr-attr-bad.rs:97:35 | LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] -10 => () } } - | ^^^^ help: try using the maximum value for the type: `0..=MAX` + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) error: expected one of `=>`, `if`, or `|`, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:95:38 + --> $DIR/attr-stmt-expr-attr-bad.rs:97:38 | LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] -10 => () } } | ^ expected one of `=>`, `if`, or `|` error: unexpected token: `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:98:39 + --> $DIR/attr-stmt-expr-attr-bad.rs:100:39 | LL | #[cfg(FALSE)] fn e() { match 0 { 0..=-#[attr] 10 => () } } | ^ -error: `X..=` range patterns are not supported - --> $DIR/attr-stmt-expr-attr-bad.rs:100:34 +error[E0586]: inclusive range with no end + --> $DIR/attr-stmt-expr-attr-bad.rs:102:35 | LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] FOO => () } } - | ^^^^ help: try using the maximum value for the type: `0..=MAX` + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) error: expected one of `=>`, `if`, or `|`, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:100:38 + --> $DIR/attr-stmt-expr-attr-bad.rs:102:38 | LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] FOO => () } } | ^ expected one of `=>`, `if`, or `|` error: unexpected token: `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:104:34 + --> $DIR/attr-stmt-expr-attr-bad.rs:106:34 | LL | #[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); } | ^ error: expected one of `.`, `;`, `?`, or an operator, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:104:34 + --> $DIR/attr-stmt-expr-attr-bad.rs:106:34 | LL | #[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); } | ^ expected one of `.`, `;`, `?`, or an operator error: unexpected token: `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:107:34 + --> $DIR/attr-stmt-expr-attr-bad.rs:109:34 | LL | #[cfg(FALSE)] fn e() { let _ = x.#[attr]foo(); } | ^ error: expected one of `.`, `;`, `?`, or an operator, found `#` - --> $DIR/attr-stmt-expr-attr-bad.rs:107:34 + --> $DIR/attr-stmt-expr-attr-bad.rs:109:34 | LL | #[cfg(FALSE)] fn e() { let _ = x.#[attr]foo(); } | ^ expected one of `.`, `;`, `?`, or an operator error: expected statement after outer attribute - --> $DIR/attr-stmt-expr-attr-bad.rs:112:44 + --> $DIR/attr-stmt-expr-attr-bad.rs:114:44 | LL | #[cfg(FALSE)] fn e() { { fn foo() { #[attr]; } } } | ^ error: expected statement after outer attribute - --> $DIR/attr-stmt-expr-attr-bad.rs:114:45 + --> $DIR/attr-stmt-expr-attr-bad.rs:116:45 | LL | #[cfg(FALSE)] fn e() { { fn foo() { #[attr] } } } | ^ error: aborting due to 57 previous errors +For more information about this error, try `rustc --explain E0586`. diff --git a/src/test/ui/parser/issue-63115-range-pat-interpolated.rs b/src/test/ui/parser/issue-63115-range-pat-interpolated.rs index a7d10ca9320a6..8efb3c73f034f 100644 --- a/src/test/ui/parser/issue-63115-range-pat-interpolated.rs +++ b/src/test/ui/parser/issue-63115-range-pat-interpolated.rs @@ -1,6 +1,7 @@ // check-pass #![feature(exclusive_range_pattern)] +#![feature(half_open_range_patterns)] #![allow(ellipsis_inclusive_range_patterns)] @@ -10,6 +11,11 @@ fn main() { if let 2...$e = 3 {} if let 2..=$e = 3 {} if let 2..$e = 3 {} + if let ..$e = 3 {} + if let ..=$e = 3 {} + if let $e.. = 5 {} + if let $e..5 = 4 {} + if let $e..=5 = 4 {} } } mac_expr!(4); diff --git a/src/test/ui/parser/issue-66357-unexpected-unreachable.rs b/src/test/ui/parser/issue-66357-unexpected-unreachable.rs index 1730adfa91419..5ec143fae2344 100644 --- a/src/test/ui/parser/issue-66357-unexpected-unreachable.rs +++ b/src/test/ui/parser/issue-66357-unexpected-unreachable.rs @@ -1,3 +1,5 @@ +// ignore-tidy-linelength + // The problem in #66357 was that the call trace: // // - parse_fn_block_decl @@ -11,4 +13,4 @@ fn f() { |[](* } //~^ ERROR expected one of `,` or `:`, found `(` -//~| ERROR expected one of `)`, `-`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*` +//~| ERROR expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*` diff --git a/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr b/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr index 00d84e2afe353..c3810999d2395 100644 --- a/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr +++ b/src/test/ui/parser/issue-66357-unexpected-unreachable.stderr @@ -1,11 +1,11 @@ error: expected one of `,` or `:`, found `(` - --> $DIR/issue-66357-unexpected-unreachable.rs:12:13 + --> $DIR/issue-66357-unexpected-unreachable.rs:14:13 | LL | fn f() { |[](* } | ^ expected one of `,` or `:` -error: expected one of `)`, `-`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*` - --> $DIR/issue-66357-unexpected-unreachable.rs:12:14 +error: expected one of `&`, `(`, `)`, `-`, `...`, `..=`, `..`, `[`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*` + --> $DIR/issue-66357-unexpected-unreachable.rs:14:14 | LL | fn f() { |[](* } | -^ help: `)` may belong here diff --git a/src/test/ui/parser/pat-tuple-4.rs b/src/test/ui/parser/pat-tuple-4.rs deleted file mode 100644 index 2f03160430a22..0000000000000 --- a/src/test/ui/parser/pat-tuple-4.rs +++ /dev/null @@ -1,11 +0,0 @@ -fn main() { - const PAT: u8 = 0; - - match 0 { - (.. PAT) => {} - //~^ ERROR `..X` range patterns are not supported - //~| ERROR exclusive range pattern syntax is experimental - } -} - -const RECOVERY_WITNESS: () = 0; //~ ERROR mismatched types diff --git a/src/test/ui/parser/pat-tuple-4.stderr b/src/test/ui/parser/pat-tuple-4.stderr deleted file mode 100644 index 6c64290e144c2..0000000000000 --- a/src/test/ui/parser/pat-tuple-4.stderr +++ /dev/null @@ -1,25 +0,0 @@ -error: `..X` range patterns are not supported - --> $DIR/pat-tuple-4.rs:5:10 - | -LL | (.. PAT) => {} - | ^^^^^^ help: try using the minimum value for the type: `MIN..PAT` - -error[E0658]: exclusive range pattern syntax is experimental - --> $DIR/pat-tuple-4.rs:5:10 - | -LL | (.. PAT) => {} - | ^^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/37854 - = help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable - -error[E0308]: mismatched types - --> $DIR/pat-tuple-4.rs:11:30 - | -LL | const RECOVERY_WITNESS: () = 0; - | ^ expected `()`, found integer - -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0308, E0658. -For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/parser/pat-tuple-5.rs b/src/test/ui/parser/pat-tuple-5.rs deleted file mode 100644 index 5334ef93bb3bd..0000000000000 --- a/src/test/ui/parser/pat-tuple-5.rs +++ /dev/null @@ -1,10 +0,0 @@ -fn main() { - const PAT: u8 = 0; - - match (0, 1) { - (PAT ..) => {} - //~^ ERROR `X..` range patterns are not supported - //~| ERROR exclusive range pattern syntax is experimental - //~| ERROR mismatched types - } -} diff --git a/src/test/ui/parser/pat-tuple-5.stderr b/src/test/ui/parser/pat-tuple-5.stderr deleted file mode 100644 index 8ff4f948a05ec..0000000000000 --- a/src/test/ui/parser/pat-tuple-5.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error: `X..` range patterns are not supported - --> $DIR/pat-tuple-5.rs:5:10 - | -LL | (PAT ..) => {} - | ^^^^^^ help: try using the maximum value for the type: `PAT..MAX` - -error[E0658]: exclusive range pattern syntax is experimental - --> $DIR/pat-tuple-5.rs:5:10 - | -LL | (PAT ..) => {} - | ^^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/37854 - = help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable - -error[E0308]: mismatched types - --> $DIR/pat-tuple-5.rs:5:10 - | -LL | match (0, 1) { - | ------ this expression has type `({integer}, {integer})` -LL | (PAT ..) => {} - | ^^^ expected tuple, found `u8` - | - = note: expected tuple `({integer}, {integer})` - found type `u8` - -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0308, E0658. -For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/parser/recover-range-pats.rs b/src/test/ui/parser/recover-range-pats.rs index 260e108315973..a5aae2861b282 100644 --- a/src/test/ui/parser/recover-range-pats.rs +++ b/src/test/ui/parser/recover-range-pats.rs @@ -4,6 +4,7 @@ // 2. Or at least we have parser recovery if they don't. #![feature(exclusive_range_pattern)] +#![feature(half_open_range_patterns)] #![deny(ellipsis_inclusive_range_patterns)] fn main() {} @@ -55,68 +56,64 @@ fn inclusive2_from_to() { } fn exclusive_from() { - if let 0.. = 0 {} //~ ERROR `X..` range patterns are not supported - if let X.. = 0 {} //~ ERROR `X..` range patterns are not supported - if let true.. = 0 {} //~ ERROR `X..` range patterns are not supported + if let 0.. = 0 {} + if let X.. = 0 {} + if let true.. = 0 {} //~^ ERROR only char and numeric types - if let .0.. = 0 {} //~ ERROR `X..` range patterns are not supported + if let .0.. = 0 {} //~^ ERROR float literals must have an integer part //~| ERROR mismatched types } fn inclusive_from() { - if let 0..= = 0 {} //~ ERROR `X..=` range patterns are not supported - if let X..= = 0 {} //~ ERROR `X..=` range patterns are not supported - if let true..= = 0 {} //~ ERROR `X..=` range patterns are not supported + if let 0..= = 0 {} //~ ERROR inclusive range with no end + if let X..= = 0 {} //~ ERROR inclusive range with no end + if let true..= = 0 {} //~ ERROR inclusive range with no end //~| ERROR only char and numeric types - if let .0..= = 0 {} //~ ERROR `X..=` range patterns are not supported + if let .0..= = 0 {} //~ ERROR inclusive range with no end //~^ ERROR float literals must have an integer part //~| ERROR mismatched types } fn inclusive2_from() { - if let 0... = 0 {} //~ ERROR `X...` range patterns are not supported - //~^ ERROR `...` range patterns are deprecated - if let X... = 0 {} //~ ERROR `X...` range patterns are not supported - //~^ ERROR `...` range patterns are deprecated - if let true... = 0 {} //~ ERROR `X...` range patterns are not supported - //~^ ERROR `...` range patterns are deprecated + if let 0... = 0 {} //~ ERROR inclusive range with no end + if let X... = 0 {} //~ ERROR inclusive range with no end + if let true... = 0 {} //~ ERROR inclusive range with no end //~| ERROR only char and numeric types - if let .0... = 0 {} //~ ERROR `X...` range patterns are not supported + if let .0... = 0 {} //~ ERROR inclusive range with no end //~^ ERROR float literals must have an integer part - //~| ERROR `...` range patterns are deprecated //~| ERROR mismatched types } fn exclusive_to() { - if let ..0 = 0 {} //~ ERROR `..X` range patterns are not supported - if let ..Y = 0 {} //~ ERROR `..X` range patterns are not supported - if let ..true = 0 {} //~ ERROR `..X` range patterns are not supported - //~| ERROR only char and numeric types - if let .. .0 = 0 {} //~ ERROR `..X` range patterns are not supported + if let ..0 = 0 {} + if let ..Y = 0 {} + if let ..true = 0 {} + //~^ ERROR only char and numeric types + if let .. .0 = 0 {} //~^ ERROR float literals must have an integer part //~| ERROR mismatched types } fn inclusive_to() { - if let ..=3 = 0 {} //~ ERROR `..=X` range patterns are not supported - if let ..=Y = 0 {} //~ ERROR `..=X` range patterns are not supported - if let ..=true = 0 {} //~ ERROR `..=X` range patterns are not supported - //~| ERROR only char and numeric types - if let ..=.0 = 0 {} //~ ERROR `..=X` range patterns are not supported + if let ..=3 = 0 {} + if let ..=Y = 0 {} + if let ..=true = 0 {} + //~^ ERROR only char and numeric types + if let ..=.0 = 0 {} //~^ ERROR float literals must have an integer part //~| ERROR mismatched types } fn inclusive2_to() { - if let ...3 = 0 {} //~ ERROR `...X` range patterns are not supported + if let ...3 = 0 {} //~^ ERROR `...` range patterns are deprecated - if let ...Y = 0 {} //~ ERROR `...X` range patterns are not supported + if let ...Y = 0 {} //~^ ERROR `...` range patterns are deprecated - if let ...true = 0 {} //~ ERROR `...X` range patterns are not supported + if let ...true = 0 {} //~^ ERROR `...` range patterns are deprecated //~| ERROR only char and numeric types - if let ....3 = 0 {} //~ ERROR `...X` range patterns are not supported + if let ....3 = 0 {} //~^ ERROR float literals must have an integer part //~| ERROR `...` range patterns are deprecated //~| ERROR mismatched types @@ -136,14 +133,13 @@ fn with_macro_expr_var() { macro_rules! mac { ($e:expr) => { - let ..$e; //~ ERROR `..X` range patterns are not supported - let ...$e; //~ ERROR `...X` range patterns are not supported - //~^ ERROR `...` range patterns are deprecated - let ..=$e; //~ ERROR `..=X` range patterns are not supported - let $e..; //~ ERROR `X..` range patterns are not supported - let $e...; //~ ERROR `X...` range patterns are not supported + let ..$e; + let ...$e; //~^ ERROR `...` range patterns are deprecated - let $e..=; //~ ERROR `X..=` range patterns are not supported + let ..=$e; + let $e..; + let $e...; //~ ERROR inclusive range with no end + let $e..=; //~ ERROR inclusive range with no end } } diff --git a/src/test/ui/parser/recover-range-pats.stderr b/src/test/ui/parser/recover-range-pats.stderr index 3fed64c191a8a..d3d3169022a65 100644 --- a/src/test/ui/parser/recover-range-pats.stderr +++ b/src/test/ui/parser/recover-range-pats.stderr @@ -1,377 +1,241 @@ error: float literals must have an integer part - --> $DIR/recover-range-pats.rs:21:12 + --> $DIR/recover-range-pats.rs:22:12 | LL | if let .0..Y = 0 {} | ^^ help: must have an integer part: `0.0` error: float literals must have an integer part - --> $DIR/recover-range-pats.rs:23:16 + --> $DIR/recover-range-pats.rs:24:16 | LL | if let X.. .0 = 0 {} | ^^ help: must have an integer part: `0.0` error: float literals must have an integer part - --> $DIR/recover-range-pats.rs:34:12 + --> $DIR/recover-range-pats.rs:35:12 | LL | if let .0..=Y = 0 {} | ^^ help: must have an integer part: `0.0` error: float literals must have an integer part - --> $DIR/recover-range-pats.rs:36:16 + --> $DIR/recover-range-pats.rs:37:16 | LL | if let X..=.0 = 0 {} | ^^ help: must have an integer part: `0.0` error: float literals must have an integer part - --> $DIR/recover-range-pats.rs:49:12 + --> $DIR/recover-range-pats.rs:50:12 | LL | if let .0...Y = 0 {} | ^^ help: must have an integer part: `0.0` error: float literals must have an integer part - --> $DIR/recover-range-pats.rs:52:17 + --> $DIR/recover-range-pats.rs:53:17 | LL | if let X... .0 = 0 {} | ^^ help: must have an integer part: `0.0` -error: `X..` range patterns are not supported - --> $DIR/recover-range-pats.rs:58:12 - | -LL | if let 0.. = 0 {} - | ^^^ help: try using the maximum value for the type: `0..MAX` - -error: `X..` range patterns are not supported - --> $DIR/recover-range-pats.rs:59:12 - | -LL | if let X.. = 0 {} - | ^^^ help: try using the maximum value for the type: `X..MAX` - -error: `X..` range patterns are not supported - --> $DIR/recover-range-pats.rs:60:12 - | -LL | if let true.. = 0 {} - | ^^^^^^ help: try using the maximum value for the type: `true..MAX` - error: float literals must have an integer part - --> $DIR/recover-range-pats.rs:62:12 + --> $DIR/recover-range-pats.rs:63:12 | LL | if let .0.. = 0 {} | ^^ help: must have an integer part: `0.0` -error: `X..` range patterns are not supported - --> $DIR/recover-range-pats.rs:62:12 - | -LL | if let .0.. = 0 {} - | ^^^^ help: try using the maximum value for the type: `0.0..MAX` - -error: `X..=` range patterns are not supported - --> $DIR/recover-range-pats.rs:68:12 +error[E0586]: inclusive range with no end + --> $DIR/recover-range-pats.rs:69:13 | LL | if let 0..= = 0 {} - | ^^^^ help: try using the maximum value for the type: `0..=MAX` + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) -error: `X..=` range patterns are not supported - --> $DIR/recover-range-pats.rs:69:12 +error[E0586]: inclusive range with no end + --> $DIR/recover-range-pats.rs:70:13 | LL | if let X..= = 0 {} - | ^^^^ help: try using the maximum value for the type: `X..=MAX` + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) -error: `X..=` range patterns are not supported - --> $DIR/recover-range-pats.rs:70:12 +error[E0586]: inclusive range with no end + --> $DIR/recover-range-pats.rs:71:16 | LL | if let true..= = 0 {} - | ^^^^^^^ help: try using the maximum value for the type: `true..=MAX` + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) error: float literals must have an integer part - --> $DIR/recover-range-pats.rs:72:12 + --> $DIR/recover-range-pats.rs:73:12 | LL | if let .0..= = 0 {} | ^^ help: must have an integer part: `0.0` -error: `X..=` range patterns are not supported - --> $DIR/recover-range-pats.rs:72:12 +error[E0586]: inclusive range with no end + --> $DIR/recover-range-pats.rs:73:14 | LL | if let .0..= = 0 {} - | ^^^^^ help: try using the maximum value for the type: `0.0..=MAX` + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) -error: `X...` range patterns are not supported - --> $DIR/recover-range-pats.rs:78:12 +error[E0586]: inclusive range with no end + --> $DIR/recover-range-pats.rs:79:13 | LL | if let 0... = 0 {} - | ^^^^ help: try using the maximum value for the type: `0...MAX` + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) -error: `X...` range patterns are not supported - --> $DIR/recover-range-pats.rs:80:12 +error[E0586]: inclusive range with no end + --> $DIR/recover-range-pats.rs:80:13 | LL | if let X... = 0 {} - | ^^^^ help: try using the maximum value for the type: `X...MAX` + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) -error: `X...` range patterns are not supported - --> $DIR/recover-range-pats.rs:82:12 +error[E0586]: inclusive range with no end + --> $DIR/recover-range-pats.rs:81:16 | LL | if let true... = 0 {} - | ^^^^^^^ help: try using the maximum value for the type: `true...MAX` + | ^^^ + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) error: float literals must have an integer part - --> $DIR/recover-range-pats.rs:85:12 + --> $DIR/recover-range-pats.rs:83:12 | LL | if let .0... = 0 {} | ^^ help: must have an integer part: `0.0` -error: `X...` range patterns are not supported - --> $DIR/recover-range-pats.rs:85:12 +error[E0586]: inclusive range with no end + --> $DIR/recover-range-pats.rs:83:14 | LL | if let .0... = 0 {} - | ^^^^^ help: try using the maximum value for the type: `0.0...MAX` - -error: `..X` range patterns are not supported - --> $DIR/recover-range-pats.rs:92:12 - | -LL | if let ..0 = 0 {} - | ^^^ help: try using the minimum value for the type: `MIN..0` - -error: `..X` range patterns are not supported - --> $DIR/recover-range-pats.rs:93:12 + | ^^^ | -LL | if let ..Y = 0 {} - | ^^^ help: try using the minimum value for the type: `MIN..Y` - -error: `..X` range patterns are not supported - --> $DIR/recover-range-pats.rs:94:12 - | -LL | if let ..true = 0 {} - | ^^^^^^ help: try using the minimum value for the type: `MIN..true` + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) error: float literals must have an integer part - --> $DIR/recover-range-pats.rs:96:15 + --> $DIR/recover-range-pats.rs:93:15 | LL | if let .. .0 = 0 {} | ^^ help: must have an integer part: `0.0` -error: `..X` range patterns are not supported - --> $DIR/recover-range-pats.rs:96:12 - | -LL | if let .. .0 = 0 {} - | ^^^^^ help: try using the minimum value for the type: `MIN..0.0` - -error: `..=X` range patterns are not supported - --> $DIR/recover-range-pats.rs:102:12 - | -LL | if let ..=3 = 0 {} - | ^^^^ help: try using the minimum value for the type: `MIN..=3` - -error: `..=X` range patterns are not supported - --> $DIR/recover-range-pats.rs:103:12 - | -LL | if let ..=Y = 0 {} - | ^^^^ help: try using the minimum value for the type: `MIN..=Y` - -error: `..=X` range patterns are not supported - --> $DIR/recover-range-pats.rs:104:12 - | -LL | if let ..=true = 0 {} - | ^^^^^^^ help: try using the minimum value for the type: `MIN..=true` - error: float literals must have an integer part - --> $DIR/recover-range-pats.rs:106:15 + --> $DIR/recover-range-pats.rs:103:15 | LL | if let ..=.0 = 0 {} | ^^ help: must have an integer part: `0.0` -error: `..=X` range patterns are not supported - --> $DIR/recover-range-pats.rs:106:12 - | -LL | if let ..=.0 = 0 {} - | ^^^^^ help: try using the minimum value for the type: `MIN..=0.0` - -error: `...X` range patterns are not supported - --> $DIR/recover-range-pats.rs:112:12 - | -LL | if let ...3 = 0 {} - | ^^^^ help: try using the minimum value for the type: `MIN...3` - -error: `...X` range patterns are not supported - --> $DIR/recover-range-pats.rs:114:12 - | -LL | if let ...Y = 0 {} - | ^^^^ help: try using the minimum value for the type: `MIN...Y` - -error: `...X` range patterns are not supported - --> $DIR/recover-range-pats.rs:116:12 - | -LL | if let ...true = 0 {} - | ^^^^^^^ help: try using the minimum value for the type: `MIN...true` - error: float literals must have an integer part - --> $DIR/recover-range-pats.rs:119:15 + --> $DIR/recover-range-pats.rs:116:15 | LL | if let ....3 = 0 {} | ^^ help: must have an integer part: `0.3` -error: `...X` range patterns are not supported - --> $DIR/recover-range-pats.rs:119:12 - | -LL | if let ....3 = 0 {} - | ^^^^^ help: try using the minimum value for the type: `MIN...0.3` - -error: `..X` range patterns are not supported - --> $DIR/recover-range-pats.rs:139:17 - | -LL | let ..$e; - | ^^ help: try using the minimum value for the type: `MIN..0` -... -LL | mac!(0); - | -------- in this macro invocation - -error: `...X` range patterns are not supported - --> $DIR/recover-range-pats.rs:140:17 - | -LL | let ...$e; - | ^^^ help: try using the minimum value for the type: `MIN...0` -... -LL | mac!(0); - | -------- in this macro invocation - -error: `..=X` range patterns are not supported - --> $DIR/recover-range-pats.rs:142:17 - | -LL | let ..=$e; - | ^^^ help: try using the minimum value for the type: `MIN..=0` -... -LL | mac!(0); - | -------- in this macro invocation - -error: `X..` range patterns are not supported - --> $DIR/recover-range-pats.rs:143:19 - | -LL | let $e..; - | ^^ help: try using the maximum value for the type: `0..MAX` -... -LL | mac!(0); - | -------- in this macro invocation - -error: `X...` range patterns are not supported - --> $DIR/recover-range-pats.rs:144:19 +error[E0586]: inclusive range with no end + --> $DIR/recover-range-pats.rs:141:19 | LL | let $e...; - | ^^^ help: try using the maximum value for the type: `0...MAX` + | ^^^ ... LL | mac!(0); | -------- in this macro invocation + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) -error: `X..=` range patterns are not supported - --> $DIR/recover-range-pats.rs:146:19 +error[E0586]: inclusive range with no end + --> $DIR/recover-range-pats.rs:142:19 | LL | let $e..=; - | ^^^ help: try using the maximum value for the type: `0..=MAX` + | ^^^ ... LL | mac!(0); | -------- in this macro invocation + | + = help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`) error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:41:13 + --> $DIR/recover-range-pats.rs:42:13 | LL | if let 0...3 = 0 {} | ^^^ help: use `..=` for an inclusive range | note: lint level defined here - --> $DIR/recover-range-pats.rs:7:9 + --> $DIR/recover-range-pats.rs:8:9 | LL | #![deny(ellipsis_inclusive_range_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:42:13 + --> $DIR/recover-range-pats.rs:43:13 | LL | if let 0...Y = 0 {} | ^^^ help: use `..=` for an inclusive range error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:43:13 + --> $DIR/recover-range-pats.rs:44:13 | LL | if let X...3 = 0 {} | ^^^ help: use `..=` for an inclusive range error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:44:13 + --> $DIR/recover-range-pats.rs:45:13 | LL | if let X...Y = 0 {} | ^^^ help: use `..=` for an inclusive range error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:45:16 + --> $DIR/recover-range-pats.rs:46:16 | LL | if let true...Y = 0 {} | ^^^ help: use `..=` for an inclusive range error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:47:13 + --> $DIR/recover-range-pats.rs:48:13 | LL | if let X...true = 0 {} | ^^^ help: use `..=` for an inclusive range error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:49:14 + --> $DIR/recover-range-pats.rs:50:14 | LL | if let .0...Y = 0 {} | ^^^ help: use `..=` for an inclusive range error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:52:13 + --> $DIR/recover-range-pats.rs:53:13 | LL | if let X... .0 = 0 {} | ^^^ help: use `..=` for an inclusive range error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:78:13 - | -LL | if let 0... = 0 {} - | ^^^ help: use `..=` for an inclusive range - -error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:80:13 - | -LL | if let X... = 0 {} - | ^^^ help: use `..=` for an inclusive range - -error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:82:16 - | -LL | if let true... = 0 {} - | ^^^ help: use `..=` for an inclusive range - -error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:85:14 - | -LL | if let .0... = 0 {} - | ^^^ help: use `..=` for an inclusive range - -error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:112:12 + --> $DIR/recover-range-pats.rs:109:12 | LL | if let ...3 = 0 {} | ^^^ help: use `..=` for an inclusive range error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:114:12 + --> $DIR/recover-range-pats.rs:111:12 | LL | if let ...Y = 0 {} | ^^^ help: use `..=` for an inclusive range error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:116:12 + --> $DIR/recover-range-pats.rs:113:12 | LL | if let ...true = 0 {} | ^^^ help: use `..=` for an inclusive range error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:119:12 + --> $DIR/recover-range-pats.rs:116:12 | LL | if let ....3 = 0 {} | ^^^ help: use `..=` for an inclusive range error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:129:20 + --> $DIR/recover-range-pats.rs:126:20 | LL | let $e1...$e2; | ^^^ help: use `..=` for an inclusive range @@ -380,7 +244,7 @@ LL | mac2!(0, 1); | ------------ in this macro invocation error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:140:17 + --> $DIR/recover-range-pats.rs:137:17 | LL | let ...$e; | ^^^ help: use `..=` for an inclusive range @@ -388,17 +252,8 @@ LL | let ...$e; LL | mac!(0); | -------- in this macro invocation -error: `...` range patterns are deprecated - --> $DIR/recover-range-pats.rs:144:19 - | -LL | let $e...; - | ^^^ help: use `..=` for an inclusive range -... -LL | mac!(0); - | -------- in this macro invocation - error[E0029]: only char and numeric types are allowed in range patterns - --> $DIR/recover-range-pats.rs:19:12 + --> $DIR/recover-range-pats.rs:20:12 | LL | if let true..Y = 0 {} | ^^^^ - this is of type `u8` @@ -406,7 +261,7 @@ LL | if let true..Y = 0 {} | this is of type `bool` but it should be `char` or numeric error[E0029]: only char and numeric types are allowed in range patterns - --> $DIR/recover-range-pats.rs:20:15 + --> $DIR/recover-range-pats.rs:21:15 | LL | if let X..true = 0 {} | - ^^^^ this is of type `bool` but it should be `char` or numeric @@ -414,7 +269,7 @@ LL | if let X..true = 0 {} | this is of type `u8` error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:21:12 + --> $DIR/recover-range-pats.rs:22:12 | LL | if let .0..Y = 0 {} | ^^ - this is of type `u8` @@ -422,7 +277,7 @@ LL | if let .0..Y = 0 {} | expected integer, found floating-point number error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:23:16 + --> $DIR/recover-range-pats.rs:24:16 | LL | if let X.. .0 = 0 {} | - ^^ - this expression has type `u8` @@ -431,7 +286,7 @@ LL | if let X.. .0 = 0 {} | this is of type `u8` error[E0029]: only char and numeric types are allowed in range patterns - --> $DIR/recover-range-pats.rs:32:12 + --> $DIR/recover-range-pats.rs:33:12 | LL | if let true..=Y = 0 {} | ^^^^ - this is of type `u8` @@ -439,7 +294,7 @@ LL | if let true..=Y = 0 {} | this is of type `bool` but it should be `char` or numeric error[E0029]: only char and numeric types are allowed in range patterns - --> $DIR/recover-range-pats.rs:33:16 + --> $DIR/recover-range-pats.rs:34:16 | LL | if let X..=true = 0 {} | - ^^^^ this is of type `bool` but it should be `char` or numeric @@ -447,7 +302,7 @@ LL | if let X..=true = 0 {} | this is of type `u8` error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:34:12 + --> $DIR/recover-range-pats.rs:35:12 | LL | if let .0..=Y = 0 {} | ^^ - this is of type `u8` @@ -455,7 +310,7 @@ LL | if let .0..=Y = 0 {} | expected integer, found floating-point number error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:36:16 + --> $DIR/recover-range-pats.rs:37:16 | LL | if let X..=.0 = 0 {} | - ^^ - this expression has type `u8` @@ -464,7 +319,7 @@ LL | if let X..=.0 = 0 {} | this is of type `u8` error[E0029]: only char and numeric types are allowed in range patterns - --> $DIR/recover-range-pats.rs:45:12 + --> $DIR/recover-range-pats.rs:46:12 | LL | if let true...Y = 0 {} | ^^^^ - this is of type `u8` @@ -472,7 +327,7 @@ LL | if let true...Y = 0 {} | this is of type `bool` but it should be `char` or numeric error[E0029]: only char and numeric types are allowed in range patterns - --> $DIR/recover-range-pats.rs:47:16 + --> $DIR/recover-range-pats.rs:48:16 | LL | if let X...true = 0 {} | - ^^^^ this is of type `bool` but it should be `char` or numeric @@ -480,7 +335,7 @@ LL | if let X...true = 0 {} | this is of type `u8` error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:49:12 + --> $DIR/recover-range-pats.rs:50:12 | LL | if let .0...Y = 0 {} | ^^ - this is of type `u8` @@ -488,7 +343,7 @@ LL | if let .0...Y = 0 {} | expected integer, found floating-point number error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:52:17 + --> $DIR/recover-range-pats.rs:53:17 | LL | if let X... .0 = 0 {} | - ^^ - this expression has type `u8` @@ -497,78 +352,78 @@ LL | if let X... .0 = 0 {} | this is of type `u8` error[E0029]: only char and numeric types are allowed in range patterns - --> $DIR/recover-range-pats.rs:60:12 + --> $DIR/recover-range-pats.rs:61:12 | LL | if let true.. = 0 {} | ^^^^ this is of type `bool` but it should be `char` or numeric error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:62:12 + --> $DIR/recover-range-pats.rs:63:12 | LL | if let .0.. = 0 {} | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns - --> $DIR/recover-range-pats.rs:70:12 + --> $DIR/recover-range-pats.rs:71:12 | LL | if let true..= = 0 {} | ^^^^ this is of type `bool` but it should be `char` or numeric error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:72:12 + --> $DIR/recover-range-pats.rs:73:12 | LL | if let .0..= = 0 {} | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns - --> $DIR/recover-range-pats.rs:82:12 + --> $DIR/recover-range-pats.rs:81:12 | LL | if let true... = 0 {} | ^^^^ this is of type `bool` but it should be `char` or numeric error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:85:12 + --> $DIR/recover-range-pats.rs:83:12 | LL | if let .0... = 0 {} | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns - --> $DIR/recover-range-pats.rs:94:14 + --> $DIR/recover-range-pats.rs:91:14 | LL | if let ..true = 0 {} | ^^^^ this is of type `bool` but it should be `char` or numeric error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:96:15 + --> $DIR/recover-range-pats.rs:93:15 | LL | if let .. .0 = 0 {} | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns - --> $DIR/recover-range-pats.rs:104:15 + --> $DIR/recover-range-pats.rs:101:15 | LL | if let ..=true = 0 {} | ^^^^ this is of type `bool` but it should be `char` or numeric error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:106:15 + --> $DIR/recover-range-pats.rs:103:15 | LL | if let ..=.0 = 0 {} | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns - --> $DIR/recover-range-pats.rs:116:15 + --> $DIR/recover-range-pats.rs:113:15 | LL | if let ...true = 0 {} | ^^^^ this is of type `bool` but it should be `char` or numeric error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:119:15 + --> $DIR/recover-range-pats.rs:116:15 | LL | if let ....3 = 0 {} | ^^ expected integer, found floating-point number -error: aborting due to 85 previous errors +error: aborting due to 60 previous errors -Some errors have detailed explanations: E0029, E0308. +Some errors have detailed explanations: E0029, E0308, E0586. For more information about an error, try `rustc --explain E0029`. diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index da1e3760e010d..0642823404aed 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -1,6 +1,8 @@ #![crate_name = "compiletest"] -#![feature(test)] #![deny(warnings)] +// The `test` crate is the only unstable feature +// allowed here, just to share similar code. +#![feature(test)] extern crate test;