Skip to content

Commit a58010d

Browse files
committed
Auto merge of #153782 - JonathanBrouwer:rollup-p5MIIiQ, r=<try>
Rollup of 5 pull requests try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1
2 parents d1ee5e5 + 00aa2f8 commit a58010d

File tree

15 files changed

+265
-94
lines changed

15 files changed

+265
-94
lines changed

compiler/rustc_data_structures/src/sync.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
//! | `Lock<T>` | `RefCell<T>` | `RefCell<T>` or |
2222
//! | | | `parking_lot::Mutex<T>` |
2323
//! | `RwLock<T>` | `RefCell<T>` | `parking_lot::RwLock<T>` |
24-
//! | `MTLock<T>` [^1] | `T` | `Lock<T>` |
25-
//!
26-
//! [^1]: `MTLock` is similar to `Lock`, but the serial version avoids the cost
27-
//! of a `RefCell`. This is appropriate when interior mutability is not
28-
//! required.
2924
3025
use std::collections::HashMap;
3126
use std::hash::{BuildHasher, Hash};
@@ -106,38 +101,6 @@ mod mode {
106101
}
107102
}
108103

109-
// FIXME(parallel_compiler): Get rid of these aliases across the compiler.
110-
111-
#[derive(Debug, Default)]
112-
pub struct MTLock<T>(Lock<T>);
113-
114-
impl<T> MTLock<T> {
115-
#[inline(always)]
116-
pub fn new(inner: T) -> Self {
117-
MTLock(Lock::new(inner))
118-
}
119-
120-
#[inline(always)]
121-
pub fn into_inner(self) -> T {
122-
self.0.into_inner()
123-
}
124-
125-
#[inline(always)]
126-
pub fn get_mut(&mut self) -> &mut T {
127-
self.0.get_mut()
128-
}
129-
130-
#[inline(always)]
131-
pub fn lock(&self) -> LockGuard<'_, T> {
132-
self.0.lock()
133-
}
134-
135-
#[inline(always)]
136-
pub fn lock_mut(&self) -> LockGuard<'_, T> {
137-
self.lock()
138-
}
139-
}
140-
141104
/// This makes locks panic if they are already held.
142105
/// It is only useful when you are running in a single thread
143106
const ERROR_CHECKING: bool = false;

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ use std::cell::OnceCell;
209209
use std::ops::ControlFlow;
210210

211211
use rustc_data_structures::fx::FxIndexMap;
212-
use rustc_data_structures::sync::{MTLock, par_for_each_in};
212+
use rustc_data_structures::sync::{Lock, par_for_each_in};
213213
use rustc_data_structures::unord::{UnordMap, UnordSet};
214214
use rustc_hir as hir;
215215
use rustc_hir::attrs::InlineAttr;
@@ -251,12 +251,12 @@ pub(crate) enum MonoItemCollectionStrategy {
251251
/// The state that is shared across the concurrent threads that are doing collection.
252252
struct SharedState<'tcx> {
253253
/// Items that have been or are currently being recursively collected.
254-
visited: MTLock<UnordSet<MonoItem<'tcx>>>,
254+
visited: Lock<UnordSet<MonoItem<'tcx>>>,
255255
/// Items that have been or are currently being recursively treated as "mentioned", i.e., their
256256
/// consts are evaluated but nothing is added to the collection.
257-
mentioned: MTLock<UnordSet<MonoItem<'tcx>>>,
257+
mentioned: Lock<UnordSet<MonoItem<'tcx>>>,
258258
/// Which items are being used where, for better errors.
259-
usage_map: MTLock<UsageMap<'tcx>>,
259+
usage_map: Lock<UsageMap<'tcx>>,
260260
}
261261

262262
pub(crate) struct UsageMap<'tcx> {
@@ -359,7 +359,7 @@ fn collect_items_root<'tcx>(
359359
state: &SharedState<'tcx>,
360360
recursion_limit: Limit,
361361
) {
362-
if !state.visited.lock_mut().insert(starting_item.node) {
362+
if !state.visited.lock().insert(starting_item.node) {
363363
// We've been here already, no need to search again.
364364
return;
365365
}
@@ -568,21 +568,21 @@ fn collect_items_rec<'tcx>(
568568
// This is part of the output of collection and hence only relevant for "used" items.
569569
// ("Mentioned" items are only considered internally during collection.)
570570
if mode == CollectionMode::UsedItems {
571-
state.usage_map.lock_mut().record_used(starting_item.node, &used_items);
571+
state.usage_map.lock().record_used(starting_item.node, &used_items);
572572
}
573573

574574
{
575575
let mut visited = OnceCell::default();
576576
if mode == CollectionMode::UsedItems {
577577
used_items
578578
.items
579-
.retain(|k, _| visited.get_mut_or_init(|| state.visited.lock_mut()).insert(*k));
579+
.retain(|k, _| visited.get_mut_or_init(|| state.visited.lock()).insert(*k));
580580
}
581581

582582
let mut mentioned = OnceCell::default();
583583
mentioned_items.items.retain(|k, _| {
584584
!visited.get_or_init(|| state.visited.lock()).contains(k)
585-
&& mentioned.get_mut_or_init(|| state.mentioned.lock_mut()).insert(*k)
585+
&& mentioned.get_mut_or_init(|| state.mentioned.lock()).insert(*k)
586586
});
587587
}
588588
if mode == CollectionMode::MentionedItems {
@@ -1810,9 +1810,9 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
18101810
debug!("building mono item graph, beginning at roots");
18111811

18121812
let state = SharedState {
1813-
visited: MTLock::new(UnordSet::default()),
1814-
mentioned: MTLock::new(UnordSet::default()),
1815-
usage_map: MTLock::new(UsageMap::new()),
1813+
visited: Lock::new(UnordSet::default()),
1814+
mentioned: Lock::new(UnordSet::default()),
1815+
usage_map: Lock::new(UsageMap::new()),
18161816
};
18171817
let recursion_limit = tcx.recursion_limit();
18181818

compiler/rustc_target/src/callconv/hexagon.rs

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,76 @@
1-
use rustc_abi::TyAbiInterface;
1+
use rustc_abi::{HasDataLayout, TyAbiInterface};
22

3-
use crate::callconv::{ArgAbi, FnAbi};
3+
use crate::callconv::{ArgAbi, FnAbi, Reg, Uniform};
44

5-
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
6-
if ret.layout.is_aggregate() && ret.layout.size.bits() > 64 {
7-
ret.make_indirect();
8-
} else {
5+
fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>)
6+
where
7+
Ty: TyAbiInterface<'a, C> + Copy,
8+
C: HasDataLayout,
9+
{
10+
if !ret.layout.is_sized() {
11+
return;
12+
}
13+
14+
if !ret.layout.is_aggregate() {
915
ret.extend_integer_width_to(32);
16+
return;
17+
}
18+
19+
// Per the Hexagon ABI:
20+
// - Aggregates up to 32 bits are returned in R0
21+
// - Aggregates 33-64 bits are returned in R1:R0
22+
// - Aggregates > 64 bits are returned indirectly via hidden first argument
23+
let size = ret.layout.size;
24+
let bits = size.bits();
25+
if bits <= 32 {
26+
ret.cast_to(Uniform::new(Reg::i32(), size));
27+
} else if bits <= 64 {
28+
ret.cast_to(Uniform::new(Reg::i64(), size));
29+
} else {
30+
ret.make_indirect();
1031
}
1132
}
1233

1334
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
1435
where
1536
Ty: TyAbiInterface<'a, C> + Copy,
37+
C: HasDataLayout,
1638
{
39+
if !arg.layout.is_sized() {
40+
return;
41+
}
1742
if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
1843
arg.make_indirect();
1944
return;
2045
}
21-
if arg.layout.is_aggregate() && arg.layout.size.bits() > 64 {
22-
arg.make_indirect();
23-
} else {
46+
47+
if !arg.layout.is_aggregate() {
2448
arg.extend_integer_width_to(32);
49+
return;
50+
}
51+
52+
// Per the Hexagon ABI:
53+
// - Aggregates up to 32 bits are passed in a single register
54+
// - Aggregates 33-64 bits are passed in a register pair
55+
// - Aggregates > 64 bits are passed on the stack
56+
let size = arg.layout.size;
57+
let bits = size.bits();
58+
if bits <= 32 {
59+
arg.cast_to(Uniform::new(Reg::i32(), size));
60+
} else if bits <= 64 {
61+
arg.cast_to(Uniform::new(Reg::i64(), size));
62+
} else {
63+
arg.pass_by_stack_offset(None);
2564
}
2665
}
2766

2867
pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
2968
where
3069
Ty: TyAbiInterface<'a, C> + Copy,
70+
C: HasDataLayout,
3171
{
3272
if !fn_abi.ret.is_ignore() {
33-
classify_ret(&mut fn_abi.ret);
73+
classify_ret(cx, &mut fn_abi.ret);
3474
}
3575

3676
for arg in fn_abi.args.iter_mut() {

compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,12 +1030,15 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
10301030
let args = self.node_args_opt(expr.hir_id)?;
10311031
let span = tcx.hir_span(segment.hir_id);
10321032
let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
1033+
let have_turbofish = segment.args.is_some_and(|args| {
1034+
args.args.iter().any(|arg| arg.is_ty_or_const())
1035+
});
10331036
InsertableGenericArgs {
10341037
insert_span,
10351038
args,
10361039
generics_def_id: def_id,
10371040
def_id,
1038-
have_turbofish: false,
1041+
have_turbofish,
10391042
}
10401043
};
10411044
return Box::new(insertable.into_iter());

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

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -864,23 +864,63 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
864864
.collect::<Vec<_>>()
865865
.join(", ");
866866

867-
if matches!(obligation.cause.code(), ObligationCauseCode::FunctionArg { .. })
867+
if let ObligationCauseCode::FunctionArg { arg_hir_id, .. } = obligation.cause.code()
868868
&& obligation.cause.span.can_be_used_for_suggestions()
869869
{
870-
let (span, sugg) = if let Some(snippet) =
871-
self.tcx.sess.source_map().span_to_snippet(obligation.cause.span).ok()
872-
&& snippet.starts_with("|")
873-
{
874-
(obligation.cause.span, format!("({snippet})({args})"))
875-
} else {
876-
(obligation.cause.span.shrink_to_hi(), format!("({args})"))
870+
let span = obligation.cause.span;
871+
872+
let arg_expr = match self.tcx.hir_node(*arg_hir_id) {
873+
hir::Node::Expr(expr) => Some(expr),
874+
_ => None,
877875
};
878876

879-
// When the obligation error has been ensured to have been caused by
880-
// an argument, the `obligation.cause.span` points at the expression
881-
// of the argument, so we can provide a suggestion. Otherwise, we give
882-
// a more general note.
883-
err.span_suggestion_verbose(span, msg, sugg, Applicability::HasPlaceholders);
877+
let is_closure_expr =
878+
arg_expr.is_some_and(|expr| matches!(expr.kind, hir::ExprKind::Closure(..)));
879+
880+
// If the user wrote `|| {}()`, suggesting to call the closure would produce `(|| {}())()`,
881+
// which doesn't help and is often outright wrong.
882+
if args.is_empty()
883+
&& let Some(expr) = arg_expr
884+
&& let hir::ExprKind::Closure(closure) = expr.kind
885+
{
886+
let mut body = self.tcx.hir_body(closure.body).value;
887+
888+
// Async closures desugar to a closure returning a coroutine
889+
if let hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async) =
890+
closure.kind
891+
{
892+
let peeled = body.peel_blocks().peel_drop_temps();
893+
if let hir::ExprKind::Closure(inner) = peeled.kind {
894+
body = self.tcx.hir_body(inner.body).value;
895+
}
896+
}
897+
898+
let peeled_body = body.peel_blocks().peel_drop_temps();
899+
if let hir::ExprKind::Call(callee, call_args) = peeled_body.kind
900+
&& call_args.is_empty()
901+
&& let hir::ExprKind::Block(..) = callee.peel_blocks().peel_drop_temps().kind
902+
{
903+
return false;
904+
}
905+
}
906+
907+
if is_closure_expr {
908+
err.multipart_suggestion_verbose(
909+
msg,
910+
vec![
911+
(span.shrink_to_lo(), "(".to_string()),
912+
(span.shrink_to_hi(), format!(")({args})")),
913+
],
914+
Applicability::HasPlaceholders,
915+
);
916+
} else {
917+
err.span_suggestion_verbose(
918+
span.shrink_to_hi(),
919+
msg,
920+
format!("({args})"),
921+
Applicability::HasPlaceholders,
922+
);
923+
}
884924
} else if let DefIdOrName::DefId(def_id) = def_id_or_name {
885925
let name = match self.tcx.hir_get_if_local(def_id) {
886926
Some(hir::Node::Expr(hir::Expr {

src/bootstrap/src/core/config/flags.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,16 +570,21 @@ impl Subcommand {
570570

571571
pub fn test_target(&self) -> TestTarget {
572572
match *self {
573-
Subcommand::Test { all_targets, doc, tests, .. }
574-
| Subcommand::Miri { all_targets, doc, tests, .. } => match (all_targets, doc, tests) {
575-
(true, true, _) | (true, _, true) | (_, true, true) => {
576-
panic!("You can only set one of `--all-targets`, `--doc` and `--tests`.")
573+
Subcommand::Test { mut all_targets, doc, tests, no_doc, .. }
574+
| Subcommand::Miri { mut all_targets, doc, tests, no_doc, .. } => {
575+
// for backwards compatibility --no-doc keeps working
576+
all_targets = all_targets || no_doc;
577+
578+
match (all_targets, doc, tests) {
579+
(true, true, _) | (true, _, true) | (_, true, true) => {
580+
panic!("You can only set one of `--all-targets`, `--doc` and `--tests`.")
581+
}
582+
(true, false, false) => TestTarget::AllTargets,
583+
(false, true, false) => TestTarget::DocOnly,
584+
(false, false, true) => TestTarget::Tests,
585+
(false, false, false) => TestTarget::Default,
577586
}
578-
(true, false, false) => TestTarget::AllTargets,
579-
(false, true, false) => TestTarget::DocOnly,
580-
(false, false, true) => TestTarget::Tests,
581-
(false, false, false) => TestTarget::Default,
582-
},
587+
}
583588
_ => TestTarget::Default,
584589
}
585590
}

src/doc/rustc-dev-guide/src/parallel-rustc.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ are implemented differently depending on whether `parallel-compiler` is true.
4848
| -------------------------------- | --------------------------------------------------- | ------------ |
4949
| Lock\<T> | (parking_lot::Mutex\<T>) | (std::cell::RefCell) |
5050
| RwLock\<T> | (parking_lot::RwLock\<T>) | (std::cell::RefCell) |
51-
| MTLock\<T> | (Lock\<T>) | (T) |
5251
| ReadGuard | parking_lot::RwLockReadGuard | std::cell::Ref |
5352
| MappedReadGuard | parking_lot::MappedRwLockReadGuard | std::cell::Ref |
5453
| WriteGuard | parking_lot::RwLockWriteGuard | std::cell::RefMut |

tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ LL | fn check(_: impl std::marker::ConstParamTy_) {}
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
3333
help: use parentheses to call this closure
3434
|
35-
LL - check(|| {});
36-
LL + check((|| {})());
37-
|
35+
LL | check((|| {})());
36+
| + +++
3837

3938
error[E0277]: `fn()` can't be used as a const parameter type
4039
--> $DIR/const_param_ty_bad.rs:9:11
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Regression test for #153732.
2+
//
3+
// When a method call already has turbofish type arguments, don't suggest
4+
// rewriting them — the suggestion just rewrites user syntax into
5+
// fully-qualified form without resolving anything.
6+
//
7+
// The span still points at the method name rather than the unresolved `_`;
8+
// fixing that is left as future work.
9+
10+
struct S;
11+
12+
impl S {
13+
fn f<A, B>(self, _a: A) -> B {
14+
todo!()
15+
}
16+
}
17+
18+
fn with_turbofish() {
19+
S.f::<u32, _>(42);
20+
//~^ ERROR type annotations needed
21+
}
22+
23+
fn without_turbofish() {
24+
S.f(42);
25+
//~^ ERROR type annotations needed
26+
}
27+
28+
fn main() {}

0 commit comments

Comments
 (0)