@@ -7,6 +7,43 @@ use walkdir::WalkDir;
77
88mod groups;
99
10+ /// List of lints which have been renamed.
11+ ///
12+ /// These will get redirects in the output to the new name. The
13+ /// format is `(level, [(old_name, new_name), ...])`.
14+ ///
15+ /// Note: This hard-coded list is a temporary hack. The intent is in the
16+ /// future to have `rustc` expose this information in some way (like a `-Z`
17+ /// flag spitting out JSON). Also, this does not yet support changing the
18+ /// level of the lint, which will be more difficult to support, since rustc
19+ /// currently does not track that historical information.
20+ static RENAMES : & [ ( Level , & [ ( & str , & str ) ] ) ] = & [
21+ (
22+ Level :: Allow ,
23+ & [
24+ ( "single-use-lifetime" , "single-use-lifetimes" ) ,
25+ ( "elided-lifetime-in-path" , "elided-lifetimes-in-paths" ) ,
26+ ( "async-idents" , "keyword-idents" ) ,
27+ ( "disjoint-capture-migration" , "rust-2021-incompatible-closure-captures" ) ,
28+ ( "or-patterns-back-compat" , "rust-2021-incompatible-or-patterns" ) ,
29+ ] ,
30+ ) ,
31+ (
32+ Level :: Warn ,
33+ & [
34+ ( "bare-trait-object" , "bare-trait-objects" ) ,
35+ ( "unstable-name-collision" , "unstable-name-collisions" ) ,
36+ ( "unused-doc-comment" , "unused-doc-comments" ) ,
37+ ( "redundant-semicolon" , "redundant-semicolons" ) ,
38+ ( "overlapping-patterns" , "overlapping-range-endpoints" ) ,
39+ ( "non-fmt-panic" , "non-fmt-panics" ) ,
40+ ( "unused-tuple-struct-fields" , "dead-code" ) ,
41+ ( "static-mut-ref" , "static-mut-refs" ) ,
42+ ] ,
43+ ) ,
44+ ( Level :: Deny , & [ ( "exceeding-bitshifts" , "arithmetic-overflow" ) ] ) ,
45+ ] ;
46+
1047pub struct LintExtractor < ' a > {
1148 /// Path to the `src` directory, where it will scan for `.rs` files to
1249 /// find lint declarations.
@@ -126,6 +163,7 @@ impl<'a> LintExtractor<'a> {
126163 )
127164 } ) ?;
128165 }
166+ add_renamed_lints ( & mut lints) ;
129167 self . save_lints_markdown ( & lints) ?;
130168 self . generate_group_docs ( & lints) ?;
131169 Ok ( ( ) )
@@ -483,6 +521,7 @@ impl<'a> LintExtractor<'a> {
483521 }
484522 result. push ( '\n' ) ;
485523 }
524+ add_rename_redirect ( level, & mut result) ;
486525 let out_path = self . out_path . join ( "listing" ) . join ( level. doc_filename ( ) ) ;
487526 // Delete the output because rustbuild uses hard links in its copies.
488527 let _ = fs:: remove_file ( & out_path) ;
@@ -492,6 +531,56 @@ impl<'a> LintExtractor<'a> {
492531 }
493532}
494533
534+ /// Adds `Lint`s that have been renamed.
535+ fn add_renamed_lints ( lints : & mut Vec < Lint > ) {
536+ for ( level, names) in RENAMES {
537+ for ( from, to) in * names {
538+ lints. push ( Lint {
539+ name : from. to_string ( ) ,
540+ doc : vec ! [ format!( "The lint `{from}` has been renamed to [`{to}`](#{to})." ) ] ,
541+ level : * level,
542+ path : PathBuf :: new ( ) ,
543+ lineno : 0 ,
544+ } ) ;
545+ }
546+ }
547+ }
548+
549+ // This uses DOMContentLoaded instead of running immediately because for some
550+ // reason on Firefox (124 of this writing) doesn't update the `target` CSS
551+ // selector if only the hash changes.
552+ static RENAME_START : & str = "
553+ <script>
554+ document.addEventListener(\" DOMContentLoaded\" , (event) => {
555+ var fragments = {
556+ " ;
557+
558+ static RENAME_END : & str = "\
559+ };
560+ var target = fragments[window.location.hash];
561+ if (target) {
562+ var url = window.location.toString();
563+ var base = url.substring(0, url.lastIndexOf('/'));
564+ window.location.replace(base + \" /\" + target);
565+ }
566+ });
567+ </script>
568+ " ;
569+
570+ /// Adds the javascript redirection code to the given markdown output.
571+ fn add_rename_redirect ( level : Level , output : & mut String ) {
572+ for ( rename_level, names) in RENAMES {
573+ if * rename_level == level {
574+ let filename = level. doc_filename ( ) . replace ( ".md" , ".html" ) ;
575+ output. push_str ( RENAME_START ) ;
576+ for ( from, to) in * names {
577+ write ! ( output, " \" #{from}\" : \" {filename}#{to}\" ,\n " ) . unwrap ( ) ;
578+ }
579+ output. push_str ( RENAME_END ) ;
580+ }
581+ }
582+ }
583+
495584/// Extracts the lint name (removing the visibility modifier, and checking validity).
496585fn lint_name ( line : & str ) -> Result < String , & ' static str > {
497586 // Skip over any potential `pub` visibility.
0 commit comments