-
Notifications
You must be signed in to change notification settings - Fork 13.4k
librustc: Implement arbitrary lifetimes in trait objects. #16068
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
librustc: Implement arbitrary lifetimes in trait objects. #16068
Conversation
(please tease apart the functional changes to rustc from the fallout from said changes. If you want to delegate that task to me, I am happy to do it.) |
Does this require that all trait objects in structures and impl headers have an explicitly marked lifetime? This looks like it unfortunately makes working with trait objects much more verbose. |
Yes. However, it is needed for safety. |
Niko has plans to fix some of the verbosity, but I don't know specifically what they are. I think we should merge this, because verbosity is no excuse for memory unsafety in safe code. |
All trait objects must be annotated with a lifetime. This means that code like this breaks: fn f(x: Box<Trait>) { ... } fn g<'a>(x: &'a Trait) { ... } Change this code to: fn f(x: Box<Trait+'static>) { ... } fn g<'a>(x: &'a Trait<'a>) { ... } This will be eventually addressed by some additions that @nikomatsakis wants. However, the fundamental thrust of this change is necessary to achieve memory safety. Further additions to improve ergonomics will follow. Closes rust-lang#5723.
I will review but it is difficult this week due to TC39. |
@nikomatsakis I'm happy to punt to @pnkfelix if you'd like. |
unsafe { | ||
// FIXME(pcwalton): This is totally bogus with the | ||
// lifetimes. I have no idea how this even worked to begin | ||
// with. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly it should not have type-checked before, but it is not bogus. In my branch the result of this function is Box<MacResult+'cx>
where 'cx
is the lifetime of the cx
variable.
Obsoleted by #16483. |
(I assume the link above was supposed to be to #16453 ) |
…e-conflicts, r=Veykril fix: pick up new names when the name conflicts in 'introduce_named_generic' Improve generation of names for generic parameters in `introduce_named_generics`. fix rust-lang#15731. ### Changes - Modified `for_generic_parameter` function in `suggest_name.rs` to handle conflicts with existing generic parameters and generate unique names accordingly. - Update `introduce_named_generic` function and pass existing params to `for_generic_parameter`, enabling the detection and handling of name collisions.
librustc: Implement arbitrary lifetimes in trait objects. …
All trait objects must be annotated with a lifetime. This means that
code like this breaks:
Change this code to:
This will be eventually addressed by some additions that @nikomatsakis
wants. However, the fundamental thrust of this change is necessary to
achieve memory safety. Further additions to improve ergonomics will
follow.
Closes #5723.
r? @nikomatsakis