Skip to content

Commit 8132d4e

Browse files
committed
Move is_place_expr to be a method on hir::Expr
1 parent 79fcc58 commit 8132d4e

File tree

3 files changed

+62
-60
lines changed

3 files changed

+62
-60
lines changed

src/librustc/hir/mod.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,59 @@ impl Expr {
13451345
ExprKind::Yield(..) => ExprPrecedence::Yield,
13461346
}
13471347
}
1348+
1349+
pub fn is_place_expr(&self) -> bool {
1350+
match self.node {
1351+
ExprKind::Path(QPath::Resolved(_, ref path)) => {
1352+
match path.def {
1353+
Def::Local(..) | Def::Upvar(..) | Def::Static(..) | Def::Err => true,
1354+
_ => false,
1355+
}
1356+
}
1357+
1358+
ExprKind::Type(ref e, _) => {
1359+
e.is_place_expr()
1360+
}
1361+
1362+
ExprKind::Unary(UnDeref, _) |
1363+
ExprKind::Field(..) |
1364+
ExprKind::Index(..) => {
1365+
true
1366+
}
1367+
1368+
// Partially qualified paths in expressions can only legally
1369+
// refer to associated items which are always rvalues.
1370+
ExprKind::Path(QPath::TypeRelative(..)) |
1371+
1372+
ExprKind::Call(..) |
1373+
ExprKind::MethodCall(..) |
1374+
ExprKind::Struct(..) |
1375+
ExprKind::Tup(..) |
1376+
ExprKind::If(..) |
1377+
ExprKind::Match(..) |
1378+
ExprKind::Closure(..) |
1379+
ExprKind::Block(..) |
1380+
ExprKind::Repeat(..) |
1381+
ExprKind::Array(..) |
1382+
ExprKind::Break(..) |
1383+
ExprKind::Continue(..) |
1384+
ExprKind::Ret(..) |
1385+
ExprKind::While(..) |
1386+
ExprKind::Loop(..) |
1387+
ExprKind::Assign(..) |
1388+
ExprKind::InlineAsm(..) |
1389+
ExprKind::AssignOp(..) |
1390+
ExprKind::Lit(_) |
1391+
ExprKind::Unary(..) |
1392+
ExprKind::Box(..) |
1393+
ExprKind::AddrOf(..) |
1394+
ExprKind::Binary(..) |
1395+
ExprKind::Yield(..) |
1396+
ExprKind::Cast(..) => {
1397+
false
1398+
}
1399+
}
1400+
}
13481401
}
13491402

13501403
impl fmt::Debug for Expr {

src/librustc_typeck/check/mod.rs

Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,59 +2447,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
24472447
}
24482448
}
24492449

2450-
fn is_place_expr(&self, expr: &hir::Expr) -> bool {
2451-
match expr.node {
2452-
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
2453-
match path.def {
2454-
Def::Local(..) | Def::Upvar(..) | Def::Static(..) | Def::Err => true,
2455-
_ => false,
2456-
}
2457-
}
2458-
2459-
hir::ExprKind::Type(ref e, _) => {
2460-
self.is_place_expr(e)
2461-
}
2462-
2463-
hir::ExprKind::Unary(hir::UnDeref, _) |
2464-
hir::ExprKind::Field(..) |
2465-
hir::ExprKind::Index(..) => {
2466-
true
2467-
}
2468-
2469-
// Partially qualified paths in expressions can only legally
2470-
// refer to associated items which are always rvalues.
2471-
hir::ExprKind::Path(hir::QPath::TypeRelative(..)) |
2472-
2473-
hir::ExprKind::Call(..) |
2474-
hir::ExprKind::MethodCall(..) |
2475-
hir::ExprKind::Struct(..) |
2476-
hir::ExprKind::Tup(..) |
2477-
hir::ExprKind::If(..) |
2478-
hir::ExprKind::Match(..) |
2479-
hir::ExprKind::Closure(..) |
2480-
hir::ExprKind::Block(..) |
2481-
hir::ExprKind::Repeat(..) |
2482-
hir::ExprKind::Array(..) |
2483-
hir::ExprKind::Break(..) |
2484-
hir::ExprKind::Continue(..) |
2485-
hir::ExprKind::Ret(..) |
2486-
hir::ExprKind::While(..) |
2487-
hir::ExprKind::Loop(..) |
2488-
hir::ExprKind::Assign(..) |
2489-
hir::ExprKind::InlineAsm(..) |
2490-
hir::ExprKind::AssignOp(..) |
2491-
hir::ExprKind::Lit(_) |
2492-
hir::ExprKind::Unary(..) |
2493-
hir::ExprKind::Box(..) |
2494-
hir::ExprKind::AddrOf(..) |
2495-
hir::ExprKind::Binary(..) |
2496-
hir::ExprKind::Yield(..) |
2497-
hir::ExprKind::Cast(..) => {
2498-
false
2499-
}
2500-
}
2501-
}
2502-
25032450
/// For the overloaded place expressions (`*x`, `x[3]`), the trait
25042451
/// returns a type of `&T`, but the actual type we assign to the
25052452
/// *expression* is `T`. So this function just peels off the return
@@ -3762,10 +3709,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
37623709
ty
37633710
}
37643711

3765-
fn check_expr_kind(&self,
3766-
expr: &'gcx hir::Expr,
3767-
expected: Expectation<'tcx>,
3768-
needs: Needs) -> Ty<'tcx> {
3712+
fn check_expr_kind(
3713+
&self,
3714+
expr: &'gcx hir::Expr,
3715+
expected: Expectation<'tcx>,
3716+
needs: Needs
3717+
) -> Ty<'tcx> {
37693718
let tcx = self.tcx;
37703719
let id = expr.id;
37713720
match expr.node {
@@ -3862,7 +3811,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38623811
let hint = expected.only_has_type(self).map_or(NoExpectation, |ty| {
38633812
match ty.sty {
38643813
ty::Ref(_, ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) => {
3865-
if self.is_place_expr(&oprnd) {
3814+
if oprnd.is_place_expr() {
38663815
// Places may legitimately have unsized types.
38673816
// For example, dereferences of a fat pointer and
38683817
// the last field of a struct can be unsized.
@@ -4041,7 +3990,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
40413990
_ => {
40423991
// Only check this if not in an `if` condition, as the
40433992
// mistyped comparison help is more appropriate.
4044-
if !self.is_place_expr(&lhs) {
3993+
if !lhs.is_place_expr() {
40453994
struct_span_err!(self.tcx.sess, expr.span, E0070,
40463995
"invalid left-hand side expression")
40473996
.span_label(expr.span, "left-hand of expression not valid")

src/librustc_typeck/check/op.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4040
return_ty
4141
};
4242

43-
if !self.is_place_expr(lhs_expr) {
43+
if !lhs_expr.is_place_expr() {
4444
struct_span_err!(
4545
self.tcx.sess, lhs_expr.span,
4646
E0067, "invalid left-hand side expression")

0 commit comments

Comments
 (0)