Skip to content

Commit

Permalink
Extract turbofish_span
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jul 26, 2024
1 parent ec48f75 commit 8d212a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions compiler/noirc_frontend/src/ast/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,18 @@ pub struct PathSegment {
pub span: Span,
}

impl PathSegment {
/// Returns the span where turbofish happen. For example:
///
/// foo::<T>
/// ~^^^^
///
/// Returns an empty span at the end of `foo` if there's no turbofish.
pub fn turbofish_span(&self) -> Span {
Span::from(self.ident.span().end()..self.span.end())
}
}

impl From<Ident> for PathSegment {
fn from(ident: Ident) -> PathSegment {
let span = ident.span();
Expand Down
4 changes: 3 additions & 1 deletion compiler/noirc_frontend/src/elaborator/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,13 @@ impl<'context> Elaborator<'context> {
}
};

let turbofish_span = last_segment.turbofish_span();

let struct_generics = self.resolve_struct_turbofish_generics(
&r#type.borrow(),
struct_generics,
last_segment.generics,
Span::from(last_segment.ident.span().end()..last_segment.span.end()),
turbofish_span,
);

let struct_type = r#type.clone();
Expand Down
4 changes: 3 additions & 1 deletion compiler/noirc_frontend/src/elaborator/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,13 @@ impl<'context> Elaborator<'context> {
}
};

let turbofish_span = last_segment.turbofish_span();

let generics = self.resolve_struct_turbofish_generics(
&struct_type.borrow(),
generics,
last_segment.generics,
Span::from(last_segment.ident.span().end()..last_segment.span.end()),
turbofish_span,
);

let actual_type = Type::Struct(struct_type.clone(), generics);
Expand Down

0 comments on commit 8d212a7

Please sign in to comment.