@@ -59,7 +59,7 @@ impl HTMLFormatter {
5959 ) -> Result < ( ) , Box < dyn Error > > {
6060 let mut output_file = File :: create ( parent_dir. join ( err_code) . with_extension ( "html" ) ) ?;
6161
62- self . header ( & mut output_file, "../" ) ?;
62+ self . header ( & mut output_file, "../" , "" ) ?;
6363 self . title ( & mut output_file, & format ! ( "Error code {}" , err_code) ) ?;
6464
6565 let mut id_map = IdMap :: new ( ) ;
@@ -90,7 +90,12 @@ impl HTMLFormatter {
9090 self . footer ( & mut output_file)
9191 }
9292
93- fn header ( & self , output : & mut dyn Write , extra : & str ) -> Result < ( ) , Box < dyn Error > > {
93+ fn header (
94+ & self ,
95+ output : & mut dyn Write ,
96+ extra_path : & str ,
97+ extra : & str ,
98+ ) -> Result < ( ) , Box < dyn Error > > {
9499 write ! (
95100 output,
96101 r##"<!DOCTYPE html>
@@ -99,14 +104,14 @@ impl HTMLFormatter {
99104<title>Rust Compiler Error Index</title>
100105<meta charset="utf-8">
101106<!-- Include rust.css after light.css so its rules take priority. -->
102- <link rel="stylesheet" type="text/css" href="{extra }rustdoc{suffix}.css"/>
103- <link rel="stylesheet" type="text/css" href="{extra }light{suffix}.css"/>
104- <link rel="stylesheet" type="text/css" href="{extra }rust.css"/>
107+ <link rel="stylesheet" type="text/css" href="{extra_path }rustdoc{suffix}.css"/>
108+ <link rel="stylesheet" type="text/css" href="{extra_path }light{suffix}.css"/>
109+ <link rel="stylesheet" type="text/css" href="{extra_path }rust.css"/>
105110<style>
106111.error-undescribed {{
107112 display: none;
108113}}
109- </style>
114+ </style>{extra}
110115</head>
111116<body>
112117"## ,
@@ -153,7 +158,22 @@ fn render_html(output_path: &Path, formatter: HTMLFormatter) -> Result<(), Box<d
153158 create_dir_all ( & parent) ?;
154159 }
155160
156- formatter. header ( & mut output_file, "" ) ?;
161+ formatter. header (
162+ & mut output_file,
163+ "" ,
164+ & format ! (
165+ r#"<script>(function() {{
166+ if (window.location.hash) {{
167+ let code = window.location.hash.replace(/^#/, '');
168+ // We have to make sure this pattern matches to avoid inadvertently creating an
169+ // open redirect.
170+ if (/^E[0-9]+$/.test(code)) {{
171+ window.location = './{error_codes_dir}/' + code + '.html';
172+ }}
173+ }}
174+ }})()</script>"#
175+ ) ,
176+ ) ?;
157177 formatter. title ( & mut output_file, "Rust Compiler Error Index" ) ?;
158178
159179 write ! (
0 commit comments