Skip to content

Commit 5bc1586

Browse files
committed
Move ExprUseVisitor and mem_categorization to rustc_typeck
`MemCategorizationContext` is now private, the remaining types and traits remain public for Clippy.
1 parent c87de41 commit 5bc1586

File tree

6 files changed

+44
-39
lines changed

6 files changed

+44
-39
lines changed

src/librustc/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,13 @@ pub mod infer;
9696
pub mod lint;
9797

9898
pub mod middle {
99-
pub mod expr_use_visitor;
10099
pub mod cstore;
101100
pub mod dependency_format;
102101
pub mod diagnostic_items;
103102
pub mod exported_symbols;
104103
pub mod free_region;
105104
pub mod lib_features;
106105
pub mod lang_items;
107-
pub mod mem_categorization;
108106
pub mod privacy;
109107
pub mod reachable;
110108
pub mod region;

src/librustc_typeck/check/regionck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
7575
use crate::check::dropck;
7676
use crate::check::FnCtxt;
77-
use crate::middle::mem_categorization as mc;
77+
use crate::mem_categorization as mc;
7878
use crate::middle::region;
7979
use rustc::hir::def_id::DefId;
8080
use rustc::infer::outlives::env::OutlivesEnvironment;

src/librustc_typeck/check/upvar.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
3333
use super::FnCtxt;
3434

35-
use crate::middle::expr_use_visitor as euv;
36-
use crate::middle::mem_categorization as mc;
37-
use crate::middle::mem_categorization::PlaceBase;
35+
use crate::expr_use_visitor as euv;
36+
use crate::mem_categorization as mc;
37+
use crate::mem_categorization::PlaceBase;
3838
use rustc::hir;
3939
use rustc::hir::def_id::DefId;
4040
use rustc::hir::def_id::LocalDefId;

src/librustc/middle/expr_use_visitor.rs src/librustc_typeck/expr_use_visitor.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
pub use self::ConsumeMode::*;
66
use self::OverloadedCallType::*;
77

8-
use crate::hir::def::Res;
9-
use crate::hir::def_id::DefId;
10-
use crate::hir::ptr::P;
11-
use crate::infer::InferCtxt;
12-
use crate::middle::mem_categorization as mc;
13-
use crate::ty::{self, TyCtxt, adjustment};
14-
15-
use crate::hir::{self, PatKind};
8+
// Export these here so that Clippy can use them.
9+
pub use mc::{PlaceBase, Place, Projection};
10+
11+
use rustc::hir::{self, PatKind};
12+
use rustc::hir::def::Res;
13+
use rustc::hir::def_id::DefId;
14+
use rustc::hir::ptr::P;
15+
use rustc::infer::InferCtxt;
16+
use rustc::ty::{self, TyCtxt, adjustment};
17+
18+
use crate::mem_categorization as mc;
1619
use syntax_pos::Span;
1720

1821
///////////////////////////////////////////////////////////////////////////
@@ -147,7 +150,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
147150
self.mc.tcx()
148151
}
149152

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

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

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

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

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

535538

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

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

623626
fn copy_or_move<'a, 'tcx>(
624627
mc: &mc::MemCategorizationContext<'a, 'tcx>,
625-
place: &mc::Place<'tcx>,
628+
place: &Place<'tcx>,
626629
) -> ConsumeMode {
627630
if !mc.type_is_copy_modulo_regions(place.ty, place.span) {
628631
Move

src/librustc_typeck/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ This API is completely unstable and subject to change.
7575

7676
#[macro_use] extern crate rustc;
7777

78+
// This is used by Clippy.
79+
pub mod expr_use_visitor;
80+
7881
mod astconv;
7982
mod check;
8083
mod check_unused;
@@ -83,6 +86,7 @@ mod collect;
8386
mod constrained_generic_params;
8487
mod structured_errors;
8588
mod impl_wf_check;
89+
mod mem_categorization;
8690
mod namespace;
8791
mod outlives;
8892
mod variance;

src/librustc/middle/mem_categorization.rs src/librustc_typeck/mem_categorization.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@
4848
//! result of `*x'`, effectively, where `x'` is a `Categorization::Upvar` reference
4949
//! tied to `x`. The type of `x'` will be a borrowed pointer.
5050
51-
use crate::hir::def_id::DefId;
52-
use crate::infer::InferCtxt;
53-
use crate::hir::def::{Res, DefKind};
54-
use crate::ty::adjustment;
55-
use crate::ty::{self, Ty, TyCtxt};
56-
use crate::ty::fold::TypeFoldable;
57-
58-
use crate::hir::PatKind;
59-
use crate::hir;
51+
use rustc::hir;
52+
use rustc::hir::PatKind;
53+
use rustc::hir::def_id::DefId;
54+
use rustc::hir::def::{Res, DefKind};
55+
use rustc::infer::InferCtxt;
56+
use rustc::ty::adjustment;
57+
use rustc::ty::{self, Ty, TyCtxt};
58+
use rustc::ty::fold::TypeFoldable;
59+
6060
use syntax_pos::Span;
6161

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

117-
pub trait HirNode {
117+
crate trait HirNode {
118118
fn hir_id(&self) -> hir::HirId;
119119
fn span(&self) -> Span;
120120
}
@@ -130,19 +130,19 @@ impl HirNode for hir::Pat {
130130
}
131131

132132
#[derive(Clone)]
133-
pub struct MemCategorizationContext<'a, 'tcx> {
134-
pub tables: &'a ty::TypeckTables<'tcx>,
133+
crate struct MemCategorizationContext<'a, 'tcx> {
134+
crate tables: &'a ty::TypeckTables<'tcx>,
135135
infcx: &'a InferCtxt<'a, 'tcx>,
136136
param_env: ty::ParamEnv<'tcx>,
137137
body_owner: DefId,
138138
upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
139139
}
140140

141-
pub type McResult<T> = Result<T, ()>;
141+
crate type McResult<T> = Result<T, ()>;
142142

143143
impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
144144
/// Creates a `MemCategorizationContext`.
145-
pub fn new(
145+
crate fn new(
146146
infcx: &'a InferCtxt<'a, 'tcx>,
147147
param_env: ty::ParamEnv<'tcx>,
148148
body_owner: DefId,
@@ -276,7 +276,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
276276
Ok(ret_ty)
277277
}
278278

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

298-
pub fn cat_expr_adjusted(&self, expr: &hir::Expr,
298+
crate fn cat_expr_adjusted(&self, expr: &hir::Expr,
299299
previous: Place<'tcx>,
300300
adjustment: &adjustment::Adjustment<'tcx>)
301301
-> McResult<Place<'tcx>> {
@@ -334,7 +334,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
334334
}
335335
}
336336

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

340340
let expr_ty = self.expr_ty(expr)?;
@@ -475,7 +475,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
475475
Ok(ret)
476476
}
477477

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

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

0 commit comments

Comments
 (0)