096a28607f
This change makes the compiler no longer infer whether types (structures and enumerations) implement the `Copy` trait (and thus are implicitly copyable). Rather, you must implement `Copy` yourself via `impl Copy for MyType {}`. A new warning has been added, `missing_copy_implementations`, to warn you if a non-generic public type has been added that could have implemented `Copy` but didn't. For convenience, you may *temporarily* opt out of this behavior by using `#![feature(opt_out_copy)]`. Note though that this feature gate will never be accepted and will be removed by the time that 1.0 is released, so you should transition your code away from using it. This breaks code like: #[deriving(Show)] struct Point2D { x: int, y: int, } fn main() { let mypoint = Point2D { x: 1, y: 1, }; let otherpoint = mypoint; println!("{}{}", mypoint, otherpoint); } Change this code to: #[deriving(Show)] struct Point2D { x: int, y: int, } impl Copy for Point2D {} fn main() { let mypoint = Point2D { x: 1, y: 1, }; let otherpoint = mypoint; println!("{}{}", mypoint, otherpoint); } This is the backwards-incompatible part of #13231. Part of RFC #3. [breaking-change]
96 lines
3.0 KiB
Rust
96 lines
3.0 KiB
Rust
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
// file at the top-level directory of this distribution and at
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
|
|
// Checks that all rvalues in a crate have statically known size. check_crate
|
|
// is the public starting point.
|
|
|
|
use middle::expr_use_visitor as euv;
|
|
use middle::mem_categorization as mc;
|
|
use middle::ty::ParameterEnvironment;
|
|
use middle::ty;
|
|
use util::ppaux::ty_to_string;
|
|
|
|
use syntax::ast;
|
|
use syntax::codemap::Span;
|
|
use syntax::visit;
|
|
|
|
pub fn check_crate(tcx: &ty::ctxt,
|
|
krate: &ast::Crate) {
|
|
let mut rvcx = RvalueContext { tcx: tcx };
|
|
visit::walk_crate(&mut rvcx, krate);
|
|
}
|
|
|
|
struct RvalueContext<'a, 'tcx: 'a> {
|
|
tcx: &'a ty::ctxt<'tcx>
|
|
}
|
|
|
|
impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> {
|
|
fn visit_fn(&mut self,
|
|
fk: visit::FnKind<'v>,
|
|
fd: &'v ast::FnDecl,
|
|
b: &'v ast::Block,
|
|
s: Span,
|
|
fn_id: ast::NodeId) {
|
|
{
|
|
let param_env = ParameterEnvironment::for_item(self.tcx, fn_id);
|
|
let mut euv = euv::ExprUseVisitor::new(self, self.tcx, param_env);
|
|
euv.walk_fn(fd, b);
|
|
}
|
|
visit::walk_fn(self, fk, fd, b, s)
|
|
}
|
|
}
|
|
|
|
impl<'a, 'tcx> euv::Delegate<'tcx> for RvalueContext<'a, 'tcx> {
|
|
fn consume(&mut self,
|
|
_: ast::NodeId,
|
|
span: Span,
|
|
cmt: mc::cmt<'tcx>,
|
|
_: euv::ConsumeMode) {
|
|
debug!("consume; cmt: {}; type: {}", *cmt, ty_to_string(self.tcx, cmt.ty));
|
|
if !ty::type_is_sized(self.tcx, cmt.ty) {
|
|
span_err!(self.tcx.sess, span, E0161,
|
|
"cannot move a value of type {0}: the size of {0} cannot be statically determined",
|
|
ty_to_string(self.tcx, cmt.ty));
|
|
}
|
|
}
|
|
|
|
fn matched_pat(&mut self,
|
|
_matched_pat: &ast::Pat,
|
|
_cmt: mc::cmt,
|
|
_mode: euv::MatchMode) {}
|
|
|
|
fn consume_pat(&mut self,
|
|
_consume_pat: &ast::Pat,
|
|
_cmt: mc::cmt,
|
|
_mode: euv::ConsumeMode) {
|
|
}
|
|
|
|
fn borrow(&mut self,
|
|
_borrow_id: ast::NodeId,
|
|
_borrow_span: Span,
|
|
_cmt: mc::cmt,
|
|
_loan_region: ty::Region,
|
|
_bk: ty::BorrowKind,
|
|
_loan_cause: euv::LoanCause) {
|
|
}
|
|
|
|
fn decl_without_init(&mut self,
|
|
_id: ast::NodeId,
|
|
_span: Span) {
|
|
}
|
|
|
|
fn mutate(&mut self,
|
|
_assignment_id: ast::NodeId,
|
|
_assignment_span: Span,
|
|
_assignee_cmt: mc::cmt,
|
|
_mode: euv::MutateMode) {
|
|
}
|
|
}
|