Skip to content

Rollup of 4 pull requests #132595

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

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2dfbcb6
docs: create setup documentation
davidkurilla Oct 15, 2024
be7865e
style: fix typos
davidkurilla Oct 15, 2024
32b05c1
docs: remove unnecessary prerequisites setup.md
davidkurilla Oct 22, 2024
3bb20dd
fix: auto-complete import for aliased function and module
dqkqd Oct 23, 2024
af3f990
Add assist to generate a type alias for a function
Giga-Bowser Oct 23, 2024
0ac5c8a
Fix alphabetical order of handlers
Giga-Bowser Oct 23, 2024
75a659e
refactor: separate function for getting import name
dqkqd Oct 24, 2024
1b699b5
fix: handle aliased pattern and simplify testcase
dqkqd Oct 24, 2024
a00b4c2
Add `ty_fn_ptr` function to create function pointer type
Giga-Bowser Oct 24, 2024
d0de3fa
Rework `generate_fn_type_alias`
Giga-Bowser Oct 24, 2024
d7615a9
Cleanup TypeRef lowering
ChayimFriedman2 Oct 28, 2024
a1eb6b3
Merge pull request #18427 from ChayimFriedman2/cleanup-ty
Veykril Oct 29, 2024
1407065
fix: Fix the server not honoring diagnostic refresh support
Veykril Oct 29, 2024
c21de28
Merge pull request #18432 from Veykril/lw-yptzmuxyvxxt
Veykril Oct 29, 2024
d8f6538
Do not render meta info when hovering usages
Veykril Oct 29, 2024
711961d
Publish test-fixture => ra_ap_test_fixture
sam-mccall Oct 29, 2024
8a51cbf
Style hover messages a bit differently
Veykril Oct 29, 2024
3ab7a69
Merge pull request #18436 from Veykril/lw-yvkqwpnwsouo
Veykril Oct 30, 2024
5fe280e
Merge pull request #18385 from Giga-Bowser/master
Veykril Oct 30, 2024
482e63d
Merge pull request #18382 from dqkqd/issue-17042
Veykril Oct 30, 2024
cee3257
Merge pull request #18304 from davidkurilla/docs-create-setup-document
Veykril Oct 30, 2024
6a6b61a
Only parse `safe` as contextual kw in extern blocks
ChayimFriedman2 Oct 30, 2024
2d5b758
Merge pull request #18446 from ChayimFriedman2/safe-statement
Veykril Oct 30, 2024
5aff110
Avoid interior mutability in `TyLoweringContext`
ChayimFriedman2 Oct 30, 2024
7ca05b5
Merge pull request #18437 from sam-mccall/publish_fixture
Veykril Oct 31, 2024
bc862b8
Move child_by_source from hir-def to hir
Veykril Oct 31, 2024
2a9b851
Merge pull request #18448 from Veykril/push-zwuuoytnmnqz
Veykril Oct 31, 2024
b25a3de
Merge pull request #18447 from ChayimFriedman2/cleanup-tylowerctx
Veykril Oct 31, 2024
f0bf75d
Parse patterns with leading pipe properly in all places
ChayimFriedman2 Oct 31, 2024
a5b5b46
Merge pull request #18453 from ChayimFriedman2/leading-or
Veykril Oct 31, 2024
21544d8
Preparing for merge from rust-lang/rust
lnicola Nov 1, 2024
d94c49c
Merge from rust-lang/rust
lnicola Nov 1, 2024
7303227
Bump rustc crates
lnicola Nov 1, 2024
9acf57c
Format code
lnicola Nov 1, 2024
cf6bc48
Merge pull request #18457 from lnicola/sync-from-rust
lnicola Nov 1, 2024
7591eb6
Fix compiler panic with a large number of threads
practicalrs Oct 30, 2024
c10fe34
No need to instantiate binder in confirm_async_closure_candidate
compiler-errors Nov 2, 2024
b431237
Allow static initializers to be const evaluated
Veykril Nov 2, 2024
f5e1dce
Improve error message for too new proc-macro server
benluiwj Nov 2, 2024
db29fd3
Merge pull request #18463 from benluiwj/fix/proc-macro-server-msg-imp…
lnicola Nov 2, 2024
72d9929
Merge pull request #18469 from Veykril/push-zwnywqmvtuts
Veykril Nov 3, 2024
56e89bc
Allow interpreting consts and statics with interpret function command
Veykril Nov 3, 2024
43c20c2
Merge pull request #18470 from Veykril/push-rxmtkvpulotn
Veykril Nov 3, 2024
9f4e719
Fix feature name casing
lnicola Nov 4, 2024
0cd3fb2
Merge pull request #18472 from lnicola/reinterpret-function-casing
lnicola Nov 4, 2024
7faa84e
Stabilise 'const_char_encode_utf16';
bjoernager Nov 4, 2024
2c94cb0
Rollup merge of #132153 - bjoernager:const-char-encode-utf16, r=dtolnay
matthiaskrgr Nov 4, 2024
5fad940
Rollup merge of #132355 - practicalrs:fix_117638, r=SparrowLii
matthiaskrgr Nov 4, 2024
ab693d6
Rollup merge of #132486 - compiler-errors:no-binder, r=lcnr
matthiaskrgr Nov 4, 2024
5e494c4
Rollup merge of #132594 - lnicola:sync-from-ra, r=lnicola
matthiaskrgr Nov 4, 2024
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
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
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
7 changes: 5 additions & 2 deletions library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ impl char {
/// '𝕊'.encode_utf16(&mut b);
/// ```
#[stable(feature = "unicode_encode_char", since = "1.15.0")]
#[rustc_const_unstable(feature = "const_char_encode_utf16", issue = "130660")]
#[rustc_const_stable(feature = "const_char_encode_utf16", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub const fn encode_utf16(self, dst: &mut [u16]) -> &mut [u16] {
encode_utf16_raw(self as u32, dst)
Expand Down Expand Up @@ -1819,7 +1819,10 @@ pub const fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> &mut [u8] {
/// Panics if the buffer is not large enough.
/// A buffer of length 2 is large enough to encode any `char`.
#[unstable(feature = "char_internals", reason = "exposed only for libstd", issue = "none")]
#[rustc_const_unstable(feature = "const_char_encode_utf16", issue = "130660")]
#[cfg_attr(
bootstrap,
rustc_const_stable(feature = "const_char_encode_utf16", since = "CURRENT_RUSTC_VERSION")
)]
#[doc(hidden)]
#[inline]
pub const fn encode_utf16_raw(mut code: u32, dst: &mut [u16]) -> &mut [u16] {
Expand Down
1 change: 0 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
#![feature(const_align_of_val_raw)]
#![feature(const_alloc_layout)]
#![feature(const_black_box)]
#![feature(const_char_encode_utf16)]
#![feature(const_eval_select)]
#![feature(const_exact_div)]
#![feature(const_float_methods)]
Expand Down
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/.github/workflows/autopublish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
cargo workspaces rename --from proc-macro-api proc_macro_api
cargo workspaces rename --from proc-macro-srv proc_macro_srv
cargo workspaces rename --from project-model project_model
cargo workspaces rename --from test-fixture test_fixture
cargo workspaces rename --from test-utils test_utils
cargo workspaces rename --from text-edit text_edit
# Remove library crates from the workspaces so we don't auto-publish them as well
Expand Down
24 changes: 12 additions & 12 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1492,9 +1492,9 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_abi"
version = "0.75.0"
version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5bc2cfc7264d84215a08875ef90a1d35f76b5c9ad1993515d2da7e4e40b2b4b"
checksum = "709fde78db053c78c87776ec738677649f791645883f82ff145f68caf9f18e1a"
dependencies = [
"bitflags 2.6.0",
"ra-ap-rustc_index",
Expand All @@ -1503,9 +1503,9 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_index"
version = "0.75.0"
version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8929140697812e5dd09e19cf446d85146332363f0dbc125d4214834c34ead96"
checksum = "da115d496e5abd65e2dceb6883d7597593badfe23fea3439202b8da5a11ea250"
dependencies = [
"arrayvec",
"ra-ap-rustc_index_macros",
Expand All @@ -1514,9 +1514,9 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_index_macros"
version = "0.75.0"
version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "514a3f5d04c8b4a2750f29746cc9abb1f78deb7e72e4ad1dc95bbc608f3db157"
checksum = "be86d06a75a8125c1ace197d5030e6e02721348d32e572baea35c891669ad1e2"
dependencies = [
"proc-macro2",
"quote",
Expand All @@ -1525,29 +1525,29 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_lexer"
version = "0.75.0"
version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "276fcb1205da071a0cd64416f3f0e198043c11f176c5b501a45dbf0cb33979f2"
checksum = "b64b46ae0d8f59acc32e64e0085532b831f0d6182d870a7cd86c046c2c46e722"
dependencies = [
"unicode-properties",
"unicode-xid",
]

[[package]]
name = "ra-ap-rustc_parse_format"
version = "0.75.0"
version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "961b30b22cfac296b14b72e9f95e79c16cebc8c926872755fb1568a6c4243a62"
checksum = "dbdaad19ddbd0ff46e947ca8dbb6ae678a112d3938669fb3ad6bfd244917e24b"
dependencies = [
"ra-ap-rustc_index",
"ra-ap-rustc_lexer",
]

[[package]]
name = "ra-ap-rustc_pattern_analysis"
version = "0.75.0"
version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "614232513814a4b714fea7f11345d31c0c277bca3089bb6ca1ec20870bfc022a"
checksum = "dc5761e37c78d98ede9f20f6b66526093d0be66aa256d5cbdf214495843ba74d"
dependencies = [
"ra-ap-rustc_index",
"rustc-hash 2.0.0",
Expand Down
10 changes: 5 additions & 5 deletions src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ tt = { path = "./crates/tt", version = "0.0.0" }
vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
vfs = { path = "./crates/vfs", version = "0.0.0" }

ra-ap-rustc_lexer = { version = "0.75", default-features = false }
ra-ap-rustc_parse_format = { version = "0.75", default-features = false }
ra-ap-rustc_index = { version = "0.75", default-features = false }
ra-ap-rustc_abi = { version = "0.75", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.75", default-features = false }
ra-ap-rustc_lexer = { version = "0.76", default-features = false }
ra-ap-rustc_parse_format = { version = "0.76", default-features = false }
ra-ap-rustc_index = { version = "0.76", default-features = false }
ra-ap-rustc_abi = { version = "0.76", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.76", default-features = false }

# local crates that aren't published to crates.io. These should not have versions.
test-fixture = { path = "./crates/test-fixture" }
Expand Down
16 changes: 9 additions & 7 deletions src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl ExprCollector<'_> {
let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
let generic_args = e
.generic_arg_list()
.and_then(|it| GenericArgs::from_ast(&self.ctx(), it))
.and_then(|it| GenericArgs::from_ast(&mut self.ctx(), it))
.map(Box::new);
self.alloc_expr(
Expr::MethodCall { receiver, method_name, args, generic_args },
Expand Down Expand Up @@ -533,7 +533,7 @@ impl ExprCollector<'_> {
ast::Expr::TryExpr(e) => self.collect_try_operator(syntax_ptr, e),
ast::Expr::CastExpr(e) => {
let expr = self.collect_expr_opt(e.expr());
let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.ty());
let type_ref = TypeRef::from_ast_opt(&mut self.ctx(), e.ty());
self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
}
ast::Expr::RefExpr(e) => {
Expand Down Expand Up @@ -572,13 +572,15 @@ impl ExprCollector<'_> {
arg_types.reserve_exact(num_params);
for param in pl.params() {
let pat = this.collect_pat_top(param.pat());
let type_ref = param.ty().map(|it| TypeRef::from_ast(&this.ctx(), it));
let type_ref = param.ty().map(|it| TypeRef::from_ast(&mut this.ctx(), it));
args.push(pat);
arg_types.push(type_ref);
}
}
let ret_type =
e.ret_type().and_then(|r| r.ty()).map(|it| TypeRef::from_ast(&this.ctx(), it));
let ret_type = e
.ret_type()
.and_then(|r| r.ty())
.map(|it| TypeRef::from_ast(&mut this.ctx(), it));

let prev_is_lowering_coroutine = mem::take(&mut this.is_lowering_coroutine);
let prev_try_block_label = this.current_try_block_label.take();
Expand Down Expand Up @@ -705,7 +707,7 @@ impl ExprCollector<'_> {
ast::Expr::UnderscoreExpr(_) => self.alloc_expr(Expr::Underscore, syntax_ptr),
ast::Expr::AsmExpr(e) => self.lower_inline_asm(e, syntax_ptr),
ast::Expr::OffsetOfExpr(e) => {
let container = TypeRef::from_ast_opt(&self.ctx(), e.ty());
let container = TypeRef::from_ast_opt(&mut self.ctx(), e.ty());
let fields = e.fields().map(|it| it.as_name()).collect();
self.alloc_expr(Expr::OffsetOf(OffsetOf { container, fields }), syntax_ptr)
}
Expand Down Expand Up @@ -1317,7 +1319,7 @@ impl ExprCollector<'_> {
return;
}
let pat = self.collect_pat_top(stmt.pat());
let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&self.ctx(), it));
let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&mut self.ctx(), it));
let initializer = stmt.initializer().map(|e| self.collect_expr(e));
let else_branch = stmt
.let_else()
Expand Down
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/crates/hir-def/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct FunctionData {
pub name: Name,
pub params: Box<[TypeRefId]>,
pub ret_type: TypeRefId,
// FIXME: why are these stored here? They should be accessed via the query
pub attrs: Attrs,
pub visibility: RawVisibility,
pub abi: Option<Symbol>,
Expand Down
74 changes: 73 additions & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/dyn_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,79 @@
//!
//! This is a work of fiction. Any similarities to Kotlin's `BindingContext` are
//! a coincidence.
pub mod keys;

pub mod keys {
use std::marker::PhantomData;

use hir_expand::{attrs::AttrId, MacroCallId};
use rustc_hash::FxHashMap;
use syntax::{ast, AstNode, AstPtr};

use crate::{
dyn_map::{DynMap, Policy},
BlockId, ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId,
LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId,
TraitId, TypeAliasId, TypeOrConstParamId, UnionId, UseId,
};

pub type Key<K, V> = crate::dyn_map::Key<AstPtr<K>, V, AstPtrPolicy<K, V>>;

pub const BLOCK: Key<ast::BlockExpr, BlockId> = Key::new();
pub const FUNCTION: Key<ast::Fn, FunctionId> = Key::new();
pub const CONST: Key<ast::Const, ConstId> = Key::new();
pub const STATIC: Key<ast::Static, StaticId> = Key::new();
pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new();
pub const IMPL: Key<ast::Impl, ImplId> = Key::new();
pub const TRAIT: Key<ast::Trait, TraitId> = Key::new();
pub const TRAIT_ALIAS: Key<ast::TraitAlias, TraitAliasId> = Key::new();
pub const STRUCT: Key<ast::Struct, StructId> = Key::new();
pub const UNION: Key<ast::Union, UnionId> = Key::new();
pub const ENUM: Key<ast::Enum, EnumId> = Key::new();
pub const EXTERN_CRATE: Key<ast::ExternCrate, ExternCrateId> = Key::new();
pub const USE: Key<ast::Use, UseId> = Key::new();

pub const ENUM_VARIANT: Key<ast::Variant, EnumVariantId> = Key::new();
pub const TUPLE_FIELD: Key<ast::TupleField, FieldId> = Key::new();
pub const RECORD_FIELD: Key<ast::RecordField, FieldId> = Key::new();
pub const TYPE_PARAM: Key<ast::TypeParam, TypeOrConstParamId> = Key::new();
pub const CONST_PARAM: Key<ast::ConstParam, TypeOrConstParamId> = Key::new();
pub const LIFETIME_PARAM: Key<ast::LifetimeParam, LifetimeParamId> = Key::new();

pub const MACRO_RULES: Key<ast::MacroRules, MacroRulesId> = Key::new();
pub const MACRO2: Key<ast::MacroDef, Macro2Id> = Key::new();
pub const PROC_MACRO: Key<ast::Fn, ProcMacroId> = Key::new();
pub const MACRO_CALL: Key<ast::MacroCall, MacroCallId> = Key::new();
pub const ATTR_MACRO_CALL: Key<ast::Item, MacroCallId> = Key::new();
pub const DERIVE_MACRO_CALL: Key<ast::Attr, (AttrId, MacroCallId, Box<[Option<MacroCallId>]>)> =
Key::new();

/// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are
/// equal if they point to exactly the same object.
///
/// In general, we do not guarantee that we have exactly one instance of a
/// syntax tree for each file. We probably should add such guarantee, but, for
/// the time being, we will use identity-less AstPtr comparison.
pub struct AstPtrPolicy<AST, ID> {
_phantom: PhantomData<(AST, ID)>,
}

impl<AST: AstNode + 'static, ID: 'static> Policy for AstPtrPolicy<AST, ID> {
type K = AstPtr<AST>;
type V = ID;
fn insert(map: &mut DynMap, key: AstPtr<AST>, value: ID) {
map.map
.entry::<FxHashMap<AstPtr<AST>, ID>>()
.or_insert_with(Default::default)
.insert(key, value);
}
fn get<'a>(map: &'a DynMap, key: &AstPtr<AST>) -> Option<&'a ID> {
map.map.get::<FxHashMap<AstPtr<AST>, ID>>()?.get(key)
}
fn is_empty(map: &DynMap) -> bool {
map.map.get::<FxHashMap<AstPtr<AST>, ID>>().map_or(true, |it| it.is_empty())
}
}
}

use std::{
hash::Hash,
Expand Down
Loading
Loading