Permalink
Comparing changes
Open a pull request
13
contributors
Commits on Dec 22, 2019
Implementation of rust-lang/rfcs#2799
Commits on Jan 07, 2020
Commits on Jan 08, 2020
Commits on Jan 09, 2020
Commits on Jan 10, 2020
This is used for both the `?const` syntax in bounds as well as the `impl const Trait` syntax. I also considered handling these separately by adding a variant of `TraitBoundModifier` and a field to `ItemKind::Impl`, but this approach was less intrusive.
The grammar also handles `?const ?Trait` even though this is semantically redundant.
This means the new syntax will always fail to compile, even when the feature gate is enabled. These checks will be removed in a later PR once the implementation is done.
Reduce special treatment for zsts addresses #67467 (comment) cc @RalfJung
Parse the syntax described in RFC 2632 This adds support for both `impl const Trait for Ty` and `?const Trait` bound syntax from rust-lang/rfcs#2632 to the parser. For now, both modifiers end up in a newly-added `constness` field on `ast::TraitRef`, although this may change once the implementation is fleshed out. I was planning on using `delay_span_bug` when this syntax is encountered during lowering, but I can't write `should-ice` UI tests. I emit a normal error instead, which causes duplicates when the feature gate is not enabled (see the `.stderr` files for the feature gate tests). Not sure what the desired approach is; Maybe just do nothing when the syntax is encountered with the feature gate is enabled? @oli-obk I went with `const_trait_impl` and `const_trait_bound_opt_out` for the names of these features. Are these to your liking? cc #67792 #67794 r? @Centril
rustc_ast_lowering: misc cleanup & rustc dep reductions - The first two commits do some code simplification. - The next three do some file splitting (getting `lib.rs` below the 3kloc tidy lint). - The remaining commits reduce the number of `rustc::` imports. This works towards making lowering independent of the `rustc` crate. r? @oli-obk cc @Zoxc
expect `fn` after `const unsafe` / `const extern` Fixes #68062 r? @estebank @petrochenkov cc @Aaron1011
Rollup of 6 pull requests Successful merges: - #66463 (Point at opaque and closure type definitions in type errors) - #67501 (Reduce special treatment for zsts) - #67820 (Parse the syntax described in RFC 2632) - #67922 (rustc_ast_lowering: misc cleanup & rustc dep reductions) - #68071 (Extend support of `_` in type parameters) - #68073 (expect `fn` after `const unsafe` / `const extern`) Failed merges: r? @ghost
…bles query-invocation-specific event_ids.
…dian platforms.
… r=wesleywiser self-profiling: Support recording query keys This PR makes self-profiling able to record query keys. The implementation is not as efficient as it could be yet (all query keys except for `DefId`s cause string data to be duplicated) and the rendered strings could be nicer too. But the implementation is functional and introduces the basic framework for emitting per-query-invocation event data. I tried to add proper documentation on how everything works. Let me know if more documentation is needed. r? @wesleywiser @Mark-Simulacrum, heads up: This updates `measureme` to 0.7.0 which means that `summarize` on perf.rlo needs to be update accordingly once this is merged.
Add method Result::into_ok Implementation of rust-lang/rfcs#2799 Tracking issue #61695
Introduce `X..`, `..X`, and `..=X` range patterns Tracking issue: #67264 Feature gate: `#![feature(half_open_range_patterns)]` --------------------------- In this PR, we introduce range-from (`X..`), range-to (`..X`), and range-to-inclusive (`..=X`) patterns. These correspond to the `RangeFrom`, `RangeTo`, and `RangeToInclusive` expression forms introduced with the same syntaxes. The correspondence is both syntactic and semantic (in the sense that e.g. a `X..` pattern matching on a scrutinee `s` holds exactly when `(X..).contains(&s)` holds). --------------------------- Noteworthy: - The compiler complexity added with this PR is around 10 lines (discounting new tests, which account for the large PR size). - `...X` is accepted syntactically with the same meaning as `..=X`. This is done primarily to simplify and unify the implementation & spec. If-and-when we decide to make `X...Y` a hard error on a new edition, we can do the same for `...X` patterns as well. - `X...` and `X..=` is rejected syntactically just like it is for the expression equivalents. We should perhaps make these into semantic restrictions (cc @petrochenkov). - In HAIR, these half-open ranges are represented by inserting the max/min values for the approprate types. That is, `X..` where `X: u8` would become `X..=u8::MAX` in HAIR (note the `..=` since `RangeFrom` includes the end). - Exhaustive integer / char matching does not (yet) allow for e.g. exhaustive matching on `0usize..` or `..5usize | 5..` (same idea for `isize`). This would be a substantially more invasive change, and could be added in some other PR. - The issues with slice pattern syntax has been resolved as we decided to use `..` to mean a "rest-pattern" and `[xs @ ..]` to bind the rest to a name in a slice pattern. - Like with #35712, which provided `X..Y` range patterns, this is not yet backed up by an RFC. I'm providing this experimental implementation now to have something concrete to discuss. I would be happy to provide an RFC for this PR as well as for #35712 to finalize and confirm the ideas with the larger community. Closes rust-lang/rfcs#947. --------------------------- r? @varkor cc @matthewjasper @oli-obk I would recommend reviewing this (in particular HAIR-lowering and pattern parsing changes) with whitespace changes ignored.
Build compiletest with in-tree libtest This updates compiletest to build in `Mode::ToolStd`, using the locally-built crates for `std` and especially `test`. This way we're immune to unstable differences in the bootstrap compiler crates, whether that's a prior-release stage0 or a current release local rebuild. Fixes #59264. As a minor cleanup, this also removes the unused `llvm_tools` flag.
Canonicalize rustc_error imports r? @Mark-Simulacrum
Rollup of 8 pull requests Successful merges: - #66045 (Add method Result::into_ok) - #67258 (Introduce `X..`, `..X`, and `..=X` range patterns) - #68014 (Unify output of "variant not found" errors) - #68019 (Build compiletest with in-tree libtest) - #68039 (remove explicit strip-hidden pass from compiler doc generation) - #68050 (Canonicalize rustc_error imports) - #68059 (Allow specifying LLVM args in target specifications) - #68075 (rustbuild: Cleanup book generation) Failed merges: - #68089 (Unstabilize `Vec::remove_item`) r? @ghost
Unified
Split
Showing
441 changed files
with
5,398 additions
and 2,628 deletions.
| @@ -1995,9 +1995,9 @@ dependencies = [ | ||
|
|
||
| [[package]] | ||
| name = "measureme" | ||
| version = "0.5.0" | ||
| version = "0.7.1" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "c420bbc064623934620b5ab2dc0cf96451b34163329e82f95e7fa1b7b99a6ac8" | ||
| checksum = "fef709d3257013bba7cff14fc504e07e80631d3fe0f6d38ce63b8f6510ccb932" | ||
| dependencies = [ | ||
| "byteorder", | ||
| "memmap", | ||
| @@ -3079,6 +3079,7 @@ dependencies = [ | ||
| "graphviz", | ||
| "jobserver", | ||
| "log", | ||
| "measureme", | ||
| "parking_lot", | ||
| "polonius-engine", | ||
| "rustc-rayon", | ||
| @@ -3653,6 +3654,7 @@ dependencies = [ | ||
| "log", | ||
| "rustc", | ||
| "rustc_data_structures", | ||
| "rustc_errors", | ||
| "rustc_feature", | ||
| "rustc_hir", | ||
| "rustc_index", | ||
| @@ -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<PathBuf> { | ||
| INTERNER.intern_path(builder.src.join("src/doc")) | ||
| } | ||
|
|
||
| #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] | ||
| pub struct UnstableBook { | ||
| target: Interned<String>, | ||
| @@ -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<String>, | ||
| name: Interned<String>, | ||
| } | ||
|
|
||
| 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<String>, | ||
| @@ -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<String>, | ||
| name: &'static str, | ||
| } | ||
|
|
||
| impl Step for TheBook { | ||
| @@ -198,53 +156,37 @@ 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", | ||
| }); | ||
| } | ||
|
|
||
| /// Builds the book and associated stuff. | ||
| /// | ||
| /// 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`. | ||
| @@ -289,8 +289,8 @@ fn rustbook_features() -> Vec<String> { | ||
| 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; | ||
| @@ -1092,6 +1092,44 @@ impl<T: Default, E> Result<T, E> { | ||
| } | ||
| } | ||
|
|
||
| #[unstable(feature = "unwrap_infallible", reason = "newly added", issue = "61695")] | ||
| impl<T, E: Into<!>> Result<T, E> { | ||
| /// Unwraps a result that can never be an [`Err`], yielding the content of the [`Ok`]. | ||
| /// | ||
| /// Unlike [`unwrap`], this method is known to never panic on the | ||
| /// result types it is implemented for. Therefore, it can be used | ||
| /// instead of `unwrap` as a maintainability safeguard that will fail | ||
| /// to compile if the error type of the `Result` is later changed | ||
| /// to an error that can actually occur. | ||
| /// | ||
| /// [`Ok`]: enum.Result.html#variant.Ok | ||
| /// [`Err`]: enum.Result.html#variant.Err | ||
| /// [`unwrap`]: enum.Result.html#method.unwrap | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// Basic usage: | ||
| /// | ||
| /// ``` | ||
| /// # #![feature(never_type)] | ||
| /// # #![feature(unwrap_infallible)] | ||
| /// | ||
| /// fn only_good_news() -> Result<String, !> { | ||
| /// Ok("this is fine".into()) | ||
| /// } | ||
| /// | ||
| /// let s: String = only_good_news().into_ok(); | ||
| /// println!("{}", s); | ||
| /// ``` | ||
| #[inline] | ||
| pub fn into_ok(self) -> T { | ||
| match self { | ||
| Ok(x) => x, | ||
| Err(e) => e.into(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[unstable(feature = "inner_deref", reason = "newly added", issue = "50264")] | ||
| impl<T: Deref, E> Result<T, E> { | ||
| /// Converts from `Result<T, E>` (or `&Result<T, E>`) to `Result<&T::Target, &E>`. | ||
| @@ -40,6 +40,8 @@ | ||
| #![feature(slice_from_raw_parts)] | ||
| #![feature(const_slice_from_raw_parts)] | ||
| #![feature(const_raw_ptr_deref)] | ||
| #![feature(never_type)] | ||
| #![feature(unwrap_infallible)] | ||
|
|
||
| extern crate test; | ||
|
|
||
| @@ -183,6 +183,28 @@ pub fn test_unwrap_or_default() { | ||
| assert_eq!(op2().unwrap_or_default(), 0); | ||
| } | ||
|
|
||
| #[test] | ||
| pub fn test_into_ok() { | ||
| fn infallible_op() -> Result<isize, !> { | ||
| Ok(666) | ||
| } | ||
|
|
||
| assert_eq!(infallible_op().into_ok(), 666); | ||
|
|
||
| enum MyNeverToken {} | ||
| impl From<MyNeverToken> for ! { | ||
| fn from(never: MyNeverToken) -> ! { | ||
| match never {} | ||
| } | ||
| } | ||
|
|
||
| fn infallible_op2() -> Result<isize, MyNeverToken> { | ||
| Ok(667) | ||
| } | ||
|
|
||
| assert_eq!(infallible_op2().into_ok(), 667); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_try() { | ||
| fn try_result_some() -> Option<u8> { | ||
| @@ -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" } | ||
| @@ -36,5 +36,6 @@ parking_lot = "0.9" | ||
| byteorder = { version = "1.3" } | ||
| chalk-engine = { version = "0.9.0", default-features=false } | ||
| smallvec = { version = "1.0", features = ["union", "may_dangle"] } | ||
| measureme = "0.7.1" | ||
| rustc_error_codes = { path = "../librustc_error_codes" } | ||
| rustc_session = { path = "../librustc_session" } | ||
Oops, something went wrong.