7561: Avoid using ModPath's fields directly r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2021-02-04 21:42:57 +00:00 committed by GitHub
commit 842033b150
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 8 deletions

View file

@ -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)

View file

@ -129,7 +129,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
}
}
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<ast::Path> {

View file

@ -75,9 +75,10 @@ fn convert_path(prefix: Option<ModPath>, 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