We have made some progress on this issue.
Here's a list of everywhere within function bodies where we annotate types, with check boxes on the ones that are currently getting checked by the MIR-borrowck / NLL.
Let bindings
Simple local variable declarations, eg. let x: u32 = 3;
More complicated let bindings. eg. let (x, y): (u32, u32) = (33, 54);
"Ignored" bindings, eg. let _: Foo<'long> = c_is_short_oops; (support ascription for patterns in NLL #53873 )
Simple bindings with no initializer, e.g., let x: T; (support ascription for patterns in NLL #53873 )
Complex bindings with no initializer, e.g., let (x, y): (u32, u32);
ref bindings: e.g. let ref x: u32 = 3;, broken out into handle user type annotations in NLL for ref bindings #55401
Turbofish
Function calls. eg. "2048".parse::<u32>() -- MIR: support user-given type annotations on fns, structs, and enums #53225
Fully qualified paths. eg. <T as Trait<_>>::method -- MIR: support user-given type annotations on fns, structs, and enums #53225
Fully qualified paths. eg. <_ as Trait<T>>::method -- MIR: support user-given type annotations on fns, structs, and enums #53225
Fully qualified paths. eg. <_ as Trait<_>>::method<T> -- MIR: support user-given type annotations on fns, structs, and enums #53225
Multi-segment paths. e.g. Foo::<X>::method -- broken out into nll should respect lifetime annotations from multi-segment paths #54574
Value references. eg. let x = foo::<...>; -- MIR: support user-given type annotations on fns, structs, and enums #53225
Struct names. eg. let x = SomeStruct::<'static> { field: u32 }; -- MIR: support user-given type annotations on fns, structs, and enums #53225
Associated constants in expressions: <T as Foo>::BAR ? (broken out to nll: respect user type annotations with constants in expressions #54571 )
Associated constants in patterns: <T as Foo>::BAR ? (nll: respect user type annotations with constants in patterns #55511 )
Lifetimes in patterns: let A::<'static>(r) = ... ? -- broken out into nll should respect lifetime annotations from patterns #54573
Calls to enum variants / struct ctors: Enum::Variant::<...>(...) -- MIR: support user-given type annotations on fns, structs, and enums #53225
Reference to nullary structs / variants: None::<&'static u32> -- MIR: support user-given type annotations on fns, structs, and enums #53225
Casts: x as T (broken out into NLL should respect lifetimes in as expressions #54332 )
Type ascription: x: &'static u32 (broken out into nll should preserve user types in type ascription #54331 )
Method call disambiguation. eg. <Type as Trait>::method(args); -- MIR: support user-given type annotations on fns, structs, and enums #53225
Lifetimes defined but not used, this currently only occurs in the yield-subtype.rs test but that will also need resolved.
Normalization code is probably wrong (the user types need, I suspect, to be normalized? Not sure, have to look.)
(We should update this list as we think of more.)
Original bug report follows:
This code compiles with 1.24.0-nightly (2018-01-03 0a3761e ):
#![ feature( nll) ]
fn main ( ) {
let vec: Vec < & ' static String > = vec ! [ & String :: new( ) ] ;
// fn only_static(_: Vec<&'static String>) {}
// only_static(vec);
}
This is confusing as the Vec almost certainly cannot contain a reference of a 'static lifetime. If you uncomment the call to only_static, you get the expected error that the String does not live long enough.
@nikomatsakis said:
NLL currently ignores hand-written type annotations, in particular, those that appear in local variables.
We have made some progress on this issue.
Here's a list of everywhere within function bodies where we annotate types, with check boxes on the ones that are currently getting checked by the MIR-borrowck / NLL.
let x: u32 = 3;let (x, y): (u32, u32) = (33, 54);patterns.rsUI test.let _: Foo<'long> = c_is_short_oops;(support ascription for patterns in NLL #53873)let x: T;(support ascription for patterns in NLL #53873)let (x, y): (u32, u32);refbindings: e.g.let ref x: u32 = 3;, broken out into handle user type annotations in NLL forrefbindings #55401"2048".parse::<u32>()-- MIR: support user-given type annotations on fns, structs, and enums #53225<T as Trait<_>>::method-- MIR: support user-given type annotations on fns, structs, and enums #53225<_ as Trait<T>>::method-- MIR: support user-given type annotations on fns, structs, and enums #53225<_ as Trait<_>>::method<T>-- MIR: support user-given type annotations on fns, structs, and enums #53225Foo::<X>::method-- broken out into nll should respect lifetime annotations from multi-segment paths #54574let x = foo::<...>;-- MIR: support user-given type annotations on fns, structs, and enums #53225let x = SomeStruct::<'static> { field: u32 };-- MIR: support user-given type annotations on fns, structs, and enums #53225<T as Foo>::BAR? (broken out to nll: respect user type annotations with constants in expressions #54571)<T as Foo>::BAR? (nll: respect user type annotations with constants in patterns #55511)let A::<'static>(r) = ...? -- broken out into nll should respect lifetime annotations from patterns #54573Enum::Variant::<...>(...)-- MIR: support user-given type annotations on fns, structs, and enums #53225None::<&'static u32>-- MIR: support user-given type annotations on fns, structs, and enums #53225x as T(broken out into NLL should respect lifetimes inasexpressions #54332)x: &'static u32(broken out into nll should preserve user types in type ascription #54331)<Type as Trait>::method(args);-- MIR: support user-given type annotations on fns, structs, and enums #53225yield-subtype.rstest but that will also need resolved.(We should update this list as we think of more.)
Original bug report follows:
This code compiles with 1.24.0-nightly (2018-01-03 0a3761e):
This is confusing as the
Vecalmost certainly cannot contain a reference of a'staticlifetime. If you uncomment the call toonly_static, you get the expected error that theStringdoes not live long enough.@nikomatsakis said: