Skip to content

Commit 82c24ec

Browse files
committed
Auto merge of rust-lang#132603 - matthiaskrgr:rollup-ikzofgc, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#132355 (Fix compiler panic with a large number of threads) - rust-lang#132486 (No need to instantiate binder in `confirm_async_closure_candidate`) - rust-lang#132544 (Use backticks instead of single quotes for library feature names in diagnostics) - rust-lang#132559 (find the generic container rather than simply looking up for the assoc with const arg) - rust-lang#132579 (add rustc std workspace crate sources) - rust-lang#132583 (Suggest creating unary tuples when types don't match a trait) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 432972c + a4f323c commit 82c24ec

File tree

140 files changed

+725
-451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+725
-451
lines changed

Cargo.lock

+12
Original file line numberDiff line numberDiff line change
@@ -3196,6 +3196,18 @@ version = "0.1.0"
31963196
source = "registry+https://github.com/rust-lang/crates.io-index"
31973197
checksum = "e5c9f15eec8235d7cb775ee6f81891db79b98fd54ba1ad8fae565b88ef1ae4e2"
31983198

3199+
[[package]]
3200+
name = "rustc-std-workspace-alloc"
3201+
version = "1.0.1"
3202+
3203+
[[package]]
3204+
name = "rustc-std-workspace-core"
3205+
version = "1.0.1"
3206+
3207+
[[package]]
3208+
name = "rustc-std-workspace-std"
3209+
version = "1.0.1"
3210+
31993211
[[package]]
32003212
name = "rustc_abi"
32013213
version = "0.0.0"

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ resolver = "2"
33
members = [
44
"compiler/rustc",
55
"src/etc/test-float-parse",
6+
"src/rustc-std-workspace/rustc-std-workspace-core",
7+
"src/rustc-std-workspace/rustc-std-workspace-alloc",
8+
"src/rustc-std-workspace/rustc-std-workspace-std",
69
"src/rustdoc-json-types",
710
"src/tools/build_helper",
811
"src/tools/cargotest",

compiler/rustc_hir_analysis/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ hir_analysis_missing_trait_item_suggestion = implement the missing item: `{$snip
311311
312312
hir_analysis_missing_trait_item_unstable = not all trait items implemented, missing: `{$missing_item_name}`
313313
.note = default implementation of `{$missing_item_name}` is unstable
314-
.some_note = use of unstable library feature '{$feature}': {$reason}
315-
.none_note = use of unstable library feature '{$feature}'
314+
.some_note = use of unstable library feature `{$feature}`: {$reason}
315+
.none_note = use of unstable library feature `{$feature}`
316316
317317
hir_analysis_missing_type_params =
318318
the type {$parameterCount ->

compiler/rustc_hir_analysis/src/collect/type_of.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,13 @@ fn const_arg_anon_type_of<'tcx>(tcx: TyCtxt<'tcx>, arg_hir_id: HirId, span: Span
175175
// arm would handle this.
176176
//
177177
// I believe this match arm is only needed for GAT but I am not 100% sure - BoxyUwU
178-
Node::Ty(hir_ty @ hir::Ty { kind: TyKind::Path(QPath::TypeRelative(_, segment)), .. }) => {
178+
Node::Ty(hir_ty @ hir::Ty { kind: TyKind::Path(QPath::TypeRelative(ty, segment)), .. }) => {
179179
// Find the Item containing the associated type so we can create an ItemCtxt.
180180
// Using the ItemCtxt lower the HIR for the unresolved assoc type into a
181181
// ty which is a fully resolved projection.
182182
// For the code example above, this would mean lowering `Self::Assoc<3>`
183183
// to a ty::Alias(ty::Projection, `<Self as Foo>::Assoc<3>`).
184-
let item_def_id = tcx
185-
.hir()
186-
.parent_owner_iter(arg_hir_id)
187-
.find(|(_, node)| matches!(node, OwnerNode::Item(_)))
188-
.unwrap()
189-
.0
190-
.def_id;
184+
let item_def_id = tcx.hir().get_parent_item(ty.hir_id).def_id;
191185
let ty = ItemCtxt::new(tcx, item_def_id).lower_ty(hir_ty);
192186

193187
// Iterate through the generics of the projection to find the one that corresponds to

compiler/rustc_middle/src/middle/stability.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ pub fn report_unstable(
112112
soft_handler: impl FnOnce(&'static Lint, Span, String),
113113
) {
114114
let msg = match reason {
115-
Some(r) => format!("use of unstable library feature '{feature}': {r}"),
116-
None => format!("use of unstable library feature '{feature}'"),
115+
Some(r) => format!("use of unstable library feature `{feature}`: {r}"),
116+
None => format!("use of unstable library feature `{feature}`"),
117117
};
118118

119119
if is_soft {

compiler/rustc_session/src/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2466,6 +2466,10 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
24662466
early_dcx.early_fatal("value for threads must be a positive non-zero integer");
24672467
}
24682468

2469+
if unstable_opts.threads == parse::MAX_THREADS_CAP {
2470+
early_dcx.early_warn(format!("number of threads was capped at {}", parse::MAX_THREADS_CAP));
2471+
}
2472+
24692473
let fuel = unstable_opts.fuel.is_some() || unstable_opts.print_fuel.is_some();
24702474
if fuel && unstable_opts.threads > 1 {
24712475
early_dcx.early_fatal("optimization fuel is incompatible with multiple threads");

compiler/rustc_session/src/options.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,11 @@ mod desc {
457457
"either a boolean (`yes`, `no`, `on`, `off`, etc), or `nll` (default: `nll`)";
458458
}
459459

460-
mod parse {
460+
pub mod parse {
461461
use std::str::FromStr;
462462

463463
pub(crate) use super::*;
464+
pub(crate) const MAX_THREADS_CAP: usize = 256;
464465

465466
/// This is for boolean options that don't take a value and start with
466467
/// `no-`. This style of option is deprecated.
@@ -657,7 +658,7 @@ mod parse {
657658
}
658659

659660
pub(crate) fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
660-
match v.and_then(|s| s.parse().ok()) {
661+
let ret = match v.and_then(|s| s.parse().ok()) {
661662
Some(0) => {
662663
*slot = std::thread::available_parallelism().map_or(1, NonZero::<usize>::get);
663664
true
@@ -667,7 +668,11 @@ mod parse {
667668
true
668669
}
669670
None => false,
670-
}
671+
};
672+
// We want to cap the number of threads here to avoid large numbers like 999999 and compiler panics.
673+
// This solution was suggested here https://github.com/rust-lang/rust/issues/117638#issuecomment-1800925067
674+
*slot = slot.clone().min(MAX_THREADS_CAP);
675+
ret
671676
}
672677

673678
/// Use this for any numeric option that has a static default.

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
471471
}
472472

473473
self.try_to_add_help_message(
474+
&root_obligation,
474475
&obligation,
475476
leaf_trait_predicate,
476477
&mut err,
@@ -2488,6 +2489,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
24882489

24892490
fn try_to_add_help_message(
24902491
&self,
2492+
root_obligation: &PredicateObligation<'tcx>,
24912493
obligation: &PredicateObligation<'tcx>,
24922494
trait_predicate: ty::PolyTraitPredicate<'tcx>,
24932495
err: &mut Diag<'_>,
@@ -2575,6 +2577,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
25752577
impl_candidates.as_slice(),
25762578
span,
25772579
);
2580+
2581+
self.suggest_tuple_wrapping(err, root_obligation, obligation);
25782582
}
25792583
}
25802584

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

+35
Original file line numberDiff line numberDiff line change
@@ -4452,6 +4452,41 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
44524452
}
44534453
}
44544454

4455+
/// If the type failed selection but the trait is implemented for `(T,)`, suggest that the user
4456+
/// creates a unary tuple
4457+
///
4458+
/// This is a common gotcha when using libraries that emulate variadic functions with traits for tuples.
4459+
pub(super) fn suggest_tuple_wrapping(
4460+
&self,
4461+
err: &mut Diag<'_>,
4462+
root_obligation: &PredicateObligation<'tcx>,
4463+
obligation: &PredicateObligation<'tcx>,
4464+
) {
4465+
let ObligationCauseCode::FunctionArg { arg_hir_id, .. } = obligation.cause.code() else {
4466+
return;
4467+
};
4468+
4469+
let Some(root_pred) = root_obligation.predicate.as_trait_clause() else { return };
4470+
4471+
let trait_ref = root_pred.map_bound(|root_pred| {
4472+
root_pred
4473+
.trait_ref
4474+
.with_self_ty(self.tcx, Ty::new_tup(self.tcx, &[root_pred.trait_ref.self_ty()]))
4475+
});
4476+
4477+
let obligation =
4478+
Obligation::new(self.tcx, obligation.cause.clone(), obligation.param_env, trait_ref);
4479+
4480+
if self.predicate_must_hold_modulo_regions(&obligation) {
4481+
let arg_span = self.tcx.hir().span(*arg_hir_id);
4482+
err.multipart_suggestion_verbose(
4483+
format!("use a unary tuple instead"),
4484+
vec![(arg_span.shrink_to_lo(), "(".into()), (arg_span.shrink_to_hi(), ",)".into())],
4485+
Applicability::MaybeIncorrect,
4486+
);
4487+
}
4488+
}
4489+
44554490
pub(super) fn explain_hrtb_projection(
44564491
&self,
44574492
diag: &mut Diag<'_>,

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -951,18 +951,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
951951
});
952952

953953
// We must additionally check that the return type impls `Future`.
954-
955-
// FIXME(async_closures): Investigate this before stabilization.
956-
// We instantiate this binder eagerly because the `confirm_future_candidate`
957-
// method doesn't support higher-ranked futures, which the `AsyncFn`
958-
// traits expressly allow the user to write. To fix this correctly,
959-
// we'd need to instantiate trait bounds before we get to selection,
960-
// like the new trait solver does.
961954
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
962-
let placeholder_output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
963955
nested.push(obligation.with(
964956
tcx,
965-
ty::TraitRef::new(tcx, future_trait_def_id, [placeholder_output_ty]),
957+
sig.output().map_bound(|output_ty| {
958+
ty::TraitRef::new(tcx, future_trait_def_id, [output_ty])
959+
}),
966960
));
967961

968962
(trait_ref, Ty::from_closure_kind(tcx, ty::ClosureKind::Fn))

library/rustc-std-workspace-core/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ it'll look like
2727

2828
when Cargo invokes the compiler, satisfying the implicit `extern crate core`
2929
directive injected by the compiler.
30+
31+
The sources for the crates.io version can be found in
32+
[`src/rustc-std-workspace`](../../src/rustc-std-workspace).

src/rustc-std-workspace/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
See [`library/rustc-std-workspace-core/README.md`](../../library/rustc-std-workspace-core/README.md) for context.
2+
3+
These are the crates.io versions of these crates, as opposed to the versions
4+
in `library` which are the ones used inside the rustc workspace.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "rustc-std-workspace-alloc"
3+
version = "1.0.1"
4+
authors = ["Alex Crichton <[email protected]>"]
5+
edition = "2021"
6+
license = 'MIT/Apache-2.0'
7+
description = """
8+
crate for integration of crates.io crates into rust-lang/rust standard library workspace
9+
"""
10+
11+
repository = "https://github.com/rust-lang/rust/tree/master/src/rustc-std-workspace"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![no_std]
2+
extern crate alloc as the_alloc;
3+
pub use the_alloc::*;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "rustc-std-workspace-core"
3+
version = "1.0.1"
4+
authors = ["Alex Crichton <[email protected]>"]
5+
edition = "2021"
6+
license = "MIT/Apache-2.0"
7+
description = """
8+
crate for integration of crates.io crates into rust-lang/rust standard library workspace
9+
"""
10+
11+
repository = "https://github.com/rust-lang/rust/tree/master/src/rustc-std-workspace"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![no_std]
2+
extern crate core as the_core;
3+
pub use the_core::*;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "rustc-std-workspace-std"
3+
version = "1.0.1"
4+
authors = ["Alex Crichton <[email protected]>"]
5+
edition = "2021"
6+
license = "MIT/Apache-2.0"
7+
description = """
8+
crate for integration of crates.io crates into rust-lang/rust standard library workspace
9+
"""
10+
11+
repository = "https://github.com/rust-lang/rust/tree/master/src/rustc-std-workspace"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub use std::*;

tests/ui-fulldeps/hash-stable-is-unstable.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1+
//@ ignore-stage1 FIXME: this line can be removed once these new error messages are in stage 0 rustc
12
//@ compile-flags: -Zdeduplicate-diagnostics=yes
23
extern crate rustc_data_structures;
3-
//~^ use of unstable library feature 'rustc_private'
4+
//~^ use of unstable library feature `rustc_private`
45
//~| NOTE: issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
56
//~| NOTE: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
67
extern crate rustc_macros;
7-
//~^ use of unstable library feature 'rustc_private'
8+
//~^ use of unstable library feature `rustc_private`
89
//~| NOTE: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
910
//~| NOTE: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1011
extern crate rustc_query_system;
11-
//~^ use of unstable library feature 'rustc_private'
12+
//~^ use of unstable library feature `rustc_private`
1213
//~| NOTE: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
1314
//~| NOTE: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1415

1516
use rustc_macros::HashStable;
16-
//~^ use of unstable library feature 'rustc_private'
17+
//~^ use of unstable library feature `rustc_private`
1718
//~| NOTE: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
1819
//~| NOTE: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1920

2021
#[derive(HashStable)]
21-
//~^ use of unstable library feature 'rustc_private'
22+
//~^ use of unstable library feature `rustc_private`
2223
//~| NOTE: in this expansion of #[derive(HashStable)]
2324
//~| NOTE: in this expansion of #[derive(HashStable)]
2425
//~| NOTE: in this expansion of #[derive(HashStable)]

tests/ui-fulldeps/hash-stable-is-unstable.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
2-
--> $DIR/hash-stable-is-unstable.rs:2:1
1+
error[E0658]: use of unstable library feature `rustc_private`: this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
2+
--> $DIR/hash-stable-is-unstable.rs:3:1
33
|
44
LL | extern crate rustc_data_structures;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,8 +8,8 @@ LL | extern crate rustc_data_structures;
88
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

11-
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
12-
--> $DIR/hash-stable-is-unstable.rs:6:1
11+
error[E0658]: use of unstable library feature `rustc_private`: this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
12+
--> $DIR/hash-stable-is-unstable.rs:7:1
1313
|
1414
LL | extern crate rustc_macros;
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -18,8 +18,8 @@ LL | extern crate rustc_macros;
1818
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

21-
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
22-
--> $DIR/hash-stable-is-unstable.rs:10:1
21+
error[E0658]: use of unstable library feature `rustc_private`: this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
22+
--> $DIR/hash-stable-is-unstable.rs:11:1
2323
|
2424
LL | extern crate rustc_query_system;
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -28,8 +28,8 @@ LL | extern crate rustc_query_system;
2828
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
2929
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3030

31-
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
32-
--> $DIR/hash-stable-is-unstable.rs:15:5
31+
error[E0658]: use of unstable library feature `rustc_private`: this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
32+
--> $DIR/hash-stable-is-unstable.rs:16:5
3333
|
3434
LL | use rustc_macros::HashStable;
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -38,8 +38,8 @@ LL | use rustc_macros::HashStable;
3838
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
3939
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
4040

41-
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
42-
--> $DIR/hash-stable-is-unstable.rs:20:10
41+
error[E0658]: use of unstable library feature `rustc_private`: this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
42+
--> $DIR/hash-stable-is-unstable.rs:21:10
4343
|
4444
LL | #[derive(HashStable)]
4545
| ^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
//@ ignore-stage1 FIXME: this line can be removed once these new error messages are in stage 0 rustc
12
//@ edition:2018
23
//@ compile-flags:--extern rustc_middle
34

45
// Test that `--extern rustc_middle` fails with `rustc_private`.
56

67
pub use rustc_middle;
7-
//~^ ERROR use of unstable library feature 'rustc_private'
8+
//~^ ERROR use of unstable library feature `rustc_private`
89

910
fn main() {}

tests/ui-fulldeps/pathless-extern-unstable.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
2-
--> $DIR/pathless-extern-unstable.rs:6:9
1+
error[E0658]: use of unstable library feature `rustc_private`: this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
2+
--> $DIR/pathless-extern-unstable.rs:7:9
33
|
44
LL | pub use rustc_middle;
55
| ^^^^^^^^^^^^

tests/ui/associated-inherent-types/assoc-inherent-unstable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
#![feature(inherent_associated_types)]
55
#![allow(incomplete_features)]
66

7-
type Data = aux::Owner::Data; //~ ERROR use of unstable library feature 'data'
7+
type Data = aux::Owner::Data; //~ ERROR use of unstable library feature `data`
88

99
fn main() {}

tests/ui/associated-inherent-types/assoc-inherent-unstable.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0658]: use of unstable library feature 'data'
1+
error[E0658]: use of unstable library feature `data`
22
--> $DIR/assoc-inherent-unstable.rs:7:13
33
|
44
LL | type Data = aux::Owner::Data;

tests/ui/async-await/async-fn/edition-2015.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fn foo(x: impl async Fn()) -> impl async Fn() { x }
33
//~| ERROR `async` trait bounds are only allowed in Rust 2018 or later
44
//~| ERROR async closures are unstable
55
//~| ERROR async closures are unstable
6-
//~| ERROR use of unstable library feature 'async_closure'
7-
//~| ERROR use of unstable library feature 'async_closure'
6+
//~| ERROR use of unstable library feature `async_closure`
7+
//~| ERROR use of unstable library feature `async_closure`
88

99
fn main() {}

0 commit comments

Comments
 (0)