Skip to content

Commit 079d231

Browse files
committed
Auto merge of rust-lang#132595 - matthiaskrgr:rollup-2904x8u, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#132153 (Stabilise `const_char_encode_utf16`.) - 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#132594 (Subtree update of `rust-analyzer`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 432972c + 5e494c4 commit 079d231

Some content is hidden

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

73 files changed

+1927
-864
lines changed

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/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/core/src/char/methods.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ impl char {
711711
/// '𝕊'.encode_utf16(&mut b);
712712
/// ```
713713
#[stable(feature = "unicode_encode_char", since = "1.15.0")]
714-
#[rustc_const_unstable(feature = "const_char_encode_utf16", issue = "130660")]
714+
#[rustc_const_stable(feature = "const_char_encode_utf16", since = "CURRENT_RUSTC_VERSION")]
715715
#[inline]
716716
pub const fn encode_utf16(self, dst: &mut [u16]) -> &mut [u16] {
717717
encode_utf16_raw(self as u32, dst)
@@ -1819,7 +1819,10 @@ pub const fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> &mut [u8] {
18191819
/// Panics if the buffer is not large enough.
18201820
/// A buffer of length 2 is large enough to encode any `char`.
18211821
#[unstable(feature = "char_internals", reason = "exposed only for libstd", issue = "none")]
1822-
#[rustc_const_unstable(feature = "const_char_encode_utf16", issue = "130660")]
1822+
#[cfg_attr(
1823+
bootstrap,
1824+
rustc_const_stable(feature = "const_char_encode_utf16", since = "CURRENT_RUSTC_VERSION")
1825+
)]
18231826
#[doc(hidden)]
18241827
#[inline]
18251828
pub const fn encode_utf16_raw(mut code: u32, dst: &mut [u16]) -> &mut [u16] {

library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@
114114
#![feature(const_align_of_val_raw)]
115115
#![feature(const_alloc_layout)]
116116
#![feature(const_black_box)]
117-
#![feature(const_char_encode_utf16)]
118117
#![feature(const_eval_select)]
119118
#![feature(const_exact_div)]
120119
#![feature(const_float_methods)]

src/tools/rust-analyzer/.github/workflows/autopublish.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
cargo workspaces rename --from proc-macro-api proc_macro_api
5252
cargo workspaces rename --from proc-macro-srv proc_macro_srv
5353
cargo workspaces rename --from project-model project_model
54+
cargo workspaces rename --from test-fixture test_fixture
5455
cargo workspaces rename --from test-utils test_utils
5556
cargo workspaces rename --from text-edit text_edit
5657
# Remove library crates from the workspaces so we don't auto-publish them as well

src/tools/rust-analyzer/Cargo.lock

+12-12
Original file line numberDiff line numberDiff line change
@@ -1492,9 +1492,9 @@ dependencies = [
14921492

14931493
[[package]]
14941494
name = "ra-ap-rustc_abi"
1495-
version = "0.75.0"
1495+
version = "0.76.0"
14961496
source = "registry+https://github.com/rust-lang/crates.io-index"
1497-
checksum = "d5bc2cfc7264d84215a08875ef90a1d35f76b5c9ad1993515d2da7e4e40b2b4b"
1497+
checksum = "709fde78db053c78c87776ec738677649f791645883f82ff145f68caf9f18e1a"
14981498
dependencies = [
14991499
"bitflags 2.6.0",
15001500
"ra-ap-rustc_index",
@@ -1503,9 +1503,9 @@ dependencies = [
15031503

15041504
[[package]]
15051505
name = "ra-ap-rustc_index"
1506-
version = "0.75.0"
1506+
version = "0.76.0"
15071507
source = "registry+https://github.com/rust-lang/crates.io-index"
1508-
checksum = "e8929140697812e5dd09e19cf446d85146332363f0dbc125d4214834c34ead96"
1508+
checksum = "da115d496e5abd65e2dceb6883d7597593badfe23fea3439202b8da5a11ea250"
15091509
dependencies = [
15101510
"arrayvec",
15111511
"ra-ap-rustc_index_macros",
@@ -1514,9 +1514,9 @@ dependencies = [
15141514

15151515
[[package]]
15161516
name = "ra-ap-rustc_index_macros"
1517-
version = "0.75.0"
1517+
version = "0.76.0"
15181518
source = "registry+https://github.com/rust-lang/crates.io-index"
1519-
checksum = "514a3f5d04c8b4a2750f29746cc9abb1f78deb7e72e4ad1dc95bbc608f3db157"
1519+
checksum = "be86d06a75a8125c1ace197d5030e6e02721348d32e572baea35c891669ad1e2"
15201520
dependencies = [
15211521
"proc-macro2",
15221522
"quote",
@@ -1525,29 +1525,29 @@ dependencies = [
15251525

15261526
[[package]]
15271527
name = "ra-ap-rustc_lexer"
1528-
version = "0.75.0"
1528+
version = "0.76.0"
15291529
source = "registry+https://github.com/rust-lang/crates.io-index"
1530-
checksum = "276fcb1205da071a0cd64416f3f0e198043c11f176c5b501a45dbf0cb33979f2"
1530+
checksum = "b64b46ae0d8f59acc32e64e0085532b831f0d6182d870a7cd86c046c2c46e722"
15311531
dependencies = [
15321532
"unicode-properties",
15331533
"unicode-xid",
15341534
]
15351535

15361536
[[package]]
15371537
name = "ra-ap-rustc_parse_format"
1538-
version = "0.75.0"
1538+
version = "0.76.0"
15391539
source = "registry+https://github.com/rust-lang/crates.io-index"
1540-
checksum = "961b30b22cfac296b14b72e9f95e79c16cebc8c926872755fb1568a6c4243a62"
1540+
checksum = "dbdaad19ddbd0ff46e947ca8dbb6ae678a112d3938669fb3ad6bfd244917e24b"
15411541
dependencies = [
15421542
"ra-ap-rustc_index",
15431543
"ra-ap-rustc_lexer",
15441544
]
15451545

15461546
[[package]]
15471547
name = "ra-ap-rustc_pattern_analysis"
1548-
version = "0.75.0"
1548+
version = "0.76.0"
15491549
source = "registry+https://github.com/rust-lang/crates.io-index"
1550-
checksum = "614232513814a4b714fea7f11345d31c0c277bca3089bb6ca1ec20870bfc022a"
1550+
checksum = "dc5761e37c78d98ede9f20f6b66526093d0be66aa256d5cbdf214495843ba74d"
15511551
dependencies = [
15521552
"ra-ap-rustc_index",
15531553
"rustc-hash 2.0.0",

src/tools/rust-analyzer/Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ tt = { path = "./crates/tt", version = "0.0.0" }
8484
vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
8585
vfs = { path = "./crates/vfs", version = "0.0.0" }
8686

87-
ra-ap-rustc_lexer = { version = "0.75", default-features = false }
88-
ra-ap-rustc_parse_format = { version = "0.75", default-features = false }
89-
ra-ap-rustc_index = { version = "0.75", default-features = false }
90-
ra-ap-rustc_abi = { version = "0.75", default-features = false }
91-
ra-ap-rustc_pattern_analysis = { version = "0.75", default-features = false }
87+
ra-ap-rustc_lexer = { version = "0.76", default-features = false }
88+
ra-ap-rustc_parse_format = { version = "0.76", default-features = false }
89+
ra-ap-rustc_index = { version = "0.76", default-features = false }
90+
ra-ap-rustc_abi = { version = "0.76", default-features = false }
91+
ra-ap-rustc_pattern_analysis = { version = "0.76", default-features = false }
9292

9393
# local crates that aren't published to crates.io. These should not have versions.
9494
test-fixture = { path = "./crates/test-fixture" }

src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl ExprCollector<'_> {
407407
let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
408408
let generic_args = e
409409
.generic_arg_list()
410-
.and_then(|it| GenericArgs::from_ast(&self.ctx(), it))
410+
.and_then(|it| GenericArgs::from_ast(&mut self.ctx(), it))
411411
.map(Box::new);
412412
self.alloc_expr(
413413
Expr::MethodCall { receiver, method_name, args, generic_args },
@@ -533,7 +533,7 @@ impl ExprCollector<'_> {
533533
ast::Expr::TryExpr(e) => self.collect_try_operator(syntax_ptr, e),
534534
ast::Expr::CastExpr(e) => {
535535
let expr = self.collect_expr_opt(e.expr());
536-
let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.ty());
536+
let type_ref = TypeRef::from_ast_opt(&mut self.ctx(), e.ty());
537537
self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
538538
}
539539
ast::Expr::RefExpr(e) => {
@@ -572,13 +572,15 @@ impl ExprCollector<'_> {
572572
arg_types.reserve_exact(num_params);
573573
for param in pl.params() {
574574
let pat = this.collect_pat_top(param.pat());
575-
let type_ref = param.ty().map(|it| TypeRef::from_ast(&this.ctx(), it));
575+
let type_ref = param.ty().map(|it| TypeRef::from_ast(&mut this.ctx(), it));
576576
args.push(pat);
577577
arg_types.push(type_ref);
578578
}
579579
}
580-
let ret_type =
581-
e.ret_type().and_then(|r| r.ty()).map(|it| TypeRef::from_ast(&this.ctx(), it));
580+
let ret_type = e
581+
.ret_type()
582+
.and_then(|r| r.ty())
583+
.map(|it| TypeRef::from_ast(&mut this.ctx(), it));
582584

583585
let prev_is_lowering_coroutine = mem::take(&mut this.is_lowering_coroutine);
584586
let prev_try_block_label = this.current_try_block_label.take();
@@ -705,7 +707,7 @@ impl ExprCollector<'_> {
705707
ast::Expr::UnderscoreExpr(_) => self.alloc_expr(Expr::Underscore, syntax_ptr),
706708
ast::Expr::AsmExpr(e) => self.lower_inline_asm(e, syntax_ptr),
707709
ast::Expr::OffsetOfExpr(e) => {
708-
let container = TypeRef::from_ast_opt(&self.ctx(), e.ty());
710+
let container = TypeRef::from_ast_opt(&mut self.ctx(), e.ty());
709711
let fields = e.fields().map(|it| it.as_name()).collect();
710712
self.alloc_expr(Expr::OffsetOf(OffsetOf { container, fields }), syntax_ptr)
711713
}
@@ -1317,7 +1319,7 @@ impl ExprCollector<'_> {
13171319
return;
13181320
}
13191321
let pat = self.collect_pat_top(stmt.pat());
1320-
let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&self.ctx(), it));
1322+
let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&mut self.ctx(), it));
13211323
let initializer = stmt.initializer().map(|e| self.collect_expr(e));
13221324
let else_branch = stmt
13231325
.let_else()

src/tools/rust-analyzer/crates/hir-def/src/data.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct FunctionData {
3737
pub name: Name,
3838
pub params: Box<[TypeRefId]>,
3939
pub ret_type: TypeRefId,
40+
// FIXME: why are these stored here? They should be accessed via the query
4041
pub attrs: Attrs,
4142
pub visibility: RawVisibility,
4243
pub abi: Option<Symbol>,

src/tools/rust-analyzer/crates/hir-def/src/dyn_map.rs

+73-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,79 @@
2121
//!
2222
//! This is a work of fiction. Any similarities to Kotlin's `BindingContext` are
2323
//! a coincidence.
24-
pub mod keys;
24+
25+
pub mod keys {
26+
use std::marker::PhantomData;
27+
28+
use hir_expand::{attrs::AttrId, MacroCallId};
29+
use rustc_hash::FxHashMap;
30+
use syntax::{ast, AstNode, AstPtr};
31+
32+
use crate::{
33+
dyn_map::{DynMap, Policy},
34+
BlockId, ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId,
35+
LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId,
36+
TraitId, TypeAliasId, TypeOrConstParamId, UnionId, UseId,
37+
};
38+
39+
pub type Key<K, V> = crate::dyn_map::Key<AstPtr<K>, V, AstPtrPolicy<K, V>>;
40+
41+
pub const BLOCK: Key<ast::BlockExpr, BlockId> = Key::new();
42+
pub const FUNCTION: Key<ast::Fn, FunctionId> = Key::new();
43+
pub const CONST: Key<ast::Const, ConstId> = Key::new();
44+
pub const STATIC: Key<ast::Static, StaticId> = Key::new();
45+
pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new();
46+
pub const IMPL: Key<ast::Impl, ImplId> = Key::new();
47+
pub const TRAIT: Key<ast::Trait, TraitId> = Key::new();
48+
pub const TRAIT_ALIAS: Key<ast::TraitAlias, TraitAliasId> = Key::new();
49+
pub const STRUCT: Key<ast::Struct, StructId> = Key::new();
50+
pub const UNION: Key<ast::Union, UnionId> = Key::new();
51+
pub const ENUM: Key<ast::Enum, EnumId> = Key::new();
52+
pub const EXTERN_CRATE: Key<ast::ExternCrate, ExternCrateId> = Key::new();
53+
pub const USE: Key<ast::Use, UseId> = Key::new();
54+
55+
pub const ENUM_VARIANT: Key<ast::Variant, EnumVariantId> = Key::new();
56+
pub const TUPLE_FIELD: Key<ast::TupleField, FieldId> = Key::new();
57+
pub const RECORD_FIELD: Key<ast::RecordField, FieldId> = Key::new();
58+
pub const TYPE_PARAM: Key<ast::TypeParam, TypeOrConstParamId> = Key::new();
59+
pub const CONST_PARAM: Key<ast::ConstParam, TypeOrConstParamId> = Key::new();
60+
pub const LIFETIME_PARAM: Key<ast::LifetimeParam, LifetimeParamId> = Key::new();
61+
62+
pub const MACRO_RULES: Key<ast::MacroRules, MacroRulesId> = Key::new();
63+
pub const MACRO2: Key<ast::MacroDef, Macro2Id> = Key::new();
64+
pub const PROC_MACRO: Key<ast::Fn, ProcMacroId> = Key::new();
65+
pub const MACRO_CALL: Key<ast::MacroCall, MacroCallId> = Key::new();
66+
pub const ATTR_MACRO_CALL: Key<ast::Item, MacroCallId> = Key::new();
67+
pub const DERIVE_MACRO_CALL: Key<ast::Attr, (AttrId, MacroCallId, Box<[Option<MacroCallId>]>)> =
68+
Key::new();
69+
70+
/// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are
71+
/// equal if they point to exactly the same object.
72+
///
73+
/// In general, we do not guarantee that we have exactly one instance of a
74+
/// syntax tree for each file. We probably should add such guarantee, but, for
75+
/// the time being, we will use identity-less AstPtr comparison.
76+
pub struct AstPtrPolicy<AST, ID> {
77+
_phantom: PhantomData<(AST, ID)>,
78+
}
79+
80+
impl<AST: AstNode + 'static, ID: 'static> Policy for AstPtrPolicy<AST, ID> {
81+
type K = AstPtr<AST>;
82+
type V = ID;
83+
fn insert(map: &mut DynMap, key: AstPtr<AST>, value: ID) {
84+
map.map
85+
.entry::<FxHashMap<AstPtr<AST>, ID>>()
86+
.or_insert_with(Default::default)
87+
.insert(key, value);
88+
}
89+
fn get<'a>(map: &'a DynMap, key: &AstPtr<AST>) -> Option<&'a ID> {
90+
map.map.get::<FxHashMap<AstPtr<AST>, ID>>()?.get(key)
91+
}
92+
fn is_empty(map: &DynMap) -> bool {
93+
map.map.get::<FxHashMap<AstPtr<AST>, ID>>().map_or(true, |it| it.is_empty())
94+
}
95+
}
96+
}
2597

2698
use std::{
2799
hash::Hash,

0 commit comments

Comments
 (0)