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

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -