From 3a800bf5c75fc9889178e401b0ab5fab87deb00d Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 2 May 2022 23:25:08 -0500 Subject: [PATCH 1/9] [bootstrap] Give a better error when trying to run a path with no registered step Before: ``` thread 'main' panicked at 'error: no rules matched invalid', src/bootstrap/builder.rs:287:17 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` After: ``` error: no `check` rules matched 'invalid' help: run `x.py check --help --verbose` to show a list of available paths note: if you are adding a new Step to bootstrap itself, make sure you register it with `describe!` ``` --- src/bootstrap/builder.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index edfe31319e8..c399b004ead 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -284,7 +284,19 @@ fn run(v: &[StepDescription], builder: &Builder<'_>, paths: &[PathBuf]) { } if !attempted_run { - panic!("error: no rules matched {}", path.display()); + eprintln!( + "error: no `{}` rules matched '{}'", + builder.kind.as_str(), + path.display() + ); + eprintln!( + "help: run `x.py {} --help --verbose` to show a list of available paths", + builder.kind.as_str() + ); + eprintln!( + "note: if you are adding a new Step to bootstrap itself, make sure you register it with `describe!`" + ); + std::process::exit(1); } } } From 519aa6e4d7d6bb839591a5ec3b9bf479b94663f7 Mon Sep 17 00:00:00 2001 From: kraktus Date: Wed, 4 May 2022 13:43:33 +0200 Subject: [PATCH 2/9] update `jemallocator` example to use 2018 edition import syntax --- library/std/src/alloc.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index 49b6cd4232c..63c527b64da 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -42,8 +42,6 @@ //! [`GlobalAlloc`] trait. This type can be provided by an external library: //! //! ```rust,ignore (demonstrates crates.io usage) -//! extern crate jemallocator; -//! //! use jemallocator::Jemalloc; //! //! #[global_allocator] From 436c0e129ca535d249fbf8d61d3b9334e5cd6767 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 6 May 2022 07:15:35 +0900 Subject: [PATCH 3/9] Fix an ICE on #96738 --- compiler/rustc_typeck/src/check/method/suggest.rs | 3 +-- src/test/ui/typeck/issue-96738.rs | 3 +++ src/test/ui/typeck/issue-96738.stderr | 11 +++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/typeck/issue-96738.rs create mode 100644 src/test/ui/typeck/issue-96738.stderr diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 634ba2baf96..f36d2496673 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -367,8 +367,7 @@ pub fn report_method_error( if self.is_fn_ty(rcvr_ty, span) { if let SelfSource::MethodCall(expr) = source { - let suggest = if let ty::FnDef(def_id, _) = rcvr_ty.kind() { - let local_id = def_id.expect_local(); + let suggest = if let ty::FnDef(def_id, _) = rcvr_ty.kind() && let Some(local_id) = def_id.as_local() { let hir_id = tcx.hir().local_def_id_to_hir_id(local_id); let node = tcx.hir().get(hir_id); let fields = node.tuple_fields(); diff --git a/src/test/ui/typeck/issue-96738.rs b/src/test/ui/typeck/issue-96738.rs new file mode 100644 index 00000000000..7f1d1428eb9 --- /dev/null +++ b/src/test/ui/typeck/issue-96738.rs @@ -0,0 +1,3 @@ +fn main() { + Some.nonexistent_method(); //~ ERROR: no method named `nonexistent_method` found +} diff --git a/src/test/ui/typeck/issue-96738.stderr b/src/test/ui/typeck/issue-96738.stderr new file mode 100644 index 00000000000..6f9bffbb790 --- /dev/null +++ b/src/test/ui/typeck/issue-96738.stderr @@ -0,0 +1,11 @@ +error[E0599]: no method named `nonexistent_method` found for fn item `fn(_) -> Option<_> {Option::<_>::Some}` in the current scope + --> $DIR/issue-96738.rs:2:10 + | +LL | Some.nonexistent_method(); + | ---- ^^^^^^^^^^^^^^^^^^ method not found in `fn(_) -> Option<_> {Option::<_>::Some}` + | | + | this is a function, perhaps you wish to call it + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. From 80087b98ccea66b0734c514b97014399b5100255 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 6 May 2022 03:00:39 +0100 Subject: [PATCH 4/9] bootstrap: bsd platform flags for split debuginfo Bootstrap currently provides `-Zunstable-options` for OpenBSD when using split debuginfo - this commit provides it for all BSD targets. Signed-off-by: David Wood --- src/bootstrap/builder.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 2224bf5f66e..e91a9991806 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1405,8 +1405,12 @@ pub fn cargo( // FIXME(davidtwco): #[cfg(not(bootstrap))] - #95612 needs to be in the bootstrap compiler // for this conditional to be removed. if !target.contains("windows") || compiler.stage >= 1 { - if target.contains("linux") || target.contains("windows") || target.contains("openbsd") - { + let needs_unstable_opts = target.contains("linux") + || target.contains("windows") + || target.contains("bsd") + || target.contains("dragonfly"); + + if needs_unstable_opts { rustflags.arg("-Zunstable-options"); } match self.config.rust_split_debuginfo { From 35d77c17101852d17ebd27434c09b3652689e5c6 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 7 May 2022 00:43:50 +0900 Subject: [PATCH 5/9] Also suggest calling constructors for external DefIds --- .../rustc_typeck/src/check/method/suggest.rs | 30 ++++++++++++------- src/test/ui/typeck/issue-96738.stderr | 7 ++++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index f36d2496673..294a42a1148 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -367,16 +367,26 @@ pub fn report_method_error( if self.is_fn_ty(rcvr_ty, span) { if let SelfSource::MethodCall(expr) = source { - let suggest = if let ty::FnDef(def_id, _) = rcvr_ty.kind() && let Some(local_id) = def_id.as_local() { - let hir_id = tcx.hir().local_def_id_to_hir_id(local_id); - let node = tcx.hir().get(hir_id); - let fields = node.tuple_fields(); - - if let Some(fields) = fields - && let Some(DefKind::Ctor(of, _)) = self.tcx.opt_def_kind(local_id) { - Some((fields, of)) + let suggest = if let ty::FnDef(def_id, _) = rcvr_ty.kind() { + if let Some(local_id) = def_id.as_local() { + let hir_id = tcx.hir().local_def_id_to_hir_id(local_id); + let node = tcx.hir().get(hir_id); + let fields = node.tuple_fields(); + if let Some(fields) = fields + && let Some(DefKind::Ctor(of, _)) = self.tcx.opt_def_kind(local_id) { + Some((fields.len(), of)) + } else { + None + } } else { - None + // The logic here isn't smart but `associated_item_def_ids` + // doesn't work nicely on local. + if let DefKind::Ctor(of, _) = tcx.def_kind(def_id) { + let parent_def_id = tcx.parent(*def_id); + Some((tcx.associated_item_def_ids(parent_def_id).len(), of)) + } else { + None + } } } else { None @@ -384,7 +394,7 @@ pub fn report_method_error( // If the function is a tuple constructor, we recommend that they call it if let Some((fields, kind)) = suggest { - suggest_call_constructor(expr.span, kind, fields.len(), &mut err); + suggest_call_constructor(expr.span, kind, fields, &mut err); } else { // General case err.span_label( diff --git a/src/test/ui/typeck/issue-96738.stderr b/src/test/ui/typeck/issue-96738.stderr index 6f9bffbb790..58c83a36a3b 100644 --- a/src/test/ui/typeck/issue-96738.stderr +++ b/src/test/ui/typeck/issue-96738.stderr @@ -4,7 +4,12 @@ error[E0599]: no method named `nonexistent_method` found for fn item `fn(_) -> O LL | Some.nonexistent_method(); | ---- ^^^^^^^^^^^^^^^^^^ method not found in `fn(_) -> Option<_> {Option::<_>::Some}` | | - | this is a function, perhaps you wish to call it + | this is the constructor of an enum variant + | +help: call the constructor + | +LL | (Some)(_).nonexistent_method(); + | + ++++ error: aborting due to previous error From 7b773e890e9b1f85a4cf7ea3893536422ee2b378 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 7 May 2022 01:11:32 +0900 Subject: [PATCH 6/9] Remove closures on `expect_local` to apply `#[track_caller]` --- compiler/rustc_span/src/def_id.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index 6b529d5e083..3976c062221 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -281,7 +281,12 @@ pub fn as_local(self) -> Option { #[inline] #[track_caller] pub fn expect_local(self) -> LocalDefId { - self.as_local().unwrap_or_else(|| panic!("DefId::expect_local: `{:?}` isn't local", self)) + // NOTE: `match` below is required to apply `#[track_caller]`, + // i.e. don't use closures. + match self.as_local() { + Some(local_def_id) => local_def_id, + None => panic!("DefId::expect_local: `{:?}` isn't local", self), + } } #[inline] From d6c64f4368c2b34c0a7accf601114eb46636c1b2 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 7 May 2022 01:21:40 +0900 Subject: [PATCH 7/9] Fix an incorrect link in The Unstable Book https://github.com/rust-lang/rust/blob/master/src/librustc_session/lint/builtin.rs returns page not found. The following is the background of the move. First https://github.com/rust-lang/rust/pull/74862 moves from src/librustc_session/lint/builtin.rs to compiler/rustc_session/src/lint/builtin.rs Then https://github.com/rust-lang/rust/commit/23018a5 moves from compiler/rustc_session/src/lint/builtin.rs to compiler/rustc_lint_defs/src/builtin.rs So, the current correct link is https://github.com/rust-lang/rust/blob/master/compiler/rustc_lint_defs/src/builtin.rs This PR fixes a broken link on the following page: https://doc.rust-lang.org/beta/unstable-book/language-features/plugin.html --- src/doc/unstable-book/src/language-features/plugin.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/unstable-book/src/language-features/plugin.md b/src/doc/unstable-book/src/language-features/plugin.md index 040f46f8b7c..56fe9a31bfe 100644 --- a/src/doc/unstable-book/src/language-features/plugin.md +++ b/src/doc/unstable-book/src/language-features/plugin.md @@ -102,7 +102,7 @@ The components of a lint plugin are: Lint passes are syntax traversals, but they run at a late stage of compilation where type information is available. `rustc`'s [built-in -lints](https://github.com/rust-lang/rust/blob/master/src/librustc_session/lint/builtin.rs) +lints](https://github.com/rust-lang/rust/blob/master/compiler/rustc_lint_defs/src/builtin.rs) mostly use the same infrastructure as lint plugins, and provide examples of how to access type information. From d7d928e9672761ecabccc320dcd8ae5060560237 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Fri, 6 May 2022 20:35:06 +0300 Subject: [PATCH 8/9] Link to correct issue in issue-95034 test --- src/test/ui/hrtb/{issue-94034.rs => issue-95034.rs} | 2 ++ src/test/ui/hrtb/{issue-94034.stderr => issue-95034.stderr} | 0 2 files changed, 2 insertions(+) rename src/test/ui/hrtb/{issue-94034.rs => issue-95034.rs} (97%) rename src/test/ui/hrtb/{issue-94034.stderr => issue-95034.stderr} (100%) diff --git a/src/test/ui/hrtb/issue-94034.rs b/src/test/ui/hrtb/issue-95034.rs similarity index 97% rename from src/test/ui/hrtb/issue-94034.rs rename to src/test/ui/hrtb/issue-95034.rs index 5239e5db11c..aee6fe61ba8 100644 --- a/src/test/ui/hrtb/issue-94034.rs +++ b/src/test/ui/hrtb/issue-95034.rs @@ -17,6 +17,8 @@ // This should not ICE. +// Refer to the issue for more minimized versions. + use std::{ future::Future, marker::PhantomData, diff --git a/src/test/ui/hrtb/issue-94034.stderr b/src/test/ui/hrtb/issue-95034.stderr similarity index 100% rename from src/test/ui/hrtb/issue-94034.stderr rename to src/test/ui/hrtb/issue-95034.stderr From 848028c0a7bfc5e8d507e927b8114313037931a7 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 6 May 2022 22:28:22 -0400 Subject: [PATCH 9/9] Add regression test for #96319 --- .../issue-96319-coinductive-cycle.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/incremental/issue-96319-coinductive-cycle.rs diff --git a/src/test/incremental/issue-96319-coinductive-cycle.rs b/src/test/incremental/issue-96319-coinductive-cycle.rs new file mode 100644 index 00000000000..b5ff9112a20 --- /dev/null +++ b/src/test/incremental/issue-96319-coinductive-cycle.rs @@ -0,0 +1,34 @@ +// edition:2018 +// revisions: rpass1 rpass2 + +pub struct Stmt { + pub stmt_type: StmtKind, + #[cfg(rpass1)] pub stmt_tag: Option, + #[cfg(rpass2)] pub renamed_tag: Option, +} +pub struct LintTag; +pub enum StmtKind { + If(If), + Block(&'static str), + Return(Return), +} +pub struct If { + pub condition: Function, +} +pub struct Return { + pub value: Function, +} +pub struct Function { + pub parameters: Box, +} +pub fn start_late_pass(stmt_receiver: Box) { + spawn(async { stmt_receiver }); +} + +pub fn spawn(_: T) +where + T: Send, +{ +} + +fn main() {}