@@ -522,30 +522,35 @@ impl LintInfo {
522522 }
523523}
524524
525- pub fn explain ( name : & str ) -> i32 {
526- let target = format ! ( "clippy::{}" , name. to_ascii_uppercase( ) ) ;
527-
528- if let Some ( info) = declared_lints:: LINTS . iter ( ) . find ( |info| info. lint . name == target) {
529- // Remove tags and hidden code:
530- let mut explanation = String :: with_capacity ( 128 ) ;
531- let mut in_code = false ;
532- for line in info. explanation . lines ( ) . map ( |line| line. trim ( ) ) {
533- if let Some ( lang) = line. strip_prefix ( "```" ) {
534- let tag = lang. split_once ( ',' ) . map_or ( lang, |( left, _) | left) ;
535- if !in_code && matches ! ( tag, "" | "rust" | "ignore" | "should_panic" | "no_run" | "compile_fail" ) {
536- explanation += "```rust\n " ;
537- } else {
538- explanation += line;
539- explanation. push ( '\n' ) ;
540- }
541- in_code = !in_code;
542- } else if !( in_code && line. starts_with ( "# " ) ) {
525+ // Remove code tags and code behind '# 's, as they are not needed for the lint docs and --explain
526+ pub fn sanitize_explanation ( raw_docs : & str ) -> String {
527+ // Remove tags and hidden code:
528+ let mut explanation = String :: with_capacity ( 128 ) ;
529+ let mut in_code = false ;
530+ for line in raw_docs. lines ( ) . map ( |line| line. trim ( ) ) {
531+ if let Some ( lang) = line. strip_prefix ( "```" ) {
532+ let tag = lang. split_once ( ',' ) . map_or ( lang, |( left, _) | left) ;
533+ if !in_code && matches ! ( tag, "" | "rust" | "ignore" | "should_panic" | "no_run" | "compile_fail" ) {
534+ explanation += "```rust\n " ;
535+ } else {
543536 explanation += line;
544537 explanation. push ( '\n' ) ;
545538 }
539+ in_code = !in_code;
540+ } else if !( in_code && line. starts_with ( "# " ) ) {
541+ explanation += line;
542+ explanation. push ( '\n' ) ;
546543 }
544+ }
547545
548- println ! ( "{}" , explanation) ;
546+ explanation
547+ }
548+
549+ pub fn explain ( name : & str ) -> i32 {
550+ let target = format ! ( "clippy::{}" , name. to_ascii_uppercase( ) ) ;
551+
552+ if let Some ( info) = declared_lints:: LINTS . iter ( ) . find ( |info| info. lint . name == target) {
553+ println ! ( "{}" , sanitize_explanation( info. explanation) ) ;
549554 // Check if the lint has configuration
550555 let mut mdconf = get_configuration_metadata ( ) ;
551556 let name = name. to_ascii_lowercase ( ) ;
0 commit comments