aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-02-04 19:49:24 +0000
committerJonas Schievink <[email protected]>2021-02-04 19:49:24 +0000
commit5d99ba1d9a5acf02a5cd50e456f164bd80b523b5 (patch)
tree073b41689b789308030b4df4344c3aa147cba195
parent36191543a679d4e01c206d2e98a2d7ae170a25e2 (diff)
Make `ModPath`'s representation private
-rw-r--r--crates/assists/src/handlers/extract_struct_from_enum_variant.rs4
-rw-r--r--crates/completion/src/completions/flyimport.rs2
-rw-r--r--crates/completion/src/completions/unqualified_path.rs2
-rw-r--r--crates/completion/src/item.rs4
-rw-r--r--crates/completion/src/render.rs2
-rw-r--r--crates/completion/src/render/enum_variant.rs4
-rw-r--r--crates/hir_def/src/find_path.rs10
-rw-r--r--crates/hir_def/src/item_tree.rs8
-rw-r--r--crates/hir_def/src/item_tree/lower.rs3
-rw-r--r--crates/hir_def/src/lib.rs2
-rw-r--r--crates/hir_def/src/nameres/collector.rs4
-rw-r--r--crates/hir_def/src/nameres/path_resolution.rs20
-rw-r--r--crates/hir_def/src/path.rs29
-rw-r--r--crates/hir_def/src/resolver.rs12
-rw-r--r--crates/hir_def/src/visibility.rs9
-rw-r--r--crates/hir_ty/src/infer.rs2
-rw-r--r--crates/ide_db/src/helpers.rs2
-rw-r--r--crates/rust-analyzer/src/handlers.rs2
18 files changed, 70 insertions, 51 deletions
diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs
index e3ef04932..5c7678b53 100644
--- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -151,8 +151,8 @@ fn insert_import(
151 ctx.config.insert_use.prefix_kind, 151 ctx.config.insert_use.prefix_kind,
152 ); 152 );
153 if let Some(mut mod_path) = mod_path { 153 if let Some(mut mod_path) = mod_path {
154 mod_path.segments.pop(); 154 mod_path.pop_segment();
155 mod_path.segments.push(variant_hir_name.clone()); 155 mod_path.push_segment(variant_hir_name.clone());
156 let scope = ImportScope::find_insert_use_container(scope_node, &ctx.sema)?; 156 let scope = ImportScope::find_insert_use_container(scope_node, &ctx.sema)?;
157 *rewriter += insert_use(&scope, mod_path_to_ast(&mod_path), ctx.config.insert_use.merge); 157 *rewriter += insert_use(&scope, mod_path_to_ast(&mod_path), ctx.config.insert_use.merge);
158 } 158 }
diff --git a/crates/completion/src/completions/flyimport.rs b/crates/completion/src/completions/flyimport.rs
index 9c6a5a40c..c9f928483 100644
--- a/crates/completion/src/completions/flyimport.rs
+++ b/crates/completion/src/completions/flyimport.rs
@@ -175,7 +175,7 @@ fn compute_fuzzy_completion_order_key(
175 user_input_lowercased: &str, 175 user_input_lowercased: &str,
176) -> usize { 176) -> usize {
177 mark::hit!(certain_fuzzy_order_test); 177 mark::hit!(certain_fuzzy_order_test);
178 let proposed_import_name = match proposed_mod_path.segments.last() { 178 let proposed_import_name = match proposed_mod_path.segments().last() {
179 Some(name) => name.to_string().to_lowercase(), 179 Some(name) => name.to_string().to_lowercase(),
180 None => return usize::MAX, 180 None => return usize::MAX,
181 }; 181 };
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs
index 5d62fab97..e2482f959 100644
--- a/crates/completion/src/completions/unqualified_path.rs
+++ b/crates/completion/src/completions/unqualified_path.rs
@@ -63,7 +63,7 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T
63 if let Some(path) = module.find_use_path(ctx.db, ModuleDef::from(variant)) { 63 if let Some(path) = module.find_use_path(ctx.db, ModuleDef::from(variant)) {
64 // Variants with trivial paths are already added by the existing completion logic, 64 // Variants with trivial paths are already added by the existing completion logic,
65 // so we should avoid adding these twice 65 // so we should avoid adding these twice
66 if path.segments.len() > 1 { 66 if path.segments().len() > 1 {
67 acc.add_qualified_enum_variant(ctx, variant, path); 67 acc.add_qualified_enum_variant(ctx, variant, path);
68 } 68 }
69 } 69 }
diff --git a/crates/completion/src/item.rs b/crates/completion/src/item.rs
index 8ec4ac65e..884711f11 100644
--- a/crates/completion/src/item.rs
+++ b/crates/completion/src/item.rs
@@ -332,9 +332,9 @@ impl Builder {
332 label = format!("{} ({})", label, import_to_add.import_path); 332 label = format!("{} ({})", label, import_to_add.import_path);
333 } else { 333 } else {
334 let mut import_path_without_last_segment = import_to_add.import_path.to_owned(); 334 let mut import_path_without_last_segment = import_to_add.import_path.to_owned();
335 let _ = import_path_without_last_segment.segments.pop(); 335 let _ = import_path_without_last_segment.pop_segment();
336 336
337 if !import_path_without_last_segment.segments.is_empty() { 337 if !import_path_without_last_segment.segments().is_empty() {
338 lookup = lookup.or_else(|| Some(label.clone())); 338 lookup = lookup.or_else(|| Some(label.clone()));
339 insert_text = insert_text.or_else(|| Some(label.clone())); 339 insert_text = insert_text.or_else(|| Some(label.clone()));
340 label = format!("{}::{}", import_path_without_last_segment, label); 340 label = format!("{}::{}", import_path_without_last_segment, label);
diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs
index e11b881ca..eddaaa6f3 100644
--- a/crates/completion/src/render.rs
+++ b/crates/completion/src/render.rs
@@ -57,7 +57,7 @@ pub(crate) fn render_resolution_with_import<'a>(
57 ScopeDef::ModuleDef(ModuleDef::Function(f)) => f.name(ctx.completion.db).to_string(), 57 ScopeDef::ModuleDef(ModuleDef::Function(f)) => f.name(ctx.completion.db).to_string(),
58 ScopeDef::ModuleDef(ModuleDef::Const(c)) => c.name(ctx.completion.db)?.to_string(), 58 ScopeDef::ModuleDef(ModuleDef::Const(c)) => c.name(ctx.completion.db)?.to_string(),
59 ScopeDef::ModuleDef(ModuleDef::TypeAlias(t)) => t.name(ctx.completion.db).to_string(), 59 ScopeDef::ModuleDef(ModuleDef::TypeAlias(t)) => t.name(ctx.completion.db).to_string(),
60 _ => import_edit.import_path.segments.last()?.to_string(), 60 _ => import_edit.import_path.segments().last()?.to_string(),
61 }; 61 };
62 Render::new(ctx).render_resolution(local_name, Some(import_edit), resolution).map(|mut item| { 62 Render::new(ctx).render_resolution(local_name, Some(import_edit), resolution).map(|mut item| {
63 item.completion_kind = CompletionKind::Magic; 63 item.completion_kind = CompletionKind::Magic;
diff --git a/crates/completion/src/render/enum_variant.rs b/crates/completion/src/render/enum_variant.rs
index adcddebd1..9214193b4 100644
--- a/crates/completion/src/render/enum_variant.rs
+++ b/crates/completion/src/render/enum_variant.rs
@@ -45,8 +45,8 @@ impl<'a> EnumRender<'a> {
45 let (qualified_name, short_qualified_name) = match &path { 45 let (qualified_name, short_qualified_name) = match &path {
46 Some(path) => { 46 Some(path) => {
47 let full = path.to_string(); 47 let full = path.to_string();
48 let short = 48 let segments = path.segments();
49 path.segments[path.segments.len().saturating_sub(2)..].iter().join("::"); 49 let short = segments[segments.len().saturating_sub(2)..].iter().join("::");
50 (full, short) 50 (full, short)
51 } 51 }
52 None => (name.to_string(), name.to_string()), 52 None => (name.to_string(), name.to_string()),
diff --git a/crates/hir_def/src/find_path.rs b/crates/hir_def/src/find_path.rs
index 94a1d567d..aa2c6e04e 100644
--- a/crates/hir_def/src/find_path.rs
+++ b/crates/hir_def/src/find_path.rs
@@ -36,13 +36,13 @@ const MAX_PATH_LEN: usize = 15;
36 36
37impl ModPath { 37impl ModPath {
38 fn starts_with_std(&self) -> bool { 38 fn starts_with_std(&self) -> bool {
39 self.segments.first() == Some(&known::std) 39 self.segments().first() == Some(&known::std)
40 } 40 }
41 41
42 // When std library is present, paths starting with `std::` 42 // When std library is present, paths starting with `std::`
43 // should be preferred over paths starting with `core::` and `alloc::` 43 // should be preferred over paths starting with `core::` and `alloc::`
44 fn can_start_with_std(&self) -> bool { 44 fn can_start_with_std(&self) -> bool {
45 let first_segment = self.segments.first(); 45 let first_segment = self.segments().first();
46 first_segment == Some(&known::alloc) || first_segment == Some(&known::core) 46 first_segment == Some(&known::alloc) || first_segment == Some(&known::core)
47 } 47 }
48} 48}
@@ -157,7 +157,7 @@ fn find_path_inner(
157 if let Some(ModuleDefId::EnumVariantId(variant)) = item.as_module_def_id() { 157 if let Some(ModuleDefId::EnumVariantId(variant)) = item.as_module_def_id() {
158 if let Some(mut path) = find_path(db, ItemInNs::Types(variant.parent.into()), from) { 158 if let Some(mut path) = find_path(db, ItemInNs::Types(variant.parent.into()), from) {
159 let data = db.enum_data(variant.parent); 159 let data = db.enum_data(variant.parent);
160 path.segments.push(data.variants[variant.local_id].name.clone()); 160 path.push_segment(data.variants[variant.local_id].name.clone());
161 return Some(path); 161 return Some(path);
162 } 162 }
163 // If this doesn't work, it seems we have no way of referring to the 163 // If this doesn't work, it seems we have no way of referring to the
@@ -186,7 +186,7 @@ fn find_path_inner(
186 best_path_len - 1, 186 best_path_len - 1,
187 prefixed, 187 prefixed,
188 ) { 188 ) {
189 path.segments.push(name); 189 path.push_segment(name);
190 190
191 let new_path = if let Some(best_path) = best_path { 191 let new_path = if let Some(best_path) = best_path {
192 select_best_path(best_path, path, prefer_no_std) 192 select_best_path(best_path, path, prefer_no_std)
@@ -215,7 +215,7 @@ fn find_path_inner(
215 prefixed, 215 prefixed,
216 )?; 216 )?;
217 mark::hit!(partially_imported); 217 mark::hit!(partially_imported);
218 path.segments.push(info.path.segments.last().unwrap().clone()); 218 path.push_segment(info.path.segments.last().unwrap().clone());
219 Some(path) 219 Some(path)
220 }) 220 })
221 }); 221 });
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs
index 401556931..3233b1957 100644
--- a/crates/hir_def/src/item_tree.rs
+++ b/crates/hir_def/src/item_tree.rs
@@ -240,7 +240,7 @@ impl ItemVisibilities {
240 fn alloc(&mut self, vis: RawVisibility) -> RawVisibilityId { 240 fn alloc(&mut self, vis: RawVisibility) -> RawVisibilityId {
241 match &vis { 241 match &vis {
242 RawVisibility::Public => RawVisibilityId::PUB, 242 RawVisibility::Public => RawVisibilityId::PUB,
243 RawVisibility::Module(path) if path.segments.is_empty() => match &path.kind { 243 RawVisibility::Module(path) if path.segments().is_empty() => match &path.kind {
244 PathKind::Super(0) => RawVisibilityId::PRIV, 244 PathKind::Super(0) => RawVisibilityId::PRIV,
245 PathKind::Crate => RawVisibilityId::PUB_CRATE, 245 PathKind::Crate => RawVisibilityId::PUB_CRATE,
246 _ => RawVisibilityId(self.arena.alloc(vis).into_raw().into()), 246 _ => RawVisibilityId(self.arena.alloc(vis).into_raw().into()),
@@ -251,10 +251,8 @@ impl ItemVisibilities {
251} 251}
252 252
253static VIS_PUB: RawVisibility = RawVisibility::Public; 253static VIS_PUB: RawVisibility = RawVisibility::Public;
254static VIS_PRIV: RawVisibility = 254static VIS_PRIV: RawVisibility = RawVisibility::Module(ModPath::from_kind(PathKind::Super(0)));
255 RawVisibility::Module(ModPath { kind: PathKind::Super(0), segments: Vec::new() }); 255static VIS_PUB_CRATE: RawVisibility = RawVisibility::Module(ModPath::from_kind(PathKind::Crate));
256static VIS_PUB_CRATE: RawVisibility =
257 RawVisibility::Module(ModPath { kind: PathKind::Crate, segments: Vec::new() });
258 256
259#[derive(Default, Debug, Eq, PartialEq)] 257#[derive(Default, Debug, Eq, PartialEq)]
260struct GenericParamsStorage { 258struct GenericParamsStorage {
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs
index 93cdca55d..8f2f0b340 100644
--- a/crates/hir_def/src/item_tree/lower.rs
+++ b/crates/hir_def/src/item_tree/lower.rs
@@ -750,7 +750,8 @@ impl Ctx {
750 750
751fn desugar_future_path(orig: TypeRef) -> Path { 751fn desugar_future_path(orig: TypeRef) -> Path {
752 let path = path![core::future::Future]; 752 let path = path![core::future::Future];
753 let mut generic_args: Vec<_> = std::iter::repeat(None).take(path.segments.len() - 1).collect(); 753 let mut generic_args: Vec<_> =
754 std::iter::repeat(None).take(path.segments().len() - 1).collect();
754 let mut last = GenericArgs::empty(); 755 let mut last = GenericArgs::empty();
755 let binding = 756 let binding =
756 AssociatedTypeBinding { name: name![Output], type_ref: Some(orig), bounds: Vec::new() }; 757 AssociatedTypeBinding { name: name![Output], type_ref: Some(orig), bounds: Vec::new() };
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs
index 5dd3705b0..b50923747 100644
--- a/crates/hir_def/src/lib.rs
+++ b/crates/hir_def/src/lib.rs
@@ -662,7 +662,7 @@ impl AsMacroCall for AstIdWithPath<ast::Item> {
662 def.as_lazy_macro( 662 def.as_lazy_macro(
663 db.upcast(), 663 db.upcast(),
664 krate, 664 krate,
665 MacroCallKind::Attr(self.ast_id, self.path.segments.last()?.to_string()), 665 MacroCallKind::Attr(self.ast_id, self.path.segments().last()?.to_string()),
666 ) 666 )
667 .into(), 667 .into(),
668 ) 668 )
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index f904a97de..6bd41bc08 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -655,7 +655,7 @@ impl DefCollector<'_> {
655 } 655 }
656 } 656 }
657 } else { 657 } else {
658 match import.path.segments.last() { 658 match import.path.segments().last() {
659 Some(last_segment) => { 659 Some(last_segment) => {
660 let name = match &import.alias { 660 let name = match &import.alias {
661 Some(ImportAlias::Alias(name)) => Some(name.clone()), 661 Some(ImportAlias::Alias(name)) => Some(name.clone()),
@@ -956,7 +956,7 @@ impl DefCollector<'_> {
956 let item_tree = self.db.item_tree(import.file_id); 956 let item_tree = self.db.item_tree(import.file_id);
957 let import_data = &item_tree[import.value]; 957 let import_data = &item_tree[import.value];
958 958
959 match (import_data.path.segments.first(), &import_data.path.kind) { 959 match (import_data.path.segments().first(), &import_data.path.kind) {
960 (Some(krate), PathKind::Plain) | (Some(krate), PathKind::Abs) => { 960 (Some(krate), PathKind::Plain) | (Some(krate), PathKind::Abs) => {
961 if diagnosed_extern_crates.contains(krate) { 961 if diagnosed_extern_crates.contains(krate) {
962 continue; 962 continue;
diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs
index 2a3ac5d7b..f2b59172d 100644
--- a/crates/hir_def/src/nameres/path_resolution.rs
+++ b/crates/hir_def/src/nameres/path_resolution.rs
@@ -149,7 +149,7 @@ impl DefMap {
149 path: &ModPath, 149 path: &ModPath,
150 shadow: BuiltinShadowMode, 150 shadow: BuiltinShadowMode,
151 ) -> ResolvePathResult { 151 ) -> ResolvePathResult {
152 let mut segments = path.segments.iter().enumerate(); 152 let mut segments = path.segments().iter().enumerate();
153 let mut curr_per_ns: PerNs = match path.kind { 153 let mut curr_per_ns: PerNs = match path.kind {
154 PathKind::DollarCrate(krate) => { 154 PathKind::DollarCrate(krate) => {
155 if krate == self.krate { 155 if krate == self.krate {
@@ -190,7 +190,7 @@ impl DefMap {
190 // BuiltinShadowMode wasn't Module, then we need to try 190 // BuiltinShadowMode wasn't Module, then we need to try
191 // resolving it as a builtin. 191 // resolving it as a builtin.
192 let prefer_module = 192 let prefer_module =
193 if path.segments.len() == 1 { shadow } else { BuiltinShadowMode::Module }; 193 if path.segments().len() == 1 { shadow } else { BuiltinShadowMode::Module };
194 194
195 log::debug!("resolving {:?} in module", segment); 195 log::debug!("resolving {:?} in module", segment);
196 self.resolve_name_in_module(db, original_module, &segment, prefer_module) 196 self.resolve_name_in_module(db, original_module, &segment, prefer_module)
@@ -203,10 +203,10 @@ impl DefMap {
203 None => match &self.block { 203 None => match &self.block {
204 Some(block) => { 204 Some(block) => {
205 // Look up remaining path in parent `DefMap` 205 // Look up remaining path in parent `DefMap`
206 let new_path = ModPath { 206 let new_path = ModPath::from_segments(
207 kind: PathKind::Super(lvl - i), 207 PathKind::Super(lvl - i),
208 segments: path.segments.clone(), 208 path.segments().to_vec(),
209 }; 209 );
210 log::debug!("`super` path: {} -> {} in parent map", path, new_path); 210 log::debug!("`super` path: {} -> {} in parent map", path, new_path);
211 return block.parent.def_map(db).resolve_path_fp_with_macro( 211 return block.parent.def_map(db).resolve_path_fp_with_macro(
212 db, 212 db,
@@ -258,10 +258,10 @@ impl DefMap {
258 curr_per_ns = match curr { 258 curr_per_ns = match curr {
259 ModuleDefId::ModuleId(module) => { 259 ModuleDefId::ModuleId(module) => {
260 if module.krate != self.krate { 260 if module.krate != self.krate {
261 let path = ModPath { 261 let path = ModPath::from_segments(
262 segments: path.segments[i..].to_vec(), 262 PathKind::Super(0),
263 kind: PathKind::Super(0), 263 path.segments()[i..].iter().cloned(),
264 }; 264 );
265 log::debug!("resolving {:?} in other crate", path); 265 log::debug!("resolving {:?} in other crate", path);
266 let defp_map = module.def_map(db); 266 let defp_map = module.def_map(db);
267 let (def, s) = defp_map.resolve_path(db, module.local_id, &path, shadow); 267 let (def, s) = defp_map.resolve_path(db, module.local_id, &path, shadow);
diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs
index 84ea09b53..0caad53d3 100644
--- a/crates/hir_def/src/path.rs
+++ b/crates/hir_def/src/path.rs
@@ -20,7 +20,7 @@ use crate::{
20#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] 20#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
21pub struct ModPath { 21pub struct ModPath {
22 pub kind: PathKind, 22 pub kind: PathKind,
23 pub segments: Vec<Name>, 23 segments: Vec<Name>,
24} 24}
25 25
26#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] 26#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -53,6 +53,11 @@ impl ModPath {
53 ModPath { kind, segments } 53 ModPath { kind, segments }
54 } 54 }
55 55
56 /// Creates a `ModPath` from a `PathKind`, with no extra path segments.
57 pub const fn from_kind(kind: PathKind) -> ModPath {
58 ModPath { kind, segments: Vec::new() }
59 }
60
56 /// Calls `cb` with all paths, represented by this use item. 61 /// Calls `cb` with all paths, represented by this use item.
57 pub(crate) fn expand_use_item( 62 pub(crate) fn expand_use_item(
58 item_src: InFile<ast::Use>, 63 item_src: InFile<ast::Use>,
@@ -64,6 +69,18 @@ impl ModPath {
64 } 69 }
65 } 70 }
66 71
72 pub fn segments(&self) -> &[Name] {
73 &self.segments
74 }
75
76 pub fn push_segment(&mut self, segment: Name) {
77 self.segments.push(segment);
78 }
79
80 pub fn pop_segment(&mut self) -> Option<Name> {
81 self.segments.pop()
82 }
83
67 /// Returns the number of segments in the path (counting special segments like `$crate` and 84 /// Returns the number of segments in the path (counting special segments like `$crate` and
68 /// `super`). 85 /// `super`).
69 pub fn len(&self) -> usize { 86 pub fn len(&self) -> usize {
@@ -78,7 +95,7 @@ impl ModPath {
78 } 95 }
79 96
80 pub fn is_ident(&self) -> bool { 97 pub fn is_ident(&self) -> bool {
81 self.kind == PathKind::Plain && self.segments.len() == 1 98 self.as_ident().is_some()
82 } 99 }
83 100
84 pub fn is_self(&self) -> bool { 101 pub fn is_self(&self) -> bool {
@@ -87,10 +104,14 @@ impl ModPath {
87 104
88 /// If this path is a single identifier, like `foo`, return its name. 105 /// If this path is a single identifier, like `foo`, return its name.
89 pub fn as_ident(&self) -> Option<&Name> { 106 pub fn as_ident(&self) -> Option<&Name> {
90 if !self.is_ident() { 107 if self.kind != PathKind::Plain {
91 return None; 108 return None;
92 } 109 }
93 self.segments.first() 110
111 match &*self.segments {
112 [name] => Some(name),
113 _ => None,
114 }
94 } 115 }
95} 116}
96 117
diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs
index 9021ea712..f9ad50301 100644
--- a/crates/hir_def/src/resolver.rs
+++ b/crates/hir_def/src/resolver.rs
@@ -164,7 +164,7 @@ impl Resolver {
164 db: &dyn DefDatabase, 164 db: &dyn DefDatabase,
165 path: &ModPath, 165 path: &ModPath,
166 ) -> Option<(TypeNs, Option<usize>)> { 166 ) -> Option<(TypeNs, Option<usize>)> {
167 let first_name = path.segments.first()?; 167 let first_name = path.segments().first()?;
168 let skip_to_mod = path.kind != PathKind::Plain; 168 let skip_to_mod = path.kind != PathKind::Plain;
169 for scope in self.scopes.iter().rev() { 169 for scope in self.scopes.iter().rev() {
170 match scope { 170 match scope {
@@ -179,7 +179,7 @@ impl Resolver {
179 179
180 Scope::GenericParams { params, def } => { 180 Scope::GenericParams { params, def } => {
181 if let Some(local_id) = params.find_type_by_name(first_name) { 181 if let Some(local_id) = params.find_type_by_name(first_name) {
182 let idx = if path.segments.len() == 1 { None } else { Some(1) }; 182 let idx = if path.segments().len() == 1 { None } else { Some(1) };
183 return Some(( 183 return Some((
184 TypeNs::GenericParam(TypeParamId { local_id, parent: *def }), 184 TypeNs::GenericParam(TypeParamId { local_id, parent: *def }),
185 idx, 185 idx,
@@ -188,13 +188,13 @@ impl Resolver {
188 } 188 }
189 Scope::ImplDefScope(impl_) => { 189 Scope::ImplDefScope(impl_) => {
190 if first_name == &name![Self] { 190 if first_name == &name![Self] {
191 let idx = if path.segments.len() == 1 { None } else { Some(1) }; 191 let idx = if path.segments().len() == 1 { None } else { Some(1) };
192 return Some((TypeNs::SelfType(*impl_), idx)); 192 return Some((TypeNs::SelfType(*impl_), idx));
193 } 193 }
194 } 194 }
195 Scope::AdtScope(adt) => { 195 Scope::AdtScope(adt) => {
196 if first_name == &name![Self] { 196 if first_name == &name![Self] {
197 let idx = if path.segments.len() == 1 { None } else { Some(1) }; 197 let idx = if path.segments().len() == 1 { None } else { Some(1) };
198 return Some((TypeNs::AdtSelfType(*adt), idx)); 198 return Some((TypeNs::AdtSelfType(*adt), idx));
199 } 199 }
200 } 200 }
@@ -270,9 +270,9 @@ impl Resolver {
270 db: &dyn DefDatabase, 270 db: &dyn DefDatabase,
271 path: &ModPath, 271 path: &ModPath,
272 ) -> Option<ResolveValueResult> { 272 ) -> Option<ResolveValueResult> {
273 let n_segments = path.segments.len(); 273 let n_segments = path.segments().len();
274 let tmp = name![self]; 274 let tmp = name![self];
275 let first_name = if path.is_self() { &tmp } else { path.segments.first()? }; 275 let first_name = if path.is_self() { &tmp } else { path.segments().first()? };
276 let skip_to_mod = path.kind != PathKind::Plain && !path.is_self(); 276 let skip_to_mod = path.kind != PathKind::Plain && !path.is_self();
277 for scope in self.scopes.iter().rev() { 277 for scope in self.scopes.iter().rev() {
278 match scope { 278 match scope {
diff --git a/crates/hir_def/src/visibility.rs b/crates/hir_def/src/visibility.rs
index e79a91102..38da3132b 100644
--- a/crates/hir_def/src/visibility.rs
+++ b/crates/hir_def/src/visibility.rs
@@ -22,8 +22,7 @@ pub enum RawVisibility {
22 22
23impl RawVisibility { 23impl RawVisibility {
24 pub(crate) const fn private() -> RawVisibility { 24 pub(crate) const fn private() -> RawVisibility {
25 let path = ModPath { kind: PathKind::Super(0), segments: Vec::new() }; 25 RawVisibility::Module(ModPath::from_kind(PathKind::Super(0)))
26 RawVisibility::Module(path)
27 } 26 }
28 27
29 pub(crate) fn from_ast( 28 pub(crate) fn from_ast(
@@ -59,15 +58,15 @@ impl RawVisibility {
59 RawVisibility::Module(path) 58 RawVisibility::Module(path)
60 } 59 }
61 ast::VisibilityKind::PubCrate => { 60 ast::VisibilityKind::PubCrate => {
62 let path = ModPath { kind: PathKind::Crate, segments: Vec::new() }; 61 let path = ModPath::from_kind(PathKind::Crate);
63 RawVisibility::Module(path) 62 RawVisibility::Module(path)
64 } 63 }
65 ast::VisibilityKind::PubSuper => { 64 ast::VisibilityKind::PubSuper => {
66 let path = ModPath { kind: PathKind::Super(1), segments: Vec::new() }; 65 let path = ModPath::from_kind(PathKind::Super(1));
67 RawVisibility::Module(path) 66 RawVisibility::Module(path)
68 } 67 }
69 ast::VisibilityKind::PubSelf => { 68 ast::VisibilityKind::PubSelf => {
70 let path = ModPath { kind: PathKind::Plain, segments: Vec::new() }; 69 let path = ModPath::from_kind(PathKind::Plain);
71 RawVisibility::Module(path) 70 RawVisibility::Module(path)
72 } 71 }
73 ast::VisibilityKind::Pub => RawVisibility::Public, 72 ast::VisibilityKind::Pub => RawVisibility::Public,
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs
index d08867c70..4b683c5a7 100644
--- a/crates/hir_ty/src/infer.rs
+++ b/crates/hir_ty/src/infer.rs
@@ -461,7 +461,7 @@ impl<'a> InferenceContext<'a> {
461 (ty, variant) 461 (ty, variant)
462 } 462 }
463 Some(1) => { 463 Some(1) => {
464 let segment = path.mod_path().segments.last().unwrap(); 464 let segment = path.mod_path().segments().last().unwrap();
465 // this could be an enum variant or associated type 465 // this could be an enum variant or associated type
466 if let Some((AdtId::EnumId(enum_id), _)) = ty.as_adt() { 466 if let Some((AdtId::EnumId(enum_id), _)) = ty.as_adt() {
467 let enum_data = self.db.enum_data(enum_id); 467 let enum_data = self.db.enum_data(enum_id);
diff --git a/crates/ide_db/src/helpers.rs b/crates/ide_db/src/helpers.rs
index 0dcc4dd29..bc7aee110 100644
--- a/crates/ide_db/src/helpers.rs
+++ b/crates/ide_db/src/helpers.rs
@@ -24,7 +24,7 @@ pub fn mod_path_to_ast(path: &hir::ModPath) -> ast::Path {
24 } 24 }
25 25
26 segments.extend( 26 segments.extend(
27 path.segments 27 path.segments()
28 .iter() 28 .iter()
29 .map(|segment| make::path_segment(make::name_ref(&segment.to_string()))), 29 .map(|segment| make::path_segment(make::name_ref(&segment.to_string()))),
30 ); 30 );
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 07204436c..5a6501216 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -1729,7 +1729,7 @@ fn fill_resolve_data(
1729) -> Option<()> { 1729) -> Option<()> {
1730 let import_edit = item.import_to_add()?; 1730 let import_edit = item.import_to_add()?;
1731 let full_import_path = import_edit.import_path.to_string(); 1731 let full_import_path = import_edit.import_path.to_string();
1732 let imported_name = import_edit.import_path.segments.clone().pop()?.to_string(); 1732 let imported_name = import_edit.import_path.segments().last()?.to_string();
1733 1733
1734 *resolve_data = Some( 1734 *resolve_data = Some(
1735 to_value(CompletionResolveData { 1735 to_value(CompletionResolveData {