Closed
Description
Consider the test in-band-lifetimes/impl/dyn-trait.rs.
- An aside: Normally pnkfelix would copy the source text inline, but in this case the source text is testing a totally different bug and will probably obscure the main point I am making here.
- There is probably a much smaller test case that would also succeed in making the point here; I may try to come up with such a minimal test, and post it here if I do.
For AST-borrowck we produce this output dyn-trait.stderr:
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> $DIR/dyn-trait.rs:32:16
|
LL | static_val(x); //~ ERROR cannot infer
| ^
|
note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 31:1...
--> $DIR/dyn-trait.rs:31:1
|
LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...so that the expression is assignable:
expected std::boxed::Box<std::fmt::Debug>
found std::boxed::Box<std::fmt::Debug + 'a>
= note: but, the lifetime must be valid for the static lifetime...
= note: ...so that the types are compatible:
expected StaticTrait
found StaticTrait
error: aborting due to previous error
but for NLL we currently produce this output dyn-trait.nll.stderr:
error: free region `'a` does not outlive free region `'static`
--> $DIR/dyn-trait.rs:32:5
|
LL | static_val(x); //~ ERROR cannot infer
| ^^^^^^^^^^^^^
error: aborting due to previous error
One can debate how much utility the end user gets from the potential overload of lines that the AST-borrowck note generates, but it is certainly more useful than the output that NLL is currently generated.
At its heart, the issue here is that NLL currently builds up a set of constraints and tells us if it couldn't resolve them, but it fails to present the causes that led to that constraint set.