Skip to content

Commit 36aa7c1

Browse files
committed
Auto merge of rust-lang#96804 - compiler-errors:rollup-1mc6aw3, r=compiler-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
2 parents f6e5570 + fe52669 commit 36aa7c1

File tree

10 files changed

+100
-17
lines changed

10 files changed

+100
-17
lines changed

compiler/rustc_span/src/def_id.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,12 @@ impl DefId {
281281
#[inline]
282282
#[track_caller]
283283
pub fn expect_local(self) -> LocalDefId {
284-
self.as_local().unwrap_or_else(|| panic!("DefId::expect_local: `{:?}` isn't local", self))
284+
// NOTE: `match` below is required to apply `#[track_caller]`,
285+
// i.e. don't use closures.
286+
match self.as_local() {
287+
Some(local_def_id) => local_def_id,
288+
None => panic!("DefId::expect_local: `{:?}` isn't local", self),
289+
}
285290
}
286291

287292
#[inline]

compiler/rustc_typeck/src/check/method/suggest.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -368,24 +368,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
368368
if self.is_fn_ty(rcvr_ty, span) {
369369
if let SelfSource::MethodCall(expr) = source {
370370
let suggest = if let ty::FnDef(def_id, _) = rcvr_ty.kind() {
371-
let local_id = def_id.expect_local();
372-
let hir_id = tcx.hir().local_def_id_to_hir_id(local_id);
373-
let node = tcx.hir().get(hir_id);
374-
let fields = node.tuple_fields();
375-
376-
if let Some(fields) = fields
377-
&& let Some(DefKind::Ctor(of, _)) = self.tcx.opt_def_kind(local_id) {
378-
Some((fields, of))
371+
if let Some(local_id) = def_id.as_local() {
372+
let hir_id = tcx.hir().local_def_id_to_hir_id(local_id);
373+
let node = tcx.hir().get(hir_id);
374+
let fields = node.tuple_fields();
375+
if let Some(fields) = fields
376+
&& let Some(DefKind::Ctor(of, _)) = self.tcx.opt_def_kind(local_id) {
377+
Some((fields.len(), of))
378+
} else {
379+
None
380+
}
379381
} else {
380-
None
382+
// The logic here isn't smart but `associated_item_def_ids`
383+
// doesn't work nicely on local.
384+
if let DefKind::Ctor(of, _) = tcx.def_kind(def_id) {
385+
let parent_def_id = tcx.parent(*def_id);
386+
Some((tcx.associated_item_def_ids(parent_def_id).len(), of))
387+
} else {
388+
None
389+
}
381390
}
382391
} else {
383392
None
384393
};
385394

386395
// If the function is a tuple constructor, we recommend that they call it
387396
if let Some((fields, kind)) = suggest {
388-
suggest_call_constructor(expr.span, kind, fields.len(), &mut err);
397+
suggest_call_constructor(expr.span, kind, fields, &mut err);
389398
} else {
390399
// General case
391400
err.span_label(

library/std/src/alloc.rs

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
//! [`GlobalAlloc`] trait. This type can be provided by an external library:
4343
//!
4444
//! ```rust,ignore (demonstrates crates.io usage)
45-
//! extern crate jemallocator;
46-
//!
4745
//! use jemallocator::Jemalloc;
4846
//!
4947
//! #[global_allocator]

src/bootstrap/builder.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,19 @@ impl StepDescription {
284284
}
285285

286286
if !attempted_run {
287-
panic!("error: no rules matched {}", path.display());
287+
eprintln!(
288+
"error: no `{}` rules matched '{}'",
289+
builder.kind.as_str(),
290+
path.display()
291+
);
292+
eprintln!(
293+
"help: run `x.py {} --help --verbose` to show a list of available paths",
294+
builder.kind.as_str()
295+
);
296+
eprintln!(
297+
"note: if you are adding a new Step to bootstrap itself, make sure you register it with `describe!`"
298+
);
299+
std::process::exit(1);
288300
}
289301
}
290302
}
@@ -1405,8 +1417,12 @@ impl<'a> Builder<'a> {
14051417
// FIXME(davidtwco): #[cfg(not(bootstrap))] - #95612 needs to be in the bootstrap compiler
14061418
// for this conditional to be removed.
14071419
if !target.contains("windows") || compiler.stage >= 1 {
1408-
if target.contains("linux") || target.contains("windows") || target.contains("openbsd")
1409-
{
1420+
let needs_unstable_opts = target.contains("linux")
1421+
|| target.contains("windows")
1422+
|| target.contains("bsd")
1423+
|| target.contains("dragonfly");
1424+
1425+
if needs_unstable_opts {
14101426
rustflags.arg("-Zunstable-options");
14111427
}
14121428
match self.config.rust_split_debuginfo {

src/doc/unstable-book/src/language-features/plugin.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ The components of a lint plugin are:
102102

103103
Lint passes are syntax traversals, but they run at a late stage of compilation
104104
where type information is available. `rustc`'s [built-in
105-
lints](https://github.com/rust-lang/rust/blob/master/src/librustc_session/lint/builtin.rs)
105+
lints](https://github.com/rust-lang/rust/blob/master/compiler/rustc_lint_defs/src/builtin.rs)
106106
mostly use the same infrastructure as lint plugins, and provide examples of how
107107
to access type information.
108108

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// edition:2018
2+
// revisions: rpass1 rpass2
3+
4+
pub struct Stmt {
5+
pub stmt_type: StmtKind,
6+
#[cfg(rpass1)] pub stmt_tag: Option<LintTag>,
7+
#[cfg(rpass2)] pub renamed_tag: Option<LintTag>,
8+
}
9+
pub struct LintTag;
10+
pub enum StmtKind {
11+
If(If),
12+
Block(&'static str),
13+
Return(Return),
14+
}
15+
pub struct If {
16+
pub condition: Function,
17+
}
18+
pub struct Return {
19+
pub value: Function,
20+
}
21+
pub struct Function {
22+
pub parameters: Box<Stmt>,
23+
}
24+
pub fn start_late_pass(stmt_receiver: Box<Stmt>) {
25+
spawn(async { stmt_receiver });
26+
}
27+
28+
pub fn spawn<T>(_: T)
29+
where
30+
T: Send,
31+
{
32+
}
33+
34+
fn main() {}

src/test/ui/hrtb/issue-94034.rs src/test/ui/hrtb/issue-95034.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
// This should not ICE.
1919

20+
// Refer to the issue for more minimized versions.
21+
2022
use std::{
2123
future::Future,
2224
marker::PhantomData,
File renamed without changes.

src/test/ui/typeck/issue-96738.rs

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

src/test/ui/typeck/issue-96738.stderr

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0599]: no method named `nonexistent_method` found for fn item `fn(_) -> Option<_> {Option::<_>::Some}` in the current scope
2+
--> $DIR/issue-96738.rs:2:10
3+
|
4+
LL | Some.nonexistent_method();
5+
| ---- ^^^^^^^^^^^^^^^^^^ method not found in `fn(_) -> Option<_> {Option::<_>::Some}`
6+
| |
7+
| this is the constructor of an enum variant
8+
|
9+
help: call the constructor
10+
|
11+
LL | (Some)(_).nonexistent_method();
12+
| + ++++
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)