@@ -201,19 +201,19 @@ impl<'tcx> Context<'tcx> {
201201 } else {
202202 tyname. as_str ( )
203203 } ;
204- let page = layout:: Page {
205- css_class : tyname_s,
206- root_path : & self . root_path ( ) ,
207- static_root_path : self . shared . static_root_path . as_deref ( ) ,
208- title : & title,
209- description : & desc,
210- keywords : & keywords,
211- resource_suffix : & self . shared . resource_suffix ,
212- extra_scripts : & [ ] ,
213- static_extra_scripts : & [ ] ,
214- } ;
215204
216205 if !self . render_redirect_pages {
206+ let page = layout:: Page {
207+ css_class : tyname_s,
208+ root_path : & self . root_path ( ) ,
209+ static_root_path : self . shared . static_root_path . as_deref ( ) ,
210+ title : & title,
211+ description : & desc,
212+ keywords : & keywords,
213+ resource_suffix : & self . shared . resource_suffix ,
214+ extra_scripts : & [ ] ,
215+ static_extra_scripts : & [ ] ,
216+ } ;
217217 layout:: render (
218218 & self . shared . layout ,
219219 & page,
@@ -223,23 +223,31 @@ impl<'tcx> Context<'tcx> {
223223 )
224224 } else {
225225 if let Some ( & ( ref names, ty) ) = self . cache ( ) . paths . get ( & it. def_id . expect_def_id ( ) ) {
226- let mut path = String :: new ( ) ;
227- for name in & names[ ..names. len ( ) - 1 ] {
228- path. push_str ( & name. as_str ( ) ) ;
229- path. push ( '/' ) ;
230- }
231- path. push_str ( & item_path ( ty, & names. last ( ) . unwrap ( ) . as_str ( ) ) ) ;
232- match self . shared . redirections {
233- Some ( ref redirections) => {
234- let mut current_path = String :: new ( ) ;
235- for name in & self . current {
236- current_path. push_str ( & name. as_str ( ) ) ;
237- current_path. push ( '/' ) ;
226+ if self . current . len ( ) + 1 != names. len ( )
227+ || self . current . iter ( ) . zip ( names. iter ( ) ) . any ( |( a, b) | a != b)
228+ {
229+ // We checked that the redirection isn't pointing to the current file,
230+ // preventing an infinite redirection loop in the generated
231+ // documentation.
232+
233+ let mut path = String :: new ( ) ;
234+ for name in & names[ ..names. len ( ) - 1 ] {
235+ path. push_str ( & name. as_str ( ) ) ;
236+ path. push ( '/' ) ;
237+ }
238+ path. push_str ( & item_path ( ty, & names. last ( ) . unwrap ( ) . as_str ( ) ) ) ;
239+ match self . shared . redirections {
240+ Some ( ref redirections) => {
241+ let mut current_path = String :: new ( ) ;
242+ for name in & self . current {
243+ current_path. push_str ( & name. as_str ( ) ) ;
244+ current_path. push ( '/' ) ;
245+ }
246+ current_path. push_str ( & item_path ( ty, & names. last ( ) . unwrap ( ) . as_str ( ) ) ) ;
247+ redirections. borrow_mut ( ) . insert ( current_path, path) ;
238248 }
239- current_path. push_str ( & item_path ( ty, & names. last ( ) . unwrap ( ) . as_str ( ) ) ) ;
240- redirections. borrow_mut ( ) . insert ( current_path, path) ;
249+ None => return layout:: redirect ( & format ! ( "{}{}" , self . root_path( ) , path) ) ,
241250 }
242- None => return layout:: redirect ( & format ! ( "{}{}" , self . root_path( ) , path) ) ,
243251 }
244252 }
245253 String :: new ( )
0 commit comments