Skip to content

Subtree update of rust-analyzer #134377

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

Merged
merged 43 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1bafbe1
Unload proc-macro dlls on changed timestamp
Veykril Dec 11, 2024
aef05d4
Fix copied proc-macros not being cleaned up on exit
Veykril Dec 11, 2024
3dcda33
minor: Add `item_const` constructor to `SyntaxFactory`
Giga-Bowser Dec 8, 2024
92ba350
internal: Move `is_body_const` to `ide_assists::utils`
Giga-Bowser Dec 8, 2024
e230052
feat: Add an assist to extract an expression into a constant
Giga-Bowser Dec 9, 2024
2d54e06
minor: Add `item_static` constructor to `SyntaxFactory`
Giga-Bowser Dec 11, 2024
2950325
Properly handle different defaults for severity of lints
ChayimFriedman2 Nov 2, 2024
a63defa
feat: Add an assist to extract an expression into a static
Giga-Bowser Dec 11, 2024
d16909c
minor: Group `extract_function` with other extraction assists
Giga-Bowser Dec 11, 2024
ef879f7
Fix publish workflow link in manual
samestep Dec 11, 2024
4dc0f27
Merge pull request #18666 from samestep/manual-autopublish-link
lnicola Dec 11, 2024
96d9761
Merge pull request #18466 from ChayimFriedman2/proper-lint-severity
lnicola Dec 11, 2024
41bd955
Generate implementation with items even if snippet text edit is disabled
1hakusai1 Dec 12, 2024
c17d430
Merge pull request #18667 from 1hakusai1/generate_custom_imple_with_n…
Veykril Dec 12, 2024
0815dfb
fix: Fix sourceroot construction for virtual manifests
Veykril Dec 12, 2024
5182170
Merge pull request #18660 from Veykril/push-snumrtvzwqvw
Veykril Dec 12, 2024
d41ad2c
Merge pull request #18668 from Veykril/push-tpkmsyllunqv
Veykril Dec 12, 2024
1428cf6
Only parse the object file once
Veykril Dec 12, 2024
b6b7c57
Fix clippy lints in proc-macro-srv
Veykril Dec 12, 2024
508ce7c
Merge pull request #18669 from Veykril/push-qqkuxtvsmsut
Veykril Dec 12, 2024
05f9d44
Merge pull request #18652 from Giga-Bowser/extract-constant
Veykril Dec 12, 2024
1ae8416
internal: Drop proc-macro server support for ~1.66.0 and older toolch…
Veykril Dec 12, 2024
648a009
Merge pull request #18670 from Veykril/push-ylomnylswnxm
Veykril Dec 12, 2024
ec6e098
Fix typo in error message for invalid casting
p-hofer Dec 12, 2024
3e61459
Merge pull request #18671 from p-hofer/master
Veykril Dec 12, 2024
8f004a2
fix: Panic when displaying generic params with defaults, again
ShoyuVanilla Dec 12, 2024
42aefa7
Merge pull request #18675 from ShoyuVanilla/issue-18664
Veykril Dec 12, 2024
88457c0
internal: Implement `naked_asm!` builtin
Veykril Dec 12, 2024
c57aec8
Merge pull request #18677 from Veykril/push-uumpxklsqpzk
Veykril Dec 12, 2024
54f467b
Do not require a special env var to be set for the proc-macro-srv
Veykril Dec 12, 2024
3a83938
Show expansion errors in expand_macro feature
Veykril Dec 12, 2024
7718173
Merge pull request #18672 from Veykril/push-lurnqpqtzvzq
Veykril Dec 13, 2024
6c1138e
Merge pull request #18674 from Veykril/push-lrxotqknvxvr
Veykril Dec 13, 2024
c8abe14
Fix a few typos
regexident Dec 13, 2024
326a2e5
Merge pull request #18678 from regexident/fix-typos
lnicola Dec 13, 2024
9847e01
Bump typos
lnicola Dec 13, 2024
2338efa
Merge pull request #18681 from lnicola/bump-typos
lnicola Dec 13, 2024
f69b6fc
fix: Revert changes to client capabilities in `bac0ed5`
Giga-Bowser Dec 13, 2024
97de6dc
Merge pull request #18684 from Giga-Bowser/revert-client-changes
lnicola Dec 13, 2024
9e22cbf
internal: Show mir eval errors on hover with debug env var set
Veykril Dec 15, 2024
31a462f
fix: Fix proc-macro dylib names on windows
Veykril Dec 15, 2024
d501b3c
Merge pull request #18694 from Veykril/push-uxpuruvqpwmx
Veykril Dec 15, 2024
5c6bae0
Merge pull request #18693 from Veykril/push-wzoomkkmuolm
lnicola Dec 15, 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
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/.github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ jobs:
timeout-minutes: 10
env:
FORCE_COLOR: 1
TYPOS_VERSION: v1.18.0
TYPOS_VERSION: v1.28.3
steps:
- name: download typos
run: curl -LsSf https://github.com/crate-ci/typos/releases/download/$TYPOS_VERSION/typos-$TYPOS_VERSION-x86_64-unknown-linux-musl.tar.gz | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
Expand Down
7 changes: 6 additions & 1 deletion src/tools/rust-analyzer/.typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ extend-ignore-re = [
"raison d'être",
"inout",
"INOUT",
"optin"
"optin",
"=Pn",
]

[default.extend-words]
Expand All @@ -26,8 +27,12 @@ fo = "fo"
ket = "ket"
makro = "makro"
trivias = "trivias"
thir = "thir"
jod = "jod"

[default.extend-identifiers]
anc = "anc"
datas = "datas"
impl_froms = "impl_froms"
selfs = "selfs"
taits = "taits"
6 changes: 6 additions & 0 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bda8e21c04aca2ae33ffc2fd8c23134f3cac46db123ba97bd9d3f3b8a4a85e1"

[[package]]
name = "edition"
version = "0.0.0"

[[package]]
name = "either"
version = "1.13.0"
Expand Down Expand Up @@ -1266,6 +1270,7 @@ name = "parser"
version = "0.0.0"
dependencies = [
"drop_bomb",
"edition",
"expect-test",
"limit",
"ra-ap-rustc_lexer",
Expand Down Expand Up @@ -2662,6 +2667,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"directories",
"edition",
"either",
"flate2",
"itertools",
Expand Down
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ toolchain = { path = "./crates/toolchain", version = "0.0.0" }
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" }
edition = { path = "./crates/edition", version = "0.0.0" }

ra-ap-rustc_lexer = { version = "0.85", default-features = false }
ra-ap-rustc_parse_format = { version = "0.85", default-features = false }
Expand Down
13 changes: 13 additions & 0 deletions src/tools/rust-analyzer/crates/edition/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "edition"
version = "0.0.0"
rust-version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
repository.workspace = true

[dependencies]

[lints]
workspace = true
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! The edition of the Rust language used in a crate.
// Ideally this would be defined in the span crate, but the dependency chain is all over the place
// wrt to span, parser and syntax.
// This should live in a separate crate because we use it in both actual code and codegen.
use std::fmt;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl BuiltinFnLikeExpander {
}

pub fn is_asm(&self) -> bool {
matches!(self, Self::Asm | Self::GlobalAsm)
matches!(self, Self::Asm | Self::GlobalAsm | Self::NakedAsm)
}
}

Expand Down Expand Up @@ -122,6 +122,7 @@ register_builtin! {
(stringify, Stringify) => stringify_expand,
(asm, Asm) => asm_expand,
(global_asm, GlobalAsm) => asm_expand,
(naked_asm, NakedAsm) => asm_expand,
(cfg, Cfg) => cfg_expand,
(core_panic, CorePanic) => panic_expand,
(std_panic, StdPanic) => panic_expand,
Expand Down
17 changes: 11 additions & 6 deletions src/tools/rust-analyzer/crates/hir-expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use rustc_hash::FxHashMap;
use stdx::TupleExt;
use triomphe::Arc;

use core::fmt;
use std::hash::Hash;

use base_db::{ra_salsa::InternValueTrivial, CrateId};
Expand Down Expand Up @@ -147,6 +148,10 @@ impl ExpandError {
pub fn span(&self) -> Span {
self.inner.1
}

pub fn render_to_string(&self, db: &dyn ExpandDatabase) -> RenderedExpandError {
self.inner.0.render_to_string(db)
}
}

#[derive(Debug, PartialEq, Eq, Clone, Hash)]
Expand All @@ -164,18 +169,18 @@ pub enum ExpandErrorKind {
ProcMacroPanic(Box<str>),
}

impl ExpandError {
pub fn render_to_string(&self, db: &dyn ExpandDatabase) -> RenderedExpandError {
self.inner.0.render_to_string(db)
}
}

pub struct RenderedExpandError {
pub message: String,
pub error: bool,
pub kind: &'static str,
}

impl fmt::Display for RenderedExpandError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)
}
}

impl RenderedExpandError {
const GENERAL_KIND: &str = "macro-error";
}
Expand Down
17 changes: 15 additions & 2 deletions src/tools/rust-analyzer/crates/hir-ty/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,21 @@ impl HirDisplay for Ty {
generic_args_sans_defaults(f, Some(generic_def_id), parameters);
assert!(params_len >= parameters.len());
let defaults = params_len - parameters.len();
let without_impl =
self_param as usize + type_ + const_ + lifetime - defaults;

// Normally, functions cannot have default parameters, but they can,
// for function-like things such as struct names or enum variants.
// The former cannot have defaults but parents, and the later cannot have
// parents but defaults.
// So, if `parent_len` > 0, it have a parent and thus it doesn't have any
// default. Therefore, we shouldn't subtract defaults because those defaults
// are from their parents.
// And if `parent_len` == 0, either parents don't exists or they don't have
// any defaults. Thus, we can - and should - subtract defaults.
let without_impl = if parent_len > 0 {
params_len - parent_len - impl_
} else {
params_len - parent_len - impl_ - defaults
};
// parent's params (those from enclosing impl or trait, if any).
let (fn_params, parent_params) = parameters.split_at(without_impl + impl_);

Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-ty/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl chalk_ir::interner::Interner for Interner {
type InternedConst = Interned<InternedWrapper<ConstData>>;
type InternedConcreteConst = ConstScalar;
type InternedGenericArg = GenericArgData;
// We could do the following, but that saves "only" 20mb on self while increasing inferecene
// We could do the following, but that saves "only" 20mb on self while increasing inference
// time by ~2.5%
// type InternedGoal = Interned<InternedWrapper<GoalData>>;
type InternedGoal = Arc<GoalData>;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4380,7 +4380,7 @@ fn test() {
fn associated_type_in_struct_expr_path() {
// FIXME: All annotation should be resolvable.
// For lines marked as unstable, see rust-lang/rust#86935.
// FIXME: Remove the comments once stablized.
// FIXME: Remove the comments once stabilized.
check_types(
r#"
trait Trait {
Expand Down Expand Up @@ -4416,7 +4416,7 @@ impl Trait for () {
fn associated_type_in_struct_expr_path_enum() {
// FIXME: All annotation should be resolvable.
// For lines marked as unstable, see rust-lang/rust#86935.
// FIXME: Remove the comments once stablized.
// FIXME: Remove the comments once stabilized.
check_types(
r#"
trait Trait {
Expand Down
100 changes: 28 additions & 72 deletions src/tools/rust-analyzer/crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2649,24 +2649,31 @@ impl Const {
Type::from_value_def(db, self.id)
}

/// Evaluate the constant and return the result as a string.
///
/// This function is intended for IDE assistance, different from [`Const::render_eval`].
pub fn eval(self, db: &dyn HirDatabase) -> Result<String, ConstEvalError> {
let c = db.const_eval(self.id.into(), Substitution::empty(Interner), None)?;
Ok(format!("{}", c.display(db, self.krate(db).edition(db))))
/// Evaluate the constant.
pub fn eval(self, db: &dyn HirDatabase) -> Result<EvaluatedConst, ConstEvalError> {
db.const_eval(self.id.into(), Substitution::empty(Interner), None)
.map(|it| EvaluatedConst { const_: it, def: self.id.into() })
}
}

/// Evaluate the constant and return the result as a string, with more detailed information.
///
/// This function is intended for user-facing display.
pub fn render_eval(
self,
db: &dyn HirDatabase,
edition: Edition,
) -> Result<String, ConstEvalError> {
let c = db.const_eval(self.id.into(), Substitution::empty(Interner), None)?;
let data = &c.data(Interner);
impl HasVisibility for Const {
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
db.const_visibility(self.id)
}
}

pub struct EvaluatedConst {
def: DefWithBodyId,
const_: hir_ty::Const,
}

impl EvaluatedConst {
pub fn render(&self, db: &dyn HirDatabase, edition: Edition) -> String {
format!("{}", self.const_.display(db, edition))
}

pub fn render_debug(&self, db: &dyn HirDatabase) -> Result<String, MirEvalError> {
let data = self.const_.data(Interner);
if let TyKind::Scalar(s) = data.ty.kind(Interner) {
if matches!(s, Scalar::Int(_) | Scalar::Uint(_)) {
if let hir_ty::ConstValue::Concrete(c) = &data.value {
Expand All @@ -2689,17 +2696,7 @@ impl Const {
}
}
}
if let Ok(s) = mir::render_const_using_debug_impl(db, self.id.into(), &c) {
Ok(s)
} else {
Ok(format!("{}", c.display(db, edition)))
}
}
}

impl HasVisibility for Const {
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
db.const_visibility(self.id)
mir::render_const_using_debug_impl(db, self.def, &self.const_)
}
}

Expand Down Expand Up @@ -2729,51 +2726,10 @@ impl Static {
Type::from_value_def(db, self.id)
}

/// Evaluate the static and return the result as a string.
///
/// This function is intended for IDE assistance, different from [`Static::render_eval`].
pub fn eval(self, db: &dyn HirDatabase) -> Result<String, ConstEvalError> {
let c = db.const_eval(self.id.into(), Substitution::empty(Interner), None)?;
Ok(format!("{}", c.display(db, self.krate(db).edition(db))))
}

/// Evaluate the static and return the result as a string, with more detailed information.
///
/// This function is intended for user-facing display.
pub fn render_eval(
self,
db: &dyn HirDatabase,
edition: Edition,
) -> Result<String, ConstEvalError> {
let c = db.const_eval(self.id.into(), Substitution::empty(Interner), None)?;
let data = &c.data(Interner);
if let TyKind::Scalar(s) = data.ty.kind(Interner) {
if matches!(s, Scalar::Int(_) | Scalar::Uint(_)) {
if let hir_ty::ConstValue::Concrete(c) = &data.value {
if let hir_ty::ConstScalar::Bytes(b, _) = &c.interned {
let value = u128::from_le_bytes(mir::pad16(b, false));
let value_signed =
i128::from_le_bytes(mir::pad16(b, matches!(s, Scalar::Int(_))));
let mut result = if let Scalar::Int(_) = s {
value_signed.to_string()
} else {
value.to_string()
};
if value >= 10 {
format_to!(result, " ({value:#X})");
return Ok(result);
} else {
return Ok(result);
}
}
}
}
}
if let Ok(s) = mir::render_const_using_debug_impl(db, self.id.into(), &c) {
Ok(s)
} else {
Ok(format!("{}", c.display(db, edition)))
}
/// Evaluate the static initializer.
pub fn eval(self, db: &dyn HirDatabase) -> Result<EvaluatedConst, ConstEvalError> {
db.const_eval(self.id.into(), Substitution::empty(Interner), None)
.map(|it| EvaluatedConst { const_: it, def: self.id.into() })
}
}

Expand Down
Loading
Loading