Skip to content

Commit

Permalink
Auto merge of rust-lang#96804 - compiler-errors:rollup-1mc6aw3, r=com…
Browse files Browse the repository at this point in the history
…piler-errors

Rollup of 8 pull requests

Successful merges:

 - rust-lang#96660 ([bootstrap] Give a better error when trying to run a path with no registered step)
 - rust-lang#96701 (update `jemallocator` example to use 2018 edition import syntax)
 - rust-lang#96746 (Fix an ICE on rust-lang#96738)
 - rust-lang#96758 (bootstrap: bsd platform flags for split debuginfo)
 - rust-lang#96778 (Remove closures on `expect_local` to apply `#[track_caller]`)
 - rust-lang#96781 (Fix an incorrect link in The Unstable Book)
 - rust-lang#96783 (Link to correct issue in issue-95034 known-bug)
 - rust-lang#96801 (Add regression test for rust-lang#96319)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 7, 2022
2 parents f6e5570 + fe52669 commit 36aa7c1
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 17 deletions.
7 changes: 6 additions & 1 deletion compiler/rustc_span/src/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,12 @@ impl DefId {
#[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]
Expand Down
29 changes: 19 additions & 10 deletions compiler/rustc_typeck/src/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,24 +368,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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 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))
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
};

// 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(
Expand Down
2 changes: 0 additions & 2 deletions library/std/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
22 changes: 19 additions & 3 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,19 @@ impl StepDescription {
}

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);
}
}
}
Expand Down Expand Up @@ -1405,8 +1417,12 @@ impl<'a> Builder<'a> {
// 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 {
Expand Down
2 changes: 1 addition & 1 deletion src/doc/unstable-book/src/language-features/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
34 changes: 34 additions & 0 deletions src/test/incremental/issue-96319-coinductive-cycle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// edition:2018
// revisions: rpass1 rpass2

pub struct Stmt {
pub stmt_type: StmtKind,
#[cfg(rpass1)] pub stmt_tag: Option<LintTag>,
#[cfg(rpass2)] pub renamed_tag: Option<LintTag>,
}
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<Stmt>,
}
pub fn start_late_pass(stmt_receiver: Box<Stmt>) {
spawn(async { stmt_receiver });
}

pub fn spawn<T>(_: T)
where
T: Send,
{
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

// This should not ICE.

// Refer to the issue for more minimized versions.

use std::{
future::Future,
marker::PhantomData,
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions src/test/ui/typeck/issue-96738.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
Some.nonexistent_method(); //~ ERROR: no method named `nonexistent_method` found
}
16 changes: 16 additions & 0 deletions src/test/ui/typeck/issue-96738.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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 the constructor of an enum variant
|
help: call the constructor
|
LL | (Some)(_).nonexistent_method();
| + ++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.

0 comments on commit 36aa7c1

Please sign in to comment.