Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit fc0d51a

Browse files
committed
Auto merge of rust-lang#16919 - roife:fix-issue-16800, r=Veykril
fix: handle self::super when lowering UseTree fix rust-lang#16800.
2 parents 5577612 + 0e8170e commit fc0d51a

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

crates/hir-expand/src/mod_path.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,26 @@ fn convert_path(
225225
let mut segments = path.segments();
226226

227227
let segment = &segments.next()?;
228+
let handle_super_kw = &mut |init_deg| {
229+
let mut deg = init_deg;
230+
let mut next_segment = None;
231+
for segment in segments.by_ref() {
232+
match segment.kind()? {
233+
ast::PathSegmentKind::SuperKw => deg += 1,
234+
ast::PathSegmentKind::Name(name) => {
235+
next_segment = Some(name.as_name());
236+
break;
237+
}
238+
ast::PathSegmentKind::Type { .. }
239+
| ast::PathSegmentKind::SelfTypeKw
240+
| ast::PathSegmentKind::SelfKw
241+
| ast::PathSegmentKind::CrateKw => return None,
242+
}
243+
}
244+
245+
Some(ModPath::from_segments(PathKind::Super(deg), next_segment))
246+
};
247+
228248
let mut mod_path = match segment.kind()? {
229249
ast::PathSegmentKind::Name(name_ref) => {
230250
if name_ref.text() == "$crate" {
@@ -245,26 +265,8 @@ fn convert_path(
245265
ModPath::from_segments(PathKind::Plain, Some(known::SELF_TYPE))
246266
}
247267
ast::PathSegmentKind::CrateKw => ModPath::from_segments(PathKind::Crate, iter::empty()),
248-
ast::PathSegmentKind::SelfKw => ModPath::from_segments(PathKind::Super(0), iter::empty()),
249-
ast::PathSegmentKind::SuperKw => {
250-
let mut deg = 1;
251-
let mut next_segment = None;
252-
for segment in segments.by_ref() {
253-
match segment.kind()? {
254-
ast::PathSegmentKind::SuperKw => deg += 1,
255-
ast::PathSegmentKind::Name(name) => {
256-
next_segment = Some(name.as_name());
257-
break;
258-
}
259-
ast::PathSegmentKind::Type { .. }
260-
| ast::PathSegmentKind::SelfTypeKw
261-
| ast::PathSegmentKind::SelfKw
262-
| ast::PathSegmentKind::CrateKw => return None,
263-
}
264-
}
265-
266-
ModPath::from_segments(PathKind::Super(deg), next_segment)
267-
}
268+
ast::PathSegmentKind::SelfKw => handle_super_kw(0)?,
269+
ast::PathSegmentKind::SuperKw => handle_super_kw(1)?,
268270
ast::PathSegmentKind::Type { .. } => {
269271
// not allowed in imports
270272
return None;

0 commit comments

Comments
 (0)