Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Don't re-export rustc_ast items in rustc_hir #77494

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
decl,
body_id,
span,
Some(hir::Movability::Static),
Some(Movability::Static),
);
let generator = hir::Expr {
hir_id: self.lower_node_id(closure_node_id),
Expand Down Expand Up @@ -751,7 +751,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn_decl_span: Span,
generator_kind: Option<hir::GeneratorKind>,
movability: Movability,
) -> Option<hir::Movability> {
) -> Option<Movability> {
match generator_kind {
Some(hir::GeneratorKind::Gen) => {
if decl.inputs.len() > 1 {
Expand Down Expand Up @@ -1638,7 +1638,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn expr_mut_addr_of(&mut self, span: Span, e: &'hir hir::Expr<'hir>) -> hir::Expr<'hir> {
self.expr(
span,
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, e),
hir::ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, e),
ThinVec::new(),
)
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::type_of::LayoutLlvmExt;
use crate::va_arg::emit_va_arg;
use crate::value::Value;

use rustc_ast::Mutability;
use rustc_codegen_ssa::base::{compare_simd_types, wants_msvc_seh};
use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
Expand Down Expand Up @@ -1332,7 +1333,7 @@ fn generic_simd_intrinsic(
// The second argument must be a simd vector with an element type that's a pointer
// to the element type of the first argument
let (pointer_count, underlying_ty) = match arg_tys[1].simd_type(tcx).kind() {
ty::RawPtr(p) if p.ty == in_elem && p.mutbl == hir::Mutability::Mut => {
ty::RawPtr(p) if p.ty == in_elem && p.mutbl == Mutability::Mut => {
(ptr_count(arg_tys[1].simd_type(tcx)), non_ptr(arg_tys[1].simd_type(tcx)))
}
_ => {
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Type Names for Debug Info.

use rustc_data_structures::fx::FxHashSet;
use rustc_ast::Mutability;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::{self, subst::SubstsRef, Ty, TyCtxt};
Expand Down Expand Up @@ -75,8 +76,8 @@ pub fn push_debuginfo_type_name<'tcx>(
output.push('*');
}
match mutbl {
hir::Mutability::Not => output.push_str("const "),
hir::Mutability::Mut => output.push_str("mut "),
Mutability::Not => output.push_str("const "),
Mutability::Mut => output.push_str("mut "),
}

push_debuginfo_type_name(tcx, inner_type, true, output, visited);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#![feature(min_const_generics)]
#![feature(once_cell)]
#![allow(rustc::default_hash_types)]
#![allow(rustc::pub_cross_crate_reexport)]

#[macro_use]
extern crate tracing;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use rustc_ast::node_id::NodeMap;
use rustc_ast::util::parser::ExprPrecedence;
use rustc_ast::{self as ast, CrateSugar, LlvmAsmDialect};
use rustc_ast::{AttrVec, Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy};
pub use rustc_ast::{BorrowKind, ImplPolarity, IsAuto};
pub use rustc_ast::{CaptureBy, Movability, Mutability};
use rustc_ast::{BorrowKind, ImplPolarity, IsAuto};
use rustc_ast::{CaptureBy, Movability, Mutability};
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
use rustc_macros::HashStable_Generic;
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_hir/src/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::def_id::DefId;
use crate::hir::{self, HirId, PatKind};
use rustc_span::symbol::Ident;
use rustc_span::Span;
use rustc_ast::Mutability;

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

Expand Down Expand Up @@ -179,14 +180,14 @@ impl hir::Pat<'_> {
//
// FIXME(tschottdorf): this is problematic as the HIR is being scraped, but
// ref bindings are be implicit after #42640 (default match binding modes). See issue #44848.
pub fn contains_explicit_ref_binding(&self) -> Option<hir::Mutability> {
pub fn contains_explicit_ref_binding(&self) -> Option<Mutability> {
let mut result = None;
self.each_binding(|annotation, _, _, _| match annotation {
hir::BindingAnnotation::Ref => match result {
None | Some(hir::Mutability::Not) => result = Some(hir::Mutability::Not),
None | Some(Mutability::Not) => result = Some(Mutability::Not),
_ => {}
},
hir::BindingAnnotation::RefMut => result = Some(hir::Mutability::Mut),
hir::BindingAnnotation::RefMut => result = Some(Mutability::Mut),
_ => {}
});
result
Expand Down
37 changes: 19 additions & 18 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![recursion_limit = "256"]

use rustc_ast as ast;
use rustc_ast::{BorrowKind, CaptureBy, IsAuto, ImplPolarity, Mutability};
use rustc_ast::util::parser::{self, AssocOp, Fixity};
use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
use rustc_ast_pretty::pp::{self, Breaks};
Expand Down Expand Up @@ -477,7 +478,7 @@ impl<'a> State<'a> {
}
hir::ForeignItemKind::Static(ref t, m) => {
self.head(visibility_qualified(&item.vis, "static"));
if m == hir::Mutability::Mut {
if m == Mutability::Mut {
self.word_space("mut");
}
self.print_ident(item.ident);
Expand Down Expand Up @@ -598,7 +599,7 @@ impl<'a> State<'a> {
}
hir::ItemKind::Static(ref ty, m, expr) => {
self.head(visibility_qualified(&item.vis, "static"));
if m == hir::Mutability::Mut {
if m == Mutability::Mut {
self.word_space("mut");
}
self.print_ident(item.ident);
Expand Down Expand Up @@ -719,7 +720,7 @@ impl<'a> State<'a> {
self.word_nbsp("const");
}

if let hir::ImplPolarity::Negative(_) = polarity {
if let ImplPolarity::Negative(_) = polarity {
self.s.word("!");
}

Expand Down Expand Up @@ -1257,14 +1258,14 @@ impl<'a> State<'a> {

fn print_expr_addr_of(
&mut self,
kind: hir::BorrowKind,
mutability: hir::Mutability,
kind: BorrowKind,
mutability: Mutability,
expr: &hir::Expr<'_>,
) {
self.s.word("&");
match kind {
hir::BorrowKind::Ref => self.print_mutability(mutability, false),
hir::BorrowKind::Raw => {
BorrowKind::Ref => self.print_mutability(mutability, false),
BorrowKind::Raw => {
self.word_nbsp("raw");
self.print_mutability(mutability, true);
}
Expand Down Expand Up @@ -1825,11 +1826,11 @@ impl<'a> State<'a> {
match binding_mode {
hir::BindingAnnotation::Ref => {
self.word_nbsp("ref");
self.print_mutability(hir::Mutability::Not, false);
self.print_mutability(Mutability::Not, false);
}
hir::BindingAnnotation::RefMut => {
self.word_nbsp("ref");
self.print_mutability(hir::Mutability::Mut, false);
self.print_mutability(Mutability::Mut, false);
}
hir::BindingAnnotation::Unannotated => {}
hir::BindingAnnotation::Mutable => {
Expand Down Expand Up @@ -2114,10 +2115,10 @@ impl<'a> State<'a> {
}
}

pub fn print_capture_clause(&mut self, capture_clause: hir::CaptureBy) {
pub fn print_capture_clause(&mut self, capture_clause: CaptureBy) {
match capture_clause {
hir::CaptureBy::Value => self.word_space("move"),
hir::CaptureBy::Ref => {}
CaptureBy::Value => self.word_space("move"),
CaptureBy::Ref => {}
}
}

Expand Down Expand Up @@ -2268,10 +2269,10 @@ impl<'a> State<'a> {
}
}

pub fn print_mutability(&mut self, mutbl: hir::Mutability, print_const: bool) {
pub fn print_mutability(&mut self, mutbl: Mutability, print_const: bool) {
match mutbl {
hir::Mutability::Mut => self.word_nbsp("mut"),
hir::Mutability::Not => {
Mutability::Mut => self.word_nbsp("mut"),
Mutability::Not => {
if print_const {
self.word_nbsp("const")
}
Expand Down Expand Up @@ -2410,10 +2411,10 @@ impl<'a> State<'a> {
}
}

pub fn print_is_auto(&mut self, s: hir::IsAuto) {
pub fn print_is_auto(&mut self, s: IsAuto) {
match s {
hir::IsAuto::Yes => self.word_nbsp("auto"),
hir::IsAuto::No => {}
IsAuto::Yes => self.word_nbsp("auto"),
IsAuto::No => {}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use crate::traits::{
IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode,
};

use rustc_ast::Mutability;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::{pluralize, struct_span_err};
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
Expand Down Expand Up @@ -1060,7 +1061,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
fn push_ty_ref<'tcx>(
region: &ty::Region<'tcx>,
ty: Ty<'tcx>,
mutbl: hir::Mutability,
mutbl: Mutability,
s: &mut DiagnosticStyledString,
) {
let mut r = region.to_string();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
if let Some((&ty::Ref(_, _, from_mt), &ty::Ref(_, _, to_mt))) =
get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (ty1.kind(), ty2.kind()))
{
if to_mt == hir::Mutability::Mut && from_mt == hir::Mutability::Not {
if to_mt == Mutability::Mut && from_mt == Mutability::Not {
let msg = "mutating transmuted &mut T from &T may cause undefined behavior, \
consider instead using an UnsafeCell";
cx.struct_span_lint(MUTABLE_TRANSMUTES, expr.span, |lint| lint.build(msg).emit());
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//! Clippy.

use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
use rustc_ast::{Item, ItemKind};
use rustc_ast::{Item, ItemKind, Mutability};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::Applicability;
use rustc_hir::def::Res;
use rustc_hir::{GenericArg, HirId, MutTy, Mutability, Path, PathSegment, QPath, Ty, TyKind};
use rustc_hir::{GenericArg, HirId, MutTy, Path, PathSegment, QPath, Ty, TyKind};
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
use rustc_span::hygiene::{ExpnKind, MacroKind};
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::rmeta::table::{FixedSizeEncoding, Table};
use crate::rmeta::*;

use rustc_ast as ast;
use rustc_ast::Mutability;
use rustc_attr as attr;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fingerprint::{Fingerprint, FingerprintDecoder};
Expand Down Expand Up @@ -1517,10 +1518,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
}

fn static_mutability(&self, id: DefIndex) -> Option<hir::Mutability> {
fn static_mutability(&self, id: DefIndex) -> Option<Mutability> {
match self.kind(id) {
EntryKind::ImmStatic | EntryKind::ForeignImmStatic => Some(hir::Mutability::Not),
EntryKind::MutStatic | EntryKind::ForeignMutStatic => Some(hir::Mutability::Mut),
EntryKind::ImmStatic | EntryKind::ForeignImmStatic => Some(Mutability::Not),
EntryKind::MutStatic | EntryKind::ForeignMutStatic => Some(Mutability::Mut),
_ => None,
}
}
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::rmeta::table::{FixedSizeEncoding, TableBuilder};
use crate::rmeta::*;

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

record!(self.tables.kind[def_id] <- match item.kind {
hir::ItemKind::Static(_, hir::Mutability::Mut, _) => EntryKind::MutStatic,
hir::ItemKind::Static(_, hir::Mutability::Not, _) => EntryKind::ImmStatic,
hir::ItemKind::Static(_, Mutability::Mut, _) => EntryKind::MutStatic,
hir::ItemKind::Static(_, Mutability::Not, _) => EntryKind::ImmStatic,
hir::ItemKind::Const(_, body_id) => {
let qualifs = self.tcx.at(item.span).mir_const_qualif(def_id);
EntryKind::Const(
Expand Down Expand Up @@ -1740,8 +1741,8 @@ impl EncodeContext<'a, 'tcx> {
};
EntryKind::ForeignFn(self.lazy(data))
}
hir::ForeignItemKind::Static(_, hir::Mutability::Mut) => EntryKind::ForeignMutStatic,
hir::ForeignItemKind::Static(_, hir::Mutability::Not) => EntryKind::ForeignImmStatic,
hir::ForeignItemKind::Static(_, Mutability::Mut) => EntryKind::ForeignMutStatic,
hir::ForeignItemKind::Static(_, Mutability::Not) => EntryKind::ForeignImmStatic,
hir::ForeignItemKind::Type => EntryKind::ForeignType,
});
record!(self.tables.visibility[def_id] <-
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_hir::{self, GeneratorKind};
use rustc_target::abi::VariantIdx;

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

Closure(DefId, SubstsRef<'tcx>),
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
Generator(DefId, SubstsRef<'tcx>, Movability),
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_middle/src/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,19 +245,19 @@ impl<'tcx> BinOp {
}

impl BorrowKind {
pub fn to_mutbl_lossy(self) -> hir::Mutability {
pub fn to_mutbl_lossy(self) -> Mutability {
match self {
BorrowKind::Mut { .. } => hir::Mutability::Mut,
BorrowKind::Shared => hir::Mutability::Not,
BorrowKind::Mut { .. } => Mutability::Mut,
BorrowKind::Shared => Mutability::Not,

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

// We have no type corresponding to a shallow borrow, so use
// `&` as an approximation.
BorrowKind::Shallow => hir::Mutability::Not,
BorrowKind::Shallow => Mutability::Not,
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::traits::query::{
use crate::ty::query::queries;
use crate::ty::subst::{GenericArg, SubstsRef};
use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
use rustc_ast::Mutability;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
use rustc_query_system::query::QueryDescription;

Expand Down Expand Up @@ -463,7 +464,7 @@ rustc_queries! {
}

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

Expand Down
Loading