Skip to content

Prevent regions from being closed over and hidden from view #2203

Closed
@nikomatsakis

Description

@nikomatsakis
Contributor

Because a &T type is copyable, it is currently possible to close over them using an fn@() (and, eventually, iface@). This is clearly wrong. We need a new kind---perhaps heap or gc?---indicating data which is not only copyable but also copyable into a shared closure. This goes in between copy/send, I think.

Activity

graydon

graydon commented on Apr 20, 2012

@graydon
Contributor

Shared or unique, same problem.

I don't think this is a kinding problem, I think it's a region problem. You should not be able to write a region pointer into any region other than one of its own subregions. Forming a heap closure is such a write, and should be prohibited just as forming a heap record full of stack region pointers would be.

nikomatsakis

nikomatsakis commented on Apr 20, 2012

@nikomatsakis
ContributorAuthor

A heap record is totally allowed.

nikomatsakis

nikomatsakis commented on Apr 20, 2012

@nikomatsakis
ContributorAuthor

To clarify, it is legal to do this:

let x = 3;
let f = @{g: &x};

that poses no particular problem. I could see it being useful if you have a long-running computation with some context that is passed by region ptr, but the internal data used by the computation might be garbage-collected.

Naturally all of those heap-allocated records will not be accessible after the computation finishes.

graydon

graydon commented on Apr 20, 2012

@graydon
Contributor

Wow, I totally thought (and think) that should not be legal. We'll have to discuss once I'm at an irc window :)

nikomatsakis

nikomatsakis commented on Jul 17, 2012

@nikomatsakis
ContributorAuthor

this is done for closures in commit 0e42004

pnkfelix

pnkfelix commented on Jun 13, 2013

@pnkfelix
Member

related to #5723

Aatch

Aatch commented on Aug 13, 2013

@Aatch
Contributor

I think that has been fixed by the work @bblum did on trait and closure bounds.

Closing, re-open if I'm wrong.

bblum

bblum commented on Aug 13, 2013

@bblum
Contributor

I didn't solve region-related issues; we still lack the capability to write ~Trait:'a or somesuch. @nikomatsakis can confirm.

reopened this on Aug 13, 2013
catamorphism

catamorphism commented on Sep 26, 2013

@catamorphism
Contributor

Marked as clarifying - @nikomatsakis will investigate.

pcwalton

pcwalton commented on Nov 22, 2013

@pcwalton
Contributor

Nominating because I believe this is fixed.

pnkfelix

pnkfelix commented on Dec 19, 2013

@pnkfelix
Member

@nikomatsakis still needs to investigate, he is not certain it is fixed, and if it isn't, it still is on plate for 1.0

aturon

aturon commented on Sep 18, 2014

@aturon
Member

Nominating. I believe this issue has been resolved with #16453

pnkfelix

pnkfelix commented on Sep 18, 2014

@pnkfelix
Member

closing as fixed

added a commit that references this issue on Sep 22, 2022

Auto merge of rust-lang#2203 - RalfJung:deprecate, r=oli-obk

added a commit that references this issue on Jan 21, 2025
ce0d5c1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-lifetimesArea: Lifetimes / regions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @graydon@nikomatsakis@pcwalton@pnkfelix@Aatch

      Issue actions

        Prevent regions from being closed over and hidden from view · Issue #2203 · rust-lang/rust