@@ -43,7 +43,7 @@ use std::default::Default;
43
43
use std:: error;
44
44
use std:: fmt:: { self , Display , Formatter , Write as FmtWrite } ;
45
45
use std:: ffi:: OsStr ;
46
- use std:: fs:: { self , File } ;
46
+ use std:: fs:: { self , File , OpenOptions } ;
47
47
use std:: io:: prelude:: * ;
48
48
use std:: io:: { self , BufWriter , BufReader } ;
49
49
use std:: mem;
@@ -140,6 +140,8 @@ struct SharedContext {
140
140
/// Suffix to be added on resource files (if suffix is "-v2" then "light.css" becomes
141
141
/// "light-v2.css").
142
142
pub resource_suffix : String ,
143
+ /// Option disabled by default to generate files used by RLS and some other tools.
144
+ pub generate_redirect_pages : bool ,
143
145
}
144
146
145
147
impl SharedContext {
@@ -506,6 +508,7 @@ pub fn run(mut krate: clean::Crate,
506
508
extension_css,
507
509
extern_html_root_urls,
508
510
resource_suffix,
511
+ generate_redirect_pages,
509
512
..
510
513
} = options;
511
514
@@ -533,6 +536,7 @@ pub fn run(mut krate: clean::Crate,
533
536
sort_modules_alphabetically,
534
537
themes,
535
538
resource_suffix,
539
+ generate_redirect_pages,
536
540
} ;
537
541
538
542
// If user passed in `--playground-url` arg, we fill in crate name here
@@ -2143,6 +2147,27 @@ impl Context {
2143
2147
if !self . render_redirect_pages {
2144
2148
all. append ( full_path ( self , & item) , & item_type) ;
2145
2149
}
2150
+ if self . shared . generate_redirect_pages {
2151
+ // Redirect from a sane URL using the namespace to Rustdoc's
2152
+ // URL for the page.
2153
+ let redir_name = format ! ( "{}.{}.html" , name, item_type. name_space( ) ) ;
2154
+ let redir_dst = self . dst . join ( redir_name) ;
2155
+ if let Ok ( redirect_out) = OpenOptions :: new ( ) . create_new ( true )
2156
+ . write ( true )
2157
+ . open ( & redir_dst) {
2158
+ let mut redirect_out = BufWriter :: new ( redirect_out) ;
2159
+ try_err ! ( layout:: redirect( & mut redirect_out, file_name) , & redir_dst) ;
2160
+ }
2161
+ // If the item is a macro, redirect from the old macro URL (with !)
2162
+ // to the new one (without).
2163
+ if item_type == ItemType :: Macro {
2164
+ let redir_name = format ! ( "{}.{}!.html" , item_type, name) ;
2165
+ let redir_dst = self . dst . join ( redir_name) ;
2166
+ let redirect_out = try_err ! ( File :: create( & redir_dst) , & redir_dst) ;
2167
+ let mut redirect_out = BufWriter :: new ( redirect_out) ;
2168
+ try_err ! ( layout:: redirect( & mut redirect_out, file_name) , & redir_dst) ;
2169
+ }
2170
+ }
2146
2171
}
2147
2172
}
2148
2173
Ok ( ( ) )
0 commit comments