Closed
Description
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);
- support ascription for patterns in NLL #53873 made these mostly work, but there are some edge cases where we still have problems. See the FIXME in the
patterns.rs
UI test. - remainder is broken out into handle user type annotations in NLL for complex patterns #54570
- support ascription for patterns in NLL #53873 made these mostly work, but there are some edge cases where we still have problems. See the FIXME in the
- "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);
- broken out into handle user type annotations in NLL for complex patterns #54570
-
ref
bindings: e.g.let ref x: u32 = 3;
, broken out into handle user type annotations in NLL forref
bindings #55401
- Simple local variable declarations, eg.
- 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
- Function calls. eg.
- Casts:
x as T
(broken out into NLL should respect lifetimes inas
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.
Metadata
Metadata
Assignees
Labels
Area: Non-lexical lifetimes (NLL)Category: An issue proposing an enhancement or a PR with one.Call for participation: Hard difficulty. Experience needed to fix: A lot.Working towards the "invalid code does not compile" goalRelevant to the compiler team, which will review and decide on the PR/issue.Issues about issues themselves ("bugs about bugs")