rust - Why should lifetime parameters be declared before type parameters? -


i trying out simple function when got compiler error. actual reason behind this? in case (following code), writing type parameter before lifetime parameter has no effect. shouldn't compiler know better?

use std::fmt::debug;  fn random_func<t : debug, 'a>(parameter : &'a mut t) {     println!("{:?}", parameter); }  fn main(){     let mut name : string = "random".to_string();     random_func(&mut name);     println!("{:?}", "compiled successfully"); } 

error:

life_time_trait.rs:3:27: 3:29 error: lifetime parameters must declared prior type parameters life_time_trait.rs:3 fn random_func<t : debug, 'a>(parameter : &'a mut t) {                                             ^~ 

i'm not sure the reason, remember type parameters can have lifetime bounds, lifetime parameters can't have type bounds. putting them first means don't need deal non-forward declarations.

personally, think rule makes things bit easier understand, , bit easier implement. win-win!


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -