authors = ["The Rust Project Developers"]
name = "rustc_borrowck"
version = "0.0.0"
+edition = "2018"
[lib]
name = "rustc_borrowck"
log = "0.4"
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
-graphviz = { path = "../libgraphviz" }
+# for "clarity", rename the graphviz crate to dot; graphviz within `borrowck`
+# refers to the borrowck-specific graphviz adapter traits.
+dot = { path = "../libgraphviz", package = "graphviz" }
rustc = { path = "../librustc" }
rustc_mir = { path = "../librustc_mir" }
-rustc_errors = { path = "../librustc_errors" }
-rustc_data_structures = { path = "../librustc_data_structures" }
\ No newline at end of file
+errors = { path = "../librustc_errors", package = "rustc_errors" }
+rustc_data_structures = { path = "../librustc_data_structures" }
// 3. assignments do not affect things loaned out as immutable
// 4. moves do not affect things loaned out in any way
-use self::UseError::*;
+use UseError::*;
-use borrowck::*;
-use borrowck::InteriorKind::{InteriorElement, InteriorField};
+use crate::borrowck::*;
+use crate::borrowck::InteriorKind::{InteriorElement, InteriorField};
use rustc::middle::expr_use_visitor as euv;
use rustc::middle::expr_use_visitor::MutateMode;
use rustc::middle::mem_categorization as mc;
use rustc::hir;
use rustc::hir::Node;
use rustc_mir::util::borrowck_errors::{BorrowckErrors, Origin};
+use log::debug;
use std::rc::Rc;
fn matched_pat(&mut self,
_matched_pat: &hir::Pat,
- _cmt: &mc::cmt_,
+ _cmt: &mc::cmt_<'_>,
_mode: euv::MatchMode) { }
fn consume_pat(&mut self,
pub fn report_illegal_mutation(&self,
span: Span,
loan_path: &LoanPath<'tcx>,
- loan: &Loan) {
+ loan: &Loan<'_>) {
self.bccx.cannot_assign_to_borrowed(
span, loan.span, &self.bccx.loan_path_to_string(loan_path), Origin::Ast)
.emit();
//! Computes moves.
-use borrowck::*;
-use borrowck::gather_loans::move_error::MovePlace;
-use borrowck::gather_loans::move_error::{MoveError, MoveErrorCollector};
-use borrowck::move_data::*;
+use crate::borrowck::*;
+use crate::borrowck::gather_loans::move_error::MovePlace;
+use crate::borrowck::gather_loans::move_error::{MoveError, MoveErrorCollector};
+use crate::borrowck::move_data::*;
use rustc::middle::expr_use_visitor as euv;
use rustc::middle::mem_categorization as mc;
use rustc::middle::mem_categorization::Categorization;
use syntax_pos::Span;
use rustc::hir::*;
use rustc::hir::Node;
+use log::debug;
struct GatherMoveInfo<'c, 'tcx: 'c> {
id: hir::ItemLocalId,
//! This module implements the check that the lifetime of a borrow
//! does not exceed the lifetime of the value being borrowed.
-use borrowck::*;
+use crate::borrowck::*;
use rustc::middle::expr_use_visitor as euv;
use rustc::middle::mem_categorization as mc;
use rustc::middle::mem_categorization::Categorization;
use syntax::ast;
use syntax_pos::Span;
+use log::debug;
type R = Result<(),()>;
// their associated scopes. In phase two, checking loans, we will then make
// sure that all of these loans are honored.
-use borrowck::*;
-use borrowck::move_data::MoveData;
+use crate::borrowck::*;
+use crate::borrowck::move_data::MoveData;
use rustc::middle::expr_use_visitor as euv;
use rustc::middle::mem_categorization as mc;
use rustc::middle::mem_categorization::Categorization;
use syntax::ast;
use syntax_pos::Span;
use rustc::hir;
+use log::debug;
-use self::restrictions::RestrictionResult;
+use restrictions::RestrictionResult;
mod lifetime;
mod restrictions;
// }
}
- pub fn mark_loan_path_as_mutated(&self, loan_path: &LoanPath) {
+ pub fn mark_loan_path_as_mutated(&self, loan_path: &LoanPath<'_>) {
//! For mutable loans of content whose mutability derives
//! from a local variable, mark the mutability decl as necessary.
-use borrowck::BorrowckCtxt;
+use crate::borrowck::BorrowckCtxt;
use rustc::middle::mem_categorization as mc;
use rustc::middle::mem_categorization::Categorization;
use rustc::middle::mem_categorization::NoteClosureEnv;
use syntax::ast;
use syntax_pos;
use errors::{DiagnosticBuilder, Applicability};
-use borrowck::gather_loans::gather_moves::PatternSource;
+use crate::borrowck::gather_loans::gather_moves::PatternSource;
+use log::debug;
pub struct MoveErrorCollector<'tcx> {
errors: Vec<MoveError<'tcx>>
}
}
-fn note_move_destination(mut err: DiagnosticBuilder,
+fn note_move_destination(mut err: DiagnosticBuilder<'_>,
move_to_span: syntax_pos::Span,
pat_name: ast::Name,
- is_first_note: bool) -> DiagnosticBuilder {
+ is_first_note: bool) -> DiagnosticBuilder<'_> {
if is_first_note {
err.span_label(
move_to_span,
//! Computes the restrictions that result from a borrow.
-use borrowck::*;
+use crate::borrowck::*;
use rustc::middle::expr_use_visitor as euv;
use rustc::middle::mem_categorization as mc;
use rustc::middle::mem_categorization::Categorization;
use rustc::ty;
use syntax_pos::Span;
+use log::debug;
-use borrowck::ToInteriorKind;
+use crate::borrowck::ToInteriorKind;
use std::rc::Rc;
#![allow(non_camel_case_types)]
-pub use self::LoanPathKind::*;
-pub use self::LoanPathElem::*;
-pub use self::bckerr_code::*;
-pub use self::AliasableViolationKind::*;
-pub use self::MovedValueUseKind::*;
+pub use LoanPathKind::*;
+pub use LoanPathElem::*;
+pub use bckerr_code::*;
+pub use AliasableViolationKind::*;
+pub use MovedValueUseKind::*;
-use self::InteriorKind::*;
+use InteriorKind::*;
use rustc::hir::HirId;
use rustc::hir::Node;
use syntax::ast;
use syntax_pos::{MultiSpan, Span};
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
+use log::debug;
use rustc::hir;
-use dataflow::{DataFlowContext, BitwiseOperator, DataFlowOperator, KillFrom};
+use crate::dataflow::{DataFlowContext, BitwiseOperator, DataFlowOperator, KillFrom};
pub mod check_loans;
});
}
-pub fn provide(providers: &mut Providers) {
+pub fn provide(providers: &mut Providers<'_>) {
*providers = Providers {
borrowck,
..*providers
}
fn closure_to_block(closure_id: LocalDefId,
- tcx: TyCtxt) -> ast::NodeId {
+ tcx: TyCtxt<'_, '_, '_>) -> ast::NodeId {
let closure_id = tcx.hir().local_def_id_to_node_id(closure_id);
match tcx.hir().get(closure_id) {
Node::Expr(expr) => match expr.node {
}
fn note_immutability_blame(&self,
- db: &mut DiagnosticBuilder,
- blame: Option<ImmutabilityBlame>,
+ db: &mut DiagnosticBuilder<'_>,
+ blame: Option<ImmutabilityBlame<'_>>,
error_node_id: ast::NodeId) {
match blame {
None => {}
// binding: either to make the binding mutable (if its type is
// not a mutable reference) or to avoid borrowing altogether
fn note_immutable_local(&self,
- db: &mut DiagnosticBuilder,
+ db: &mut DiagnosticBuilder<'_>,
borrowed_node_id: ast::NodeId,
binding_node_id: ast::NodeId) {
let let_span = self.tcx.hir().span(binding_node_id);
}
}
- fn note_and_explain_mutbl_error(&self, db: &mut DiagnosticBuilder, err: &BckError<'a, 'tcx>,
+ fn note_and_explain_mutbl_error(&self, db: &mut DiagnosticBuilder<'_>, err: &BckError<'a, 'tcx>,
error_span: &Span) {
match err.cmt.note {
mc::NoteClosureEnv(upvar_id) | mc::NoteUpvarRef(upvar_id) => {
}
impl<'tcx> fmt::Debug for InteriorKind {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
InteriorField(mc::FieldIndex(_, info)) => write!(f, "{}", info),
InteriorElement => write!(f, "[]"),
}
impl<'tcx> fmt::Debug for Loan<'tcx> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Loan_{}({:?}, {:?}, {:?}-{:?}, {:?})",
self.index,
self.loan_path,
}
impl<'tcx> fmt::Debug for LoanPath<'tcx> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.kind {
LpVar(id) => {
write!(f, "$({})", ty::tls::with(|tcx| tcx.hir().node_to_string(id)))
}
impl<'tcx> fmt::Display for LoanPath<'tcx> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.kind {
LpVar(id) => {
write!(f, "$({})", ty::tls::with(|tcx| tcx.hir().node_to_user_string(id)))
//! Data structures used for tracking moves. Please see the extensive
//! comments in the section "Moves and initialization" in `README.md`.
-pub use self::MoveKind::*;
+pub use MoveKind::*;
-use dataflow::{DataFlowContext, BitwiseOperator, DataFlowOperator, KillFrom};
+use crate::dataflow::{DataFlowContext, BitwiseOperator, DataFlowOperator, KillFrom};
-use borrowck::*;
+use crate::borrowck::*;
use rustc::cfg;
use rustc::ty::{self, TyCtxt};
use rustc::util::nodemap::FxHashMap;
use std::usize;
use syntax_pos::Span;
use rustc::hir;
+use log::debug;
#[derive(Default)]
pub struct MoveData<'tcx> {
pub type AssignDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, AssignDataFlowOperator>;
-fn loan_path_is_precise(loan_path: &LoanPath) -> bool {
+fn loan_path_is_precise(loan_path: &LoanPath<'_>) -> bool {
match loan_path.kind {
LpVar(_) | LpUpvar(_) => {
true
/// killed by scoping. See `README.md` for more details.
fn add_gen_kills(&self,
bccx: &BorrowckCtxt<'a, 'tcx>,
- dfcx_moves: &mut MoveDataFlow,
- dfcx_assign: &mut AssignDataFlow) {
+ dfcx_moves: &mut MoveDataFlow<'_, '_>,
+ dfcx_assign: &mut AssignDataFlow<'_, '_>) {
for (i, the_move) in self.moves.borrow().iter().enumerate() {
dfcx_moves.add_gen(the_move.id, i);
}
path: MovePathIndex,
kill_id: hir::ItemLocalId,
kill_kind: KillFrom,
- dfcx_moves: &mut MoveDataFlow) {
+ dfcx_moves: &mut MoveDataFlow<'_, '_>) {
// We can only perform kills for paths that refer to a unique location,
// since otherwise we may kill a move from one location with an
// assignment referring to another location.
use std::slice;
use syntax::ptr::P;
-use borrowck::BorrowckCtxt;
+use crate::borrowck::BorrowckCtxt;
pub fn check<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, body: &'tcx hir::Body) {
let mut used_mut = bccx.used_mut_nodes.borrow().clone();
use std::mem;
use std::usize;
use syntax::print::pprust::PrintState;
+use log::debug;
use rustc_data_structures::graph::implementation::OUTGOING;
fn initial_value(&self) -> bool;
}
-struct PropagationContext<'a, 'b: 'a, 'tcx: 'b, O: 'a> {
+struct PropagationContext<'a, 'b: 'a, 'tcx: 'b, O> {
dfcx: &'a mut DataFlowContext<'b, 'tcx, O>,
changed: bool
}
}
impl<'a, 'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, 'tcx, O> {
- fn nested(&self, state: &mut pprust::State, nested: pprust::Nested) -> io::Result<()> {
+ fn nested(&self, state: &mut pprust::State<'_>, nested: pprust::Nested) -> io::Result<()> {
pprust::PpAnn::nested(self.tcx.hir(), state, nested)
}
fn pre(&self,
- ps: &mut pprust::State,
- node: pprust::AnnNode) -> io::Result<()> {
+ ps: &mut pprust::State<'_>,
+ node: pprust::AnnNode<'_>) -> io::Result<()> {
let id = match node {
pprust::AnnNode::Name(_) => return Ok(()),
pprust::AnnNode::Expr(expr) => expr.hir_id.local_id,
//! libgraphviz traits, specialized to attaching borrowck analysis
//! data to rendered labels.
-pub use self::Variant::*;
+pub use Variant::*;
pub use rustc::cfg::graphviz::{Node, Edge};
use rustc::cfg::graphviz as cfg_dot;
-use borrowck;
-use borrowck::{BorrowckCtxt, LoanPath};
-use dot;
+use crate::borrowck::{self, BorrowckCtxt, LoanPath};
+use crate::dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit};
+use log::debug;
use rustc::cfg::CFGIndex;
-use dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit};
use std::rc::Rc;
#[derive(Debug, Copy, Clone)]
sets
}
- fn dataflow_for_variant(&self, e: EntryOrExit, n: &Node, v: Variant) -> String {
+ fn dataflow_for_variant(&self, e: EntryOrExit, n: &Node<'_>, v: Variant) -> String {
let cfgidx = n.0;
match v {
Loans => self.dataflow_loans_for(e, cfgidx),
let dfcx = &self.analysis_data.loans;
let loan_index_to_path = |loan_index| {
let all_loans = &self.analysis_data.all_loans;
- let l: &borrowck::Loan = &all_loans[loan_index];
+ let l: &borrowck::Loan<'_> = &all_loans[loan_index];
l.loan_path()
};
self.build_set(e, cfgidx, dfcx, loan_index_to_path)
html_root_url = "https://doc.rust-lang.org/nightly/")]
#![allow(non_camel_case_types)]
+#![deny(rust_2018_idioms)]
#![feature(nll)]
#![recursion_limit="256"]
-#[macro_use] extern crate log;
-extern crate syntax;
-extern crate syntax_pos;
-extern crate rustc_errors as errors;
-extern crate rustc_data_structures;
-
-// for "clarity", rename the graphviz crate to dot; graphviz within `borrowck`
-// refers to the borrowck-specific graphviz adapter traits.
-extern crate graphviz as dot;
#[macro_use]
extern crate rustc;
-extern crate rustc_mir;
pub use borrowck::check_crate;
pub use borrowck::build_borrowck_dataflow_data_for_fn;