Auto merge of #96804 - compiler-errors:rollup-1mc6aw3, r=compiler-errors

Rollup of 8 pull requests

Successful merges:

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

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2022-05-07 04:15:52 +00:00
commit 36aa7c1436
10 changed files with 100 additions and 17 deletions

View File

@ -281,7 +281,12 @@ pub fn as_local(self) -> Option<LocalDefId> {
#[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]

View File

@ -368,16 +368,25 @@ 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 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
@ -385,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(

View File

@ -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]

View File

@ -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);
}
}
}
@ -1405,8 +1417,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 {

View File

@ -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.

View File

@ -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() {}

View File

@ -17,6 +17,8 @@
// This should not ICE.
// Refer to the issue for more minimized versions.
use std::{
future::Future,
marker::PhantomData,

View File

@ -0,0 +1,3 @@
fn main() {
Some.nonexistent_method(); //~ ERROR: no method named `nonexistent_method` found
}

View File

@ -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`.