mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-26 12:27:20 +00:00
fix
This commit is contained in:
parent
1926217b86
commit
9e66f2d058
1 changed files with 7 additions and 10 deletions
|
@ -142,20 +142,19 @@ fn block_has_safety_comment(cx: &LateContext<'_>, block: &hir::Block<'_>) -> boo
|
||||||
/// Checks if the lines immediately preceding the item contain a safety comment.
|
/// Checks if the lines immediately preceding the item contain a safety comment.
|
||||||
#[allow(clippy::collapsible_match)]
|
#[allow(clippy::collapsible_match)]
|
||||||
fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> bool {
|
fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> bool {
|
||||||
if span_from_macro_expansion_has_safety_comment(cx, item.span) || span_in_body_has_safety_comment(cx, item.span) {
|
if span_from_macro_expansion_has_safety_comment(cx, item.span) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.span.ctxt() == SyntaxContext::root() {
|
if item.span.ctxt() == SyntaxContext::root() {
|
||||||
if let Some(parent_node) = get_parent_node(cx.tcx, item.hir_id()) {
|
if let Some(parent_node) = get_parent_node(cx.tcx, item.hir_id()) {
|
||||||
let comment_start;
|
let comment_start = match parent_node {
|
||||||
match parent_node {
|
|
||||||
Node::Crate(parent_mod) => {
|
Node::Crate(parent_mod) => {
|
||||||
comment_start = comment_start_before_impl_in_mod(cx, parent_mod, parent_mod.spans.inner_span, item);
|
comment_start_before_impl_in_mod(cx, parent_mod, parent_mod.spans.inner_span, item)
|
||||||
},
|
},
|
||||||
Node::Item(parent_item) => {
|
Node::Item(parent_item) => {
|
||||||
if let ItemKind::Mod(parent_mod) = &parent_item.kind {
|
if let ItemKind::Mod(parent_mod) = &parent_item.kind {
|
||||||
comment_start = comment_start_before_impl_in_mod(cx, parent_mod, parent_item.span, item);
|
comment_start_before_impl_in_mod(cx, parent_mod, parent_item.span, item)
|
||||||
} else {
|
} else {
|
||||||
// Doesn't support impls in this position. Pretend a comment was found.
|
// Doesn't support impls in this position. Pretend a comment was found.
|
||||||
return true;
|
return true;
|
||||||
|
@ -164,16 +163,14 @@ fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> bool {
|
||||||
Node::Stmt(stmt) => {
|
Node::Stmt(stmt) => {
|
||||||
if let Some(stmt_parent) = get_parent_node(cx.tcx, stmt.hir_id) {
|
if let Some(stmt_parent) = get_parent_node(cx.tcx, stmt.hir_id) {
|
||||||
match stmt_parent {
|
match stmt_parent {
|
||||||
Node::Block(block) => {
|
Node::Block(block) => walk_span_to_context(block.span, SyntaxContext::root()).map(Span::lo),
|
||||||
comment_start = walk_span_to_context(block.span, SyntaxContext::root()).map(Span::lo);
|
|
||||||
},
|
|
||||||
_ => {
|
_ => {
|
||||||
// Doesn't support impls in this position. Pretend a comment was found.
|
// Doesn't support impls in this position. Pretend a comment was found.
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Doesn't support impls in this position. Pretend a comment was found.
|
// Problem getting the parent node. Pretend a comment was found.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -181,7 +178,7 @@ fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> bool {
|
||||||
// Doesn't support impls in this position. Pretend a comment was found.
|
// Doesn't support impls in this position. Pretend a comment was found.
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
let source_map = cx.sess().source_map();
|
let source_map = cx.sess().source_map();
|
||||||
if let Some(comment_start) = comment_start
|
if let Some(comment_start) = comment_start
|
||||||
|
|
Loading…
Add table
Reference in a new issue