@@ -87,6 +87,7 @@ use rustc_hir::{
8787 Mutability , Node , Param , Pat , PatKind , Path , PathSegment , PrimTy , QPath , Stmt , StmtKind , TraitItem , TraitItemKind ,
8888 TraitRef , TyKind , UnOp ,
8989} ;
90+ use rustc_lexer:: { tokenize, TokenKind } ;
9091use rustc_lint:: { LateContext , Level , Lint , LintContext } ;
9192use rustc_middle:: hir:: place:: PlaceBase ;
9293use rustc_middle:: ty as rustc_ty;
@@ -104,6 +105,7 @@ use rustc_semver::RustcVersion;
104105use rustc_session:: Session ;
105106use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
106107use rustc_span:: source_map:: original_sp;
108+ use rustc_span:: source_map:: SourceMap ;
107109use rustc_span:: sym;
108110use rustc_span:: symbol:: { kw, Symbol } ;
109111use rustc_span:: { Span , DUMMY_SP } ;
@@ -2278,6 +2280,18 @@ pub fn walk_to_expr_usage<'tcx, T>(
22782280 None
22792281}
22802282
2283+ /// Checks whether a given span has any comment token
2284+ /// This checks for all types of comment: line "//", block "/**", doc "///" "//!"
2285+ pub fn span_contains_comment ( sm : & SourceMap , span : Span ) -> bool {
2286+ let Ok ( snippet) = sm. span_to_snippet ( span) else { return false } ;
2287+ return tokenize ( & snippet) . any ( |token| {
2288+ matches ! (
2289+ token. kind,
2290+ TokenKind :: BlockComment { .. } | TokenKind :: LineComment { .. }
2291+ )
2292+ } ) ;
2293+ }
2294+
22812295macro_rules! op_utils {
22822296 ( $( $name: ident $assign: ident) * ) => {
22832297 /// Binary operation traits like `LangItem::Add`
0 commit comments