Skip to content

Commit db6e337

Browse files
committed
refac: remove procedures for linting inside macros
1 parent ac57ec5 commit db6e337

File tree

1 file changed

+1
-51
lines changed

1 file changed

+1
-51
lines changed

clippy_lints/src/undocumented_unsafe_blocks.rs

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,7 @@ fn block_has_safety_comment(cx: &LateContext<'_>, span: Span) -> bool {
340340
// ```
341341
// won't work. This is to avoid dealing with where such a comment should be place relative to
342342
// attributes and doc comments.
343-
344-
matches!(
345-
span_from_macro_expansion_has_safety_comment(cx, span),
346-
HasSafetyComment::Yes(_)
347-
) || span_in_body_has_safety_comment(cx, span)
343+
span_in_body_has_safety_comment(cx, span)
348344
}
349345

350346
enum HasSafetyComment {
@@ -356,11 +352,6 @@ enum HasSafetyComment {
356352
/// Checks if the lines immediately preceding the item contain a safety comment.
357353
#[allow(clippy::collapsible_match)]
358354
fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> HasSafetyComment {
359-
match span_from_macro_expansion_has_safety_comment(cx, item.span) {
360-
HasSafetyComment::Maybe => (),
361-
has_safety_comment => return has_safety_comment,
362-
}
363-
364355
if item.span.ctxt() != SyntaxContext::root() {
365356
return HasSafetyComment::No;
366357
}
@@ -420,11 +411,6 @@ fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> HasSaf
420411
/// Checks if the lines immediately preceding the item contain a safety comment.
421412
#[allow(clippy::collapsible_match)]
422413
fn stmt_has_safety_comment(cx: &LateContext<'_>, span: Span, hir_id: HirId) -> HasSafetyComment {
423-
match span_from_macro_expansion_has_safety_comment(cx, span) {
424-
HasSafetyComment::Maybe => (),
425-
has_safety_comment => return has_safety_comment,
426-
}
427-
428414
if span.ctxt() != SyntaxContext::root() {
429415
return HasSafetyComment::No;
430416
}
@@ -490,42 +476,6 @@ fn comment_start_before_item_in_mod(
490476
})
491477
}
492478

493-
fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span) -> HasSafetyComment {
494-
let source_map = cx.sess().source_map();
495-
let ctxt = span.ctxt();
496-
if ctxt == SyntaxContext::root() {
497-
HasSafetyComment::Maybe
498-
} else {
499-
// From a macro expansion. Get the text from the start of the macro declaration to start of the
500-
// unsafe block.
501-
// macro_rules! foo { () => { stuff }; (x) => { unsafe { stuff } }; }
502-
// ^--------------------------------------------^
503-
if let Ok(unsafe_line) = source_map.lookup_line(span.lo())
504-
&& let Ok(macro_line) = source_map.lookup_line(ctxt.outer_expn_data().def_site.lo())
505-
&& Lrc::ptr_eq(&unsafe_line.sf, &macro_line.sf)
506-
&& let Some(src) = unsafe_line.sf.src.as_deref()
507-
{
508-
unsafe_line.sf.lines(|lines| {
509-
if macro_line.line < unsafe_line.line {
510-
match text_has_safety_comment(
511-
src,
512-
&lines[macro_line.line + 1..=unsafe_line.line],
513-
unsafe_line.sf.start_pos.to_usize(),
514-
) {
515-
Some(b) => HasSafetyComment::Yes(b),
516-
None => HasSafetyComment::No,
517-
}
518-
} else {
519-
HasSafetyComment::No
520-
}
521-
})
522-
} else {
523-
// Problem getting source text. Pretend a comment was found.
524-
HasSafetyComment::Maybe
525-
}
526-
}
527-
}
528-
529479
fn get_body_search_span(cx: &LateContext<'_>) -> Option<Span> {
530480
let body = cx.enclosing_body?;
531481
let map = cx.tcx.hir();

0 commit comments

Comments
 (0)