Skip to content

Commit

Permalink
Move ExprUseVisitor and mem_categorization to rustc_typeck
Browse files Browse the repository at this point in the history
`MemCategorizationContext` is now private, the remaining types and
traits remain public for Clippy.
  • Loading branch information
matthewjasper committed Nov 27, 2019
1 parent c87de41 commit 5bc1586
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 39 deletions.
2 changes: 0 additions & 2 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,13 @@ pub mod infer;
pub mod lint;

pub mod middle {
pub mod expr_use_visitor;
pub mod cstore;
pub mod dependency_format;
pub mod diagnostic_items;
pub mod exported_symbols;
pub mod free_region;
pub mod lib_features;
pub mod lang_items;
pub mod mem_categorization;
pub mod privacy;
pub mod reachable;
pub mod region;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/regionck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

use crate::check::dropck;
use crate::check::FnCtxt;
use crate::middle::mem_categorization as mc;
use crate::mem_categorization as mc;
use crate::middle::region;
use rustc::hir::def_id::DefId;
use rustc::infer::outlives::env::OutlivesEnvironment;
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

use super::FnCtxt;

use crate::middle::expr_use_visitor as euv;
use crate::middle::mem_categorization as mc;
use crate::middle::mem_categorization::PlaceBase;
use crate::expr_use_visitor as euv;
use crate::mem_categorization as mc;
use crate::mem_categorization::PlaceBase;
use rustc::hir;
use rustc::hir::def_id::DefId;
use rustc::hir::def_id::LocalDefId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
pub use self::ConsumeMode::*;
use self::OverloadedCallType::*;

use crate::hir::def::Res;
use crate::hir::def_id::DefId;
use crate::hir::ptr::P;
use crate::infer::InferCtxt;
use crate::middle::mem_categorization as mc;
use crate::ty::{self, TyCtxt, adjustment};

use crate::hir::{self, PatKind};
// Export these here so that Clippy can use them.
pub use mc::{PlaceBase, Place, Projection};

use rustc::hir::{self, PatKind};
use rustc::hir::def::Res;
use rustc::hir::def_id::DefId;
use rustc::hir::ptr::P;
use rustc::infer::InferCtxt;
use rustc::ty::{self, TyCtxt, adjustment};

use crate::mem_categorization as mc;
use syntax_pos::Span;

///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -147,7 +150,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
self.mc.tcx()
}

fn delegate_consume(&mut self, place: &mc::Place<'tcx>) {
fn delegate_consume(&mut self, place: &Place<'tcx>) {
debug!("delegate_consume(place={:?})", place);

let mode = copy_or_move(&self.mc, place);
Expand Down Expand Up @@ -516,7 +519,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
}
}

fn walk_arm(&mut self, discr_place: &mc::Place<'tcx>, arm: &hir::Arm) {
fn walk_arm(&mut self, discr_place: &Place<'tcx>, arm: &hir::Arm) {
self.walk_pat(discr_place, &arm.pat);

if let Some(hir::Guard::If(ref e)) = arm.guard {
Expand All @@ -528,13 +531,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {

/// Walks a pat that occurs in isolation (i.e., top-level of fn argument or
/// let binding, and *not* a match arm or nested pat.)
fn walk_irrefutable_pat(&mut self, discr_place: &mc::Place<'tcx>, pat: &hir::Pat) {
fn walk_irrefutable_pat(&mut self, discr_place: &Place<'tcx>, pat: &hir::Pat) {
self.walk_pat(discr_place, pat);
}


/// The core driver for walking a pattern
fn walk_pat(&mut self, discr_place: &mc::Place<'tcx>, pat: &hir::Pat) {
fn walk_pat(&mut self, discr_place: &Place<'tcx>, pat: &hir::Pat) {
debug!("walk_pat(discr_place={:?}, pat={:?})", discr_place, pat);

let tcx = self.tcx();
Expand Down Expand Up @@ -622,7 +625,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {

fn copy_or_move<'a, 'tcx>(
mc: &mc::MemCategorizationContext<'a, 'tcx>,
place: &mc::Place<'tcx>,
place: &Place<'tcx>,
) -> ConsumeMode {
if !mc.type_is_copy_modulo_regions(place.ty, place.span) {
Move
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ This API is completely unstable and subject to change.

#[macro_use] extern crate rustc;

// This is used by Clippy.
pub mod expr_use_visitor;

mod astconv;
mod check;
mod check_unused;
Expand All @@ -83,6 +86,7 @@ mod collect;
mod constrained_generic_params;
mod structured_errors;
mod impl_wf_check;
mod mem_categorization;
mod namespace;
mod outlives;
mod variance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@
//! result of `*x'`, effectively, where `x'` is a `Categorization::Upvar` reference
//! tied to `x`. The type of `x'` will be a borrowed pointer.

use crate::hir::def_id::DefId;
use crate::infer::InferCtxt;
use crate::hir::def::{Res, DefKind};
use crate::ty::adjustment;
use crate::ty::{self, Ty, TyCtxt};
use crate::ty::fold::TypeFoldable;

use crate::hir::PatKind;
use crate::hir;
use rustc::hir;
use rustc::hir::PatKind;
use rustc::hir::def_id::DefId;
use rustc::hir::def::{Res, DefKind};
use rustc::infer::InferCtxt;
use rustc::ty::adjustment;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::fold::TypeFoldable;

use syntax_pos::Span;

use rustc_data_structures::fx::FxIndexMap;
Expand Down Expand Up @@ -105,7 +105,7 @@ impl<'tcx> Place<'tcx> {
/// The types are in the reverse order that they are applied. So if
/// `x: &*const u32` and the `Place` is `**x`, then the types returned are
///`*const u32` then `&*const u32`.
pub fn deref_tys(&self) -> impl Iterator<Item=Ty<'tcx>> + '_ {
crate fn deref_tys(&self) -> impl Iterator<Item=Ty<'tcx>> + '_ {
self.projections.iter().rev().filter_map(|proj| if let Projection::Deref(deref_ty) = *proj {
Some(deref_ty)
} else {
Expand All @@ -114,7 +114,7 @@ impl<'tcx> Place<'tcx> {
}
}

pub trait HirNode {
crate trait HirNode {
fn hir_id(&self) -> hir::HirId;
fn span(&self) -> Span;
}
Expand All @@ -130,19 +130,19 @@ impl HirNode for hir::Pat {
}

#[derive(Clone)]
pub struct MemCategorizationContext<'a, 'tcx> {
pub tables: &'a ty::TypeckTables<'tcx>,
crate struct MemCategorizationContext<'a, 'tcx> {
crate tables: &'a ty::TypeckTables<'tcx>,
infcx: &'a InferCtxt<'a, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
body_owner: DefId,
upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
}

pub type McResult<T> = Result<T, ()>;
crate type McResult<T> = Result<T, ()>;

impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
/// Creates a `MemCategorizationContext`.
pub fn new(
crate fn new(
infcx: &'a InferCtxt<'a, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
body_owner: DefId,
Expand Down Expand Up @@ -276,7 +276,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
Ok(ret_ty)
}

pub fn cat_expr(&self, expr: &hir::Expr) -> McResult<Place<'tcx>> {
crate fn cat_expr(&self, expr: &hir::Expr) -> McResult<Place<'tcx>> {
// This recursion helper avoids going through *too many*
// adjustments, since *only* non-overloaded deref recurses.
fn helper<'a, 'tcx>(
Expand All @@ -295,7 +295,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
helper(self, expr, self.tables.expr_adjustments(expr))
}

pub fn cat_expr_adjusted(&self, expr: &hir::Expr,
crate fn cat_expr_adjusted(&self, expr: &hir::Expr,
previous: Place<'tcx>,
adjustment: &adjustment::Adjustment<'tcx>)
-> McResult<Place<'tcx>> {
Expand Down Expand Up @@ -334,7 +334,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
}
}

pub fn cat_expr_unadjusted(&self, expr: &hir::Expr) -> McResult<Place<'tcx>> {
crate fn cat_expr_unadjusted(&self, expr: &hir::Expr) -> McResult<Place<'tcx>> {
debug!("cat_expr: id={} expr={:?}", expr.hir_id, expr);

let expr_ty = self.expr_ty(expr)?;
Expand Down Expand Up @@ -475,7 +475,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
Ok(ret)
}

pub fn cat_rvalue(&self, hir_id: hir::HirId, span: Span, expr_ty: Ty<'tcx>) -> Place<'tcx> {
crate fn cat_rvalue(&self, hir_id: hir::HirId, span: Span, expr_ty: Ty<'tcx>) -> Place<'tcx> {
debug!("cat_rvalue hir_id={:?}, expr_ty={:?}, span={:?}", hir_id, expr_ty, span);
let ret = Place {
hir_id,
Expand Down Expand Up @@ -562,7 +562,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
Ok(ret)
}

pub fn cat_pattern<F>(&self, place: Place<'tcx>, pat: &hir::Pat, mut op: F) -> McResult<()>
crate fn cat_pattern<F>(&self, place: Place<'tcx>, pat: &hir::Pat, mut op: F) -> McResult<()>
where F: FnMut(&Place<'tcx>, &hir::Pat),
{
self.cat_pattern_(place, pat, &mut op)
Expand Down

0 comments on commit 5bc1586

Please sign in to comment.