diff options
Diffstat (limited to 'compiler/rustc_middle/src')
39 files changed, 348 insertions, 238 deletions
diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 6de68841fe9..75282f958b5 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -93,7 +93,7 @@ macro_rules! arena_types { // Interned types [] tys: rustc_type_ir::WithCachedTypeInfo<rustc_middle::ty::TyKind<'tcx>>, [] predicates: rustc_type_ir::WithCachedTypeInfo<rustc_middle::ty::PredicateKind<'tcx>>, - [] consts: rustc_middle::ty::ConstS<'tcx>, + [] consts: rustc_middle::ty::ConstData<'tcx>, // Note that this deliberately duplicates items in the `rustc_hir::arena`, // since we need to allocate this type on both the `rustc_hir` arena diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index 6b556826918..865bb70afb5 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -175,7 +175,7 @@ impl DepNodeExt for DepNode { /// DepNode. Condition (2) might not be fulfilled if a DepNode /// refers to something from the previous compilation session that /// has been removed. - fn extract_def_id<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> { + fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId> { if tcx.fingerprint_style(self.kind) == FingerprintStyle::DefPathHash { Some(tcx.def_path_hash_to_def_id(DefPathHash(self.hash.into()), &mut || { panic!("Failed to extract DefId: {:?} {}", self.kind, self.hash) diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 0450abed51b..fe640f185b6 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -18,7 +18,7 @@ use rustc_span::Span; use rustc_target::spec::abi::Abi; #[inline] -pub fn associated_body<'hir>(node: Node<'hir>) -> Option<BodyId> { +pub fn associated_body(node: Node<'_>) -> Option<BodyId> { match node { Node::Item(Item { kind: ItemKind::Const(_, body) | ItemKind::Static(.., body) | ItemKind::Fn(.., body), @@ -41,7 +41,7 @@ pub fn associated_body<'hir>(node: Node<'hir>) -> Option<BodyId> { } } -fn is_body_owner<'hir>(node: Node<'hir>, hir_id: HirId) -> bool { +fn is_body_owner(node: Node<'_>, hir_id: HirId) -> bool { match associated_body(node) { Some(b) => b.hir_id == hir_id, None => false, @@ -170,6 +170,7 @@ impl<'hir> Map<'hir> { } #[inline] + #[track_caller] pub fn local_def_id(self, hir_id: HirId) -> LocalDefId { self.opt_local_def_id(hir_id).unwrap_or_else(|| { bug!( @@ -310,6 +311,7 @@ impl<'hir> Map<'hir> { } } + #[track_caller] pub fn get_parent_node(self, hir_id: HirId) -> HirId { self.find_parent_node(hir_id) .unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id))) @@ -334,12 +336,14 @@ impl<'hir> Map<'hir> { } /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found. + #[track_caller] pub fn get(self, id: HirId) -> Node<'hir> { self.find(id).unwrap_or_else(|| bug!("couldn't find hir id {} in the HIR map", id)) } /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found. #[inline] + #[track_caller] pub fn get_by_def_id(self, id: LocalDefId) -> Node<'hir> { self.find_by_def_id(id).unwrap_or_else(|| bug!("couldn't find {:?} in the HIR map", id)) } @@ -377,6 +381,7 @@ impl<'hir> Map<'hir> { self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies[&id.hir_id.local_id] } + #[track_caller] pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> { if let Some(node) = self.find(hir_id) { node.fn_decl() @@ -385,6 +390,7 @@ impl<'hir> Map<'hir> { } } + #[track_caller] pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> { if let Some(node) = self.find(hir_id) { node.fn_sig() @@ -393,6 +399,7 @@ impl<'hir> Map<'hir> { } } + #[track_caller] pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId { for (_, node) in self.parent_iter(hir_id) { if let Some(body) = associated_body(node) { @@ -408,7 +415,7 @@ impl<'hir> Map<'hir> { /// item (possibly associated), a closure, or a `hir::AnonConst`. pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId { let parent = self.get_parent_node(hir_id); - assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id))); + assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)), "{hir_id:?}"); parent } @@ -419,10 +426,11 @@ impl<'hir> Map<'hir> { /// Given a `LocalDefId`, returns the `BodyId` associated with it, /// if the node is a body owner, otherwise returns `None`. pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId> { - self.get_if_local(id.to_def_id()).map(associated_body).flatten() + self.find_by_def_id(id).and_then(associated_body) } /// Given a body owner's id, returns the `BodyId` associated with it. + #[track_caller] pub fn body_owned_by(self, id: LocalDefId) -> BodyId { self.maybe_body_owned_by(id).unwrap_or_else(|| { let hir_id = self.local_def_id_to_hir_id(id); diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index 0331d764b38..0b32f67a81e 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -300,6 +300,16 @@ impl<'tcx, V> Canonical<'tcx, V> { let Canonical { max_universe, variables, value } = self; Canonical { max_universe, variables, value: map_op(value) } } + + /// Allows you to map the `value` of a canonical while keeping the same set of + /// bound variables. + /// + /// **WARNING:** This function is very easy to mis-use, hence the name! See + /// the comment of [Canonical::unchecked_map] for more details. + pub fn unchecked_rebind<W>(self, value: W) -> Canonical<'tcx, W> { + let Canonical { max_universe, variables, value: _ } = self; + Canonical { max_universe, variables, value } + } } pub type QueryOutlivesConstraint<'tcx> = ( diff --git a/compiler/rustc_middle/src/middle/privacy.rs b/compiler/rustc_middle/src/middle/privacy.rs index fc08d58cc40..0e18ba73d71 100644 --- a/compiler/rustc_middle/src/middle/privacy.rs +++ b/compiler/rustc_middle/src/middle/privacy.rs @@ -103,12 +103,7 @@ impl EffectiveVisibilities { pub fn public_at_level(&self, id: LocalDefId) -> Option<Level> { self.effective_vis(id).and_then(|effective_vis| { - for level in Level::all_levels() { - if effective_vis.is_public_at_level(level) { - return Some(level); - } - } - None + Level::all_levels().into_iter().find(|&level| effective_vis.is_public_at_level(level)) }) } diff --git a/compiler/rustc_middle/src/middle/region.rs b/compiler/rustc_middle/src/middle/region.rs index c886175c6ea..94ca38c0e75 100644 --- a/compiler/rustc_middle/src/middle/region.rs +++ b/compiler/rustc_middle/src/middle/region.rs @@ -147,9 +147,8 @@ rustc_index::newtype_index! { /// /// * The subscope with `first_statement_index == 1` is scope of `c`, /// and thus does not include EXPR_2, but covers the `...`. - pub struct FirstStatementIndex { - derive [HashStable] - } + #[derive(HashStable)] + pub struct FirstStatementIndex {} } // compilation error if size of `ScopeData` is not the same as a `u32` diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 61bc089e431..0836f236e24 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -223,8 +223,8 @@ pub fn deprecation_message_and_lint( ) } -pub fn early_report_deprecation<'a>( - lint_buffer: &'a mut LintBuffer, +pub fn early_report_deprecation( + lint_buffer: &mut LintBuffer, message: &str, suggestion: Option<Symbol>, lint: &'static Lint, diff --git a/compiler/rustc_middle/src/mir/coverage.rs b/compiler/rustc_middle/src/mir/coverage.rs index 0b55757eb03..e7bb3ab0bc3 100644 --- a/compiler/rustc_middle/src/mir/coverage.rs +++ b/compiler/rustc_middle/src/mir/coverage.rs @@ -10,10 +10,10 @@ rustc_index::newtype_index! { /// CounterValueReference.as_u32() (which ascend from 1) or an ExpressionOperandId.as_u32() /// (which _*descend*_ from u32::MAX). Id value `0` (zero) represents a virtual counter with a /// constant value of `0`. + #[derive(HashStable)] + #[max = 0xFFFF_FFFF] + #[debug_format = "ExpressionOperandId({})"] pub struct ExpressionOperandId { - derive [HashStable] - DEBUG_FORMAT = "ExpressionOperandId({})", - MAX = 0xFFFF_FFFF, } } @@ -32,11 +32,10 @@ impl ExpressionOperandId { } rustc_index::newtype_index! { - pub struct CounterValueReference { - derive [HashStable] - DEBUG_FORMAT = "CounterValueReference({})", - MAX = 0xFFFF_FFFF, - } + #[derive(HashStable)] + #[max = 0xFFFF_FFFF] + #[debug_format = "CounterValueReference({})"] + pub struct CounterValueReference {} } impl CounterValueReference { @@ -56,33 +55,30 @@ rustc_index::newtype_index! { /// InjectedExpressionId.as_u32() converts to ExpressionOperandId.as_u32() /// /// Values descend from u32::MAX. - pub struct InjectedExpressionId { - derive [HashStable] - DEBUG_FORMAT = "InjectedExpressionId({})", - MAX = 0xFFFF_FFFF, - } + #[derive(HashStable)] + #[max = 0xFFFF_FFFF] + #[debug_format = "InjectedExpressionId({})"] + pub struct InjectedExpressionId {} } rustc_index::newtype_index! { /// InjectedExpressionIndex.as_u32() translates to u32::MAX - ExpressionOperandId.as_u32() /// /// Values ascend from 0. - pub struct InjectedExpressionIndex { - derive [HashStable] - DEBUG_FORMAT = "InjectedExpressionIndex({})", - MAX = 0xFFFF_FFFF, - } + #[derive(HashStable)] + #[max = 0xFFFF_FFFF] + #[debug_format = "InjectedExpressionIndex({})"] + pub struct InjectedExpressionIndex {} } rustc_index::newtype_index! { /// MappedExpressionIndex values ascend from zero, and are recalculated indexes based on their /// array position in the LLVM coverage map "Expressions" array, which is assembled during the /// "mapgen" process. They cannot be computed algorithmically, from the other `newtype_index`s. - pub struct MappedExpressionIndex { - derive [HashStable] - DEBUG_FORMAT = "MappedExpressionIndex({})", - MAX = 0xFFFF_FFFF, - } + #[derive(HashStable)] + #[max = 0xFFFF_FFFF] + #[debug_format = "MappedExpressionIndex({})"] + pub struct MappedExpressionIndex {} } impl From<CounterValueReference> for ExpressionOperandId { diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index bdaa586c698..50e41e3e006 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -654,10 +654,10 @@ impl SourceInfo { // Variables and temps rustc_index::newtype_index! { + #[derive(HashStable)] + #[debug_format = "_{}"] pub struct Local { - derive [HashStable] - DEBUG_FORMAT = "_{}", - const RETURN_PLACE = 0, + const RETURN_PLACE = 0; } } @@ -1146,10 +1146,10 @@ rustc_index::newtype_index! { /// https://rustc-dev-guide.rust-lang.org/appendix/background.html#what-is-a-dataflow-analysis /// [`CriticalCallEdges`]: ../../rustc_const_eval/transform/add_call_guards/enum.AddCallGuards.html#variant.CriticalCallEdges /// [guide-mir]: https://rustc-dev-guide.rust-lang.org/mir/ + #[derive(HashStable)] + #[debug_format = "bb{}"] pub struct BasicBlock { - derive [HashStable] - DEBUG_FORMAT = "bb{}", - const START_BLOCK = 0, + const START_BLOCK = 0; } } @@ -1530,10 +1530,9 @@ rustc_index::newtype_index! { /// [wrapper]: https://rustc-dev-guide.rust-lang.org/appendix/glossary.html#newtype /// [CFG]: https://rustc-dev-guide.rust-lang.org/appendix/background.html#cfg /// [mir-datatypes]: https://rustc-dev-guide.rust-lang.org/mir/index.html#mir-data-types - pub struct Field { - derive [HashStable] - DEBUG_FORMAT = "field[{}]" - } + #[derive(HashStable)] + #[debug_format = "field[{}]"] + pub struct Field {} } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -1757,10 +1756,10 @@ impl Debug for Place<'_> { // Scopes rustc_index::newtype_index! { + #[derive(HashStable)] + #[debug_format = "scope[{}]"] pub struct SourceScope { - derive [HashStable] - DEBUG_FORMAT = "scope[{}]", - const OUTERMOST_SOURCE_SCOPE = 0, + const OUTERMOST_SOURCE_SCOPE = 0; } } @@ -1768,9 +1767,9 @@ impl SourceScope { /// Finds the original HirId this MIR item came from. /// This is necessary after MIR optimizations, as otherwise we get a HirId /// from the function that was inlined instead of the function call site. - pub fn lint_root<'tcx>( + pub fn lint_root( self, - source_scopes: &IndexVec<SourceScope, SourceScopeData<'tcx>>, + source_scopes: &IndexVec<SourceScope, SourceScopeData<'_>>, ) -> Option<HirId> { let mut data = &source_scopes[self]; // FIXME(oli-obk): we should be able to just walk the `inlined_parent_scope`, but it @@ -2755,10 +2754,9 @@ impl<'tcx> TypeVisitable<'tcx> for UserTypeProjection { } rustc_index::newtype_index! { - pub struct Promoted { - derive [HashStable] - DEBUG_FORMAT = "promoted[{}]" - } + #[derive(HashStable)] + #[debug_format = "promoted[{}]"] + pub struct Promoted {} } impl<'tcx> Debug for Constant<'tcx> { diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 2a4ff4b8810..40289af257f 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -88,7 +88,7 @@ pub fn dump_mir<'tcx, F>( dump_matched_mir_node(tcx, pass_num, pass_name, disambiguator, body, extra_data); } -pub fn dump_enabled<'tcx>(tcx: TyCtxt<'tcx>, pass_name: &str, def_id: DefId) -> bool { +pub fn dump_enabled(tcx: TyCtxt<'_>, pass_name: &str, def_id: DefId) -> bool { let Some(ref filters) = tcx.sess.opts.unstable_opts.dump_mir else { return false; }; @@ -421,7 +421,7 @@ impl<'tcx> ExtraComments<'tcx> { } } -fn use_verbose<'tcx>(ty: Ty<'tcx>, fn_def: bool) -> bool { +fn use_verbose(ty: Ty<'_>, fn_def: bool) -> bool { match *ty.kind() { ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) => false, // Unit type @@ -448,15 +448,15 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> { // FIXME: this is a poor version of `pretty_print_const_value`. let fmt_val = |val: &ConstValue<'tcx>| match val { - ConstValue::ZeroSized => format!("<ZST>"), + ConstValue::ZeroSized => "<ZST>".to_string(), ConstValue::Scalar(s) => format!("Scalar({:?})", s), - ConstValue::Slice { .. } => format!("Slice(..)"), - ConstValue::ByRef { .. } => format!("ByRef(..)"), + ConstValue::Slice { .. } => "Slice(..)".to_string(), + ConstValue::ByRef { .. } => "ByRef(..)".to_string(), }; let fmt_valtree = |valtree: &ty::ValTree<'tcx>| match valtree { ty::ValTree::Leaf(leaf) => format!("ValTree::Leaf({:?})", leaf), - ty::ValTree::Branch(_) => format!("ValTree::Branch(..)"), + ty::ValTree::Branch(_) => "ValTree::Branch(..)".to_string(), }; let val = match literal { diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs index efd7357afc4..a8a4532223c 100644 --- a/compiler/rustc_middle/src/mir/query.rs +++ b/compiler/rustc_middle/src/mir/query.rs @@ -130,10 +130,9 @@ pub struct UnsafetyCheckResult { } rustc_index::newtype_index! { - pub struct GeneratorSavedLocal { - derive [HashStable] - DEBUG_FORMAT = "_{}", - } + #[derive(HashStable)] + #[debug_format = "_{}"] + pub struct GeneratorSavedLocal {} } /// The layout of generator state. diff --git a/compiler/rustc_middle/src/mir/spanview.rs b/compiler/rustc_middle/src/mir/spanview.rs index 4e06d91012c..887ee571575 100644 --- a/compiler/rustc_middle/src/mir/spanview.rs +++ b/compiler/rustc_middle/src/mir/spanview.rs @@ -230,7 +230,7 @@ where } /// Format a string showing the start line and column, and end line and column within a file. -pub fn source_range_no_file<'tcx>(tcx: TyCtxt<'tcx>, span: Span) -> String { +pub fn source_range_no_file(tcx: TyCtxt<'_>, span: Span) -> String { let source_map = tcx.sess.source_map(); let start = source_map.lookup_char_pos(span.lo()); let end = source_map.lookup_char_pos(span.hi()); @@ -322,7 +322,7 @@ fn block_span_viewable<'tcx>( Some(SpanViewable { bb, span, id, tooltip }) } -fn compute_block_span<'tcx>(data: &BasicBlockData<'tcx>, body_span: Span) -> Span { +fn compute_block_span(data: &BasicBlockData<'_>, body_span: Span) -> Span { let mut span = data.terminator().source_info.span; for statement_span in data.statements.iter().map(|statement| statement.source_info.span) { // Only combine Spans from the root context, and within the function's body_span. @@ -522,12 +522,7 @@ where } #[inline(always)] -fn write_coverage_gap<'tcx, W>( - tcx: TyCtxt<'tcx>, - lo: BytePos, - hi: BytePos, - w: &mut W, -) -> io::Result<()> +fn write_coverage_gap<W>(tcx: TyCtxt<'_>, lo: BytePos, hi: BytePos, w: &mut W) -> io::Result<()> where W: Write, { @@ -582,8 +577,8 @@ where Ok(()) } -fn make_html_snippet<'tcx>( - tcx: TyCtxt<'tcx>, +fn make_html_snippet( + tcx: TyCtxt<'_>, span: Span, some_viewable: Option<&SpanViewable>, ) -> Option<String> { @@ -664,7 +659,7 @@ fn trim_span_hi(span: Span, to_pos: BytePos) -> Span { if to_pos >= span.hi() { span } else { span.with_hi(cmp::max(span.lo(), to_pos)) } } -fn fn_span<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Span { +fn fn_span(tcx: TyCtxt<'_>, def_id: DefId) -> Span { let fn_decl_span = tcx.def_span(def_id); if let Some(body_span) = hir_body(tcx, def_id).map(|hir_body| hir_body.value.span) { if fn_decl_span.eq_ctxt(body_span) { fn_decl_span.to(body_span) } else { body_span } @@ -673,7 +668,7 @@ fn fn_span<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Span { } } -fn hir_body<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<&'tcx rustc_hir::Body<'tcx>> { +fn hir_body(tcx: TyCtxt<'_>, def_id: DefId) -> Option<&rustc_hir::Body<'_>> { let hir_node = tcx.hir().get_if_local(def_id).expect("expected DefId is local"); hir::map::associated_body(hir_node).map(|fn_body_id| tcx.hir().body(fn_body_id)) } diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 99e59c770d7..6b4489026d3 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -320,8 +320,10 @@ pub enum StatementKind<'tcx> { /// <https://internals.rust-lang.org/t/stacked-borrows-an-aliasing-model-for-rust/8153/> for /// more details. /// - /// For code that is not specific to stacked borrows, you should consider retags to read - /// and modify the place in an opaque way. + /// For code that is not specific to stacked borrows, you should consider retags to read and + /// modify the place in an opaque way. + /// + /// Only `RetagKind::Default` and `RetagKind::FnEntry` are permitted. Retag(RetagKind, Box<Place<'tcx>>), /// Encodes a user's type ascription. These need to be preserved @@ -562,14 +564,13 @@ pub enum TerminatorKind<'tcx> { Unreachable, /// The behavior of this statement differs significantly before and after drop elaboration. - /// After drop elaboration, `Drop` executes the drop glue for the specified place, after which - /// it continues execution/unwinds at the given basic blocks. It is possible that executing drop - /// glue is special - this would be part of Rust's memory model. (**FIXME**: due we have an - /// issue tracking if drop glue has any interesting semantics in addition to those of a function - /// call?) - /// - /// `Drop` before drop elaboration is a *conditional* execution of the drop glue. Specifically, the - /// `Drop` will be executed if... + /// + /// After drop elaboration: `Drop` terminators are a complete nop for types that have no drop + /// glue. For other types, `Drop` terminators behave exactly like a call to + /// `core::mem::drop_in_place` with a pointer to the given place. + /// + /// `Drop` before drop elaboration is a *conditional* execution of the drop glue. Specifically, + /// the `Drop` will be executed if... /// /// **Needs clarification**: End of that sentence. This in effect should document the exact /// behavior of drop elaboration. The following sounds vaguely right, but I'm not quite sure: diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index fa3adafd4b8..599f0b9d3fa 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -32,8 +32,9 @@ impl<'tcx> PlaceTy<'tcx> { /// not carry a `Ty` for `T`.) /// /// Note that the resulting type has not been normalized. + #[instrument(level = "debug", skip(tcx), ret)] pub fn field_ty(self, tcx: TyCtxt<'tcx>, f: Field) -> Ty<'tcx> { - let answer = match self.ty.kind() { + match self.ty.kind() { ty::Adt(adt_def, substs) => { let variant_def = match self.variant_index { None => adt_def.non_enum_variant(), @@ -47,9 +48,7 @@ impl<'tcx> PlaceTy<'tcx> { } ty::Tuple(tys) => tys[f.index()], _ => bug!("extracting field of non-tuple non-adt: {:?}", self), - }; - debug!("field_ty self: {:?} f: {:?} yields: {:?}", self, f, answer); - answer + } } /// Convenience wrapper around `projection_ty_core` for @@ -234,7 +233,7 @@ impl<'tcx> Operand<'tcx> { { match self { &Operand::Copy(ref l) | &Operand::Move(ref l) => l.ty(local_decls, tcx).ty, - &Operand::Constant(ref c) => c.literal.ty(), + Operand::Constant(c) => c.literal.ty(), } } } diff --git a/compiler/rustc_middle/src/mir/traversal.rs b/compiler/rustc_middle/src/mir/traversal.rs index 55b2c592795..0b461d1ce41 100644 --- a/compiler/rustc_middle/src/mir/traversal.rs +++ b/compiler/rustc_middle/src/mir/traversal.rs @@ -302,7 +302,7 @@ pub fn reachable<'a, 'tcx>( } /// Returns a `BitSet` containing all basic blocks reachable from the `START_BLOCK`. -pub fn reachable_as_bitset<'tcx>(body: &Body<'tcx>) -> BitSet<BasicBlock> { +pub fn reachable_as_bitset(body: &Body<'_>) -> BitSet<BasicBlock> { let mut iter = preorder(body); (&mut iter).for_each(drop); iter.visited diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index 880632561b9..e4bb3ce3d5a 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -15,7 +15,15 @@ use rustc_span::{Span, DUMMY_SP}; /// The `Key` trait controls what types can legally be used as the key /// for a query. pub trait Key: Sized { - type CacheSelector = DefaultCacheSelector<Self>; + // N.B. Most of the keys down below have `type CacheSelector = DefaultCacheSelector<Self>;`, + // it would be reasonable to use associated type defaults, to remove the duplication... + // + // ...But r-a doesn't support them yet and using a default here causes r-a to not infer + // return types of queries which is very annoying. Thus, until r-a support associated + // type defaults, plese restrain from using them here <3 + // + // r-a issue: <https://github.com/rust-lang/rust-analyzer/issues/13693> + type CacheSelector; /// Given an instance of this key, what crate is it referring to? /// This is used to find the provider. @@ -37,6 +45,8 @@ pub trait Key: Sized { } impl Key for () { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -48,6 +58,8 @@ impl Key for () { } impl<'tcx> Key for ty::InstanceDef<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -59,6 +71,8 @@ impl<'tcx> Key for ty::InstanceDef<'tcx> { } impl<'tcx> Key for ty::Instance<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -70,6 +84,8 @@ impl<'tcx> Key for ty::Instance<'tcx> { } impl<'tcx> Key for mir::interpret::GlobalId<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -81,6 +97,8 @@ impl<'tcx> Key for mir::interpret::GlobalId<'tcx> { } impl<'tcx> Key for (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -92,6 +110,8 @@ impl<'tcx> Key for (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>) { } impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -145,6 +165,8 @@ impl Key for LocalDefId { } impl Key for DefId { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.krate == LOCAL_CRATE @@ -159,6 +181,8 @@ impl Key for DefId { } impl Key for ty::WithOptConstParam<LocalDefId> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -169,6 +193,8 @@ impl Key for ty::WithOptConstParam<LocalDefId> { } impl Key for SimplifiedType { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -179,6 +205,8 @@ impl Key for SimplifiedType { } impl Key for (DefId, DefId) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.0.krate == LOCAL_CRATE @@ -189,6 +217,8 @@ impl Key for (DefId, DefId) { } impl<'tcx> Key for (ty::Instance<'tcx>, LocalDefId) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -199,6 +229,8 @@ impl<'tcx> Key for (ty::Instance<'tcx>, LocalDefId) { } impl Key for (DefId, LocalDefId) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.0.krate == LOCAL_CRATE @@ -209,6 +241,8 @@ impl Key for (DefId, LocalDefId) { } impl Key for (LocalDefId, DefId) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -219,6 +253,8 @@ impl Key for (LocalDefId, DefId) { } impl Key for (LocalDefId, LocalDefId) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -229,6 +265,8 @@ impl Key for (LocalDefId, LocalDefId) { } impl Key for (DefId, Option<Ident>) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.0.krate == LOCAL_CRATE @@ -243,6 +281,8 @@ impl Key for (DefId, Option<Ident>) { } impl Key for (DefId, LocalDefId, Ident) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.0.krate == LOCAL_CRATE @@ -253,6 +293,8 @@ impl Key for (DefId, LocalDefId, Ident) { } impl Key for (CrateNum, DefId) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.0 == LOCAL_CRATE @@ -263,6 +305,8 @@ impl Key for (CrateNum, DefId) { } impl Key for (CrateNum, SimplifiedType) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.0 == LOCAL_CRATE @@ -273,6 +317,8 @@ impl Key for (CrateNum, SimplifiedType) { } impl Key for (DefId, SimplifiedType) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.0.krate == LOCAL_CRATE @@ -283,6 +329,8 @@ impl Key for (DefId, SimplifiedType) { } impl<'tcx> Key for SubstsRef<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -293,6 +341,8 @@ impl<'tcx> Key for SubstsRef<'tcx> { } impl<'tcx> Key for (DefId, SubstsRef<'tcx>) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.0.krate == LOCAL_CRATE @@ -303,6 +353,8 @@ impl<'tcx> Key for (DefId, SubstsRef<'tcx>) { } impl<'tcx> Key for (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { (self.0).def.did.krate == LOCAL_CRATE @@ -313,6 +365,8 @@ impl<'tcx> Key for (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>) { } impl<'tcx> Key for (LocalDefId, DefId, SubstsRef<'tcx>) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -323,6 +377,8 @@ impl<'tcx> Key for (LocalDefId, DefId, SubstsRef<'tcx>) { } impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.1.def_id().krate == LOCAL_CRATE @@ -333,6 +389,8 @@ impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) { } impl<'tcx> Key for (ty::Const<'tcx>, mir::Field) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -343,6 +401,8 @@ impl<'tcx> Key for (ty::Const<'tcx>, mir::Field) { } impl<'tcx> Key for mir::interpret::ConstAlloc<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -353,6 +413,8 @@ impl<'tcx> Key for mir::interpret::ConstAlloc<'tcx> { } impl<'tcx> Key for ty::PolyTraitRef<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.def_id().krate == LOCAL_CRATE @@ -363,6 +425,8 @@ impl<'tcx> Key for ty::PolyTraitRef<'tcx> { } impl<'tcx> Key for ty::PolyExistentialTraitRef<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.def_id().krate == LOCAL_CRATE @@ -373,6 +437,8 @@ impl<'tcx> Key for ty::PolyExistentialTraitRef<'tcx> { } impl<'tcx> Key for (ty::PolyTraitRef<'tcx>, ty::PolyTraitRef<'tcx>) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.0.def_id().krate == LOCAL_CRATE @@ -383,6 +449,8 @@ impl<'tcx> Key for (ty::PolyTraitRef<'tcx>, ty::PolyTraitRef<'tcx>) { } impl<'tcx> Key for GenericArg<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -393,6 +461,8 @@ impl<'tcx> Key for GenericArg<'tcx> { } impl<'tcx> Key for mir::ConstantKind<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -403,6 +473,8 @@ impl<'tcx> Key for mir::ConstantKind<'tcx> { } impl<'tcx> Key for ty::Const<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -413,6 +485,8 @@ impl<'tcx> Key for ty::Const<'tcx> { } impl<'tcx> Key for Ty<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -429,6 +503,8 @@ impl<'tcx> Key for Ty<'tcx> { } impl<'tcx> Key for TyAndLayout<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -439,6 +515,8 @@ impl<'tcx> Key for TyAndLayout<'tcx> { } impl<'tcx> Key for (Ty<'tcx>, Ty<'tcx>) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -449,6 +527,8 @@ impl<'tcx> Key for (Ty<'tcx>, Ty<'tcx>) { } impl<'tcx> Key for &'tcx ty::List<ty::Predicate<'tcx>> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -459,6 +539,8 @@ impl<'tcx> Key for &'tcx ty::List<ty::Predicate<'tcx>> { } impl<'tcx> Key for ty::ParamEnv<'tcx> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -469,6 +551,8 @@ impl<'tcx> Key for ty::ParamEnv<'tcx> { } impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { self.value.query_crate_is_local() @@ -479,6 +563,8 @@ impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> { } impl Key for Symbol { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -489,6 +575,8 @@ impl Key for Symbol { } impl Key for Option<Symbol> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -501,6 +589,8 @@ impl Key for Option<Symbol> { /// Canonical query goals correspond to abstract trait operations that /// are not tied to any crate in particular. impl<'tcx, T> Key for Canonical<'tcx, T> { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -512,6 +602,8 @@ impl<'tcx, T> Key for Canonical<'tcx, T> { } impl Key for (Symbol, u32, u32) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -523,6 +615,8 @@ impl Key for (Symbol, u32, u32) { } impl<'tcx> Key for (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -534,6 +628,8 @@ impl<'tcx> Key for (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>) { } impl<'tcx> Key for (ty::Predicate<'tcx>, traits::WellFormedLoc) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -545,6 +641,8 @@ impl<'tcx> Key for (ty::Predicate<'tcx>, traits::WellFormedLoc) { } impl<'tcx> Key for (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -556,6 +654,8 @@ impl<'tcx> Key for (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>) { } impl<'tcx> Key for (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -567,6 +667,8 @@ impl<'tcx> Key for (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>) { } impl<'tcx> Key for (Ty<'tcx>, ty::ValTree<'tcx>) { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true @@ -578,6 +680,8 @@ impl<'tcx> Key for (Ty<'tcx>, ty::ValTree<'tcx>) { } impl Key for HirId { + type CacheSelector = DefaultCacheSelector<Self>; + #[inline(always)] fn query_crate_is_local(&self) -> bool { true diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 8bef9dfe099..ac903010c8d 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -35,9 +35,8 @@ macro_rules! thir_with_elements { $( newtype_index! { #[derive(HashStable)] - pub struct $id { - DEBUG_FORMAT = $format - } + #[debug_format = $format] + pub struct $id {} } )* diff --git a/compiler/rustc_middle/src/traits/chalk.rs b/compiler/rustc_middle/src/traits/chalk.rs index 6d4af8bea62..dd75b0d9ebc 100644 --- a/compiler/rustc_middle/src/traits/chalk.rs +++ b/compiler/rustc_middle/src/traits/chalk.rs @@ -210,7 +210,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { Box::new(chalk_ir::TyData { kind: ty, flags: flags }) } - fn ty_data<'a>(self, ty: &'a Self::InternedType) -> &'a chalk_ir::TyData<Self> { + fn ty_data(self, ty: &Self::InternedType) -> &chalk_ir::TyData<Self> { ty } @@ -218,10 +218,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { Box::new(lifetime) } - fn lifetime_data<'a>( - self, - lifetime: &'a Self::InternedLifetime, - ) -> &'a chalk_ir::LifetimeData<Self> { + fn lifetime_data(self, lifetime: &Self::InternedLifetime) -> &chalk_ir::LifetimeData<Self> { &lifetime } @@ -229,7 +226,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { Box::new(constant) } - fn const_data<'a>(self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self> { + fn const_data(self, constant: &Self::InternedConst) -> &chalk_ir::ConstData<Self> { &constant } @@ -246,10 +243,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { Box::new(data) } - fn generic_arg_data<'a>( - self, - data: &'a Self::InternedGenericArg, - ) -> &'a chalk_ir::GenericArgData<Self> { + fn generic_arg_data(self, data: &Self::InternedGenericArg) -> &chalk_ir::GenericArgData<Self> { &data } @@ -257,7 +251,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { Box::new(goal) } - fn goal_data<'a>(self, goal: &'a Self::InternedGoal) -> &'a chalk_ir::GoalData<Self> { + fn goal_data(self, goal: &Self::InternedGoal) -> &chalk_ir::GoalData<Self> { &goal } @@ -268,7 +262,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { data.into_iter().collect::<Result<Vec<_>, _>>() } - fn goals_data<'a>(self, goals: &'a Self::InternedGoals) -> &'a [chalk_ir::Goal<Self>] { + fn goals_data(self, goals: &Self::InternedGoals) -> &[chalk_ir::Goal<Self>] { goals } @@ -279,10 +273,10 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { data.into_iter().collect::<Result<Vec<_>, _>>() } - fn substitution_data<'a>( + fn substitution_data( self, - substitution: &'a Self::InternedSubstitution, - ) -> &'a [chalk_ir::GenericArg<Self>] { + substitution: &Self::InternedSubstitution, + ) -> &[chalk_ir::GenericArg<Self>] { substitution } @@ -293,10 +287,10 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { Box::new(data) } - fn program_clause_data<'a>( + fn program_clause_data( self, - clause: &'a Self::InternedProgramClause, - ) -> &'a chalk_ir::ProgramClauseData<Self> { + clause: &Self::InternedProgramClause, + ) -> &chalk_ir::ProgramClauseData<Self> { &clause } @@ -307,10 +301,10 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { data.into_iter().collect::<Result<Vec<_>, _>>() } - fn program_clauses_data<'a>( + fn program_clauses_data( self, - clauses: &'a Self::InternedProgramClauses, - ) -> &'a [chalk_ir::ProgramClause<Self>] { + clauses: &Self::InternedProgramClauses, + ) -> &[chalk_ir::ProgramClause<Self>] { clauses } @@ -321,10 +315,10 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { data.into_iter().collect::<Result<Vec<_>, _>>() } - fn quantified_where_clauses_data<'a>( + fn quantified_where_clauses_data( self, - clauses: &'a Self::InternedQuantifiedWhereClauses, - ) -> &'a [chalk_ir::QuantifiedWhereClause<Self>] { + clauses: &Self::InternedQuantifiedWhereClauses, + ) -> &[chalk_ir::QuantifiedWhereClause<Self>] { clauses } @@ -335,10 +329,10 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { data.into_iter().collect::<Result<Vec<_>, _>>() } - fn variable_kinds_data<'a>( + fn variable_kinds_data( self, - parameter_kinds: &'a Self::InternedVariableKinds, - ) -> &'a [chalk_ir::VariableKind<Self>] { + parameter_kinds: &Self::InternedVariableKinds, + ) -> &[chalk_ir::VariableKind<Self>] { parameter_kinds } @@ -349,10 +343,10 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { data.into_iter().collect::<Result<Vec<_>, _>>() } - fn canonical_var_kinds_data<'a>( + fn canonical_var_kinds_data( self, - canonical_var_kinds: &'a Self::InternedCanonicalVarKinds, - ) -> &'a [chalk_ir::CanonicalVarKind<Self>] { + canonical_var_kinds: &Self::InternedCanonicalVarKinds, + ) -> &[chalk_ir::CanonicalVarKind<Self>] { canonical_var_kinds } @@ -363,10 +357,10 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { data.into_iter().collect::<Result<Vec<_>, _>>() } - fn constraints_data<'a>( + fn constraints_data( self, - constraints: &'a Self::InternedConstraints, - ) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] { + constraints: &Self::InternedConstraints, + ) -> &[chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] { constraints } @@ -377,10 +371,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> { data.into_iter().collect::<Result<Vec<_>, _>>() } - fn variances_data<'a>( - self, - variances: &'a Self::InternedVariances, - ) -> &'a [chalk_ir::Variance] { + fn variances_data(self, variances: &Self::InternedVariances) -> &[chalk_ir::Variance] { variances } } diff --git a/compiler/rustc_middle/src/traits/query.rs b/compiler/rustc_middle/src/traits/query.rs index 7380c62a669..6a149be3137 100644 --- a/compiler/rustc_middle/src/traits/query.rs +++ b/compiler/rustc_middle/src/traits/query.rs @@ -96,7 +96,7 @@ pub type CanonicalTypeOpProvePredicateGoal<'tcx> = pub type CanonicalTypeOpNormalizeGoal<'tcx, T> = Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::Normalize<T>>>; -#[derive(Copy, Clone, Debug, HashStable)] +#[derive(Copy, Clone, Debug, HashStable, PartialEq, Eq)] pub struct NoSolution; pub type Fallible<T> = Result<T, NoSolution>; diff --git a/compiler/rustc_middle/src/traits/specialization_graph.rs b/compiler/rustc_middle/src/traits/specialization_graph.rs index cccedc9ec6e..aad5b2fbe07 100644 --- a/compiler/rustc_middle/src/traits/specialization_graph.rs +++ b/compiler/rustc_middle/src/traits/specialization_graph.rs @@ -60,7 +60,7 @@ pub enum OverlapMode { } impl OverlapMode { - pub fn get<'tcx>(tcx: TyCtxt<'tcx>, trait_id: DefId) -> OverlapMode { + pub fn get(tcx: TyCtxt<'_>, trait_id: DefId) -> OverlapMode { let with_negative_coherence = tcx.features().with_negative_coherence; let strict_coherence = tcx.has_attr(trait_id, sym::rustc_strict_coherence); @@ -180,6 +180,7 @@ impl Iterator for Ancestors<'_> { } /// Information about the most specialized definition of an associated item. +#[derive(Debug)] pub struct LeafDef { /// The associated item described by this `LeafDef`. pub item: ty::AssocItem, @@ -253,11 +254,11 @@ impl<'tcx> Ancestors<'tcx> { /// /// Returns `Err` if an error was reported while building the specialization /// graph. -pub fn ancestors<'tcx>( - tcx: TyCtxt<'tcx>, +pub fn ancestors( + tcx: TyCtxt<'_>, trait_def_id: DefId, start_from_impl: DefId, -) -> Result<Ancestors<'tcx>, ErrorGuaranteed> { +) -> Result<Ancestors<'_>, ErrorGuaranteed> { let specialization_graph = tcx.specialization_graph_of(trait_def_id); if let Some(reported) = specialization_graph.has_errored { diff --git a/compiler/rustc_middle/src/ty/closure.rs b/compiler/rustc_middle/src/ty/closure.rs index d00553cbad1..6ade8935fc8 100644 --- a/compiler/rustc_middle/src/ty/closure.rs +++ b/compiler/rustc_middle/src/ty/closure.rs @@ -238,10 +238,7 @@ impl<'tcx> CapturedPlace<'tcx> { } } -fn symbols_for_closure_captures<'tcx>( - tcx: TyCtxt<'tcx>, - def_id: (LocalDefId, LocalDefId), -) -> Vec<Symbol> { +fn symbols_for_closure_captures(tcx: TyCtxt<'_>, def_id: (LocalDefId, LocalDefId)) -> Vec<Symbol> { let typeck_results = tcx.typeck(def_id.0); let captures = typeck_results.closure_min_captures_flattened(def_id.1); captures.into_iter().map(|captured_place| captured_place.to_symbol(tcx)).collect() diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 75f2d45eadb..8cc8286c1db 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -310,7 +310,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Const<'tcx> { fn decode(decoder: &mut D) -> Self { - let consts: ty::ConstS<'tcx> = Decodable::decode(decoder); + let consts: ty::ConstData<'tcx> = Decodable::decode(decoder); decoder.interner().mk_const(consts.kind, consts.ty) } } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index c2be08e497e..152a7e9d43f 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -14,10 +14,10 @@ pub use int::*; pub use kind::*; pub use valtree::*; -/// Use this rather than `ConstS`, whenever possible. +/// Use this rather than `ConstData, whenever possible. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)] #[rustc_pass_by_value] -pub struct Const<'tcx>(pub Interned<'tcx, ConstS<'tcx>>); +pub struct Const<'tcx>(pub(super) Interned<'tcx, ConstData<'tcx>>); impl<'tcx> fmt::Debug for Const<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -30,13 +30,13 @@ impl<'tcx> fmt::Debug for Const<'tcx> { /// Typed constant value. #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, TyEncodable, TyDecodable)] -pub struct ConstS<'tcx> { +pub struct ConstData<'tcx> { pub ty: Ty<'tcx>, pub kind: ConstKind<'tcx>, } #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -static_assert_size!(ConstS<'_>, 40); +static_assert_size!(ConstData<'_>, 40); impl<'tcx> Const<'tcx> { #[inline] @@ -239,7 +239,7 @@ impl<'tcx> Const<'tcx> { } } -pub fn const_param_default<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Const<'tcx> { +pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> Const<'_> { let default_def_id = match tcx.hir().get_by_def_id(def_id.expect_local()) { hir::Node::GenericParam(hir::GenericParam { kind: hir::GenericParamKind::Const { default: Some(ac), .. }, diff --git a/compiler/rustc_middle/src/ty/consts/int.rs b/compiler/rustc_middle/src/ty/consts/int.rs index 2a8a4d59888..48958e0d9e9 100644 --- a/compiler/rustc_middle/src/ty/consts/int.rs +++ b/compiler/rustc_middle/src/ty/consts/int.rs @@ -232,7 +232,7 @@ impl ScalarInt { } #[inline] - pub fn try_to_machine_usize<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Result<u64, Size> { + pub fn try_to_machine_usize(&self, tcx: TyCtxt<'_>) -> Result<u64, Size> { Ok(self.to_bits(tcx.data_layout.pointer_size)? as u64) } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 173c5ed4fee..5de414077a2 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -17,7 +17,7 @@ use crate::thir::Thir; use crate::traits; use crate::ty::query::{self, TyCtxtAt}; use crate::ty::{ - self, AdtDef, AdtDefData, AdtKind, Binder, Const, ConstS, DefIdTree, FloatTy, FloatVar, + self, AdtDef, AdtDefData, AdtKind, Binder, Const, ConstData, DefIdTree, FloatTy, FloatVar, FloatVid, GenericParamDefKind, ImplPolarity, InferTy, IntTy, IntVar, IntVid, List, ParamConst, ParamTy, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVar, TyVid, TypeAndMut, TypeckResults, UintTy, @@ -140,7 +140,7 @@ pub struct CtxtInterners<'tcx> { predicates: InternedSet<'tcx, List<Predicate<'tcx>>>, projs: InternedSet<'tcx, List<ProjectionKind>>, place_elems: InternedSet<'tcx, List<PlaceElem<'tcx>>>, - const_: InternedSet<'tcx, ConstS<'tcx>>, + const_: InternedSet<'tcx, ConstData<'tcx>>, const_allocation: InternedSet<'tcx, Allocation>, bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>, layout: InternedSet<'tcx, LayoutS<VariantIdx>>, @@ -331,7 +331,7 @@ impl<'tcx> CommonConsts<'tcx> { }; CommonConsts { - unit: mk_const(ty::ConstS { + unit: mk_const(ty::ConstData { kind: ty::ConstKind::Value(ty::ValTree::zst()), ty: types.unit, }), @@ -1518,7 +1518,7 @@ impl<'tcx, T: 'tcx + ?Sized> IntoPointer for InternedInSet<'tcx, T> { #[allow(rustc::usage_of_ty_tykind)] impl<'tcx, T> Borrow<T> for InternedInSet<'tcx, WithCachedTypeInfo<T>> { - fn borrow<'a>(&'a self) -> &'a T { + fn borrow(&self) -> &T { &self.0.internee } } @@ -1541,7 +1541,7 @@ impl<'tcx, T: Hash> Hash for InternedInSet<'tcx, WithCachedTypeInfo<T>> { } impl<'tcx, T> Borrow<[T]> for InternedInSet<'tcx, List<T>> { - fn borrow<'a>(&'a self) -> &'a [T] { + fn borrow(&self) -> &[T] { &self.0[..] } } @@ -1601,7 +1601,7 @@ macro_rules! direct_interners { direct_interners! { region: mk_region(RegionKind<'tcx>): Region -> Region<'tcx>, - const_: mk_const_internal(ConstS<'tcx>): Const -> Const<'tcx>, + const_: mk_const_internal(ConstData<'tcx>): Const -> Const<'tcx>, const_allocation: intern_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>, layout: intern_layout(LayoutS<VariantIdx>): Layout -> Layout<'tcx>, adt_def: intern_adt_def(AdtDefData): AdtDef -> AdtDef<'tcx>, @@ -1976,7 +1976,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_const(self, kind: impl Into<ty::ConstKind<'tcx>>, ty: Ty<'tcx>) -> Const<'tcx> { - self.mk_const_internal(ty::ConstS { kind: kind.into(), ty }) + self.mk_const_internal(ty::ConstData { kind: kind.into(), ty }) } #[inline] diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index d283ccc3ad8..8306d670a65 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -22,7 +22,7 @@ impl FlagComputation { result } - pub fn for_predicate<'tcx>(binder: ty::Binder<'tcx, ty::PredicateKind<'_>>) -> FlagComputation { + pub fn for_predicate(binder: ty::Binder<'_, ty::PredicateKind<'_>>) -> FlagComputation { let mut result = FlagComputation::new(); result.add_predicate(binder); result @@ -95,7 +95,7 @@ impl FlagComputation { self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); } - &ty::Generator(_, ref substs, _) => { + ty::Generator(_, substs, _) => { let substs = substs.as_generator(); let should_remove_further_specializable = !self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE); @@ -186,7 +186,7 @@ impl FlagComputation { &ty::Slice(tt) => self.add_ty(tt), - &ty::RawPtr(ref m) => { + ty::RawPtr(m) => { self.add_ty(m.ty); } diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index 2e70ac256a7..705adecd3b9 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -70,14 +70,6 @@ impl GenericParamDef { } } - pub fn has_default(&self) -> bool { - match self.kind { - GenericParamDefKind::Type { has_default, .. } - | GenericParamDefKind::Const { has_default } => has_default, - GenericParamDefKind::Lifetime => false, - } - } - pub fn is_anonymous_lifetime(&self) -> bool { match self.kind { GenericParamDefKind::Lifetime => { diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 7f66b993646..9e0ca44d098 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -993,7 +993,7 @@ where /// might (from a foreign exception or similar). #[inline] #[tracing::instrument(level = "debug", skip(tcx))] -pub fn fn_can_unwind<'tcx>(tcx: TyCtxt<'tcx>, fn_def_id: Option<DefId>, abi: SpecAbi) -> bool { +pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) -> bool { if let Some(did) = fn_def_id { // Special attribute for functions which can't unwind. if tcx.codegen_fn_attrs(did).flags.contains(CodegenFnAttrFlags::NEVER_UNWIND) { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 7290f0ae7c0..f01d74539a1 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -80,7 +80,7 @@ pub use self::closure::{ CAPTURE_STRUCT_LOCAL, }; pub use self::consts::{ - Const, ConstInt, ConstKind, ConstS, Expr, InferConst, ScalarInt, UnevaluatedConst, ValTree, + Const, ConstData, ConstInt, ConstKind, Expr, InferConst, ScalarInt, UnevaluatedConst, ValTree, }; pub use self::context::{ tls, CtxtInterners, DeducedParamAttrs, FreeRegionInfo, GlobalCtxt, Lift, OnDiskCache, TyCtxt, @@ -535,6 +535,17 @@ impl<'tcx> Predicate<'tcx> { self } + #[instrument(level = "debug", skip(tcx), ret)] + pub fn is_coinductive(self, tcx: TyCtxt<'tcx>) -> bool { + match self.kind().skip_binder() { + ty::PredicateKind::Clause(ty::Clause::Trait(data)) => { + tcx.trait_is_coinductive(data.def_id()) + } + ty::PredicateKind::WellFormed(_) => true, + _ => false, + } + } + /// Whether this projection can be soundly normalized. /// /// Wf predicates must not be normalized, as normalization @@ -945,7 +956,7 @@ impl<'tcx> Term<'tcx> { &*((ptr & !TAG_MASK) as *const WithCachedTypeInfo<ty::TyKind<'tcx>>), ))), CONST_TAG => TermKind::Const(ty::Const(Interned::new_unchecked( - &*((ptr & !TAG_MASK) as *const ty::ConstS<'tcx>), + &*((ptr & !TAG_MASK) as *const ty::ConstData<'tcx>), ))), _ => core::intrinsics::unreachable(), } @@ -991,7 +1002,7 @@ impl<'tcx> TermKind<'tcx> { TermKind::Const(ct) => { // Ensure we can use the tag bits. assert_eq!(mem::align_of_val(&*ct.0.0) & TAG_MASK, 0); - (CONST_TAG, ct.0.0 as *const ty::ConstS<'tcx> as usize) + (CONST_TAG, ct.0.0 as *const ty::ConstData<'tcx> as usize) } }; @@ -1018,6 +1029,24 @@ pub struct ProjectionPredicate<'tcx> { pub term: Term<'tcx>, } +impl<'tcx> ProjectionPredicate<'tcx> { + pub fn self_ty(self) -> Ty<'tcx> { + self.projection_ty.self_ty() + } + + pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ProjectionPredicate<'tcx> { + Self { projection_ty: self.projection_ty.with_self_ty(tcx, self_ty), ..self } + } + + pub fn trait_def_id(self, tcx: TyCtxt<'tcx>) -> DefId { + self.projection_ty.trait_def_id(tcx) + } + + pub fn def_id(self) -> DefId { + self.projection_ty.def_id + } +} + pub type PolyProjectionPredicate<'tcx> = Binder<'tcx, ProjectionPredicate<'tcx>>; impl<'tcx> PolyProjectionPredicate<'tcx> { @@ -1054,18 +1083,6 @@ impl<'tcx> PolyProjectionPredicate<'tcx> { } } -impl<'tcx> ProjectionPredicate<'tcx> { - pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self { - Self { - projection_ty: tcx.mk_alias_ty( - self.projection_ty.def_id, - [self_ty.into()].into_iter().chain(self.projection_ty.substs.iter().skip(1)), - ), - ..self - } - } -} - pub trait ToPolyTraitRef<'tcx> { fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx>; } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index a1d53506707..c49e75d68ad 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2883,13 +2883,19 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N /// `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable anywhere. /// /// The implementation uses similar import discovery logic to that of 'use' suggestions. +/// +/// See also [`DelayDm`](rustc_error_messages::DelayDm) and [`with_no_trimmed_paths`]. fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> FxHashMap<DefId, Symbol> { let mut map: FxHashMap<DefId, Symbol> = FxHashMap::default(); if let TrimmedDefPaths::GoodPath = tcx.sess.opts.trimmed_def_paths { + // Trimming paths is expensive and not optimized, since we expect it to only be used for error reporting. + // // For good paths causing this bug, the `rustc_middle::ty::print::with_no_trimmed_paths` // wrapper can be used to suppress this query, in exchange for full paths being formatted. - tcx.sess.delay_good_path_bug("trimmed_def_paths constructed"); + tcx.sess.delay_good_path_bug( + "trimmed_def_paths constructed but no error emitted; use `DelayDm` for lints or `with_no_trimmed_paths` for debugging", + ); } let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> = diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index c4116558bd2..4d34ca3d66b 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -428,7 +428,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( Ok(a) } - (&ty::Param(ref a_p), &ty::Param(ref b_p)) if a_p.index == b_p.index => Ok(a), + (ty::Param(a_p), ty::Param(b_p)) if a_p.index == b_p.index => Ok(a), (ty::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => Ok(a), diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 3c6800cf293..30073b541ec 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -99,12 +99,6 @@ impl<'tcx> fmt::Debug for ty::ConstVid<'tcx> { } } -impl fmt::Debug for ty::RegionVid { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "'_#{}r", self.index()) - } -} - impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { with_no_trimmed_paths!(fmt::Display::fmt(self, f)) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 66aeebab88b..f7e4c821569 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1169,7 +1169,7 @@ pub struct AliasTy<'tcx> { } impl<'tcx> AliasTy<'tcx> { - pub fn trait_def_id(&self, tcx: TyCtxt<'tcx>) -> DefId { + pub fn trait_def_id(self, tcx: TyCtxt<'tcx>) -> DefId { match tcx.def_kind(self.def_id) { DefKind::AssocTy | DefKind::AssocConst => tcx.parent(self.def_id), DefKind::ImplTraitPlaceholder => { @@ -1183,7 +1183,7 @@ impl<'tcx> AliasTy<'tcx> { /// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`, /// then this function would return a `T: Iterator` trait reference and `['a]` as the own substs pub fn trait_ref_and_own_substs( - &self, + self, tcx: TyCtxt<'tcx>, ) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) { debug_assert!(matches!(tcx.def_kind(self.def_id), DefKind::AssocTy | DefKind::AssocConst)); @@ -1202,14 +1202,18 @@ impl<'tcx> AliasTy<'tcx> { /// WARNING: This will drop the substs for generic associated types /// consider calling [Self::trait_ref_and_own_substs] to get those /// as well. - pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> { + pub fn trait_ref(self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> { let def_id = self.trait_def_id(tcx); tcx.mk_trait_ref(def_id, self.substs.truncate_to(tcx, tcx.generics_of(def_id))) } - pub fn self_ty(&self) -> Ty<'tcx> { + pub fn self_ty(self) -> Ty<'tcx> { self.substs.type_at(0) } + + pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self { + tcx.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter().skip(1))) + } } #[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, Lift)] @@ -1378,9 +1382,8 @@ pub struct ConstVid<'tcx> { rustc_index::newtype_index! { /// A **region** (lifetime) **v**ariable **ID**. #[derive(HashStable)] - pub struct RegionVid { - DEBUG_FORMAT = custom, - } + #[debug_format = "'_#{}r"] + pub struct RegionVid {} } impl Atom for RegionVid { @@ -1391,7 +1394,7 @@ impl Atom for RegionVid { rustc_index::newtype_index! { #[derive(HashStable)] - pub struct BoundVar { .. } + pub struct BoundVar {} } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index f8385c47016..0c33e5bda1a 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -90,7 +90,7 @@ impl<'tcx> GenericArgKind<'tcx> { GenericArgKind::Const(ct) => { // Ensure we can use the tag bits. assert_eq!(mem::align_of_val(&*ct.0.0) & TAG_MASK, 0); - (CONST_TAG, ct.0.0 as *const ty::ConstS<'tcx> as usize) + (CONST_TAG, ct.0.0 as *const ty::ConstData<'tcx> as usize) } }; @@ -166,7 +166,7 @@ impl<'tcx> GenericArg<'tcx> { &*((ptr & !TAG_MASK) as *const WithCachedTypeInfo<ty::TyKind<'tcx>>), ))), CONST_TAG => GenericArgKind::Const(ty::Const(Interned::new_unchecked( - &*((ptr & !TAG_MASK) as *const ty::ConstS<'tcx>), + &*((ptr & !TAG_MASK) as *const ty::ConstData<'tcx>), ))), _ => intrinsics::unreachable(), } @@ -348,7 +348,7 @@ impl<'tcx> InternalSubsts<'tcx> { substs.reserve(defs.params.len()); for param in &defs.params { let kind = mk_kind(param, substs); - assert_eq!(param.index as usize, substs.len()); + assert_eq!(param.index as usize, substs.len(), "{substs:#?}, {defs:#?}"); substs.push(kind); } } @@ -400,6 +400,7 @@ impl<'tcx> InternalSubsts<'tcx> { } #[inline] + #[track_caller] pub fn type_at(&self, i: usize) -> Ty<'tcx> { if let GenericArgKind::Type(ty) = self[i].unpack() { ty @@ -409,6 +410,7 @@ impl<'tcx> InternalSubsts<'tcx> { } #[inline] + #[track_caller] pub fn region_at(&self, i: usize) -> ty::Region<'tcx> { if let GenericArgKind::Lifetime(lt) = self[i].unpack() { lt @@ -418,6 +420,7 @@ impl<'tcx> InternalSubsts<'tcx> { } #[inline] + #[track_caller] pub fn const_at(&self, i: usize) -> ty::Const<'tcx> { if let GenericArgKind::Const(ct) = self[i].unpack() { ct @@ -427,6 +430,7 @@ impl<'tcx> InternalSubsts<'tcx> { } #[inline] + #[track_caller] pub fn type_for_def(&self, def: &ty::GenericParamDef) -> GenericArg<'tcx> { self.type_at(def.index as usize).into() } @@ -573,6 +577,10 @@ impl<T> EarlyBinder<T> { pub fn rebind<U>(&self, value: U) -> EarlyBinder<U> { EarlyBinder(value) } + + pub fn skip_binder(self) -> T { + self.0 + } } impl<T> EarlyBinder<Option<T>> { diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index 4fe85d4366f..136a4906c58 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -608,10 +608,10 @@ impl<'a, V> LocalTableInContextMut<'a, V> { } rustc_index::newtype_index! { + #[derive(HashStable)] + #[debug_format = "UserType({})"] pub struct UserTypeAnnotationIndex { - derive [HashStable] - DEBUG_FORMAT = "UserType({})", - const START_INDEX = 0, + const START_INDEX = 0; } } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 857f52c8a24..6d3b94c1fdb 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -3,6 +3,7 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::mir; use crate::ty::layout::IntegerExt; +use crate::ty::query::TyCtxtAt; use crate::ty::{ self, DefIdTree, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitable, @@ -769,6 +770,12 @@ impl<'tcx> TyCtxt<'tcx> { } } +impl<'tcx> TyCtxtAt<'tcx> { + pub fn bound_type_of(self, def_id: DefId) -> ty::EarlyBinder<Ty<'tcx>> { + ty::EarlyBinder(self.type_of(def_id)) + } +} + struct OpaqueTypeExpander<'tcx> { // Contains the DefIds of the opaque types that are currently being // expanded. When we expand an opaque type we insert the DefId of @@ -1241,7 +1248,7 @@ pub fn needs_drop_components<'tcx>( } } -pub fn is_trivially_const_drop<'tcx>(ty: Ty<'tcx>) -> bool { +pub fn is_trivially_const_drop(ty: Ty<'_>) -> bool { match *ty.kind() { ty::Bool | ty::Char diff --git a/compiler/rustc_middle/src/ty/visit.rs b/compiler/rustc_middle/src/ty/visit.rs index b302572f3ca..d5553f84f75 100644 --- a/compiler/rustc_middle/src/ty/visit.rs +++ b/compiler/rustc_middle/src/ty/visit.rs @@ -88,9 +88,11 @@ pub trait TypeVisitable<'tcx>: fmt::Debug + Clone { self.has_vars_bound_at_or_above(ty::INNERMOST) } - #[instrument(level = "trace", ret)] fn has_type_flags(&self, flags: TypeFlags) -> bool { - self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags) + let res = + self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags); + trace!(?self, ?flags, ?res, "has_type_flags"); + res } fn has_projections(&self) -> bool { self.has_type_flags(TypeFlags::HAS_PROJECTION) @@ -560,10 +562,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { type BreakTy = FoundFlags; #[inline] - #[instrument(skip(self), level = "trace", ret)] fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> { let flags = t.flags(); - trace!(t.flags=?t.flags()); if flags.intersects(self.flags) { ControlFlow::Break(FoundFlags) } else { @@ -572,10 +572,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { } #[inline] - #[instrument(skip(self), level = "trace", ret)] fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> { let flags = r.type_flags(); - trace!(r.flags=?flags); if flags.intersects(self.flags) { ControlFlow::Break(FoundFlags) } else { @@ -584,7 +582,6 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { } #[inline] - #[instrument(level = "trace", ret)] fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> { let flags = FlagComputation::for_const(c); trace!(r.flags=?flags); @@ -596,14 +593,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { } #[inline] - #[instrument(level = "trace", ret)] fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> { - debug!( - "HasTypeFlagsVisitor: predicate={:?} predicate.flags={:?} self.flags={:?}", - predicate, - predicate.flags(), - self.flags - ); if predicate.flags().intersects(self.flags) { ControlFlow::Break(FoundFlags) } else { diff --git a/compiler/rustc_middle/src/ty/vtable.rs b/compiler/rustc_middle/src/ty/vtable.rs index 802925dfb04..f77bd9f0c6f 100644 --- a/compiler/rustc_middle/src/ty/vtable.rs +++ b/compiler/rustc_middle/src/ty/vtable.rs @@ -88,8 +88,8 @@ pub(super) fn vtable_allocation_provider<'tcx>( let fn_ptr = Pointer::from(fn_alloc_id); Scalar::from_pointer(fn_ptr, &tcx) } - VtblEntry::MetadataSize => Scalar::from_uint(size, ptr_size).into(), - VtblEntry::MetadataAlign => Scalar::from_uint(align, ptr_size).into(), + VtblEntry::MetadataSize => Scalar::from_uint(size, ptr_size), + VtblEntry::MetadataAlign => Scalar::from_uint(align, ptr_size), VtblEntry::Vacant => continue, VtblEntry::Method(instance) => { // Prepare the fn ptr we write into the vtable. diff --git a/compiler/rustc_middle/src/values.rs b/compiler/rustc_middle/src/values.rs index 70b98e59a8b..c242be57031 100644 --- a/compiler/rustc_middle/src/values.rs +++ b/compiler/rustc_middle/src/values.rs @@ -1,3 +1,4 @@ +use crate::dep_graph::DepKind; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan}; use rustc_hir as hir; @@ -11,16 +12,16 @@ use rustc_span::Span; use std::fmt::Write; -impl<'tcx> Value<TyCtxt<'tcx>> for Ty<'_> { - fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &[QueryInfo]) -> Self { +impl<'tcx> Value<TyCtxt<'tcx>, DepKind> for Ty<'_> { + fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &[QueryInfo<DepKind>]) -> Self { // SAFETY: This is never called when `Self` is not `Ty<'tcx>`. // FIXME: Represent the above fact in the trait system somehow. unsafe { std::mem::transmute::<Ty<'tcx>, Ty<'_>>(tcx.ty_error()) } } } -impl<'tcx> Value<TyCtxt<'tcx>> for ty::SymbolName<'_> { - fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &[QueryInfo]) -> Self { +impl<'tcx> Value<TyCtxt<'tcx>, DepKind> for ty::SymbolName<'_> { + fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &[QueryInfo<DepKind>]) -> Self { // SAFETY: This is never called when `Self` is not `SymbolName<'tcx>`. // FIXME: Represent the above fact in the trait system somehow. unsafe { @@ -31,12 +32,12 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::SymbolName<'_> { } } -impl<'tcx> Value<TyCtxt<'tcx>> for ty::Binder<'_, ty::FnSig<'_>> { - fn from_cycle_error(tcx: TyCtxt<'tcx>, stack: &[QueryInfo]) -> Self { +impl<'tcx> Value<TyCtxt<'tcx>, DepKind> for ty::Binder<'_, ty::FnSig<'_>> { + fn from_cycle_error(tcx: TyCtxt<'tcx>, stack: &[QueryInfo<DepKind>]) -> Self { let err = tcx.ty_error(); let arity = if let Some(frame) = stack.get(0) - && frame.query.name == "fn_sig" + && frame.query.dep_kind == DepKind::fn_sig && let Some(def_id) = frame.query.def_id && let Some(node) = tcx.hir().get_if_local(def_id) && let Some(sig) = node.fn_sig() @@ -61,12 +62,12 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::Binder<'_, ty::FnSig<'_>> { } } -impl<'tcx> Value<TyCtxt<'tcx>> for Representability { - fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle: &[QueryInfo]) -> Self { +impl<'tcx> Value<TyCtxt<'tcx>, DepKind> for Representability { + fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle: &[QueryInfo<DepKind>]) -> Self { let mut item_and_field_ids = Vec::new(); let mut representable_ids = FxHashSet::default(); for info in cycle { - if info.query.name == "representability" + if info.query.dep_kind == DepKind::representability && let Some(field_id) = info.query.def_id && let Some(field_id) = field_id.as_local() && let Some(DefKind::Field) = info.query.def_kind @@ -80,7 +81,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for Representability { } } for info in cycle { - if info.query.name == "representability_adt_ty" + if info.query.dep_kind == DepKind::representability_adt_ty && let Some(def_id) = info.query.ty_adt_id && let Some(def_id) = def_id.as_local() && !item_and_field_ids.iter().any(|&(id, _)| id == def_id) |
