Skip to content

Commit 30de5b8

Browse files
committed
[WIP] Don't re-export rustc_ast items in rustc_hir
- BorrowKind - ImplPolarity - IsAuto - CaptureBy - Movability - Mutability While working on this I realized that there are many different enums named `BorrowKind`, so it should really keep the prefix and just change it from `hir::` to `ast::`.
1 parent 7820135 commit 30de5b8

File tree

120 files changed

+434
-348
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+434
-348
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
545545
decl,
546546
body_id,
547547
span,
548-
Some(hir::Movability::Static),
548+
Some(Movability::Static),
549549
);
550550
let generator = hir::Expr {
551551
hir_id: self.lower_node_id(closure_node_id),
@@ -751,7 +751,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
751751
fn_decl_span: Span,
752752
generator_kind: Option<hir::GeneratorKind>,
753753
movability: Movability,
754-
) -> Option<hir::Movability> {
754+
) -> Option<Movability> {
755755
match generator_kind {
756756
Some(hir::GeneratorKind::Gen) => {
757757
if decl.inputs.len() > 1 {
@@ -1638,7 +1638,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16381638
fn expr_mut_addr_of(&mut self, span: Span, e: &'hir hir::Expr<'hir>) -> hir::Expr<'hir> {
16391639
self.expr(
16401640
span,
1641-
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, e),
1641+
hir::ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, e),
16421642
ThinVec::new(),
16431643
)
16441644
}

compiler/rustc_codegen_llvm/src/intrinsic.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::type_of::LayoutLlvmExt;
77
use crate::va_arg::emit_va_arg;
88
use crate::value::Value;
99

10+
use rustc_ast::Mutability;
1011
use rustc_codegen_ssa::base::{compare_simd_types, wants_msvc_seh};
1112
use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
1213
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
@@ -1332,7 +1333,7 @@ fn generic_simd_intrinsic(
13321333
// The second argument must be a simd vector with an element type that's a pointer
13331334
// to the element type of the first argument
13341335
let (pointer_count, underlying_ty) = match arg_tys[1].simd_type(tcx).kind() {
1335-
ty::RawPtr(p) if p.ty == in_elem && p.mutbl == hir::Mutability::Mut => {
1336+
ty::RawPtr(p) if p.ty == in_elem && p.mutbl == Mutability::Mut => {
13361337
(ptr_count(arg_tys[1].simd_type(tcx)), non_ptr(arg_tys[1].simd_type(tcx)))
13371338
}
13381339
_ => {

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Type Names for Debug Info.
22

33
use rustc_data_structures::fx::FxHashSet;
4+
use rustc_ast::Mutability;
45
use rustc_hir as hir;
56
use rustc_hir::def_id::DefId;
67
use rustc_middle::ty::{self, subst::SubstsRef, Ty, TyCtxt};
@@ -75,8 +76,8 @@ pub fn push_debuginfo_type_name<'tcx>(
7576
output.push('*');
7677
}
7778
match mutbl {
78-
hir::Mutability::Not => output.push_str("const "),
79-
hir::Mutability::Mut => output.push_str("mut "),
79+
Mutability::Not => output.push_str("const "),
80+
Mutability::Mut => output.push_str("mut "),
8081
}
8182

8283
push_debuginfo_type_name(tcx, inner_type, true, output, visited);

compiler/rustc_data_structures/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#![feature(min_const_generics)]
3030
#![feature(once_cell)]
3131
#![allow(rustc::default_hash_types)]
32+
#![allow(rustc::pub_cross_crate_reexport)]
3233

3334
#[macro_use]
3435
extern crate tracing;

compiler/rustc_hir/src/hir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use rustc_ast::node_id::NodeMap;
77
use rustc_ast::util::parser::ExprPrecedence;
88
use rustc_ast::{self as ast, CrateSugar, LlvmAsmDialect};
99
use rustc_ast::{AttrVec, Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy};
10-
pub use rustc_ast::{BorrowKind, ImplPolarity, IsAuto};
11-
pub use rustc_ast::{CaptureBy, Movability, Mutability};
10+
use rustc_ast::{BorrowKind, ImplPolarity, IsAuto};
11+
use rustc_ast::{CaptureBy, Movability, Mutability};
1212
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
1313
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
1414
use rustc_macros::HashStable_Generic;

compiler/rustc_hir/src/pat_util.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::def_id::DefId;
33
use crate::hir::{self, HirId, PatKind};
44
use rustc_span::symbol::Ident;
55
use rustc_span::Span;
6+
use rustc_ast::Mutability;
67

78
use std::iter::{Enumerate, ExactSizeIterator};
89

@@ -179,14 +180,14 @@ impl hir::Pat<'_> {
179180
//
180181
// FIXME(tschottdorf): this is problematic as the HIR is being scraped, but
181182
// ref bindings are be implicit after #42640 (default match binding modes). See issue #44848.
182-
pub fn contains_explicit_ref_binding(&self) -> Option<hir::Mutability> {
183+
pub fn contains_explicit_ref_binding(&self) -> Option<Mutability> {
183184
let mut result = None;
184185
self.each_binding(|annotation, _, _, _| match annotation {
185186
hir::BindingAnnotation::Ref => match result {
186-
None | Some(hir::Mutability::Not) => result = Some(hir::Mutability::Not),
187+
None | Some(Mutability::Not) => result = Some(Mutability::Not),
187188
_ => {}
188189
},
189-
hir::BindingAnnotation::RefMut => result = Some(hir::Mutability::Mut),
190+
hir::BindingAnnotation::RefMut => result = Some(Mutability::Mut),
190191
_ => {}
191192
});
192193
result

compiler/rustc_hir_pretty/src/lib.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![recursion_limit = "256"]
33

44
use rustc_ast as ast;
5+
use rustc_ast::{BorrowKind, CaptureBy, IsAuto, ImplPolarity, Mutability};
56
use rustc_ast::util::parser::{self, AssocOp, Fixity};
67
use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
78
use rustc_ast_pretty::pp::{self, Breaks};
@@ -477,7 +478,7 @@ impl<'a> State<'a> {
477478
}
478479
hir::ForeignItemKind::Static(ref t, m) => {
479480
self.head(visibility_qualified(&item.vis, "static"));
480-
if m == hir::Mutability::Mut {
481+
if m == Mutability::Mut {
481482
self.word_space("mut");
482483
}
483484
self.print_ident(item.ident);
@@ -598,7 +599,7 @@ impl<'a> State<'a> {
598599
}
599600
hir::ItemKind::Static(ref ty, m, expr) => {
600601
self.head(visibility_qualified(&item.vis, "static"));
601-
if m == hir::Mutability::Mut {
602+
if m == Mutability::Mut {
602603
self.word_space("mut");
603604
}
604605
self.print_ident(item.ident);
@@ -719,7 +720,7 @@ impl<'a> State<'a> {
719720
self.word_nbsp("const");
720721
}
721722

722-
if let hir::ImplPolarity::Negative(_) = polarity {
723+
if let ImplPolarity::Negative(_) = polarity {
723724
self.s.word("!");
724725
}
725726

@@ -1257,14 +1258,14 @@ impl<'a> State<'a> {
12571258

12581259
fn print_expr_addr_of(
12591260
&mut self,
1260-
kind: hir::BorrowKind,
1261-
mutability: hir::Mutability,
1261+
kind: BorrowKind,
1262+
mutability: Mutability,
12621263
expr: &hir::Expr<'_>,
12631264
) {
12641265
self.s.word("&");
12651266
match kind {
1266-
hir::BorrowKind::Ref => self.print_mutability(mutability, false),
1267-
hir::BorrowKind::Raw => {
1267+
BorrowKind::Ref => self.print_mutability(mutability, false),
1268+
BorrowKind::Raw => {
12681269
self.word_nbsp("raw");
12691270
self.print_mutability(mutability, true);
12701271
}
@@ -1825,11 +1826,11 @@ impl<'a> State<'a> {
18251826
match binding_mode {
18261827
hir::BindingAnnotation::Ref => {
18271828
self.word_nbsp("ref");
1828-
self.print_mutability(hir::Mutability::Not, false);
1829+
self.print_mutability(Mutability::Not, false);
18291830
}
18301831
hir::BindingAnnotation::RefMut => {
18311832
self.word_nbsp("ref");
1832-
self.print_mutability(hir::Mutability::Mut, false);
1833+
self.print_mutability(Mutability::Mut, false);
18331834
}
18341835
hir::BindingAnnotation::Unannotated => {}
18351836
hir::BindingAnnotation::Mutable => {
@@ -2114,10 +2115,10 @@ impl<'a> State<'a> {
21142115
}
21152116
}
21162117

2117-
pub fn print_capture_clause(&mut self, capture_clause: hir::CaptureBy) {
2118+
pub fn print_capture_clause(&mut self, capture_clause: CaptureBy) {
21182119
match capture_clause {
2119-
hir::CaptureBy::Value => self.word_space("move"),
2120-
hir::CaptureBy::Ref => {}
2120+
CaptureBy::Value => self.word_space("move"),
2121+
CaptureBy::Ref => {}
21212122
}
21222123
}
21232124

@@ -2268,10 +2269,10 @@ impl<'a> State<'a> {
22682269
}
22692270
}
22702271

2271-
pub fn print_mutability(&mut self, mutbl: hir::Mutability, print_const: bool) {
2272+
pub fn print_mutability(&mut self, mutbl: Mutability, print_const: bool) {
22722273
match mutbl {
2273-
hir::Mutability::Mut => self.word_nbsp("mut"),
2274-
hir::Mutability::Not => {
2274+
Mutability::Mut => self.word_nbsp("mut"),
2275+
Mutability::Not => {
22752276
if print_const {
22762277
self.word_nbsp("const")
22772278
}
@@ -2410,10 +2411,10 @@ impl<'a> State<'a> {
24102411
}
24112412
}
24122413

2413-
pub fn print_is_auto(&mut self, s: hir::IsAuto) {
2414+
pub fn print_is_auto(&mut self, s: IsAuto) {
24142415
match s {
2415-
hir::IsAuto::Yes => self.word_nbsp("auto"),
2416-
hir::IsAuto::No => {}
2416+
IsAuto::Yes => self.word_nbsp("auto"),
2417+
IsAuto::No => {}
24172418
}
24182419
}
24192420
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use crate::traits::{
5656
IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode,
5757
};
5858

59+
use rustc_ast::Mutability;
5960
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
6061
use rustc_errors::{pluralize, struct_span_err};
6162
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
@@ -1060,7 +1061,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10601061
fn push_ty_ref<'tcx>(
10611062
region: &ty::Region<'tcx>,
10621063
ty: Ty<'tcx>,
1063-
mutbl: hir::Mutability,
1064+
mutbl: Mutability,
10641065
s: &mut DiagnosticStyledString,
10651066
) {
10661067
let mut r = region.to_string();

compiler/rustc_lint/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
11681168
if let Some((&ty::Ref(_, _, from_mt), &ty::Ref(_, _, to_mt))) =
11691169
get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (ty1.kind(), ty2.kind()))
11701170
{
1171-
if to_mt == hir::Mutability::Mut && from_mt == hir::Mutability::Not {
1171+
if to_mt == Mutability::Mut && from_mt == Mutability::Not {
11721172
let msg = "mutating transmuted &mut T from &T may cause undefined behavior, \
11731173
consider instead using an UnsafeCell";
11741174
cx.struct_span_lint(MUTABLE_TRANSMUTES, expr.span, |lint| lint.build(msg).emit());

compiler/rustc_lint/src/internal.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
//! Clippy.
33
44
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
5-
use rustc_ast::{Item, ItemKind};
5+
use rustc_ast::{Item, ItemKind, Mutability};
66
use rustc_data_structures::fx::FxHashMap;
77
use rustc_errors::Applicability;
88
use rustc_hir::def::Res;
9-
use rustc_hir::{GenericArg, HirId, MutTy, Mutability, Path, PathSegment, QPath, Ty, TyKind};
9+
use rustc_hir::{GenericArg, HirId, MutTy, Path, PathSegment, QPath, Ty, TyKind};
1010
use rustc_middle::ty;
1111
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
1212
use rustc_span::hygiene::{ExpnKind, MacroKind};

compiler/rustc_metadata/src/rmeta/decoder.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::rmeta::table::{FixedSizeEncoding, Table};
55
use crate::rmeta::*;
66

77
use rustc_ast as ast;
8+
use rustc_ast::Mutability;
89
use rustc_attr as attr;
910
use rustc_data_structures::captures::Captures;
1011
use rustc_data_structures::fingerprint::{Fingerprint, FingerprintDecoder};
@@ -1517,10 +1518,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
15171518
}
15181519
}
15191520

1520-
fn static_mutability(&self, id: DefIndex) -> Option<hir::Mutability> {
1521+
fn static_mutability(&self, id: DefIndex) -> Option<Mutability> {
15211522
match self.kind(id) {
1522-
EntryKind::ImmStatic | EntryKind::ForeignImmStatic => Some(hir::Mutability::Not),
1523-
EntryKind::MutStatic | EntryKind::ForeignMutStatic => Some(hir::Mutability::Mut),
1523+
EntryKind::ImmStatic | EntryKind::ForeignImmStatic => Some(Mutability::Not),
1524+
EntryKind::MutStatic | EntryKind::ForeignMutStatic => Some(Mutability::Mut),
15241525
_ => None,
15251526
}
15261527
}

compiler/rustc_metadata/src/rmeta/encoder.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::rmeta::table::{FixedSizeEncoding, TableBuilder};
22
use crate::rmeta::*;
33

44
use rustc_ast as ast;
5+
use rustc_ast::Mutability;
56
use rustc_data_structures::fingerprint::{Fingerprint, FingerprintEncoder};
67
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
78
use rustc_data_structures::stable_hasher::StableHasher;
@@ -1228,8 +1229,8 @@ impl EncodeContext<'a, 'tcx> {
12281229
self.encode_ident_span(def_id, item.ident);
12291230

12301231
record!(self.tables.kind[def_id] <- match item.kind {
1231-
hir::ItemKind::Static(_, hir::Mutability::Mut, _) => EntryKind::MutStatic,
1232-
hir::ItemKind::Static(_, hir::Mutability::Not, _) => EntryKind::ImmStatic,
1232+
hir::ItemKind::Static(_, Mutability::Mut, _) => EntryKind::MutStatic,
1233+
hir::ItemKind::Static(_, Mutability::Not, _) => EntryKind::ImmStatic,
12331234
hir::ItemKind::Const(_, body_id) => {
12341235
let qualifs = self.tcx.at(item.span).mir_const_qualif(def_id);
12351236
EntryKind::Const(
@@ -1740,8 +1741,8 @@ impl EncodeContext<'a, 'tcx> {
17401741
};
17411742
EntryKind::ForeignFn(self.lazy(data))
17421743
}
1743-
hir::ForeignItemKind::Static(_, hir::Mutability::Mut) => EntryKind::ForeignMutStatic,
1744-
hir::ForeignItemKind::Static(_, hir::Mutability::Not) => EntryKind::ForeignImmStatic,
1744+
hir::ForeignItemKind::Static(_, Mutability::Mut) => EntryKind::ForeignMutStatic,
1745+
hir::ForeignItemKind::Static(_, Mutability::Not) => EntryKind::ForeignImmStatic,
17451746
hir::ForeignItemKind::Type => EntryKind::ForeignType,
17461747
});
17471748
record!(self.tables.visibility[def_id] <-

compiler/rustc_middle/src/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_hir::{self, GeneratorKind};
2020
use rustc_target::abi::VariantIdx;
2121

2222
use polonius_engine::Atom;
23-
pub use rustc_ast::Mutability;
23+
pub use rustc_ast::{Movability, Mutability};
2424
use rustc_data_structures::fx::FxHashSet;
2525
use rustc_data_structures::graph::dominators::{dominators, Dominators};
2626
use rustc_data_structures::graph::{self, GraphSuccessors};
@@ -2084,7 +2084,7 @@ pub enum AggregateKind<'tcx> {
20842084
Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),
20852085

20862086
Closure(DefId, SubstsRef<'tcx>),
2087-
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
2087+
Generator(DefId, SubstsRef<'tcx>, Movability),
20882088
}
20892089

20902090
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]

compiler/rustc_middle/src/mir/tcx.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,19 @@ impl<'tcx> BinOp {
245245
}
246246

247247
impl BorrowKind {
248-
pub fn to_mutbl_lossy(self) -> hir::Mutability {
248+
pub fn to_mutbl_lossy(self) -> Mutability {
249249
match self {
250-
BorrowKind::Mut { .. } => hir::Mutability::Mut,
251-
BorrowKind::Shared => hir::Mutability::Not,
250+
BorrowKind::Mut { .. } => Mutability::Mut,
251+
BorrowKind::Shared => Mutability::Not,
252252

253253
// We have no type corresponding to a unique imm borrow, so
254254
// use `&mut`. It gives all the capabilities of an `&uniq`
255255
// and hence is a safe "over approximation".
256-
BorrowKind::Unique => hir::Mutability::Mut,
256+
BorrowKind::Unique => Mutability::Mut,
257257

258258
// We have no type corresponding to a shallow borrow, so use
259259
// `&` as an approximation.
260-
BorrowKind::Shallow => hir::Mutability::Not,
260+
BorrowKind::Shallow => Mutability::Not,
261261
}
262262
}
263263
}

compiler/rustc_middle/src/query/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::traits::query::{
99
use crate::ty::query::queries;
1010
use crate::ty::subst::{GenericArg, SubstsRef};
1111
use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
12+
use rustc_ast::Mutability;
1213
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
1314
use rustc_query_system::query::QueryDescription;
1415

@@ -463,7 +464,7 @@ rustc_queries! {
463464
}
464465

465466
/// Returns `Some(mutability)` if the node pointed to by `def_id` is a static item.
466-
query static_mutability(def_id: DefId) -> Option<hir::Mutability> {
467+
query static_mutability(def_id: DefId) -> Option<Mutability> {
467468
desc { |tcx| "looking up static mutability of `{}`", tcx.def_path_str(def_id) }
468469
}
469470

0 commit comments

Comments
 (0)