Skip to content

Commit

Permalink
librustc_borrowck => 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Feb 8, 2019
1 parent 1efdda1 commit a2c4a36
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 69 deletions.
9 changes: 6 additions & 3 deletions src/librustc_borrowck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"]
name = "rustc_borrowck"
version = "0.0.0"
edition = "2018"

[lib]
name = "rustc_borrowck"
Expand All @@ -13,8 +14,10 @@ test = false
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" }
errors = { path = "../librustc_errors", package = "rustc_errors" }
rustc_data_structures = { path = "../librustc_data_structures" }
11 changes: 6 additions & 5 deletions src/librustc_borrowck/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// 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;
Expand All @@ -22,6 +22,7 @@ use syntax_pos::Span;
use rustc::hir;
use rustc::hir::Node;
use rustc_mir::util::borrowck_errors::{BorrowckErrors, Origin};
use log::debug;

use std::rc::Rc;

Expand Down Expand Up @@ -101,7 +102,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {

fn matched_pat(&mut self,
_matched_pat: &hir::Pat,
_cmt: &mc::cmt_,
_cmt: &mc::cmt_<'_>,
_mode: euv::MatchMode) { }

fn consume_pat(&mut self,
Expand Down Expand Up @@ -910,7 +911,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
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();
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! 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;
Expand All @@ -15,6 +15,7 @@ use syntax::ast;
use syntax_pos::Span;
use rustc::hir::*;
use rustc::hir::Node;
use log::debug;

struct GatherMoveInfo<'c, 'tcx: 'c> {
id: hir::ItemLocalId,
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_borrowck/borrowck/gather_loans/lifetime.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! 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;
Expand All @@ -10,6 +10,7 @@ use rustc::ty;

use syntax::ast;
use syntax_pos::Span;
use log::debug;

type R = Result<(),()>;

Expand Down
9 changes: 5 additions & 4 deletions src/librustc_borrowck/borrowck/gather_loans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// 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;
Expand All @@ -17,8 +17,9 @@ use rustc::ty::{self, TyCtxt};
use syntax::ast;
use syntax_pos::Span;
use rustc::hir;
use log::debug;

use self::restrictions::RestrictionResult;
use restrictions::RestrictionResult;

mod lifetime;
mod restrictions;
Expand Down Expand Up @@ -427,7 +428,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
// }
}

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.
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_borrowck/borrowck/gather_loans/move_error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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;
Expand All @@ -8,7 +8,8 @@ use rustc_mir::util::borrowck_errors::{BorrowckErrors, Origin};
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>>
Expand Down Expand Up @@ -167,10 +168,10 @@ fn report_cannot_move_out_of<'a, 'tcx>(bccx: &'a BorrowckCtxt<'a, '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,
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_borrowck/borrowck/gather_loans/restrictions.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! 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;

Expand Down
35 changes: 18 additions & 17 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#![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;
Expand Down Expand Up @@ -37,10 +37,11 @@ use std::hash::{Hash, Hasher};
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;

Expand All @@ -61,7 +62,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
});
}

pub fn provide(providers: &mut Providers) {
pub fn provide(providers: &mut Providers<'_>) {
*providers = Providers {
borrowck,
..*providers
Expand Down Expand Up @@ -398,7 +399,7 @@ pub enum LoanPathElem<'tcx> {
}

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 {
Expand Down Expand Up @@ -1214,8 +1215,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
}

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 => {}
Expand Down Expand Up @@ -1271,7 +1272,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
// 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);
Expand Down Expand Up @@ -1349,7 +1350,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
}
}

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) => {
Expand Down Expand Up @@ -1487,7 +1488,7 @@ impl DataFlowOperator for LoanDataFlowOperator {
}

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, "[]"),
Expand All @@ -1496,7 +1497,7 @@ impl<'tcx> fmt::Debug for InteriorKind {
}

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,
Expand All @@ -1508,7 +1509,7 @@ impl<'tcx> fmt::Debug for Loan<'tcx> {
}

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)))
Expand Down Expand Up @@ -1543,7 +1544,7 @@ impl<'tcx> fmt::Debug for LoanPath<'tcx> {
}

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)))
Expand Down
15 changes: 8 additions & 7 deletions src/librustc_borrowck/borrowck/move_data.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! 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;
Expand All @@ -15,6 +15,7 @@ use std::rc::Rc;
use std::usize;
use syntax_pos::Span;
use rustc::hir;
use log::debug;

#[derive(Default)]
pub struct MoveData<'tcx> {
Expand Down Expand Up @@ -145,7 +146,7 @@ pub struct AssignDataFlowOperator;

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
Expand Down Expand Up @@ -428,8 +429,8 @@ impl<'a, 'tcx> MoveData<'tcx> {
/// 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);
}
Expand Down Expand Up @@ -537,7 +538,7 @@ impl<'a, 'tcx> MoveData<'tcx> {
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.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use errors::Applicability;
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();
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_borrowck/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::io;
use std::mem;
use std::usize;
use syntax::print::pprust::PrintState;
use log::debug;

use rustc_data_structures::graph::implementation::OUTGOING;

Expand Down Expand Up @@ -80,7 +81,7 @@ pub trait DataFlowOperator : BitwiseOperator {
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
}
Expand All @@ -99,12 +100,12 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
}

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,
Expand Down
Loading

0 comments on commit a2c4a36

Please sign in to comment.