Skip to content

Commit

Permalink
Rollup merge of rust-lang#118081 - nnethercote:rustc_ty_utils, r=comp…
Browse files Browse the repository at this point in the history
…iler-errors

`rustc_ty_utils` cleanups

Minor improvements I found while looking at this code.

r? `@lcnr`
  • Loading branch information
compiler-errors authored Nov 21, 2023
2 parents 4427629 + 9e6ee72 commit 3b12a59
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 33 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_target::spec::abi::Abi as SpecAbi;

use std::iter;

pub fn provide(providers: &mut Providers) {
pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers { fn_abi_of_fn_ptr, fn_abi_of_instance, ..*providers };
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/assoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_middle::query::Providers;
use rustc_middle::ty::{self, GenericArgs, ImplTraitInTraitData, Ty, TyCtxt};
use rustc_span::symbol::kw;

pub fn provide(providers: &mut Providers) {
pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers {
associated_item,
associated_item_def_ids,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ty_utils/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::errors::{GenericConstantTooComplex, GenericConstantTooComplexSub};

/// Destructures array, ADT or tuple constants into the constants
/// of their fields.
pub(crate) fn destructure_const<'tcx>(
fn destructure_const<'tcx>(
tcx: TyCtxt<'tcx>,
const_: ty::Const<'tcx>,
) -> ty::DestructuredConst<'tcx> {
Expand Down Expand Up @@ -396,7 +396,7 @@ impl<'a, 'tcx> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> {
}

/// Builds an abstract const, do not use this directly, but use `AbstractConst::new` instead.
pub fn thir_abstract_const(
fn thir_abstract_const(
tcx: TyCtxt<'_>,
def: LocalDefId,
) -> Result<Option<ty::EarlyBinder<ty::Const<'_>>>, ErrorGuaranteed> {
Expand Down Expand Up @@ -428,6 +428,6 @@ pub fn thir_abstract_const(
Ok(Some(ty::EarlyBinder::bind(recurse_build(tcx, body, body_id, root_span)?)))
}

pub fn provide(providers: &mut Providers) {
pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers { destructure_const, thir_abstract_const, ..*providers };
}
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/implied_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::Span;
use std::iter;

pub fn provide(providers: &mut Providers) {
pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers {
assumed_wf_types,
assumed_wf_types_for_rpitit: |tcx, def_id| {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,6 @@ fn resolve_associated_item<'tcx>(
})
}

pub fn provide(providers: &mut Providers) {
pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers { resolve_instance, ..*providers };
}
22 changes: 6 additions & 16 deletions compiler/rustc_ty_utils/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::errors::{
};
use crate::layout_sanity_check::sanity_check_layout;

pub fn provide(providers: &mut Providers) {
pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers { layout_of, ..*providers };
}

Expand Down Expand Up @@ -65,7 +65,11 @@ fn layout_of<'tcx>(
let layout = layout_of_uncached(&cx, ty)?;
let layout = TyAndLayout { ty, layout };

record_layout_for_printing(&cx, layout);
// If we are running with `-Zprint-type-sizes`, maybe record layouts
// for dumping later.
if cx.tcx.sess.opts.unstable_opts.print_type_sizes {
record_layout_for_printing(&cx, layout);
}

sanity_check_layout(&cx, &layout);

Expand Down Expand Up @@ -911,21 +915,7 @@ fn coroutine_layout<'tcx>(
Ok(layout)
}

/// This is invoked by the `layout_of` query to record the final
/// layout of each type.
#[inline(always)]
fn record_layout_for_printing<'tcx>(cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, layout: TyAndLayout<'tcx>) {
// If we are running with `-Zprint-type-sizes`, maybe record layouts
// for dumping later.
if cx.tcx.sess.opts.unstable_opts.print_type_sizes {
record_layout_for_printing_outlined(cx, layout)
}
}

fn record_layout_for_printing_outlined<'tcx>(
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
layout: TyAndLayout<'tcx>,
) {
// Ignore layouts that are done with non-empty environments or
// non-monomorphic layouts, as the user only wants to see the stuff
// resulting from the final codegen session.
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_ty_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#![allow(internal_features)]
#![feature(assert_matches)]
#![feature(associated_type_defaults)]
#![feature(box_patterns)]
#![feature(if_let_guard)]
#![feature(iterator_try_collect)]
#![feature(let_chains)]
#![feature(if_let_guard)]
#![feature(never_type)]
#![feature(box_patterns)]
#![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
Expand All @@ -34,13 +34,13 @@ mod common_traits;
mod consts;
mod errors;
mod implied_bounds;
pub mod instance;
mod instance;
mod layout;
mod layout_sanity_check;
mod needs_drop;
mod opaque_types;
pub mod representability;
pub mod sig_types;
mod representability;
mod sig_types;
mod structural_match;
mod ty;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/representability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_middle::query::Providers;
use rustc_middle::ty::{self, Representability, Ty, TyCtxt};
use rustc_span::def_id::LocalDefId;

pub fn provide(providers: &mut Providers) {
pub(crate) fn provide(providers: &mut Providers) {
*providers =
Providers { representability, representability_adt_ty, params_in_repr, ..*providers };
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ty_utils/src/sig_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_span::Span;
use rustc_type_ir::visit::TypeVisitable;

pub trait SpannedTypeVisitor<'tcx> {
pub(crate) trait SpannedTypeVisitor<'tcx> {
type BreakTy = !;
fn visit(
&mut self,
Expand All @@ -17,7 +17,7 @@ pub trait SpannedTypeVisitor<'tcx> {
) -> ControlFlow<Self::BreakTy>;
}

pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
pub(crate) fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
tcx: TyCtxt<'tcx>,
item: LocalDefId,
visitor: &mut V,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/structural_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ fn has_structural_eq_impls<'tcx>(tcx: TyCtxt<'tcx>, adt_ty: Ty<'tcx>) -> bool {
ocx.select_all_or_error().is_empty()
}

pub fn provide(providers: &mut Providers) {
pub(crate) fn provide(providers: &mut Providers) {
providers.has_structural_eq_impls = has_structural_eq_impls;
}
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32
unsizing_params
}

pub fn provide(providers: &mut Providers) {
pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers {
asyncness,
adt_sized_constraint,
Expand Down

0 comments on commit 3b12a59

Please sign in to comment.