Impl foo for bar {}; trait foo : bar { ... }

Hello Rustaceans,

I'm a bit puzzled with this piece of code below
(source : https://github.com/rust-lang/miri/blob/master/src/helpers.rs#L16-L18)

I have two questions regarding line 18..

  1. Assuming 'mir and 'tcx are lifetime parameters, what does 'tcx: 'mir mean?? Can lifetime parameters work like trait bounds??
  2. What does crate::MiriEvalContextExt<'mir, 'tcx> do in line 18?? What does it mean to have something after a trait name and a colon?? I

I still feel that I have a long way to go to even properly appreciate Rust code..
Any help would be appreciated! Thanks :smile:

I think I may have just come up with an answer to my second question :
inheritance
https://doc.rust-lang.org/1.8.0/book/traits.html#inheritance

This specifies that lifetime 'tcx must live at least as long as lifetime 'mir

This specifies that any implementation of EvalContextExt must also implement crate::MiriEvalContextExt for the give lifetime parameters, it is just syntactic sugar for

trait EvalContextExt<'mir, 'tcx: 'mir> where Self: MiriEvalContextExt<'mir, tcx> {
   // ...
}
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.