simplify reexports in rustc::hir

This commit is contained in:
Mazdak Farrokhzad 2020-01-05 01:50:05 +01:00
parent 7785834159
commit 62ac10ffde
23 changed files with 72 additions and 78 deletions

View File

@ -3,22 +3,11 @@
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html
pub mod check_attr;
pub use rustc_hir::def;
pub mod exports;
pub use rustc_hir::def_id;
pub use rustc_hir::hir_id::*;
pub mod intravisit;
pub use rustc_hir::itemlikevisit;
pub mod map;
pub use rustc_hir::pat_util;
pub use rustc_hir::print;
pub mod upvars;
pub use rustc_hir::BlockCheckMode::*;
pub use rustc_hir::FunctionRetTy::*;
pub use rustc_hir::PrimTy::*;
pub use rustc_hir::UnOp::*;
pub use rustc_hir::UnsafeSource::*;
pub use rustc_hir::*;
use crate::ty::query::Providers;

View File

@ -867,7 +867,7 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(
}
pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionRetTy<'v>) {
if let Return(ref output_ty) = *ret_ty {
if let FunctionRetTy::Return(ref output_ty) = *ret_ty {
visitor.visit_ty(output_ty)
}
}

View File

@ -207,9 +207,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_unop(&mut self, u: UnOp) -> hir::UnOp {
match u {
UnOp::Deref => hir::UnDeref,
UnOp::Not => hir::UnNot,
UnOp::Neg => hir::UnNeg,
UnOp::Deref => hir::UnOp::UnDeref,
UnOp::Not => hir::UnOp::UnNot,
UnOp::Neg => hir::UnOp::UnNeg,
}
}
@ -1374,7 +1374,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
stmts: &[],
expr: Some(expr),
hir_id,
rules: hir::UnsafeBlock(hir::CompilerGenerated),
rules: hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::CompilerGenerated),
span,
targeted_by_break: false,
}),

View File

@ -2144,12 +2144,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} else {
match decl.output {
FunctionRetTy::Ty(ref ty) => match in_band_ty_params {
Some((def_id, _)) if impl_trait_return_allow => {
hir::Return(self.lower_ty(ty, ImplTraitContext::OpaqueTy(Some(def_id))))
}
_ => hir::Return(self.lower_ty(ty, ImplTraitContext::disallowed())),
Some((def_id, _)) if impl_trait_return_allow => hir::FunctionRetTy::Return(
self.lower_ty(ty, ImplTraitContext::OpaqueTy(Some(def_id))),
),
_ => hir::FunctionRetTy::Return(
self.lower_ty(ty, ImplTraitContext::disallowed()),
),
},
FunctionRetTy::Default(span) => hir::DefaultReturn(span),
FunctionRetTy::Default(span) => hir::FunctionRetTy::DefaultReturn(span),
}
};
@ -2940,8 +2942,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode {
match *b {
BlockCheckMode::Default => hir::DefaultBlock,
BlockCheckMode::Unsafe(u) => hir::UnsafeBlock(self.lower_unsafe_source(u)),
BlockCheckMode::Default => hir::BlockCheckMode::DefaultBlock,
BlockCheckMode::Unsafe(u) => {
hir::BlockCheckMode::UnsafeBlock(self.lower_unsafe_source(u))
}
}
}
@ -2956,8 +2960,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_unsafe_source(&mut self, u: UnsafeSource) -> hir::UnsafeSource {
match u {
CompilerGenerated => hir::CompilerGenerated,
UserProvided => hir::UserProvided,
CompilerGenerated => hir::UnsafeSource::CompilerGenerated,
UserProvided => hir::UnsafeSource::UserProvided,
}
}
@ -3004,7 +3008,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
stmts,
expr,
hir_id: self.next_id(),
rules: hir::DefaultBlock,
rules: hir::BlockCheckMode::DefaultBlock,
span,
targeted_by_break: false,
};

View File

@ -376,7 +376,7 @@ fn lint_literal<'a, 'tcx>(
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx hir::Expr<'tcx>) {
match e.kind {
hir::ExprKind::Unary(hir::UnNeg, ref expr) => {
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => {
// propagate negation, if the negation itself isn't negated
if self.negated_expr_id != e.hir_id {
self.negated_expr_id = expr.hir_id;
@ -969,7 +969,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
self.check_type_for_ffi_and_report_errors(input_hir.span, input_ty, false);
}
if let hir::Return(ref ret_hir) = decl.output {
if let hir::FunctionRetTy::Return(ref ret_hir) = decl.output {
let ret_ty = sig.output();
if !ret_ty.is_unit() {
self.check_type_for_ffi_and_report_errors(ret_hir.span, ret_ty, false);

View File

@ -814,7 +814,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
}
}
hir::ExprKind::Path(ref qpath) => *self.lower_path(qpath, expr.hir_id, expr.span).kind,
hir::ExprKind::Unary(hir::UnNeg, ref expr) => {
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => {
let ty = self.tables.expr_ty(expr);
let lit = match expr.kind {
hir::ExprKind::Lit(ref lit) => lit,

View File

@ -482,7 +482,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> {
fn visit_block(&mut self, block: &'tcx hir::Block<'tcx>) {
hir::intravisit::walk_block(self, block);
if let hir::UnsafeBlock(hir::UserProvided) = block.rules {
if let hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::UserProvided) = block.rules {
self.unsafe_blocks.push((block.hir_id, self.used_unsafe.contains(&block.hir_id)));
}
}

View File

@ -651,7 +651,7 @@ fn resolve_local<'tcx>(
match expr.kind {
hir::ExprKind::AddrOf(_, _, ref subexpr)
| hir::ExprKind::Unary(hir::UnDeref, ref subexpr)
| hir::ExprKind::Unary(hir::UnOp::UnDeref, ref subexpr)
| hir::ExprKind::Field(ref subexpr, _)
| hir::ExprKind::Index(ref subexpr, _) => {
expr = &subexpr;

View File

@ -26,7 +26,7 @@ use rustc::hir::def::{self, CtorKind, CtorOf, DefKind, NonMacroAttrKind, Partial
use rustc::hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc::hir::exports::ExportMap;
use rustc::hir::map::Definitions;
use rustc::hir::{Bool, Char, Float, Int, PrimTy, Str, Uint};
use rustc::hir::PrimTy::{self, Bool, Char, Float, Int, Str, Uint};
use rustc::hir::{GlobMap, TraitMap};
use rustc::lint;
use rustc::middle::cstore::{CrateStore, MetadataLoaderDyn};

View File

@ -846,8 +846,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
fn visit_fn_decl(&mut self, fd: &'tcx hir::FnDecl<'tcx>) {
let output = match fd.output {
hir::DefaultReturn(_) => None,
hir::Return(ref ty) => Some(&**ty),
hir::FunctionRetTy::DefaultReturn(_) => None,
hir::FunctionRetTy::Return(ref ty) => Some(&**ty),
};
self.visit_fn_like_elision(&fd.inputs, output);
}

View File

@ -2554,12 +2554,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
assert_eq!(opt_self_ty, None);
self.prohibit_generics(path.segments);
match prim_ty {
hir::Bool => tcx.types.bool,
hir::Char => tcx.types.char,
hir::Int(it) => tcx.mk_mach_int(it),
hir::Uint(uit) => tcx.mk_mach_uint(uit),
hir::Float(ft) => tcx.mk_mach_float(ft),
hir::Str => tcx.mk_str(),
hir::PrimTy::Bool => tcx.types.bool,
hir::PrimTy::Char => tcx.types.char,
hir::PrimTy::Int(it) => tcx.mk_mach_int(it),
hir::PrimTy::Uint(uit) => tcx.mk_mach_uint(uit),
hir::PrimTy::Float(ft) => tcx.mk_mach_float(ft),
hir::PrimTy::Str => tcx.mk_str(),
}
}
Res::Err => {
@ -2773,11 +2773,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
let input_tys = decl.inputs.iter().map(|a| self.ty_of_arg(a, None));
let output_ty = match decl.output {
hir::Return(ref output) => {
hir::FunctionRetTy::Return(ref output) => {
visitor.visit_ty(output);
self.ast_ty_to_ty(output)
}
hir::DefaultReturn(..) => tcx.mk_unit(),
hir::FunctionRetTy::DefaultReturn(..) => tcx.mk_unit(),
};
debug!("ty_of_fn: output_ty={:?}", output_ty);

View File

@ -548,8 +548,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// First, convert the types that the user supplied (if any).
let supplied_arguments = decl.inputs.iter().map(|a| astconv.ast_ty_to_ty(a));
let supplied_return = match decl.output {
hir::Return(ref output) => astconv.ast_ty_to_ty(&output),
hir::DefaultReturn(_) => match body.generator_kind {
hir::FunctionRetTy::Return(ref output) => astconv.ast_ty_to_ty(&output),
hir::FunctionRetTy::DefaultReturn(_) => match body.generator_kind {
// In the case of the async block that we create for a function body,
// we expect the return type of the block to match that of the enclosing
// function.
@ -696,7 +696,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx.types.err
});
if let hir::Return(ref output) = decl.output {
if let hir::FunctionRetTy::Return(ref output) = decl.output {
astconv.ast_ty_to_ty(&output);
}

View File

@ -306,11 +306,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> Ty<'tcx> {
let tcx = self.tcx;
let expected_inner = match unop {
hir::UnNot | hir::UnNeg => expected,
hir::UnDeref => NoExpectation,
hir::UnOp::UnNot | hir::UnOp::UnNeg => expected,
hir::UnOp::UnDeref => NoExpectation,
};
let needs = match unop {
hir::UnDeref => needs,
hir::UnOp::UnDeref => needs,
_ => Needs::None,
};
let mut oprnd_t = self.check_expr_with_expectation_and_needs(&oprnd, expected_inner, needs);
@ -318,7 +318,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if !oprnd_t.references_error() {
oprnd_t = self.structurally_resolved_type(expr.span, oprnd_t);
match unop {
hir::UnDeref => {
hir::UnOp::UnDeref => {
if let Some(mt) = oprnd_t.builtin_deref(true) {
oprnd_t = mt.ty;
} else if let Some(ok) = self.try_overloaded_deref(expr.span, oprnd_t, needs) {
@ -362,14 +362,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
oprnd_t = tcx.types.err;
}
}
hir::UnNot => {
hir::UnOp::UnNot => {
let result = self.check_user_unop(expr, oprnd_t, unop);
// If it's builtin, we can reuse the type, this helps inference.
if !(oprnd_t.is_integral() || oprnd_t.kind == ty::Bool) {
oprnd_t = result;
}
}
hir::UnNeg => {
hir::UnOp::UnNeg => {
let result = self.check_user_unop(expr, oprnd_t, unop);
// If it's builtin, we can reuse the type, this helps inference.
if !oprnd_t.is_numeric() {

View File

@ -425,7 +425,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
match exprs.last().unwrap().kind {
hir::ExprKind::Field(ref expr, _)
| hir::ExprKind::Index(ref expr, _)
| hir::ExprKind::Unary(hir::UnDeref, ref expr) => exprs.push(&expr),
| hir::ExprKind::Unary(hir::UnOp::UnDeref, ref expr) => exprs.push(&expr),
_ => break,
}
}
@ -471,7 +471,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
&[index_expr_ty],
);
}
hir::ExprKind::Unary(hir::UnDeref, ref base_expr) => {
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref base_expr) => {
self.convert_place_op_to_mutable(PlaceOp::Deref, expr, base_expr, &[]);
}
_ => {}

View File

@ -390,6 +390,7 @@ impl UnsafetyState {
}
pub fn recurse(&mut self, blk: &hir::Block<'_>) -> UnsafetyState {
use hir::BlockCheckMode;
match self.unsafety {
// If this unsafe, then if the outer function was already marked as
// unsafe we shouldn't attribute the unsafe'ness to the block. This
@ -399,16 +400,16 @@ impl UnsafetyState {
unsafety => {
let (unsafety, def, count) = match blk.rules {
hir::PushUnsafeBlock(..) => {
BlockCheckMode::PushUnsafeBlock(..) => {
(unsafety, blk.hir_id, self.unsafe_push_count.checked_add(1).unwrap())
}
hir::PopUnsafeBlock(..) => {
BlockCheckMode::PopUnsafeBlock(..) => {
(unsafety, blk.hir_id, self.unsafe_push_count.checked_sub(1).unwrap())
}
hir::UnsafeBlock(..) => {
BlockCheckMode::UnsafeBlock(..) => {
(hir::Unsafety::Unsafe, blk.hir_id, self.unsafe_push_count)
}
hir::DefaultBlock => (unsafety, self.def, self.unsafe_push_count),
BlockCheckMode::DefaultBlock => (unsafety, self.def, self.unsafe_push_count),
};
UnsafetyState { def, unsafety, unsafe_push_count: count, from_fn: false }
}

View File

@ -689,16 +689,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
),
);
match actual.kind {
Uint(_) if op == hir::UnNeg => {
Uint(_) if op == hir::UnOp::UnNeg => {
err.note("unsigned values cannot be negated");
}
Str | Never | Char | Tuple(_) | Array(_, _) => {}
Ref(_, ref lty, _) if lty.kind == Str => {}
_ => {
let missing_trait = match op {
hir::UnNeg => "std::ops::Neg",
hir::UnNot => "std::ops::Not",
hir::UnDeref => "std::ops::UnDerf",
hir::UnOp::UnNeg => "std::ops::Neg",
hir::UnOp::UnNot => "std::ops::Not",
hir::UnOp::UnDeref => "std::ops::UnDerf",
};
err.note(&format!(
"an implementation of `{}` might \
@ -771,9 +771,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span_bug!(span, "&& and || are not overloadable")
}
}
} else if let Op::Unary(hir::UnNot, _) = op {
} else if let Op::Unary(hir::UnOp::UnNot, _) = op {
("not", lang.not_trait())
} else if let Op::Unary(hir::UnNeg, _) = op {
} else if let Op::Unary(hir::UnOp::UnNeg, _) = op {
("neg", lang.neg_trait())
} else {
bug!("lookup_op_method: op not supported: {:?}", op)

View File

@ -492,7 +492,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
if is_method_call {
let origin = match expr.kind {
hir::ExprKind::MethodCall(..) => infer::ParameterOrigin::MethodCall,
hir::ExprKind::Unary(op, _) if op == hir::UnDeref => {
hir::ExprKind::Unary(op, _) if op == hir::UnOp::UnDeref => {
infer::ParameterOrigin::OverloadedDeref
}
_ => infer::ParameterOrigin::OverloadedOperator,
@ -577,7 +577,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
intravisit::walk_expr(self, expr);
}
hir::ExprKind::Unary(hir::UnDeref, ref base) => {
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref base) => {
// For *a, the lifetime of a must enclose the deref
if is_method_call {
self.constrain_call(expr, Some(base), None::<hir::Expr<'_>>.iter());

View File

@ -133,8 +133,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
// operating on scalars, we clear the overload.
fn fix_scalar_builtin_expr(&mut self, e: &hir::Expr<'_>) {
match e.kind {
hir::ExprKind::Unary(hir::UnNeg, ref inner)
| hir::ExprKind::Unary(hir::UnNot, ref inner) => {
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref inner)
| hir::ExprKind::Unary(hir::UnOp::UnNot, ref inner) => {
let inner_ty = self.fcx.node_ty(inner.hir_id);
let inner_ty = self.fcx.resolve_vars_if_possible(&inner_ty);

View File

@ -2499,7 +2499,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
for (input, ty) in decl.inputs.iter().zip(*fty.inputs().skip_binder()) {
check(&input, ty)
}
if let hir::Return(ref ty) = decl.output {
if let hir::FunctionRetTy::Return(ref ty) = decl.output {
check(&ty, *fty.output().skip_binder())
}
}

View File

@ -192,7 +192,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
hir::ExprKind::Type(ref subexpr, _) => self.walk_expr(subexpr),
hir::ExprKind::Unary(hir::UnDeref, ref base) => {
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref base) => {
// *base
self.select_from_expr(base);
}

View File

@ -347,7 +347,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
let expr_ty = self.expr_ty(expr)?;
match expr.kind {
hir::ExprKind::Unary(hir::UnDeref, ref e_base) => {
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref e_base) => {
if self.tables.is_method_call(expr) {
self.cat_overloaded_place(expr, e_base)
} else {

View File

@ -1003,8 +1003,8 @@ impl<'tcx> Clean<FnDecl> for (DefId, ty::PolyFnSig<'tcx>) {
impl Clean<FunctionRetTy> for hir::FunctionRetTy<'_> {
fn clean(&self, cx: &DocContext<'_>) -> FunctionRetTy {
match *self {
hir::Return(ref typ) => Return(typ.clean(cx)),
hir::DefaultReturn(..) => DefaultReturn,
Self::Return(ref typ) => Return(typ.clean(cx)),
Self::DefaultReturn(..) => DefaultReturn,
}
}
}

View File

@ -567,12 +567,12 @@ pub fn resolve_type(cx: &DocContext<'_>, path: Path, id: hir::HirId) -> Type {
let is_generic = match path.res {
Res::PrimTy(p) => match p {
hir::Str => return Primitive(PrimitiveType::Str),
hir::Bool => return Primitive(PrimitiveType::Bool),
hir::Char => return Primitive(PrimitiveType::Char),
hir::Int(int_ty) => return Primitive(int_ty.into()),
hir::Uint(uint_ty) => return Primitive(uint_ty.into()),
hir::Float(float_ty) => return Primitive(float_ty.into()),
hir::PrimTy::Str => return Primitive(PrimitiveType::Str),
hir::PrimTy::Bool => return Primitive(PrimitiveType::Bool),
hir::PrimTy::Char => return Primitive(PrimitiveType::Char),
hir::PrimTy::Int(int_ty) => return Primitive(int_ty.into()),
hir::PrimTy::Uint(uint_ty) => return Primitive(uint_ty.into()),
hir::PrimTy::Float(float_ty) => return Primitive(float_ty.into()),
},
Res::SelfTy(..) if path.segments.len() == 1 => {
return Generic(kw::SelfUpper.to_string());