diff options
| author | bors <bors@rust-lang.org> | 2024-03-22 07:45:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-22 07:45:50 +0000 |
| commit | fc0d51ae655dd17ffe73fdf0b9a4819d262a8e1b (patch) | |
| tree | c383f323408b5666551883166855410844f2b057 | |
| parent | 5577612fd0007e5eee9bd4cd8170dbc7cb8a92f7 (diff) | |
| parent | 0e8170e846388d520b2242c01085c08eb59daa28 (diff) | |
| download | rust-fc0d51ae655dd17ffe73fdf0b9a4819d262a8e1b.tar.gz rust-fc0d51ae655dd17ffe73fdf0b9a4819d262a8e1b.zip | |
Auto merge of #16919 - roife:fix-issue-16800, r=Veykril
fix: handle self::super when lowering UseTree fix #16800.
| -rw-r--r-- | crates/hir-expand/src/mod_path.rs | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/crates/hir-expand/src/mod_path.rs b/crates/hir-expand/src/mod_path.rs index fc186d2c26d..46f8c2b9d8c 100644 --- a/crates/hir-expand/src/mod_path.rs +++ b/crates/hir-expand/src/mod_path.rs @@ -225,6 +225,26 @@ fn convert_path( let mut segments = path.segments(); let segment = &segments.next()?; + let handle_super_kw = &mut |init_deg| { + let mut deg = init_deg; + let mut next_segment = None; + for segment in segments.by_ref() { + match segment.kind()? { + ast::PathSegmentKind::SuperKw => deg += 1, + ast::PathSegmentKind::Name(name) => { + next_segment = Some(name.as_name()); + break; + } + ast::PathSegmentKind::Type { .. } + | ast::PathSegmentKind::SelfTypeKw + | ast::PathSegmentKind::SelfKw + | ast::PathSegmentKind::CrateKw => return None, + } + } + + Some(ModPath::from_segments(PathKind::Super(deg), next_segment)) + }; + let mut mod_path = match segment.kind()? { ast::PathSegmentKind::Name(name_ref) => { if name_ref.text() == "$crate" { @@ -245,26 +265,8 @@ fn convert_path( ModPath::from_segments(PathKind::Plain, Some(known::SELF_TYPE)) } ast::PathSegmentKind::CrateKw => ModPath::from_segments(PathKind::Crate, iter::empty()), - ast::PathSegmentKind::SelfKw => ModPath::from_segments(PathKind::Super(0), iter::empty()), - ast::PathSegmentKind::SuperKw => { - let mut deg = 1; - let mut next_segment = None; - for segment in segments.by_ref() { - match segment.kind()? { - ast::PathSegmentKind::SuperKw => deg += 1, - ast::PathSegmentKind::Name(name) => { - next_segment = Some(name.as_name()); - break; - } - ast::PathSegmentKind::Type { .. } - | ast::PathSegmentKind::SelfTypeKw - | ast::PathSegmentKind::SelfKw - | ast::PathSegmentKind::CrateKw => return None, - } - } - - ModPath::from_segments(PathKind::Super(deg), next_segment) - } + ast::PathSegmentKind::SelfKw => handle_super_kw(0)?, + ast::PathSegmentKind::SuperKw => handle_super_kw(1)?, ast::PathSegmentKind::Type { .. } => { // not allowed in imports return None; |
