Skip to content

Commit 3369e82

Browse files
committed
Auto merge of #147210 - lnicola:sync-from-ra, r=lnicola
`rust-analyzer` subtree update Subtree update of `rust-analyzer` to rust-lang/rust-analyzer@a6bc4a4. Created using https://github.com/rust-lang/josh-sync. r? `@ghost`
2 parents 4da69df + 9cb7d98 commit 3369e82

File tree

118 files changed

+3736
-1519
lines changed

Some content is hidden

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

118 files changed

+3736
-1519
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ jobs:
5656
# Install a pinned rustc commit to avoid surprises
5757
- name: Install Rust toolchain
5858
run: |
59-
RUSTC_VERSION=`cat rust-version`
60-
rustup-toolchain-install-master ${RUSTC_VERSION} -c rust-src -c rustfmt
59+
RUSTC_VERSION=$(cat rust-version)
60+
rustup-toolchain-install-master ${RUSTC_VERSION} -c cargo -c rust-src -c rustfmt
6161
rustup default ${RUSTC_VERSION}
6262
6363
# Emulate a nightly toolchain, because the toolchain installed above does not have "nightly"
@@ -98,9 +98,9 @@ jobs:
9898
run: |
9999
rustup update --no-self-update stable
100100
rustup default stable
101-
rustup component add --toolchain stable rust-src clippy
102-
# We always use a nightly rustfmt, regardless of channel, because we need
103-
# --file-lines.
101+
rustup component add --toolchain stable rust-src clippy rustfmt
102+
# We also install a nightly rustfmt, because we use `--file-lines` in
103+
# a test.
104104
rustup toolchain install nightly --profile minimal --component rustfmt
105105
# https://github.com/actions-rust-lang/setup-rust-toolchain/blob/main/rust.json
106106
- name: Install Rust Problem Matcher

src/tools/rust-analyzer/Cargo.lock

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,12 @@ dependencies = [
545545
"windows-sys 0.59.0",
546546
]
547547

548+
[[package]]
549+
name = "fixedbitset"
550+
version = "0.5.7"
551+
source = "registry+https://github.com/rust-lang/crates.io-index"
552+
checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99"
553+
548554
[[package]]
549555
name = "flate2"
550556
version = "1.1.2"
@@ -775,6 +781,7 @@ dependencies = [
775781
"itertools",
776782
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
777783
"oorandom",
784+
"petgraph",
778785
"project-model",
779786
"query-group-macro",
780787
"ra-ap-rustc_abi",
@@ -1327,9 +1334,9 @@ dependencies = [
13271334

13281335
[[package]]
13291336
name = "memchr"
1330-
version = "2.7.5"
1337+
version = "2.7.6"
13311338
source = "registry+https://github.com/rust-lang/crates.io-index"
1332-
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
1339+
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
13331340

13341341
[[package]]
13351342
name = "memmap2"
@@ -1594,6 +1601,17 @@ dependencies = [
15941601
"libc",
15951602
]
15961603

1604+
[[package]]
1605+
name = "petgraph"
1606+
version = "0.8.2"
1607+
source = "registry+https://github.com/rust-lang/crates.io-index"
1608+
checksum = "54acf3a685220b533e437e264e4d932cfbdc4cc7ec0cd232ed73c08d03b8a7ca"
1609+
dependencies = [
1610+
"fixedbitset",
1611+
"hashbrown 0.15.4",
1612+
"indexmap",
1613+
]
1614+
15971615
[[package]]
15981616
name = "pin-project-lite"
15991617
version = "0.2.16"

src/tools/rust-analyzer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ tracing-subscriber = { version = "0.3.20", default-features = false, features =
170170
triomphe = { version = "0.1.14", default-features = false, features = ["std"] }
171171
url = "2.5.4"
172172
xshell = "0.2.7"
173+
petgraph = { version = "0.8.2", default-features = false }
173174

174175
# We need to freeze the version of the crate, as the raw-api feature is considered unstable
175176
dashmap = { version = "=6.1.0", features = ["raw-api", "inline"] }

src/tools/rust-analyzer/crates/hir-ty/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ rustc_apfloat = "0.2.3"
3434
query-group.workspace = true
3535
salsa.workspace = true
3636
salsa-macros.workspace = true
37+
petgraph.workspace = true
3738

3839
ra-ap-rustc_abi.workspace = true
3940
ra-ap-rustc_index.workspace = true

src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ const AUTODEREF_RECURSION_LIMIT: usize = 20;
3232
/// - the yielded types don't contain inference variables (but may contain `TyKind::Error`).
3333
/// - a type won't be yielded more than once; in other words, the returned iterator will stop if it
3434
/// detects a cycle in the deref chain.
35-
pub fn autoderef(
36-
db: &dyn HirDatabase,
37-
env: Arc<TraitEnvironment>,
35+
pub fn autoderef<'db>(
36+
db: &'db dyn HirDatabase,
37+
env: Arc<TraitEnvironment<'db>>,
3838
ty: crate::Canonical<crate::Ty>,
39-
) -> impl Iterator<Item = crate::Ty> {
39+
) -> impl Iterator<Item = crate::Ty> + use<> {
4040
let mut table = InferenceTable::new(db, env);
4141
let interner = table.interner;
4242
let ty = table.instantiate_canonical(ty);
@@ -298,7 +298,7 @@ fn structurally_normalize_ty<'db>(
298298
) -> Option<(Ty<'db>, PredicateObligations<'db>)> {
299299
let mut ocx = ObligationCtxt::new(&table.infer_ctxt);
300300
let Ok(normalized_ty) =
301-
ocx.structurally_normalize_ty(&ObligationCause::misc(), table.param_env, ty)
301+
ocx.structurally_normalize_ty(&ObligationCause::misc(), table.trait_env.env, ty)
302302
else {
303303
// We shouldn't have errors here in the old solver, except for
304304
// evaluate/fulfill mismatches, but that's not a reason for an ICE.

src/tools/rust-analyzer/crates/hir-ty/src/builder.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
use chalk_ir::{
44
AdtId, DebruijnIndex, Scalar,
55
cast::{Cast, CastTo, Caster},
6-
fold::TypeFoldable,
7-
interner::HasInterner,
86
};
97
use hir_def::{GenericDefId, GenericParamId, TraitId, TypeAliasId, builtin_type::BuiltinType};
108
use smallvec::SmallVec;
119

1210
use crate::{
13-
Binders, BoundVar, CallableSig, GenericArg, GenericArgData, Interner, ProjectionTy,
14-
Substitution, TraitRef, Ty, TyDefId, TyExt, TyKind, consteval::unknown_const_as_generic,
15-
db::HirDatabase, error_lifetime, generics::generics, infer::unify::InferenceTable, primitive,
16-
to_assoc_type_id, to_chalk_trait_id,
11+
BoundVar, CallableSig, GenericArg, GenericArgData, Interner, ProjectionTy, Substitution,
12+
TraitRef, Ty, TyDefId, TyExt, TyKind,
13+
consteval::unknown_const_as_generic,
14+
db::HirDatabase,
15+
error_lifetime,
16+
generics::generics,
17+
infer::unify::InferenceTable,
18+
next_solver::{DbInterner, EarlyBinder, mapping::ChalkToNextSolver},
19+
primitive, to_assoc_type_id, to_chalk_trait_id,
1720
};
1821

1922
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -345,19 +348,20 @@ impl TyBuilder<TypeAliasId> {
345348
}
346349
}
347350

348-
impl<T: HasInterner<Interner = Interner> + TypeFoldable<Interner>> TyBuilder<Binders<T>> {
349-
pub fn build(self) -> T {
351+
impl<'db, T: rustc_type_ir::TypeFoldable<DbInterner<'db>>> TyBuilder<EarlyBinder<'db, T>> {
352+
pub fn build(self, interner: DbInterner<'db>) -> T {
350353
let (b, subst) = self.build_internal();
351-
b.substitute(Interner, &subst)
354+
let args: crate::next_solver::GenericArgs<'db> = subst.to_nextsolver(interner);
355+
b.instantiate(interner, args)
352356
}
353357
}
354358

355-
impl TyBuilder<Binders<Ty>> {
359+
impl<'db> TyBuilder<EarlyBinder<'db, crate::next_solver::Ty<'db>>> {
356360
pub fn def_ty(
357-
db: &dyn HirDatabase,
361+
db: &'db dyn HirDatabase,
358362
def: TyDefId,
359363
parent_subst: Option<Substitution>,
360-
) -> TyBuilder<Binders<Ty>> {
364+
) -> TyBuilder<EarlyBinder<'db, crate::next_solver::Ty<'db>>> {
361365
let poly_ty = db.ty(def);
362366
let id: GenericDefId = match def {
363367
TyDefId::BuiltinType(_) => {
@@ -370,7 +374,10 @@ impl TyBuilder<Binders<Ty>> {
370374
TyBuilder::subst_for_def(db, id, parent_subst).with_data(poly_ty)
371375
}
372376

373-
pub fn impl_self_ty(db: &dyn HirDatabase, def: hir_def::ImplId) -> TyBuilder<Binders<Ty>> {
377+
pub fn impl_self_ty(
378+
db: &'db dyn HirDatabase,
379+
def: hir_def::ImplId,
380+
) -> TyBuilder<EarlyBinder<'db, crate::next_solver::Ty<'db>>> {
374381
TyBuilder::subst_for_def(db, def, None).with_data(db.impl_self_ty(def))
375382
}
376383
}

src/tools/rust-analyzer/crates/hir-ty/src/chalk_ext.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ use crate::{
1515
AdtId, AliasEq, AliasTy, Binders, CallableDefId, CallableSig, Canonical, CanonicalVarKinds,
1616
ClosureId, DynTy, FnPointer, ImplTraitId, InEnvironment, Interner, Lifetime, ProjectionTy,
1717
QuantifiedWhereClause, Substitution, ToChalk, TraitRef, Ty, TyBuilder, TyKind, TypeFlags,
18-
WhereClause, db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id,
19-
from_placeholder_idx, generics::generics, to_chalk_trait_id, utils::ClosureSubst,
18+
WhereClause,
19+
db::HirDatabase,
20+
from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, from_placeholder_idx,
21+
generics::generics,
22+
next_solver::{DbInterner, mapping::NextSolverToChalk},
23+
to_chalk_trait_id,
24+
utils::ClosureSubst,
2025
};
2126

2227
pub trait TyExt {
@@ -372,7 +377,10 @@ impl TyExt for Ty {
372377
let trait_ref = TyBuilder::trait_ref(db, copy_trait).push(self).build();
373378
let env = db.trait_environment_for_body(owner);
374379
let goal = Canonical {
375-
value: InEnvironment::new(&env.env, trait_ref.cast(Interner)),
380+
value: InEnvironment::new(
381+
&env.env.to_chalk(DbInterner::new_with(db, Some(env.krate), env.block)),
382+
trait_ref.cast(Interner),
383+
),
376384
binders: CanonicalVarKinds::empty(Interner),
377385
};
378386
!db.trait_solve(crate_id, None, goal).no_solution()

src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ pub(crate) fn const_eval_cycle_result(
229229
_: &dyn HirDatabase,
230230
_: GeneralConstId,
231231
_: Substitution,
232-
_: Option<Arc<TraitEnvironment>>,
232+
_: Option<Arc<TraitEnvironment<'_>>>,
233233
) -> Result<Const, ConstEvalError> {
234234
Err(ConstEvalError::MirLowerError(MirLowerError::Loop))
235235
}
@@ -252,7 +252,7 @@ pub(crate) fn const_eval_query(
252252
db: &dyn HirDatabase,
253253
def: GeneralConstId,
254254
subst: Substitution,
255-
trait_env: Option<Arc<TraitEnvironment>>,
255+
trait_env: Option<Arc<TraitEnvironment<'_>>>,
256256
) -> Result<Const, ConstEvalError> {
257257
let body = match def {
258258
GeneralConstId::ConstId(c) => {
@@ -327,7 +327,7 @@ pub(crate) fn eval_to_const(
327327
debruijn: DebruijnIndex,
328328
) -> Const {
329329
let db = ctx.db;
330-
let infer = ctx.clone().resolve_all();
330+
let infer = ctx.fixme_resolve_all_clone();
331331
fn has_closure(body: &Body, expr: ExprId) -> bool {
332332
if matches!(body[expr], Expr::Closure { .. }) {
333333
return true;

src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ fn check_fail(
3636
error: impl FnOnce(ConstEvalError) -> bool,
3737
) {
3838
let (db, file_id) = TestDB::with_single_file(ra_fixture);
39-
match eval_goal(&db, file_id) {
39+
salsa::attach(&db, || match eval_goal(&db, file_id) {
4040
Ok(_) => panic!("Expected fail, but it succeeded"),
4141
Err(e) => {
42-
assert!(error(simplify(e.clone())), "Actual error was: {}", pretty_print_err(e, db))
42+
assert!(error(simplify(e.clone())), "Actual error was: {}", pretty_print_err(e, &db))
4343
}
44-
}
44+
})
4545
}
4646

4747
#[track_caller]
@@ -79,36 +79,38 @@ fn check_answer(
7979
check: impl FnOnce(&[u8], &MemoryMap<'_>),
8080
) {
8181
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
82-
let file_id = *file_ids.last().unwrap();
83-
let r = match eval_goal(&db, file_id) {
84-
Ok(t) => t,
85-
Err(e) => {
86-
let err = pretty_print_err(e, db);
87-
panic!("Error in evaluating goal: {err}");
88-
}
89-
};
90-
match &r.data(Interner).value {
91-
chalk_ir::ConstValue::Concrete(c) => match &c.interned {
92-
ConstScalar::Bytes(b, mm) => {
93-
check(b, mm);
82+
salsa::attach(&db, || {
83+
let file_id = *file_ids.last().unwrap();
84+
let r = match eval_goal(&db, file_id) {
85+
Ok(t) => t,
86+
Err(e) => {
87+
let err = pretty_print_err(e, &db);
88+
panic!("Error in evaluating goal: {err}");
9489
}
95-
x => panic!("Expected number but found {x:?}"),
96-
},
97-
_ => panic!("result of const eval wasn't a concrete const"),
98-
}
90+
};
91+
match &r.data(Interner).value {
92+
chalk_ir::ConstValue::Concrete(c) => match &c.interned {
93+
ConstScalar::Bytes(b, mm) => {
94+
check(b, mm);
95+
}
96+
x => panic!("Expected number but found {x:?}"),
97+
},
98+
_ => panic!("result of const eval wasn't a concrete const"),
99+
}
100+
});
99101
}
100102

101-
fn pretty_print_err(e: ConstEvalError, db: TestDB) -> String {
103+
fn pretty_print_err(e: ConstEvalError, db: &TestDB) -> String {
102104
let mut err = String::new();
103105
let span_formatter = |file, range| format!("{file:?} {range:?}");
104106
let display_target =
105-
DisplayTarget::from_crate(&db, *db.all_crates().last().expect("no crate graph present"));
107+
DisplayTarget::from_crate(db, *db.all_crates().last().expect("no crate graph present"));
106108
match e {
107109
ConstEvalError::MirLowerError(e) => {
108-
e.pretty_print(&mut err, &db, span_formatter, display_target)
110+
e.pretty_print(&mut err, db, span_formatter, display_target)
109111
}
110112
ConstEvalError::MirEvalError(e) => {
111-
e.pretty_print(&mut err, &db, span_formatter, display_target)
113+
e.pretty_print(&mut err, db, span_formatter, display_target)
112114
}
113115
}
114116
.unwrap();

src/tools/rust-analyzer/crates/hir-ty/src/consteval_nextsolver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ pub(crate) fn const_eval_discriminant_variant(
222222
// and make this function private. See the fixme comment on `InferenceContext::resolve_all`.
223223
pub(crate) fn eval_to_const<'db>(expr: ExprId, ctx: &mut InferenceContext<'db>) -> Const<'db> {
224224
let interner = DbInterner::new_with(ctx.db, None, None);
225-
let infer = ctx.clone().resolve_all();
225+
let infer = ctx.fixme_resolve_all_clone();
226226
fn has_closure(body: &Body, expr: ExprId) -> bool {
227227
if matches!(body[expr], Expr::Closure { .. }) {
228228
return true;

0 commit comments

Comments
 (0)