Is there a way to obtain elided lifetime parameters from the Rust compiler?

依然范特西╮ 提交于 2020-02-04 02:40:53

问题


Given a Rust program, which compiles correctly, can I get the compiler to tell me what the elided lifetimes were inferred to be?


回答1:


The cases where the compiler (currently1) can allow elided lifetimes are actually so simple that there isn't much the compiler could tell you about what it inferred:

Given a function, all elided lifetimes have the same value.

The compiler doesn't accept elided lifetimes in cases where it would have a choice to make. The exception is in methods, but tying all lifetimes to self is nearly always what is intended, so it makes sense for it to make this assumption.

[1] If a future version of Rust performed more sophisticated inference on elided lifetimes, then this question might have a far less trivial answer. For example the compiler could analyse the entire codebase to deduce a coherent set of lifetimes for all functions (or impls or structs if elision was permitted there too).



来源:https://stackoverflow.com/questions/34704612/is-there-a-way-to-obtain-elided-lifetime-parameters-from-the-rust-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!