From 474df093a9d91e2995e34608b577bff2b28f1e04 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 4 Feb 2021 22:42:21 +0100 Subject: Avoid using ModPath's fields directly --- crates/hir_def/src/path.rs | 8 ++++---- crates/hir_def/src/path/lower.rs | 2 +- crates/hir_def/src/path/lower/lower_use.rs | 7 ++++--- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index 0caad53d3..0e60dc2b6 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs @@ -201,10 +201,10 @@ impl Path { } let res = Path { type_anchor: self.type_anchor.clone(), - mod_path: ModPath { - kind: self.mod_path.kind.clone(), - segments: self.mod_path.segments[..self.mod_path.segments.len() - 1].to_vec(), - }, + mod_path: ModPath::from_segments( + self.mod_path.kind.clone(), + self.mod_path.segments[..self.mod_path.segments.len() - 1].iter().cloned(), + ), generic_args: self.generic_args[..self.generic_args.len() - 1].to_vec(), }; Some(res) diff --git a/crates/hir_def/src/path/lower.rs b/crates/hir_def/src/path/lower.rs index 9518ac109..a469546c1 100644 --- a/crates/hir_def/src/path/lower.rs +++ b/crates/hir_def/src/path/lower.rs @@ -129,7 +129,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option } } - let mod_path = ModPath { kind, segments }; + let mod_path = ModPath::from_segments(kind, segments); return Some(Path { type_anchor, mod_path, generic_args }); fn qualifier(path: &ast::Path) -> Option { diff --git a/crates/hir_def/src/path/lower/lower_use.rs b/crates/hir_def/src/path/lower/lower_use.rs index ba0d1f0e7..d584b0b70 100644 --- a/crates/hir_def/src/path/lower/lower_use.rs +++ b/crates/hir_def/src/path/lower/lower_use.rs @@ -75,9 +75,10 @@ fn convert_path(prefix: Option, path: ast::Path, hygiene: &Hygiene) -> match hygiene.name_ref_to_name(name_ref) { Either::Left(name) => { // no type args in use - let mut res = prefix.unwrap_or_else(|| ModPath { - kind: segment.coloncolon_token().map_or(PathKind::Plain, |_| PathKind::Abs), - segments: Vec::with_capacity(1), + let mut res = prefix.unwrap_or_else(|| { + ModPath::from_kind( + segment.coloncolon_token().map_or(PathKind::Plain, |_| PathKind::Abs), + ) }); res.segments.push(name); res -- cgit v1.2.3