Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #132603

Merged
merged 14 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3196,6 +3196,18 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5c9f15eec8235d7cb775ee6f81891db79b98fd54ba1ad8fae565b88ef1ae4e2"

[[package]]
name = "rustc-std-workspace-alloc"
version = "1.0.1"

[[package]]
name = "rustc-std-workspace-core"
version = "1.0.1"

[[package]]
name = "rustc-std-workspace-std"
version = "1.0.1"

[[package]]
name = "rustc_abi"
version = "0.0.0"
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ resolver = "2"
members = [
"compiler/rustc",
"src/etc/test-float-parse",
"src/rustc-std-workspace/rustc-std-workspace-core",
"src/rustc-std-workspace/rustc-std-workspace-alloc",
"src/rustc-std-workspace/rustc-std-workspace-std",
"src/rustdoc-json-types",
"src/tools/build_helper",
"src/tools/cargotest",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ hir_analysis_missing_trait_item_suggestion = implement the missing item: `{$snip

hir_analysis_missing_trait_item_unstable = not all trait items implemented, missing: `{$missing_item_name}`
.note = default implementation of `{$missing_item_name}` is unstable
.some_note = use of unstable library feature '{$feature}': {$reason}
.none_note = use of unstable library feature '{$feature}'
.some_note = use of unstable library feature `{$feature}`: {$reason}
.none_note = use of unstable library feature `{$feature}`

hir_analysis_missing_type_params =
the type {$parameterCount ->
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,13 @@ fn const_arg_anon_type_of<'tcx>(tcx: TyCtxt<'tcx>, arg_hir_id: HirId, span: Span
// arm would handle this.
//
// I believe this match arm is only needed for GAT but I am not 100% sure - BoxyUwU
Node::Ty(hir_ty @ hir::Ty { kind: TyKind::Path(QPath::TypeRelative(_, segment)), .. }) => {
Node::Ty(hir_ty @ hir::Ty { kind: TyKind::Path(QPath::TypeRelative(ty, segment)), .. }) => {
// Find the Item containing the associated type so we can create an ItemCtxt.
// Using the ItemCtxt lower the HIR for the unresolved assoc type into a
// ty which is a fully resolved projection.
// For the code example above, this would mean lowering `Self::Assoc<3>`
// to a ty::Alias(ty::Projection, `<Self as Foo>::Assoc<3>`).
let item_def_id = tcx
.hir()
.parent_owner_iter(arg_hir_id)
.find(|(_, node)| matches!(node, OwnerNode::Item(_)))
.unwrap()
.0
.def_id;
let item_def_id = tcx.hir().get_parent_item(ty.hir_id).def_id;
let ty = ItemCtxt::new(tcx, item_def_id).lower_ty(hir_ty);

// Iterate through the generics of the projection to find the one that corresponds to
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ pub fn report_unstable(
soft_handler: impl FnOnce(&'static Lint, Span, String),
) {
let msg = match reason {
Some(r) => format!("use of unstable library feature '{feature}': {r}"),
None => format!("use of unstable library feature '{feature}'"),
Some(r) => format!("use of unstable library feature `{feature}`: {r}"),
None => format!("use of unstable library feature `{feature}`"),
};

if is_soft {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2466,6 +2466,10 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
early_dcx.early_fatal("value for threads must be a positive non-zero integer");
}

if unstable_opts.threads == parse::MAX_THREADS_CAP {
early_dcx.early_warn(format!("number of threads was capped at {}", parse::MAX_THREADS_CAP));
}

let fuel = unstable_opts.fuel.is_some() || unstable_opts.print_fuel.is_some();
if fuel && unstable_opts.threads > 1 {
early_dcx.early_fatal("optimization fuel is incompatible with multiple threads");
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,11 @@ mod desc {
"either a boolean (`yes`, `no`, `on`, `off`, etc), or `nll` (default: `nll`)";
}

mod parse {
pub mod parse {
use std::str::FromStr;

pub(crate) use super::*;
pub(crate) const MAX_THREADS_CAP: usize = 256;

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

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

/// Use this for any numeric option that has a static default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}

self.try_to_add_help_message(
&root_obligation,
&obligation,
leaf_trait_predicate,
&mut err,
Expand Down Expand Up @@ -2488,6 +2489,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {

fn try_to_add_help_message(
&self,
root_obligation: &PredicateObligation<'tcx>,
obligation: &PredicateObligation<'tcx>,
trait_predicate: ty::PolyTraitPredicate<'tcx>,
err: &mut Diag<'_>,
Expand Down Expand Up @@ -2575,6 +2577,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
impl_candidates.as_slice(),
span,
);

self.suggest_tuple_wrapping(err, root_obligation, obligation);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4452,6 +4452,41 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}
}

/// If the type failed selection but the trait is implemented for `(T,)`, suggest that the user
/// creates a unary tuple
///
/// This is a common gotcha when using libraries that emulate variadic functions with traits for tuples.
pub(super) fn suggest_tuple_wrapping(
&self,
err: &mut Diag<'_>,
root_obligation: &PredicateObligation<'tcx>,
obligation: &PredicateObligation<'tcx>,
) {
let ObligationCauseCode::FunctionArg { arg_hir_id, .. } = obligation.cause.code() else {
return;
};

let Some(root_pred) = root_obligation.predicate.as_trait_clause() else { return };

let trait_ref = root_pred.map_bound(|root_pred| {
root_pred
.trait_ref
.with_self_ty(self.tcx, Ty::new_tup(self.tcx, &[root_pred.trait_ref.self_ty()]))
});

let obligation =
Obligation::new(self.tcx, obligation.cause.clone(), obligation.param_env, trait_ref);

if self.predicate_must_hold_modulo_regions(&obligation) {
let arg_span = self.tcx.hir().span(*arg_hir_id);
err.multipart_suggestion_verbose(
format!("use a unary tuple instead"),
vec![(arg_span.shrink_to_lo(), "(".into()), (arg_span.shrink_to_hi(), ",)".into())],
Applicability::MaybeIncorrect,
);
}
}

pub(super) fn explain_hrtb_projection(
&self,
diag: &mut Diag<'_>,
Expand Down
12 changes: 3 additions & 9 deletions compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,18 +951,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
});

// We must additionally check that the return type impls `Future`.

// FIXME(async_closures): Investigate this before stabilization.
// We instantiate this binder eagerly because the `confirm_future_candidate`
// method doesn't support higher-ranked futures, which the `AsyncFn`
// traits expressly allow the user to write. To fix this correctly,
// we'd need to instantiate trait bounds before we get to selection,
// like the new trait solver does.
let future_trait_def_id = tcx.require_lang_item(LangItem::Future, None);
let placeholder_output_ty = self.infcx.enter_forall_and_leak_universe(sig.output());
nested.push(obligation.with(
tcx,
ty::TraitRef::new(tcx, future_trait_def_id, [placeholder_output_ty]),
sig.output().map_bound(|output_ty| {
ty::TraitRef::new(tcx, future_trait_def_id, [output_ty])
}),
));

(trait_ref, Ty::from_closure_kind(tcx, ty::ClosureKind::Fn))
Expand Down
3 changes: 3 additions & 0 deletions library/rustc-std-workspace-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ it'll look like

when Cargo invokes the compiler, satisfying the implicit `extern crate core`
directive injected by the compiler.

The sources for the crates.io version can be found in
[`src/rustc-std-workspace`](../../src/rustc-std-workspace).
4 changes: 4 additions & 0 deletions src/rustc-std-workspace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
See [`library/rustc-std-workspace-core/README.md`](../../library/rustc-std-workspace-core/README.md) for context.

These are the crates.io versions of these crates, as opposed to the versions
in `library` which are the ones used inside the rustc workspace.
11 changes: 11 additions & 0 deletions src/rustc-std-workspace/rustc-std-workspace-alloc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "rustc-std-workspace-alloc"
version = "1.0.1"
authors = ["Alex Crichton <[email protected]>"]
edition = "2021"
license = 'MIT/Apache-2.0'
description = """
crate for integration of crates.io crates into rust-lang/rust standard library workspace
"""

repository = "https://github.com/rust-lang/rust/tree/master/src/rustc-std-workspace"
3 changes: 3 additions & 0 deletions src/rustc-std-workspace/rustc-std-workspace-alloc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![no_std]
extern crate alloc as the_alloc;
pub use the_alloc::*;
11 changes: 11 additions & 0 deletions src/rustc-std-workspace/rustc-std-workspace-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "rustc-std-workspace-core"
version = "1.0.1"
authors = ["Alex Crichton <[email protected]>"]
edition = "2021"
license = "MIT/Apache-2.0"
description = """
crate for integration of crates.io crates into rust-lang/rust standard library workspace
"""

repository = "https://github.com/rust-lang/rust/tree/master/src/rustc-std-workspace"
3 changes: 3 additions & 0 deletions src/rustc-std-workspace/rustc-std-workspace-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![no_std]
extern crate core as the_core;
pub use the_core::*;
11 changes: 11 additions & 0 deletions src/rustc-std-workspace/rustc-std-workspace-std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "rustc-std-workspace-std"
version = "1.0.1"
authors = ["Alex Crichton <[email protected]>"]
edition = "2021"
license = "MIT/Apache-2.0"
description = """
crate for integration of crates.io crates into rust-lang/rust standard library workspace
"""

repository = "https://github.com/rust-lang/rust/tree/master/src/rustc-std-workspace"
1 change: 1 addition & 0 deletions src/rustc-std-workspace/rustc-std-workspace-std/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use std::*;
11 changes: 6 additions & 5 deletions tests/ui-fulldeps/hash-stable-is-unstable.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
//@ ignore-stage1 FIXME: this line can be removed once these new error messages are in stage 0 rustc
//@ compile-flags: -Zdeduplicate-diagnostics=yes
extern crate rustc_data_structures;
//~^ use of unstable library feature 'rustc_private'
//~^ use of unstable library feature `rustc_private`
//~| NOTE: issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
//~| NOTE: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
extern crate rustc_macros;
//~^ use of unstable library feature 'rustc_private'
//~^ use of unstable library feature `rustc_private`
//~| NOTE: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
//~| NOTE: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
extern crate rustc_query_system;
//~^ use of unstable library feature 'rustc_private'
//~^ use of unstable library feature `rustc_private`
//~| NOTE: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
//~| NOTE: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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

#[derive(HashStable)]
//~^ use of unstable library feature 'rustc_private'
//~^ use of unstable library feature `rustc_private`
//~| NOTE: in this expansion of #[derive(HashStable)]
//~| NOTE: in this expansion of #[derive(HashStable)]
//~| NOTE: in this expansion of #[derive(HashStable)]
Expand Down
20 changes: 10 additions & 10 deletions tests/ui-fulldeps/hash-stable-is-unstable.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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?
--> $DIR/hash-stable-is-unstable.rs:2: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?
--> $DIR/hash-stable-is-unstable.rs:3:1
|
LL | extern crate rustc_data_structures;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -8,8 +8,8 @@ LL | extern crate rustc_data_structures;
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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?
--> $DIR/hash-stable-is-unstable.rs:6: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?
--> $DIR/hash-stable-is-unstable.rs:7:1
|
LL | extern crate rustc_macros;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -18,8 +18,8 @@ LL | extern crate rustc_macros;
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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?
--> $DIR/hash-stable-is-unstable.rs:10: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?
--> $DIR/hash-stable-is-unstable.rs:11:1
|
LL | extern crate rustc_query_system;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -28,8 +28,8 @@ LL | extern crate rustc_query_system;
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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?
--> $DIR/hash-stable-is-unstable.rs:15:5
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?
--> $DIR/hash-stable-is-unstable.rs:16:5
|
LL | use rustc_macros::HashStable;
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -38,8 +38,8 @@ LL | use rustc_macros::HashStable;
= help: add `#![feature(rustc_private)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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?
--> $DIR/hash-stable-is-unstable.rs:20:10
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?
--> $DIR/hash-stable-is-unstable.rs:21:10
|
LL | #[derive(HashStable)]
| ^^^^^^^^^^
Expand Down
3 changes: 2 additions & 1 deletion tests/ui-fulldeps/pathless-extern-unstable.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//@ ignore-stage1 FIXME: this line can be removed once these new error messages are in stage 0 rustc
//@ edition:2018
//@ compile-flags:--extern rustc_middle

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

pub use rustc_middle;
//~^ ERROR use of unstable library feature 'rustc_private'
//~^ ERROR use of unstable library feature `rustc_private`

fn main() {}
4 changes: 2 additions & 2 deletions tests/ui-fulldeps/pathless-extern-unstable.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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?
--> $DIR/pathless-extern-unstable.rs:6:9
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?
--> $DIR/pathless-extern-unstable.rs:7:9
|
LL | pub use rustc_middle;
| ^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#![feature(inherent_associated_types)]
#![allow(incomplete_features)]

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

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0658]: use of unstable library feature 'data'
error[E0658]: use of unstable library feature `data`
--> $DIR/assoc-inherent-unstable.rs:7:13
|
LL | type Data = aux::Owner::Data;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/async-await/async-fn/edition-2015.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fn foo(x: impl async Fn()) -> impl async Fn() { x }
//~| ERROR `async` trait bounds are only allowed in Rust 2018 or later
//~| ERROR async closures are unstable
//~| ERROR async closures are unstable
//~| ERROR use of unstable library feature 'async_closure'
//~| ERROR use of unstable library feature 'async_closure'
//~| ERROR use of unstable library feature `async_closure`
//~| ERROR use of unstable library feature `async_closure`

fn main() {}
Loading
Loading