Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual has incorrect statement of what lvalues are #10890

Closed
ezyang opened this issue Dec 10, 2013 · 1 comment
Closed

Manual has incorrect statement of what lvalues are #10890

ezyang opened this issue Dec 10, 2013 · 1 comment

Comments

@ezyang
Copy link
Contributor

ezyang commented Dec 10, 2013

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.

@nikomatsakis
Copy link
Contributor

I agree. I would define lvalues like:

"An lvalue is an expression that represents a memory location. These expressions are paths to local variables, function and method arguments (including self), and static variables as well as dereferences (*expr), indexing expressions (expr[expr]), and field references (expr.f)."

@bors bors closed this as completed in b1b905f Dec 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants