]> git.lizzy.rs Git - rust.git/blobdiff - crates/hir_def/src/path/lower.rs
Move incorrect case diagnostic things into their module
[rust.git] / crates / hir_def / src / path / lower.rs
index 82bdcd5a86ddc66f44d71fc8ab8519e0348f05f5..3abc48d95dfcf03fe54a3074784ec282759479dd 100644 (file)
@@ -6,7 +6,7 @@
 
 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::{
@@ -70,18 +70,13 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
                     }
                     // <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 =
@@ -139,7 +134,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
     }
 
     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() {
@@ -193,7 +188,7 @@ pub(super) fn lower_generic_args(
     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)
@@ -229,5 +224,5 @@ fn lower_generic_args_from_fn_path(
             bounds: Vec::new(),
         });
     }
-    Some(GenericArgs { args, has_self_type: false, bindings })
+    Some(GenericArgs { args, has_self_type: false, bindings, desugared_from_fn: true })
 }