use either::Either;
use hir_expand::name::{name, AsName};
-use syntax::ast::{self, AstNode, TypeBoundsOwner};
+use syntax::ast::{self, AstNode, HasTypeBounds};
use super::AssociatedTypeBinding;
use crate::{
}
// <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo
Some(trait_ref) => {
- let path = Path::from_src(trait_ref.path()?, ctx)?;
- let mod_path = (*path.mod_path).clone();
- let num_segments = path.mod_path.segments.len();
+ let Path { mod_path, generic_args: path_generic_args, .. } =
+ Path::from_src(trait_ref.path()?, ctx)?;
+ let num_segments = mod_path.segments.len();
kind = mod_path.kind;
- let mut prefix_segments = mod_path.segments;
- prefix_segments.reverse();
- segments.extend(prefix_segments);
-
- let mut prefix_args = path.generic_args;
- prefix_args.reverse();
- generic_args.extend(prefix_args);
+ segments.extend(mod_path.segments.iter().cloned().rev());
+ generic_args.extend(Vec::from(path_generic_args).into_iter().rev());
// Insert the type reference (T in the above example) as Self parameter for the trait
let last_segment =
break;
}
ast::PathSegmentKind::SelfKw => {
- // don't break out if `self` is the last segment of a path, this mean we got an
+ // don't break out if `self` is the last segment of a path, this mean we got a
// use tree like `foo::{self}` which we want to resolve as `foo`
if !segments.is_empty() {
kind = PathKind::Super(0);
}
let mod_path = Interned::new(ModPath::from_segments(kind, segments));
- return Some(Path { type_anchor, mod_path, generic_args });
+ return Some(Path { type_anchor, mod_path, generic_args: generic_args.into() });
fn qualifier(path: &ast::Path) -> Option<ast::Path> {
if let Some(q) = path.qualifier() {
if args.is_empty() && bindings.is_empty() {
return None;
}
- Some(GenericArgs { args, has_self_type: false, bindings })
+ Some(GenericArgs { args, has_self_type: false, bindings, desugared_from_fn: false })
}
/// Collect `GenericArgs` from the parts of a fn-like path, i.e. `Fn(X, Y)
let params = params?;
let mut param_types = Vec::new();
for param in params.params() {
- let type_ref = TypeRef::from_ast_opt(&ctx, param.ty());
+ let type_ref = TypeRef::from_ast_opt(ctx, param.ty());
param_types.push(type_ref);
}
let arg = GenericArg::Type(TypeRef::Tuple(param_types));
args.push(arg);
if let Some(ret_type) = ret_type {
- let type_ref = TypeRef::from_ast_opt(&ctx, ret_type.ty());
+ let type_ref = TypeRef::from_ast_opt(ctx, ret_type.ty());
bindings.push(AssociatedTypeBinding {
name: name![Output],
type_ref: Some(type_ref),
bounds: Vec::new(),
});
}
- Some(GenericArgs { args, has_self_type: false, bindings })
+ Some(GenericArgs { args, has_self_type: false, bindings, desugared_from_fn: true })
}