about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2014-05-01 03:00:19 -0400
committerDaniel Micay <danielmicay@gmail.com>2014-05-01 17:43:00 -0400
commite93cb04c4b011088d3b13a17bdf4cb865730dd38 (patch)
tree2cf2ba7c72610463373666ad9480ffaad1d4f0c5
parent7852625b8671211125564cba69d982dd4ee5db24 (diff)
downloadrust-e93cb04c4b011088d3b13a17bdf4cb865730dd38.tar.gz
rust-e93cb04c4b011088d3b13a17bdf4cb865730dd38.zip
fix error message for obsolete &"foo" literal
-rw-r--r--src/librustc/middle/typeck/check/mod.rs127
1 files changed, 65 insertions, 62 deletions
diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs
index cc899b849b6..5c3f99d1905 100644
--- a/src/librustc/middle/typeck/check/mod.rs
+++ b/src/librustc/middle/typeck/check/mod.rs
@@ -2564,71 +2564,74 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
     let tcx = fcx.ccx.tcx;
     let id = expr.id;
     match expr.node {
-      ast::ExprVstore(ev, vst) => {
-        let typ = match ev.node {
-          ast::ExprVec(ref args) => {
-            let mutability = match vst {
-                ast::ExprVstoreMutSlice => ast::MutMutable,
-                _ => ast::MutImmutable,
-            };
-            let mut any_error = false;
-            let mut any_bot = false;
-            let t: ty::t = fcx.infcx().next_ty_var();
-            for e in args.iter() {
-                check_expr_has_type(fcx, *e, t);
-                let arg_t = fcx.expr_ty(*e);
-                if ty::type_is_error(arg_t) {
-                    any_error = true;
+        ast::ExprVstore(ev, vst) => {
+            let typ = match ev.node {
+                ast::ExprVec(ref args) => {
+                    let mutability = match vst {
+                        ast::ExprVstoreMutSlice => ast::MutMutable,
+                        _ => ast::MutImmutable,
+                    };
+                    let mut any_error = false;
+                    let mut any_bot = false;
+                    let t: ty::t = fcx.infcx().next_ty_var();
+                    for e in args.iter() {
+                        check_expr_has_type(fcx, *e, t);
+                        let arg_t = fcx.expr_ty(*e);
+                        if ty::type_is_error(arg_t) {
+                            any_error = true;
+                        }
+                        else if ty::type_is_bot(arg_t) {
+                            any_bot = true;
+                        }
+                    }
+                    if any_error {
+                        ty::mk_err()
+                    } else if any_bot {
+                        ty::mk_bot()
+                    } else {
+                        ast_expr_vstore_to_ty(fcx, ev, vst, ||
+                            ty::mt{ ty: ty::mk_vec(tcx,
+                                                   ty::mt {ty: t, mutbl: mutability},
+                                                   None),
+                                                   mutbl: mutability })
+                    }
                 }
-                else if ty::type_is_bot(arg_t) {
-                    any_bot = true;
+                ast::ExprRepeat(element, count_expr) => {
+                    check_expr_with_hint(fcx, count_expr, ty::mk_uint());
+                    let _ = ty::eval_repeat_count(fcx, count_expr);
+                    let mutability = match vst {
+                        ast::ExprVstoreMutSlice => ast::MutMutable,
+                        _ => ast::MutImmutable,
+                    };
+                    let t = fcx.infcx().next_ty_var();
+                    check_expr_has_type(fcx, element, t);
+                    let arg_t = fcx.expr_ty(element);
+                    if ty::type_is_error(arg_t) {
+                        ty::mk_err()
+                    } else if ty::type_is_bot(arg_t) {
+                        ty::mk_bot()
+                    } else {
+                        ast_expr_vstore_to_ty(fcx, ev, vst, ||
+                            ty::mt{ ty: ty::mk_vec(tcx,
+                                                   ty::mt {ty: t, mutbl: mutability},
+                                                   None),
+                                                   mutbl: mutability})
+                    }
                 }
-            }
-            if any_error {
-                ty::mk_err()
-            } else if any_bot {
-                ty::mk_bot()
-            } else {
-                ast_expr_vstore_to_ty(fcx, ev, vst, ||
-                    ty::mt{ ty: ty::mk_vec(tcx,
-                                           ty::mt {ty: t, mutbl: mutability},
-                                           None),
-                            mutbl: mutability })
-            }
-          }
-          ast::ExprRepeat(element, count_expr) => {
-            check_expr_with_hint(fcx, count_expr, ty::mk_uint());
-            let _ = ty::eval_repeat_count(fcx, count_expr);
-            let mutability = match vst {
-                ast::ExprVstoreMutSlice => ast::MutMutable,
-                _ => ast::MutImmutable,
+                ast::ExprLit(_) => {
+                    let error = if vst == ast::ExprVstoreSlice {
+                        "`&\"string\"` has been removed; use `\"string\"` instead"
+                    } else {
+                        "`~\"string\"` has been removed; use `\"string\".to_owned()` instead"
+                    };
+                    tcx.sess.span_err(expr.span, error);
+                    ty::mk_err()
+                }
+                _ => tcx.sess.span_bug(expr.span, "vstore modifier on non-sequence"),
             };
-            let t = fcx.infcx().next_ty_var();
-            check_expr_has_type(fcx, element, t);
-            let arg_t = fcx.expr_ty(element);
-            if ty::type_is_error(arg_t) {
-                ty::mk_err()
-            } else if ty::type_is_bot(arg_t) {
-                ty::mk_bot()
-            } else {
-                ast_expr_vstore_to_ty(fcx, ev, vst, ||
-                    ty::mt{ ty: ty::mk_vec(tcx,
-                                           ty::mt {ty: t, mutbl: mutability},
-                                           None),
-                            mutbl: mutability})
-            }
-          }
-          ast::ExprLit(_) => {
-            tcx.sess.span_err(expr.span,
-                              "`~\"string\"` has been removed; use `\"string\".to_owned()` \
-                               instead");
-            ty::mk_err()
-          }
-          _ => tcx.sess.span_bug(expr.span, "vstore modifier on non-sequence"),
-        };
-        fcx.write_ty(ev.id, typ);
-        fcx.write_ty(id, typ);
-      }
+            fcx.write_ty(ev.id, typ);
+            fcx.write_ty(id, typ);
+        }
 
       ast::ExprBox(place, subexpr) => {
           check_expr(fcx, place);