Skip to content

Manual has incorrect statement of what lvalues are #10890

Closed
@ezyang

Description

@ezyang

Currently, the manual states that only "Path, field and index expressions are lvalues." However, this seems inaccurate; for example, *x should be considered an lvalue.

expr_kind in src/librustc/middle/ty.rs seems to have the definitive say on what is an lvalue:

    match expr.node {
        ast::ExprPath(..) | ast::ExprSelf => {
            match resolve_expr(tcx, expr) {
                ast::DefVariant(..) | ast::DefStruct(..) => RvalueDpsExpr,

                // Fn pointers are just scalar values.
                ast::DefFn(..) | ast::DefStaticMethod(..) => RvalueDatumExpr,

                // Note: there is actually a good case to be made that
                // def_args, particularly those of immediate type, ought to
                // considered rvalues.
                ast::DefStatic(..) |
                ast::DefBinding(..) |
                ast::DefUpvar(..) |
                ast::DefArg(..) |
                ast::DefLocal(..) |
                ast::DefSelf(..) => LvalueExpr,

                def => {
                    tcx.sess.span_bug(expr.span, format!(
                        "Uncategorized def for expr {:?}: {:?}",
                        expr.id, def));
                }
            }
        }

        ast::ExprUnary(_, ast::UnDeref, _) |
        ast::ExprField(..) |
        ast::ExprIndex(..) => {
            LvalueExpr
        }
[snip]

So, I suggest changing this line to something like, "Paths to memory locations, fields, index expressions and dereferences are lvalues." I can submit a pull request if people agree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions