Skip to content

Commit

Permalink
Remove checks that are already being done during typeck
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Sep 25, 2014
1 parent 7119974 commit 62e5dc9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 49 deletions.
1 change: 0 additions & 1 deletion src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ register_diagnostics!(
E0144,
E0145,
E0146,
E0148,
E0151,
E0152,
E0153,
Expand Down
49 changes: 1 addition & 48 deletions src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use util::ppaux::UserString;

use syntax::ast::*;
use syntax::codemap::Span;
use syntax::print::pprust::{expr_to_string, ident_to_string};
use syntax::print::pprust::{ident_to_string};
use syntax::visit::Visitor;
use syntax::visit;

Expand All @@ -31,10 +31,6 @@ pub struct Context<'a,'tcx:'a> {
}

impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
fn visit_expr(&mut self, ex: &Expr) {
check_expr(self, ex);
}

fn visit_fn(&mut self, fk: visit::FnKind, fd: &'v FnDecl,
b: &'v Block, s: Span, n: NodeId) {
check_fn(self, fk, fd, b, s, n);
Expand Down Expand Up @@ -161,37 +157,6 @@ fn check_fn(
}
}

pub fn check_expr(cx: &mut Context, e: &Expr) {
debug!("kind::check_expr({})", expr_to_string(e));

match e.node {
ExprRepeat(ref element, ref count_expr) => {
let count = ty::eval_repeat_count(cx.tcx, &**count_expr);
if count > 1 {
let element_ty = ty::expr_ty(cx.tcx, &**element);
check_copy(cx, element_ty, element.span,
"repeated element will be copied");
}
}
ExprAssign(ref lhs, _) |
ExprAssignOp(_, ref lhs, _) => {
let lhs_ty = ty::expr_ty(cx.tcx, &**lhs);
if !ty::type_is_sized(cx.tcx, lhs_ty) {
cx.tcx.sess.span_err(lhs.span, "dynamically sized type on lhs of assignment");
}
}
ExprStruct(..) => {
let e_ty = ty::expr_ty(cx.tcx, e);
if !ty::type_is_sized(cx.tcx, e_ty) {
cx.tcx.sess.span_err(e.span, "trying to initialise a dynamically sized struct");
}
}
_ => {}
}

visit::walk_expr(cx, e);
}

fn check_ty(cx: &mut Context, aty: &Ty) {
match aty.node {
TyPath(_, _, id) => {
Expand Down Expand Up @@ -274,18 +239,6 @@ pub fn check_freevar_bounds(cx: &Context, fn_span: Span, sp: Span, ty: ty::t,
});
}

fn check_copy(cx: &Context, ty: ty::t, sp: Span, reason: &str) {
debug!("type_contents({})={}",
ty_to_string(cx.tcx, ty),
ty::type_contents(cx.tcx, ty).to_string());
if ty::type_moves_by_default(cx.tcx, ty) {
span_err!(cx.tcx.sess, sp, E0148,
"copying a value of non-copyable type `{}`",
ty_to_string(cx.tcx, ty));
span_note!(cx.tcx.sess, sp, "{}", reason.as_slice());
}
}

// Ensure that `ty` has a statically known size (i.e., it has the `Sized` bound).
fn check_sized(tcx: &ty::ctxt, ty: ty::t, name: String, sp: Span) {
if !ty::type_is_sized(tcx, ty) {
Expand Down

0 comments on commit 62e5dc9

Please sign in to comment.