Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #16813
- Loading branch information
Showing
11 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,5 +169,6 @@ register_diagnostics!( | |
E0157, | ||
E0158, | ||
E0159, | ||
E0160 | ||
E0160, | ||
E0161 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// 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; | ||
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 ty::ctxt | ||
} | ||
|
||
impl<'a> visit::Visitor<()> for RvalueContext<'a> { | ||
fn visit_fn(&mut self, | ||
_: &visit::FnKind, | ||
fd: &ast::FnDecl, | ||
b: &ast::Block, | ||
_: Span, | ||
_: ast::NodeId, | ||
_: ()) { | ||
let mut euv = euv::ExprUseVisitor::new(self, self.tcx); | ||
euv.walk_fn(fd, b); | ||
} | ||
} | ||
|
||
impl<'a> euv::Delegate for RvalueContext<'a> { | ||
fn consume(&mut self, | ||
_: ast::NodeId, | ||
span: Span, | ||
cmt: mc::cmt, | ||
_: 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 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) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// 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. | ||
|
||
// Check that dynamically sized rvalues are forbidden | ||
|
||
pub fn main() { | ||
let _x: Box<str> = box *"hello world"; | ||
//~^ ERROR E0161 | ||
|
||
let array: &[int] = &[1, 2, 3]; | ||
let _x: Box<[int]> = box *array; | ||
//~^ ERROR E0161 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
742f49c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from nikomatsakis
at nrc@742f49c
742f49c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging nick29581/rust/dst-rvalue = 742f49c into auto
742f49c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nick29581/rust/dst-rvalue = 742f49c merged ok, testing candidate = dd626b4
742f49c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/1239
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/1238
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/1238
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/1239
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/1232
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/1232
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/1232
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/1237
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/1232
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/1232
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/1235
success: http://buildbot.rust-lang.org/builders/auto-win32-32-opt/builds/69
success: http://buildbot.rust-lang.org/builders/auto-win32-32-nopt-t/builds/69
success: http://buildbot.rust-lang.org/builders/auto-win32-32-nopt-c/builds/69
742f49c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = dd626b4