mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Remove idx and parent generics from generics
This makes `hir_def::GenericParams` flatter. The logic for re-numbering the params is moved to hir instead.
This commit is contained in:
parent
30fefcc08c
commit
8e9837df21
10 changed files with 181 additions and 157 deletions
|
@ -6,7 +6,6 @@ use std::sync::Arc;
|
|||
use hir_def::{
|
||||
builtin_type::Signedness,
|
||||
expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
|
||||
generics::GenericParams,
|
||||
path::{GenericArg, GenericArgs},
|
||||
resolver::resolver_for_expr,
|
||||
AdtId, ContainerId, Lookup, StructFieldId,
|
||||
|
@ -15,7 +14,11 @@ use hir_expand::name::{self, Name};
|
|||
use ra_syntax::ast::RangeOp;
|
||||
|
||||
use crate::{
|
||||
autoderef, db::HirDatabase, method_resolution, op, traits::InEnvironment, utils::variant_data,
|
||||
autoderef,
|
||||
db::HirDatabase,
|
||||
method_resolution, op,
|
||||
traits::InEnvironment,
|
||||
utils::{generics, variant_data, Generics},
|
||||
CallableDef, InferTy, IntTy, Mutability, Obligation, ProjectionPredicate, ProjectionTy, Substs,
|
||||
TraitRef, Ty, TypeCtor, TypeWalk, Uncertain,
|
||||
};
|
||||
|
@ -596,7 +599,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
Some((ty, func)) => {
|
||||
let ty = canonicalized_receiver.decanonicalize_ty(ty);
|
||||
self.write_method_resolution(tgt_expr, func);
|
||||
(ty, self.db.value_ty(func.into()), Some(self.db.generic_params(func.into())))
|
||||
(ty, self.db.value_ty(func.into()), Some(generics(self.db, func.into())))
|
||||
}
|
||||
None => (receiver_ty, Ty::Unknown, None),
|
||||
};
|
||||
|
@ -653,16 +656,17 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
|
||||
fn substs_for_method_call(
|
||||
&mut self,
|
||||
def_generics: Option<Arc<GenericParams>>,
|
||||
def_generics: Option<Generics>,
|
||||
generic_args: Option<&GenericArgs>,
|
||||
receiver_ty: &Ty,
|
||||
) -> Substs {
|
||||
let (parent_param_count, param_count) =
|
||||
def_generics.as_ref().map_or((0, 0), |g| (g.count_parent_params(), g.params.len()));
|
||||
let (parent_param_count, param_count) = def_generics
|
||||
.as_ref()
|
||||
.map_or((0, 0), |g| (g.count_parent_params(), g.params.params.len()));
|
||||
let mut substs = Vec::with_capacity(parent_param_count + param_count);
|
||||
// Parent arguments are unknown, except for the receiver type
|
||||
if let Some(parent_generics) = def_generics.and_then(|p| p.parent_params.clone()) {
|
||||
for (_id, param) in parent_generics.params.iter() {
|
||||
if let Some(parent_generics) = def_generics.as_ref().map(|p| p.iter_parent()) {
|
||||
for (_id, param) in parent_generics {
|
||||
if param.name == name::SELF_TYPE {
|
||||
substs.push(receiver_ty.clone());
|
||||
} else {
|
||||
|
@ -706,9 +710,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
if let ContainerId::TraitId(trait_) = f.lookup(self.db).container {
|
||||
// construct a TraitDef
|
||||
let substs = a_ty.parameters.prefix(
|
||||
self.db
|
||||
.generic_params(trait_.into())
|
||||
.count_params_including_parent(),
|
||||
generics(self.db, trait_.into()).count_params_including_parent(),
|
||||
);
|
||||
self.obligations.push(Obligation::Trait(TraitRef {
|
||||
trait_: trait_.into(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue