Rollup merge of #58260 - taiki-e:librustc_borrowck-2018, r=Centril

librustc_borrowck => 2018

Transitions `librustc_borrowck` to Rust 2018; cc #58099

r? @Centril
This commit is contained in:
Mazdak Farrokhzad 2019-02-09 00:16:01 +01:00 committed by GitHub
commit c3d365f460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 71 additions and 69 deletions

View File

@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"]
name = "rustc_borrowck"
version = "0.0.0"
edition = "2018"
[lib]
name = "rustc_borrowck"
@ -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" }

View File

@ -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;
@ -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;
@ -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,
@ -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();

View File

@ -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;
@ -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,

View File

@ -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;
@ -10,6 +10,7 @@ use rustc::ty;
use syntax::ast;
use syntax_pos::Span;
use log::debug;
type R = Result<(),()>;

View File

@ -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;
@ -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;
@ -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.

View File

@ -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;
@ -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>>
@ -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,

View File

@ -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;

View File

@ -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;
@ -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;
@ -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
@ -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 {
@ -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 => {}
@ -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);
@ -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) => {
@ -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, "[]"),
@ -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,
@ -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)))
@ -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)))

View File

@ -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;
@ -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> {
@ -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
@ -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);
}
@ -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.

View File

@ -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();

View File

@ -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;
@ -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
}
@ -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,

View File

@ -2,16 +2,15 @@
//! 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)]
@ -53,7 +52,7 @@ impl<'a, 'tcx> DataflowLabeller<'a, 'tcx> {
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),
@ -89,7 +88,7 @@ impl<'a, 'tcx> DataflowLabeller<'a, 'tcx> {
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)

View File

@ -1,23 +1,14 @@
#![doc(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;