@@ -87,6 +87,7 @@ use rustc_hir::{
87
87
Mutability , Node , Param , Pat , PatKind , Path , PathSegment , PrimTy , QPath , Stmt , StmtKind , TraitItem , TraitItemKind ,
88
88
TraitRef , TyKind , UnOp ,
89
89
} ;
90
+ use rustc_lexer:: { tokenize, TokenKind } ;
90
91
use rustc_lint:: { LateContext , Level , Lint , LintContext } ;
91
92
use rustc_middle:: hir:: place:: PlaceBase ;
92
93
use rustc_middle:: ty as rustc_ty;
@@ -104,6 +105,7 @@ use rustc_semver::RustcVersion;
104
105
use rustc_session:: Session ;
105
106
use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
106
107
use rustc_span:: source_map:: original_sp;
108
+ use rustc_span:: source_map:: SourceMap ;
107
109
use rustc_span:: sym;
108
110
use rustc_span:: symbol:: { kw, Symbol } ;
109
111
use rustc_span:: { Span , DUMMY_SP } ;
@@ -2278,6 +2280,18 @@ pub fn walk_to_expr_usage<'tcx, T>(
2278
2280
None
2279
2281
}
2280
2282
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
+
2281
2295
macro_rules! op_utils {
2282
2296
( $( $name: ident $assign: ident) * ) => {
2283
2297
/// Binary operation traits like `LangItem::Add`
0 commit comments