#![allow(
clippy::enum_glob_use,
clippy::match_same_arms,
clippy::struct_field_names,
clippy::wildcard_imports
)]
#![allow(
clippy::cast_precision_loss,
clippy::cast_possible_truncation,
clippy::cast_sign_loss
)]
use super::*;
use crate::lang_helpers::bound_doc_run;
fn rendered_rows(node: &Node, doc: bool) -> (usize, usize) {
let (start, end) = (node.start_row(), node.end_row());
if doc && node.kind_id() == Rust::LineComment && end > start {
(start, end.saturating_sub(1))
} else {
(start, end)
}
}
impl Loc for RustCode {
fn compute<'a>(
node: &Node<'a>,
code: &[u8],
ancestors: Ancestors<'a, '_>,
stats: &mut Stats,
is_func_space: bool,
) {
use Rust::*;
let start = init(node, stats, is_func_space);
match node.kind_id().into() {
Block
| SourceFile
| SLASH
| SLASHSLASH
| SLASHSTAR
| STARSLASH
| OuterDocCommentMarker
| OuterDocCommentMarker2
| DocComment
| InnerDocCommentMarker
| BANG => {}
StringLiteral | RawStringLiteral => {
add_multiline_string_ploc(node, ancestors, stats, start);
}
BlockComment | LineComment => {
let doc = Self::is_doc_comment(node, code);
let (first, last) = rendered_rows(node, doc);
let documentation = doc && documents_by_placement::<Self>(node, code, ancestors);
add_comment_rows(stats, first, last, documentation);
bound_doc_run::<Self>(node, code, ancestors, |member| {
let (first, last) = rendered_rows(member, true);
stats.dloc.lines.insert_range(first, last);
});
}
Statement
| EmptyStatement
| ExpressionStatement
| LetDeclaration
| AssignmentExpression
| CompoundAssignmentExpr => {
stats.lloc.count_logical_line();
}
_ => {
check_comment_ends_on_code_line(stats, start);
stats.ploc.lines.insert(start);
}
}
}
}