Skip to content

Remove special rooting for @T #11586

Closed
@nikomatsakis

Description

@nikomatsakis

@T types currently have two rules: either the compiler can insert a root automatically, or else the borrow checker can try to take advantage of an existing root. The latter is more efficient and more flexible but occasionally less convenient, since users may have to insert a temporary by hand.

With @ moving into a library, we won't support the special auto-rooting behavior anymore. This simplifies the borrow checker and trans, but also will fix a weird case I discovered where the region inferencer fails to infer a proper lifetime:

            match expr.node {
                ast::ExprAddrOf(_, ref subexpr) |
                ast::ExprUnary(_, ast::UnDeref, ref subexpr) |
                ast::ExprField(ref subexpr, _, _) |
                ast::ExprIndex(_, ref subexpr, _) |
                ast::ExprParen(ref subexpr) => {
                    let subexpr: &'a @Expr = subexpr; // Should not be necessary
                    expr = &**subexpr;
                }
                _ => {
                    return;
                }
            }

The problem is that the region inferencer doesn't add a constraint indicating that the lifetime of &**subexpr is dependent on the region assigned to subexpr. subexpr has type &'b @Foo, and for this code to work, the region inferencer must ensure that 'b is a big enough region -- but it doesn't add the required constraint, because it thinks that the compiler will be able to root the @ box long enough.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions