Skip to content

Commit d7465cb

Browse files
Upgrade rustc crates
Changes: - `const_of_item()` was added to `Interner`, analogous to `type_of()`. No strongly-typed ID (yet). - New solver trait lang item: `TrivialClone`. - `TypeRelation` changed a bit, the code was copied from rustc.
1 parent 92630ee commit d7465cb

File tree

7 files changed

+86
-58
lines changed

7 files changed

+86
-58
lines changed

Cargo.lock

Lines changed: 22 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
8686
vfs = { path = "./crates/vfs", version = "0.0.0" }
8787
edition = { path = "./crates/edition", version = "0.0.0" }
8888

89-
ra-ap-rustc_lexer = { version = "0.139", default-features = false }
90-
ra-ap-rustc_parse_format = { version = "0.139", default-features = false }
91-
ra-ap-rustc_index = { version = "0.139", default-features = false }
92-
ra-ap-rustc_abi = { version = "0.139", default-features = false }
93-
ra-ap-rustc_pattern_analysis = { version = "0.139", default-features = false }
94-
ra-ap-rustc_ast_ir = { version = "0.139", default-features = false }
95-
ra-ap-rustc_type_ir = { version = "0.139", default-features = false }
96-
ra-ap-rustc_next_trait_solver = { version = "0.139", default-features = false }
89+
ra-ap-rustc_lexer = { version = "0.143", default-features = false }
90+
ra-ap-rustc_parse_format = { version = "0.143", default-features = false }
91+
ra-ap-rustc_index = { version = "0.143", default-features = false }
92+
ra-ap-rustc_abi = { version = "0.143", default-features = false }
93+
ra-ap-rustc_pattern_analysis = { version = "0.143", default-features = false }
94+
ra-ap-rustc_ast_ir = { version = "0.143", default-features = false }
95+
ra-ap-rustc_type_ir = { version = "0.143", default-features = false }
96+
ra-ap-rustc_next_trait_solver = { version = "0.143", default-features = false }
9797

9898
# local crates that aren't published to crates.io. These should not have versions.
9999

crates/hir-def/src/lang_item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ language_item_table! { LangItems =>
237237
StructuralTeq, sym::structural_teq, structural_teq_trait, TraitId, GenericRequirement::None;
238238
Copy, sym::copy, copy_trait, TraitId, GenericRequirement::Exact(0);
239239
Clone, sym::clone, clone_trait, TraitId, GenericRequirement::None;
240+
TrivialClone, sym::trivial_clone, clone_trait, TraitId, GenericRequirement::None;
240241
Sync, sym::sync, sync_trait, TraitId, GenericRequirement::Exact(0);
241242
DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, TraitId, GenericRequirement::None;
242243
/// The associated item of the `DiscriminantKind` trait.

crates/hir-ty/src/next_solver/infer/relate/generalize.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ use tracing::{debug, instrument, warn};
1616
use super::{
1717
PredicateEmittingRelation, Relate, RelateResult, StructurallyRelateAliases, TypeRelation,
1818
};
19-
use crate::next_solver::infer::type_variable::TypeVariableValue;
2019
use crate::next_solver::infer::unify_key::ConstVariableValue;
2120
use crate::next_solver::infer::{InferCtxt, relate};
2221
use crate::next_solver::util::MaxUniverse;
2322
use crate::next_solver::{
24-
AliasTy, Binder, ClauseKind, Const, ConstKind, DbInterner, GenericArgs, PredicateKind, Region,
25-
SolverDefId, Term, TermVid, Ty, TyKind, TypingMode, UnevaluatedConst,
23+
AliasTy, Binder, ClauseKind, Const, ConstKind, DbInterner, PredicateKind, Region, SolverDefId,
24+
Term, TermVid, Ty, TyKind, TypingMode, UnevaluatedConst,
2625
};
26+
use crate::next_solver::{GenericArgs, infer::type_variable::TypeVariableValue};
2727

2828
impl<'db> InferCtxt<'db> {
2929
/// The idea is that we should ensure that the type variable `target_vid`
@@ -384,29 +384,26 @@ impl<'db> TypeRelation<DbInterner<'db>> for Generalizer<'_, 'db> {
384384
self.infcx.interner
385385
}
386386

387-
fn relate_item_args(
387+
fn relate_ty_args(
388388
&mut self,
389-
item_def_id: SolverDefId,
390-
a_arg: GenericArgs<'db>,
391-
b_arg: GenericArgs<'db>,
392-
) -> RelateResult<'db, GenericArgs<'db>> {
393-
if self.ambient_variance == Variance::Invariant {
389+
a_ty: Ty<'db>,
390+
_: Ty<'db>,
391+
def_id: SolverDefId,
392+
a_args: GenericArgs<'db>,
393+
b_args: GenericArgs<'db>,
394+
mk: impl FnOnce(GenericArgs<'db>) -> Ty<'db>,
395+
) -> RelateResult<'db, Ty<'db>> {
396+
let args = if self.ambient_variance == Variance::Invariant {
394397
// Avoid fetching the variance if we are in an invariant
395398
// context; no need, and it can induce dependency cycles
396399
// (e.g., #41849).
397-
relate::relate_args_invariantly(self, a_arg, b_arg)
400+
relate::relate_args_invariantly(self, a_args, b_args)
398401
} else {
399-
let tcx = self.cx();
400-
let opt_variances = tcx.variances_of(item_def_id);
401-
relate::relate_args_with_variances(
402-
self,
403-
item_def_id,
404-
opt_variances,
405-
a_arg,
406-
b_arg,
407-
false,
408-
)
409-
}
402+
let interner = self.cx();
403+
let variances = interner.variances_of(def_id);
404+
relate::relate_args_with_variances(self, variances, a_args, b_args)
405+
}?;
406+
if args == a_args { Ok(a_ty) } else { Ok(mk(args)) }
410407
}
411408

412409
#[instrument(level = "debug", skip(self, variance, b), ret)]

crates/hir-ty/src/next_solver/infer/relate/lattice.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@
1818
//! [lattices]: https://en.wikipedia.org/wiki/Lattice_(order)
1919
2020
use rustc_type_ir::{
21-
AliasRelationDirection, TypeVisitableExt, Upcast, Variance,
21+
AliasRelationDirection, Interner, TypeVisitableExt, Upcast, Variance,
2222
inherent::{IntoKind, Span as _},
2323
relate::{
2424
Relate, StructurallyRelateAliases, TypeRelation, VarianceDiagInfo,
25-
combine::{PredicateEmittingRelation, super_combine_consts, super_combine_tys},
25+
combine::{
26+
PredicateEmittingRelation, combine_ty_args, super_combine_consts, super_combine_tys,
27+
},
2628
},
2729
};
2830

2931
use crate::next_solver::{
30-
AliasTy, Binder, Const, DbInterner, Goal, ParamEnv, Predicate, PredicateKind, Region, Span, Ty,
31-
TyKind,
32+
AliasTy, Binder, Const, DbInterner, GenericArgs, Goal, ParamEnv, Predicate, PredicateKind,
33+
Region, SolverDefId, Span, Ty, TyKind,
3234
infer::{
3335
InferCtxt, TypeTrace,
3436
relate::RelateResult,
@@ -82,6 +84,19 @@ impl<'db> TypeRelation<DbInterner<'db>> for LatticeOp<'_, 'db> {
8284
self.infcx.interner
8385
}
8486

87+
fn relate_ty_args(
88+
&mut self,
89+
a_ty: Ty<'db>,
90+
b_ty: Ty<'db>,
91+
def_id: SolverDefId,
92+
a_args: GenericArgs<'db>,
93+
b_args: GenericArgs<'db>,
94+
mk: impl FnOnce(GenericArgs<'db>) -> Ty<'db>,
95+
) -> RelateResult<'db, Ty<'db>> {
96+
let variances = self.cx().variances_of(def_id);
97+
combine_ty_args(self.infcx, self, a_ty, b_ty, variances, a_args, b_args, mk)
98+
}
99+
85100
fn relate_with_variance<T: Relate<DbInterner<'db>>>(
86101
&mut self,
87102
variance: Variance,

crates/hir-ty/src/next_solver/interner.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_type_ir::{
2525
elaborate::elaborate,
2626
error::TypeError,
2727
fast_reject,
28-
inherent::{self, GenericsOf, IntoKind, SliceLike as _, Span as _, Ty as _},
28+
inherent::{self, Const as _, GenericsOf, IntoKind, SliceLike as _, Span as _, Ty as _},
2929
lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem},
3030
solve::SizedTraitKind,
3131
};
@@ -39,7 +39,7 @@ use crate::{
3939
AdtIdWrapper, BoundConst, CallableIdWrapper, CanonicalVarKind, ClosureIdWrapper,
4040
CoroutineIdWrapper, Ctor, FnSig, FxIndexMap, GeneralConstIdWrapper, ImplIdWrapper,
4141
OpaqueTypeKey, RegionAssumptions, SimplifiedType, SolverContext, SolverDefIds,
42-
TraitIdWrapper, TypeAliasIdWrapper, util::explicit_item_bounds,
42+
TraitIdWrapper, TypeAliasIdWrapper, UnevaluatedConst, util::explicit_item_bounds,
4343
},
4444
};
4545

@@ -1512,6 +1512,7 @@ impl<'db> Interner for DbInterner<'db> {
15121512
SolverTraitLangItem::BikeshedGuaranteedNoDrop => {
15131513
unimplemented!()
15141514
}
1515+
SolverTraitLangItem::TrivialClone => lang_items.TrivialClone,
15151516
};
15161517
lang_item.expect("Lang item required but not found.").into()
15171518
}
@@ -1565,6 +1566,7 @@ impl<'db> Interner for DbInterner<'db> {
15651566
AsyncFn,
15661567
AsyncFnMut,
15671568
AsyncFnOnce,
1569+
TrivialClone,
15681570
)
15691571
}
15701572

@@ -1651,6 +1653,7 @@ impl<'db> Interner for DbInterner<'db> {
16511653
AsyncFn,
16521654
AsyncFnMut,
16531655
AsyncFnOnce,
1656+
TrivialClone,
16541657
)
16551658
}
16561659

@@ -2167,6 +2170,18 @@ impl<'db> Interner for DbInterner<'db> {
21672170
Some(SolverTraitLangItem::Sized | SolverTraitLangItem::MetaSized)
21682171
)
21692172
}
2173+
2174+
fn const_of_item(self, def_id: Self::DefId) -> rustc_type_ir::EarlyBinder<Self, Self::Const> {
2175+
let id = match def_id {
2176+
SolverDefId::StaticId(id) => id.into(),
2177+
SolverDefId::ConstId(id) => id.into(),
2178+
_ => unreachable!(),
2179+
};
2180+
EarlyBinder::bind(Const::new_unevaluated(
2181+
self,
2182+
UnevaluatedConst { def: GeneralConstIdWrapper(id), args: GenericArgs::empty(self) },
2183+
))
2184+
}
21702185
}
21712186

21722187
impl<'db> DbInterner<'db> {

crates/intern/src/symbol/symbols.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ define_symbols! {
161161
cfg_select,
162162
char,
163163
clone,
164+
trivial_clone,
164165
Clone,
165166
coerce_unsized,
166167
column,

0 commit comments

Comments
 (0)