From e4b87f5edb3b5b0442a5fbe887bfc85068b6a4ef Mon Sep 17 00:00:00 2001 From: flip1995 Date: Mon, 1 Apr 2019 00:02:46 +0200 Subject: [PATCH] Deny internal lints on librustc_mir --- .../borrow_check/error_reporting.rs | 30 +++++++++---------- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_mir/borrow_check/move_errors.rs | 4 +-- .../borrow_check/mutability_errors.rs | 10 +++---- .../borrow_check/nll/explain_borrow/mod.rs | 2 +- .../nll/region_infer/error_reporting/mod.rs | 2 +- .../borrow_check/nll/type_check/mod.rs | 8 ++--- .../dataflow/move_paths/builder.rs | 2 +- src/librustc_mir/hair/pattern/_match.rs | 4 +-- src/librustc_mir/hair/pattern/check_match.rs | 12 ++++---- src/librustc_mir/lib.rs | 1 + src/librustc_mir/lints.rs | 4 +-- src/librustc_mir/transform/instcombine.rs | 4 +-- src/librustc_mir/transform/lower_128bit.rs | 6 ++-- 14 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index c04a36fe9c6..01c06739e29 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -223,7 +223,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { Some(ref name) => format!("`{}`", name), None => "value".to_owned(), }; - if let ty::TyKind::Param(param_ty) = ty.sty { + if let ty::Param(param_ty) = ty.sty { let tcx = self.infcx.tcx; let generics = tcx.generics_of(self.mir_def_id); let def_id = generics.type_param(¶m_ty, tcx).def_id; @@ -1529,7 +1529,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { if let TerminatorKind::Call { func: Operand::Constant(box Constant { literal: ty::Const { - ty: &ty::TyS { sty: ty::TyKind::FnDef(id, _), .. }, + ty: &ty::TyS { sty: ty::FnDef(id, _), .. }, .. }, .. @@ -1547,7 +1547,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { }; debug!("add_moved_or_invoked_closure_note: closure={:?}", closure); - if let ty::TyKind::Closure(did, _) = self.mir.local_decls[closure].ty.sty { + if let ty::Closure(did, _) = self.mir.local_decls[closure].ty.sty { let hir_id = self.infcx.tcx.hir().as_local_hir_id(did).unwrap(); if let Some((span, name)) = self.infcx.tcx.typeck_tables_of(did) @@ -1570,7 +1570,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // Check if we are just moving a closure after it has been invoked. if let Some(target) = target { - if let ty::TyKind::Closure(did, _) = self.mir.local_decls[target].ty.sty { + if let ty::Closure(did, _) = self.mir.local_decls[target].ty.sty { let hir_id = self.infcx.tcx.hir().as_local_hir_id(did).unwrap(); if let Some((span, name)) = self.infcx.tcx.typeck_tables_of(did) @@ -1919,7 +1919,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { } else { let ty = self.infcx.tcx.type_of(self.mir_def_id); match ty.sty { - ty::TyKind::FnDef(_, _) | ty::TyKind::FnPtr(_) => self.annotate_fn_sig( + ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig( self.mir_def_id, self.infcx.tcx.fn_sig(self.mir_def_id), ), @@ -2164,12 +2164,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // anything. let return_ty = sig.output(); match return_ty.skip_binder().sty { - ty::TyKind::Ref(return_region, _, _) if return_region.has_name() && !is_closure => { + ty::Ref(return_region, _, _) if return_region.has_name() && !is_closure => { // This is case 1 from above, return type is a named reference so we need to // search for relevant arguments. let mut arguments = Vec::new(); for (index, argument) in sig.inputs().skip_binder().iter().enumerate() { - if let ty::TyKind::Ref(argument_region, _, _) = argument.sty { + if let ty::Ref(argument_region, _, _) = argument.sty { if argument_region == return_region { // Need to use the `rustc::ty` types to compare against the // `return_region`. Then use the `rustc::hir` type to get only @@ -2206,7 +2206,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { return_span, }) } - ty::TyKind::Ref(_, _, _) if is_closure => { + ty::Ref(_, _, _) if is_closure => { // This is case 2 from above but only for closures, return type is anonymous // reference so we select // the first argument. @@ -2215,9 +2215,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // Closure arguments are wrapped in a tuple, so we need to get the first // from that. - if let ty::TyKind::Tuple(elems) = argument_ty.sty { + if let ty::Tuple(elems) = argument_ty.sty { let argument_ty = elems.first()?; - if let ty::TyKind::Ref(_, _, _) = argument_ty.sty { + if let ty::Ref(_, _, _) = argument_ty.sty { return Some(AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span, @@ -2227,7 +2227,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { None } - ty::TyKind::Ref(_, _, _) => { + ty::Ref(_, _, _) => { // This is also case 2 from above but for functions, return type is still an // anonymous reference so we select the first argument. let argument_span = fn_decl.inputs.first()?.span; @@ -2238,7 +2238,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // We expect the first argument to be a reference. match argument_ty.sty { - ty::TyKind::Ref(_, _, _) => {} + ty::Ref(_, _, _) => {} _ => return None, } @@ -2366,8 +2366,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // this by hooking into the pretty printer and telling it to label the // lifetimes without names with the value `'0`. match ty.sty { - ty::TyKind::Ref(ty::RegionKind::ReLateBound(_, br), _, _) - | ty::TyKind::Ref( + ty::Ref(ty::RegionKind::ReLateBound(_, br), _, _) + | ty::Ref( ty::RegionKind::RePlaceholder(ty::PlaceholderRegion { name: br, .. }), _, _, @@ -2386,7 +2386,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, &mut s, Namespace::TypeNS); let region = match ty.sty { - ty::TyKind::Ref(region, _, _) => { + ty::Ref(region, _, _) => { match region { ty::RegionKind::ReLateBound(_, br) | ty::RegionKind::RePlaceholder(ty::PlaceholderRegion { name: br, .. }) => { diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index a8c151a22ee..bf297ae0deb 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -1741,7 +1741,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // no move out from an earlier location) then this is an attempt at initialization // of the union - we should error in that case. let tcx = this.infcx.tcx; - if let ty::TyKind::Adt(def, _) = base.ty(this.mir, tcx).ty.sty { + if let ty::Adt(def, _) = base.ty(this.mir, tcx).ty.sty { if def.is_union() { if this.move_data.path_map[mpi].iter().any(|moi| { this.move_data.moves[*moi].source.is_predecessor_of( diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index b6e7996586e..7efe1d83c2e 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -532,7 +532,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { if let StatementKind::Assign(_, box Rvalue::Ref(_, _, source)) = &stmt.kind { let ty = source.ty(self.mir, self.infcx.tcx).ty; let ty = match ty.sty { - ty::TyKind::Ref(_, ty, _) => ty, + ty::Ref(_, ty, _) => ty, _ => ty, }; debug!("borrowed_content_source: ty={:?}", ty); @@ -557,7 +557,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { let ty = source.ty(self.mir, self.infcx.tcx).ty; let ty = match ty.sty { - ty::TyKind::Ref(_, ty, _) => ty, + ty::Ref(_, ty, _) => ty, _ => ty, }; debug!("borrowed_content_source: ty={:?}", ty); diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index 8a55a59b15b..b780511315d 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -5,7 +5,7 @@ use rustc::mir::{ Mutability, Operand, Place, PlaceBase, Projection, ProjectionElem, Static, StaticKind, }; use rustc::mir::{Terminator, TerminatorKind}; -use rustc::ty::{self, Const, DefIdTree, TyS, TyKind, TyCtxt}; +use rustc::ty::{self, Const, DefIdTree, TyS, TyCtxt}; use rustc_data_structures::indexed_vec::Idx; use syntax_pos::Span; use syntax_pos::symbol::keywords; @@ -261,7 +261,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { // Otherwise, check if the name is the self kewyord - in which case // we have an explicit self. Do the same thing in this case and check // for a `self: &mut Self` to suggest removing the `&mut`. - if let ty::TyKind::Ref( + if let ty::Ref( _, _, hir::Mutability::MutMutable ) = local_decl.ty.sty { true @@ -476,7 +476,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { func: Operand::Constant(box Constant { literal: Const { ty: &TyS { - sty: TyKind::FnDef(id, substs), + sty: ty::FnDef(id, substs), .. }, .. @@ -633,8 +633,8 @@ fn annotate_struct_field( field: &mir::Field, ) -> Option<(Span, String)> { // Expect our local to be a reference to a struct of some kind. - if let ty::TyKind::Ref(_, ty, _) = ty.sty { - if let ty::TyKind::Adt(def, _) = ty.sty { + if let ty::Ref(_, ty, _) = ty.sty { + if let ty::Adt(def, _) = ty.sty { let field = def.all_fields().nth(field.index())?; // Use the HIR types to construct the diagnostic message. let hir_id = tcx.hir().as_local_hir_id(field.did)?; diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs index 67b77605f3c..e30938bc326 100644 --- a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs +++ b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs @@ -589,7 +589,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // Check the type for a trait object. return match ty.sty { // `&dyn Trait` - ty::TyKind::Ref(_, ty, _) if ty.is_trait() => true, + ty::Ref(_, ty, _) if ty.is_trait() => true, // `Box` _ if ty.is_box() && ty.boxed_ty().is_trait() => true, // `dyn Trait` diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs index 3773f1a40c7..917e383cae8 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs @@ -583,7 +583,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { (self.to_error_region(fr), self.to_error_region(outlived_fr)) { if let Some(ty::TyS { - sty: ty::TyKind::Opaque(did, substs), + sty: ty::Opaque(did, substs), .. }) = infcx .tcx diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index b06ebbdbf34..ec5637d1707 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -39,7 +39,7 @@ use rustc::traits::{ObligationCause, PredicateObligations}; use rustc::ty::fold::TypeFoldable; use rustc::ty::subst::{Subst, SubstsRef, UnpackedKind, UserSubsts}; use rustc::ty::{ - self, RegionVid, ToPolyTraitRef, Ty, TyCtxt, TyKind, UserType, + self, RegionVid, ToPolyTraitRef, Ty, TyCtxt, UserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, UserTypeAnnotationIndex, }; @@ -746,7 +746,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> { let (variant, substs) = match base_ty { PlaceTy { ty, variant_index: Some(variant_index) } => { match ty.sty { - ty::TyKind::Adt(adt_def, substs) => (&adt_def.variants[variant_index], substs), + ty::Adt(adt_def, substs) => (&adt_def.variants[variant_index], substs), _ => bug!("can't have downcast of non-adt type"), } } @@ -1136,7 +1136,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { category: ConstraintCategory, ) -> Fallible<()> { if let Err(terr) = self.sub_types(sub, sup, locations, category) { - if let TyKind::Opaque(..) = sup.sty { + if let ty::Opaque(..) = sup.sty { // When you have `let x: impl Foo = ...` in a closure, // the resulting inferend values are stored with the // def-id of the base function. @@ -1389,7 +1389,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { } => { let place_type = place.ty(mir, tcx).ty; let adt = match place_type.sty { - TyKind::Adt(adt, _) if adt.is_enum() => adt, + ty::Adt(adt, _) if adt.is_enum() => adt, _ => { span_bug!( stmt.source_info.span, diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index 011dc54f3b3..2471c01e3f3 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -425,7 +425,7 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> { base, elem: ProjectionElem::Field(_, _), }) if match base.ty(self.builder.mir, self.builder.tcx).ty.sty { - ty::TyKind::Adt(def, _) if def.is_union() => true, + ty::Adt(def, _) if def.is_union() => true, _ => false, } => base, // Otherwise, lookup the place. diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 303ffcb3bfb..a9c521f59a9 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -1754,7 +1754,7 @@ fn specialize<'p, 'a: 'p, 'tcx: 'a>( // they should be pointing to memory is when they are subslices of nonzero // slices let (opt_ptr, n, ty) = match value.ty.sty { - ty::TyKind::Array(t, n) => { + ty::Array(t, n) => { match value.val { ConstValue::ByRef(ptr, alloc) => ( Some((ptr, alloc)), @@ -1767,7 +1767,7 @@ fn specialize<'p, 'a: 'p, 'tcx: 'a>( ), } }, - ty::TyKind::Slice(t) => { + ty::Slice(t) => { match value.val { ConstValue::Slice(ptr, n) => ( ptr.to_ptr().ok().map(|ptr| ( diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 50df676aea9..7ded973701e 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -10,7 +10,7 @@ use rustc::middle::expr_use_visitor as euv; use rustc::middle::mem_categorization::cmt_; use rustc::middle::region; use rustc::session::Session; -use rustc::ty::{self, Ty, TyCtxt, TyKind}; +use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::subst::{InternalSubsts, SubstsRef}; use rustc::lint; use rustc_errors::{Applicability, DiagnosticBuilder}; @@ -481,7 +481,7 @@ fn check_exhaustive<'p, 'a: 'p, 'tcx: 'a>( } let patterns = witnesses.iter().map(|p| (**p).clone()).collect::>>(); if patterns.len() < 4 { - for sp in maybe_point_at_variant(cx, &scrut_ty.sty, patterns.as_slice()) { + for sp in maybe_point_at_variant(cx, scrut_ty, patterns.as_slice()) { err.span_label(sp, "not covered"); } } @@ -498,11 +498,11 @@ fn check_exhaustive<'p, 'a: 'p, 'tcx: 'a>( fn maybe_point_at_variant( cx: &mut MatchCheckCtxt<'a, 'tcx>, - sty: &TyKind<'tcx>, + ty: Ty<'tcx>, patterns: &[Pattern<'_>], ) -> Vec { let mut covered = vec![]; - if let ty::Adt(def, _) = sty { + if let ty::Adt(def, _) = ty.sty { // Don't point at variants that have already been covered due to other patterns to avoid // visual clutter for pattern in patterns { @@ -518,7 +518,7 @@ fn maybe_point_at_variant( .map(|field_pattern| field_pattern.pattern.clone()) .collect::>(); covered.extend( - maybe_point_at_variant(cx, sty, subpatterns.as_slice()), + maybe_point_at_variant(cx, ty, subpatterns.as_slice()), ); } } @@ -526,7 +526,7 @@ fn maybe_point_at_variant( let subpatterns = subpatterns.iter() .map(|field_pattern| field_pattern.pattern.clone()) .collect::>(); - covered.extend(maybe_point_at_variant(cx, sty, subpatterns.as_slice())); + covered.extend(maybe_point_at_variant(cx, ty, subpatterns.as_slice())); } } } diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index c45e694ebf8..deeed9a0b98 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -28,6 +28,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #![recursion_limit="256"] #![deny(rust_2018_idioms)] +#![cfg_attr(not(stage0), deny(internal))] #![allow(explicit_outlives_requirements)] #[macro_use] extern crate log; diff --git a/src/librustc_mir/lints.rs b/src/librustc_mir/lints.rs index 6d6a3f91472..572f7133cad 100644 --- a/src/librustc_mir/lints.rs +++ b/src/librustc_mir/lints.rs @@ -4,7 +4,7 @@ use rustc::hir::intravisit::FnKind; use rustc::hir::map::blocks::FnLikeNode; use rustc::lint::builtin::UNCONDITIONAL_RECURSION; use rustc::mir::{self, Mir, TerminatorKind}; -use rustc::ty::{AssociatedItem, AssociatedItemContainer, Instance, TyCtxt, TyKind}; +use rustc::ty::{self, AssociatedItem, AssociatedItemContainer, Instance, TyCtxt}; use rustc::ty::subst::InternalSubsts; pub fn check(tcx: TyCtxt<'a, 'tcx, 'tcx>, @@ -86,7 +86,7 @@ fn check_fn_for_unconditional_recursion(tcx: TyCtxt<'a, 'tcx, 'tcx>, TerminatorKind::Call { ref func, .. } => { let func_ty = func.ty(mir, tcx); - if let TyKind::FnDef(fn_def_id, substs) = func_ty.sty { + if let ty::FnDef(fn_def_id, substs) = func_ty.sty { let (call_fn_id, call_substs) = if let Some(instance) = Instance::resolve(tcx, param_env, diff --git a/src/librustc_mir/transform/instcombine.rs b/src/librustc_mir/transform/instcombine.rs index 7e925f65ee2..8187a81f0ed 100644 --- a/src/librustc_mir/transform/instcombine.rs +++ b/src/librustc_mir/transform/instcombine.rs @@ -2,7 +2,7 @@ use rustc::mir::{Constant, Location, Place, PlaceBase, Mir, Operand, ProjectionElem, Rvalue, Local}; use rustc::mir::visit::{MutVisitor, Visitor}; -use rustc::ty::{TyCtxt, TyKind}; +use rustc::ty::{self, TyCtxt}; use rustc::util::nodemap::{FxHashMap, FxHashSet}; use rustc_data_structures::indexed_vec::Idx; use std::mem; @@ -90,7 +90,7 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for OptimizationFinder<'b, 'a, 'tcx> { if let Rvalue::Len(ref place) = *rvalue { let place_ty = place.ty(&self.mir.local_decls, self.tcx).ty; - if let TyKind::Array(_, len) = place_ty.sty { + if let ty::Array(_, len) = place_ty.sty { let span = self.mir.source_info(location).span; let ty = self.tcx.types.usize; let constant = Constant { span, ty, literal: len, user_ty: None }; diff --git a/src/librustc_mir/transform/lower_128bit.rs b/src/librustc_mir/transform/lower_128bit.rs index dda9457cc8c..fd9d6bb5760 100644 --- a/src/librustc_mir/transform/lower_128bit.rs +++ b/src/librustc_mir/transform/lower_128bit.rs @@ -3,7 +3,7 @@ use rustc::hir::def_id::DefId; use rustc::middle::lang_items::LangItem; use rustc::mir::*; -use rustc::ty::{List, Ty, TyCtxt, TyKind}; +use rustc::ty::{self, List, Ty, TyCtxt}; use rustc_data_structures::indexed_vec::{Idx}; use crate::transform::{MirPass, MirSource}; @@ -183,8 +183,8 @@ impl RhsKind { fn sign_of_128bit(ty: Ty<'_>) -> Option { match ty.sty { - TyKind::Int(syntax::ast::IntTy::I128) => Some(true), - TyKind::Uint(syntax::ast::UintTy::U128) => Some(false), + ty::Int(syntax::ast::IntTy::I128) => Some(true), + ty::Uint(syntax::ast::UintTy::U128) => Some(false), _ => None, } }