Skip to content
/ rust Public
forked from rust-lang/rust

Commit 83ab648

Browse files
committed
Auto merge of rust-lang#134377 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents eedc229 + 5c6bae0 commit 83ab648

Some content is hidden

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

71 files changed

+8793
-2177
lines changed

Diff for: src/tools/rust-analyzer/.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ jobs:
220220
timeout-minutes: 10
221221
env:
222222
FORCE_COLOR: 1
223-
TYPOS_VERSION: v1.18.0
223+
TYPOS_VERSION: v1.28.3
224224
steps:
225225
- name: download typos
226226
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

Diff for: src/tools/rust-analyzer/.typos.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ extend-ignore-re = [
1616
"raison d'être",
1717
"inout",
1818
"INOUT",
19-
"optin"
19+
"optin",
20+
"=Pn",
2021
]
2122

2223
[default.extend-words]
@@ -26,8 +27,12 @@ fo = "fo"
2627
ket = "ket"
2728
makro = "makro"
2829
trivias = "trivias"
30+
thir = "thir"
31+
jod = "jod"
2932

3033
[default.extend-identifiers]
34+
anc = "anc"
3135
datas = "datas"
3236
impl_froms = "impl_froms"
3337
selfs = "selfs"
38+
taits = "taits"

Diff for: src/tools/rust-analyzer/Cargo.lock

+6
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ version = "0.1.5"
389389
source = "registry+https://github.com/rust-lang/crates.io-index"
390390
checksum = "9bda8e21c04aca2ae33ffc2fd8c23134f3cac46db123ba97bd9d3f3b8a4a85e1"
391391

392+
[[package]]
393+
name = "edition"
394+
version = "0.0.0"
395+
392396
[[package]]
393397
name = "either"
394398
version = "1.13.0"
@@ -1266,6 +1270,7 @@ name = "parser"
12661270
version = "0.0.0"
12671271
dependencies = [
12681272
"drop_bomb",
1273+
"edition",
12691274
"expect-test",
12701275
"limit",
12711276
"ra-ap-rustc_lexer",
@@ -2662,6 +2667,7 @@ version = "0.1.0"
26622667
dependencies = [
26632668
"anyhow",
26642669
"directories",
2670+
"edition",
26652671
"either",
26662672
"flate2",
26672673
"itertools",

Diff for: src/tools/rust-analyzer/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ toolchain = { path = "./crates/toolchain", version = "0.0.0" }
8383
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" }
86+
edition = { path = "./crates/edition", version = "0.0.0" }
8687

8788
ra-ap-rustc_lexer = { version = "0.85", default-features = false }
8889
ra-ap-rustc_parse_format = { version = "0.85", default-features = false }

Diff for: src/tools/rust-analyzer/crates/edition/Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "edition"
3+
version = "0.0.0"
4+
rust-version.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
authors.workspace = true
8+
repository.workspace = true
9+
10+
[dependencies]
11+
12+
[lints]
13+
workspace = true

Diff for: src/tools/rust-analyzer/crates/parser/src/edition.rs renamed to src/tools/rust-analyzer/crates/edition/src/lib.rs

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

65
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]

Diff for: src/tools/rust-analyzer/crates/hir-expand/src/builtin/fn_macro.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl BuiltinFnLikeExpander {
7474
}
7575

7676
pub fn is_asm(&self) -> bool {
77-
matches!(self, Self::Asm | Self::GlobalAsm)
77+
matches!(self, Self::Asm | Self::GlobalAsm | Self::NakedAsm)
7878
}
7979
}
8080

@@ -122,6 +122,7 @@ register_builtin! {
122122
(stringify, Stringify) => stringify_expand,
123123
(asm, Asm) => asm_expand,
124124
(global_asm, GlobalAsm) => asm_expand,
125+
(naked_asm, NakedAsm) => asm_expand,
125126
(cfg, Cfg) => cfg_expand,
126127
(core_panic, CorePanic) => panic_expand,
127128
(std_panic, StdPanic) => panic_expand,

Diff for: src/tools/rust-analyzer/crates/hir-expand/src/lib.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use rustc_hash::FxHashMap;
2828
use stdx::TupleExt;
2929
use triomphe::Arc;
3030

31+
use core::fmt;
3132
use std::hash::Hash;
3233

3334
use base_db::{ra_salsa::InternValueTrivial, CrateId};
@@ -147,6 +148,10 @@ impl ExpandError {
147148
pub fn span(&self) -> Span {
148149
self.inner.1
149150
}
151+
152+
pub fn render_to_string(&self, db: &dyn ExpandDatabase) -> RenderedExpandError {
153+
self.inner.0.render_to_string(db)
154+
}
150155
}
151156

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

167-
impl ExpandError {
168-
pub fn render_to_string(&self, db: &dyn ExpandDatabase) -> RenderedExpandError {
169-
self.inner.0.render_to_string(db)
170-
}
171-
}
172-
173172
pub struct RenderedExpandError {
174173
pub message: String,
175174
pub error: bool,
176175
pub kind: &'static str,
177176
}
178177

178+
impl fmt::Display for RenderedExpandError {
179+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
180+
write!(f, "{}", self.message)
181+
}
182+
}
183+
179184
impl RenderedExpandError {
180185
const GENERAL_KIND: &str = "macro-error";
181186
}

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/display.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1053,8 +1053,21 @@ impl HirDisplay for Ty {
10531053
generic_args_sans_defaults(f, Some(generic_def_id), parameters);
10541054
assert!(params_len >= parameters.len());
10551055
let defaults = params_len - parameters.len();
1056-
let without_impl =
1057-
self_param as usize + type_ + const_ + lifetime - defaults;
1056+
1057+
// Normally, functions cannot have default parameters, but they can,
1058+
// for function-like things such as struct names or enum variants.
1059+
// The former cannot have defaults but parents, and the later cannot have
1060+
// parents but defaults.
1061+
// So, if `parent_len` > 0, it have a parent and thus it doesn't have any
1062+
// default. Therefore, we shouldn't subtract defaults because those defaults
1063+
// are from their parents.
1064+
// And if `parent_len` == 0, either parents don't exists or they don't have
1065+
// any defaults. Thus, we can - and should - subtract defaults.
1066+
let without_impl = if parent_len > 0 {
1067+
params_len - parent_len - impl_
1068+
} else {
1069+
params_len - parent_len - impl_ - defaults
1070+
};
10581071
// parent's params (those from enclosing impl or trait, if any).
10591072
let (fn_params, parent_params) = parameters.split_at(without_impl + impl_);
10601073

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/interner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl chalk_ir::interner::Interner for Interner {
5555
type InternedConst = Interned<InternedWrapper<ConstData>>;
5656
type InternedConcreteConst = ConstScalar;
5757
type InternedGenericArg = GenericArgData;
58-
// We could do the following, but that saves "only" 20mb on self while increasing inferecene
58+
// We could do the following, but that saves "only" 20mb on self while increasing inference
5959
// time by ~2.5%
6060
// type InternedGoal = Interned<InternedWrapper<GoalData>>;
6161
type InternedGoal = Arc<GoalData>;

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4380,7 +4380,7 @@ fn test() {
43804380
fn associated_type_in_struct_expr_path() {
43814381
// FIXME: All annotation should be resolvable.
43824382
// For lines marked as unstable, see rust-lang/rust#86935.
4383-
// FIXME: Remove the comments once stablized.
4383+
// FIXME: Remove the comments once stabilized.
43844384
check_types(
43854385
r#"
43864386
trait Trait {
@@ -4416,7 +4416,7 @@ impl Trait for () {
44164416
fn associated_type_in_struct_expr_path_enum() {
44174417
// FIXME: All annotation should be resolvable.
44184418
// For lines marked as unstable, see rust-lang/rust#86935.
4419-
// FIXME: Remove the comments once stablized.
4419+
// FIXME: Remove the comments once stabilized.
44204420
check_types(
44214421
r#"
44224422
trait Trait {

Diff for: src/tools/rust-analyzer/crates/hir/src/lib.rs

+28-72
Original file line numberDiff line numberDiff line change
@@ -2649,24 +2649,31 @@ impl Const {
26492649
Type::from_value_def(db, self.id)
26502650
}
26512651

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

2660-
/// Evaluate the constant and return the result as a string, with more detailed information.
2661-
///
2662-
/// This function is intended for user-facing display.
2663-
pub fn render_eval(
2664-
self,
2665-
db: &dyn HirDatabase,
2666-
edition: Edition,
2667-
) -> Result<String, ConstEvalError> {
2668-
let c = db.const_eval(self.id.into(), Substitution::empty(Interner), None)?;
2669-
let data = &c.data(Interner);
2659+
impl HasVisibility for Const {
2660+
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
2661+
db.const_visibility(self.id)
2662+
}
2663+
}
2664+
2665+
pub struct EvaluatedConst {
2666+
def: DefWithBodyId,
2667+
const_: hir_ty::Const,
2668+
}
2669+
2670+
impl EvaluatedConst {
2671+
pub fn render(&self, db: &dyn HirDatabase, edition: Edition) -> String {
2672+
format!("{}", self.const_.display(db, edition))
2673+
}
2674+
2675+
pub fn render_debug(&self, db: &dyn HirDatabase) -> Result<String, MirEvalError> {
2676+
let data = self.const_.data(Interner);
26702677
if let TyKind::Scalar(s) = data.ty.kind(Interner) {
26712678
if matches!(s, Scalar::Int(_) | Scalar::Uint(_)) {
26722679
if let hir_ty::ConstValue::Concrete(c) = &data.value {
@@ -2689,17 +2696,7 @@ impl Const {
26892696
}
26902697
}
26912698
}
2692-
if let Ok(s) = mir::render_const_using_debug_impl(db, self.id.into(), &c) {
2693-
Ok(s)
2694-
} else {
2695-
Ok(format!("{}", c.display(db, edition)))
2696-
}
2697-
}
2698-
}
2699-
2700-
impl HasVisibility for Const {
2701-
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
2702-
db.const_visibility(self.id)
2699+
mir::render_const_using_debug_impl(db, self.def, &self.const_)
27032700
}
27042701
}
27052702

@@ -2729,51 +2726,10 @@ impl Static {
27292726
Type::from_value_def(db, self.id)
27302727
}
27312728

2732-
/// Evaluate the static and return the result as a string.
2733-
///
2734-
/// This function is intended for IDE assistance, different from [`Static::render_eval`].
2735-
pub fn eval(self, db: &dyn HirDatabase) -> Result<String, ConstEvalError> {
2736-
let c = db.const_eval(self.id.into(), Substitution::empty(Interner), None)?;
2737-
Ok(format!("{}", c.display(db, self.krate(db).edition(db))))
2738-
}
2739-
2740-
/// Evaluate the static and return the result as a string, with more detailed information.
2741-
///
2742-
/// This function is intended for user-facing display.
2743-
pub fn render_eval(
2744-
self,
2745-
db: &dyn HirDatabase,
2746-
edition: Edition,
2747-
) -> Result<String, ConstEvalError> {
2748-
let c = db.const_eval(self.id.into(), Substitution::empty(Interner), None)?;
2749-
let data = &c.data(Interner);
2750-
if let TyKind::Scalar(s) = data.ty.kind(Interner) {
2751-
if matches!(s, Scalar::Int(_) | Scalar::Uint(_)) {
2752-
if let hir_ty::ConstValue::Concrete(c) = &data.value {
2753-
if let hir_ty::ConstScalar::Bytes(b, _) = &c.interned {
2754-
let value = u128::from_le_bytes(mir::pad16(b, false));
2755-
let value_signed =
2756-
i128::from_le_bytes(mir::pad16(b, matches!(s, Scalar::Int(_))));
2757-
let mut result = if let Scalar::Int(_) = s {
2758-
value_signed.to_string()
2759-
} else {
2760-
value.to_string()
2761-
};
2762-
if value >= 10 {
2763-
format_to!(result, " ({value:#X})");
2764-
return Ok(result);
2765-
} else {
2766-
return Ok(result);
2767-
}
2768-
}
2769-
}
2770-
}
2771-
}
2772-
if let Ok(s) = mir::render_const_using_debug_impl(db, self.id.into(), &c) {
2773-
Ok(s)
2774-
} else {
2775-
Ok(format!("{}", c.display(db, edition)))
2776-
}
2729+
/// Evaluate the static initializer.
2730+
pub fn eval(self, db: &dyn HirDatabase) -> Result<EvaluatedConst, ConstEvalError> {
2731+
db.const_eval(self.id.into(), Substitution::empty(Interner), None)
2732+
.map(|it| EvaluatedConst { const_: it, def: self.id.into() })
27772733
}
27782734
}
27792735

0 commit comments

Comments
 (0)