Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use tcx.types.unit instead of Ty::new_unit(tcx) #124624

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_gcc/src/intrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ fn get_rust_try_fn<'a, 'gcc, 'tcx>(
tcx,
ty::Binder::dummy(tcx.mk_fn_sig(
iter::once(i8p),
Ty::new_unit(tcx),
tcx.types.unit,
false,
rustc_hir::Unsafety::Unsafe,
Abi::Rust,
Expand All @@ -1234,7 +1234,7 @@ fn get_rust_try_fn<'a, 'gcc, 'tcx>(
tcx,
ty::Binder::dummy(tcx.mk_fn_sig(
[i8p, i8p].iter().cloned(),
Ty::new_unit(tcx),
tcx.types.unit,
false,
rustc_hir::Unsafety::Unsafe,
Abi::Rust,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ fn get_rust_try_fn<'ll, 'tcx>(
tcx,
ty::Binder::dummy(tcx.mk_fn_sig(
[i8p],
Ty::new_unit(tcx),
tcx.types.unit,
false,
hir::Unsafety::Unsafe,
Abi::Rust,
Expand All @@ -995,7 +995,7 @@ fn get_rust_try_fn<'ll, 'tcx>(
tcx,
ty::Binder::dummy(tcx.mk_fn_sig(
[i8p, i8p],
Ty::new_unit(tcx),
tcx.types.unit,
false,
hir::Unsafety::Unsafe,
Abi::Rust,
Expand Down
44 changes: 22 additions & 22 deletions compiler/rustc_hir_analysis/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ pub fn check_intrinsic_type(
Ty::new_tup(tcx, &[param(0), tcx.types.bool]),
),
"load" => (1, vec![Ty::new_imm_ptr(tcx, param(0))], param(0)),
"store" => (1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx)),
"store" => (1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], tcx.types.unit),

"xchg" | "xadd" | "xsub" | "and" | "nand" | "or" | "xor" | "max" | "min" | "umax"
| "umin" => (1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], param(0)),
"fence" | "singlethreadfence" => (0, Vec::new(), Ty::new_unit(tcx)),
"fence" | "singlethreadfence" => (0, Vec::new(), tcx.types.unit),
op => {
tcx.dcx().emit_err(UnrecognizedAtomicOperation { span, op });
return;
Expand All @@ -224,7 +224,7 @@ pub fn check_intrinsic_type(
let (n_tps, n_cts, inputs, output) = match intrinsic_name {
sym::abort => (0, 0, vec![], tcx.types.never),
sym::unreachable => (0, 0, vec![], tcx.types.never),
sym::breakpoint => (0, 0, vec![], Ty::new_unit(tcx)),
sym::breakpoint => (0, 0, vec![], tcx.types.unit),
sym::size_of | sym::pref_align_of | sym::min_align_of | sym::variant_count => {
(1, 0, vec![], tcx.types.usize)
}
Expand All @@ -235,14 +235,14 @@ pub fn check_intrinsic_type(
sym::caller_location => (0, 0, vec![], tcx.caller_location_ty()),
sym::assert_inhabited
| sym::assert_zero_valid
| sym::assert_mem_uninitialized_valid => (1, 0, vec![], Ty::new_unit(tcx)),
sym::forget => (1, 0, vec![param(0)], Ty::new_unit(tcx)),
| sym::assert_mem_uninitialized_valid => (1, 0, vec![], tcx.types.unit),
sym::forget => (1, 0, vec![param(0)], tcx.types.unit),
sym::transmute | sym::transmute_unchecked => (2, 0, vec![param(0)], param(1)),
sym::prefetch_read_data
| sym::prefetch_write_data
| sym::prefetch_read_instruction
| sym::prefetch_write_instruction => {
(1, 0, vec![Ty::new_imm_ptr(tcx, param(0)), tcx.types.i32], Ty::new_unit(tcx))
(1, 0, vec![Ty::new_imm_ptr(tcx, param(0)), tcx.types.i32], tcx.types.unit)
}
sym::needs_drop => (1, 0, vec![], tcx.types.bool),

Expand Down Expand Up @@ -270,7 +270,7 @@ pub fn check_intrinsic_type(
Ty::new_mut_ptr(tcx, param(0)),
tcx.types.usize,
],
Ty::new_unit(tcx),
tcx.types.unit,
),
sym::volatile_copy_memory | sym::volatile_copy_nonoverlapping_memory => (
1,
Expand All @@ -280,7 +280,7 @@ pub fn check_intrinsic_type(
Ty::new_imm_ptr(tcx, param(0)),
tcx.types.usize,
],
Ty::new_unit(tcx),
tcx.types.unit,
),
sym::compare_bytes => {
let byte_ptr = Ty::new_imm_ptr(tcx, tcx.types.u8);
Expand All @@ -290,7 +290,7 @@ pub fn check_intrinsic_type(
1,
0,
vec![Ty::new_mut_ptr(tcx, param(0)), tcx.types.u8, tcx.types.usize],
Ty::new_unit(tcx),
tcx.types.unit,
),

sym::sqrtf16 => (0, 0, vec![tcx.types.f16], tcx.types.f16),
Expand Down Expand Up @@ -409,7 +409,7 @@ pub fn check_intrinsic_type(
(1, 0, vec![Ty::new_imm_ptr(tcx, param(0))], param(0))
}
sym::volatile_store | sym::unaligned_volatile_store => {
(1, 0, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx))
(1, 0, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], tcx.types.unit)
}

sym::ctpop | sym::ctlz | sym::ctlz_nonzero | sym::cttz | sym::cttz_nonzero => {
Expand Down Expand Up @@ -440,7 +440,7 @@ pub fn check_intrinsic_type(
0,
1,
vec![Ty::new_mut_ptr(tcx, tcx.types.u8), tcx.types.usize, tcx.types.usize],
Ty::new_unit(tcx),
tcx.types.unit,
),

sym::ptr_offset_from => (
Expand Down Expand Up @@ -477,16 +477,16 @@ pub fn check_intrinsic_type(
| sym::frem_algebraic => (1, 0, vec![param(0), param(0)], param(0)),
sym::float_to_int_unchecked => (2, 0, vec![param(0)], param(1)),

sym::assume => (0, 1, vec![tcx.types.bool], Ty::new_unit(tcx)),
sym::assume => (0, 1, vec![tcx.types.bool], tcx.types.unit),
sym::likely => (0, 1, vec![tcx.types.bool], tcx.types.bool),
sym::unlikely => (0, 1, vec![tcx.types.bool], tcx.types.bool),

sym::read_via_copy => (1, 0, vec![Ty::new_imm_ptr(tcx, param(0))], param(0)),
sym::write_via_move => {
(1, 0, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx))
(1, 0, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], tcx.types.unit)
}

sym::typed_swap => (1, 1, vec![Ty::new_mut_ptr(tcx, param(0)); 2], Ty::new_unit(tcx)),
sym::typed_swap => (1, 1, vec![Ty::new_mut_ptr(tcx, param(0)); 2], tcx.types.unit),

sym::discriminant_value => {
let assoc_items = tcx.associated_item_def_ids(
Expand All @@ -511,14 +511,14 @@ pub fn check_intrinsic_type(
let mut_u8 = Ty::new_mut_ptr(tcx, tcx.types.u8);
let try_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
[mut_u8],
Ty::new_unit(tcx),
tcx.types.unit,
false,
hir::Unsafety::Normal,
Abi::Rust,
));
let catch_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
[mut_u8, mut_u8],
Ty::new_unit(tcx),
tcx.types.unit,
false,
hir::Unsafety::Normal,
Abi::Rust,
Expand All @@ -532,14 +532,14 @@ pub fn check_intrinsic_type(
}

sym::va_start | sym::va_end => match mk_va_list_ty(hir::Mutability::Mut) {
Some((va_list_ref_ty, _)) => (0, 0, vec![va_list_ref_ty], Ty::new_unit(tcx)),
Some((va_list_ref_ty, _)) => (0, 0, vec![va_list_ref_ty], tcx.types.unit),
None => bug!("`va_list` lang item needed for C-variadic intrinsics"),
},

sym::va_copy => match mk_va_list_ty(hir::Mutability::Not) {
Some((va_list_ref_ty, va_list_ty)) => {
let va_list_ptr_ty = Ty::new_mut_ptr(tcx, va_list_ty);
(0, 0, vec![va_list_ptr_ty, va_list_ref_ty], Ty::new_unit(tcx))
(0, 0, vec![va_list_ptr_ty, va_list_ref_ty], tcx.types.unit)
}
None => bug!("`va_list` lang item needed for C-variadic intrinsics"),
},
Expand All @@ -550,7 +550,7 @@ pub fn check_intrinsic_type(
},

sym::nontemporal_store => {
(1, 0, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx))
(1, 0, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], tcx.types.unit)
}

sym::raw_eq => {
Expand All @@ -570,7 +570,7 @@ pub fn check_intrinsic_type(
sym::const_eval_select => (4, 1, vec![param(0), param(1), param(2)], param(3)),

sym::vtable_size | sym::vtable_align => {
(0, 0, vec![Ty::new_imm_ptr(tcx, Ty::new_unit(tcx))], tcx.types.usize)
(0, 0, vec![Ty::new_imm_ptr(tcx, tcx.types.unit)], tcx.types.usize)
}

// This type check is not particularly useful, but the `where` bounds
Expand Down Expand Up @@ -623,8 +623,8 @@ pub fn check_intrinsic_type(
sym::simd_fma => (1, 0, vec![param(0), param(0), param(0)], param(0)),
sym::simd_gather => (3, 0, vec![param(0), param(1), param(2)], param(0)),
sym::simd_masked_load => (3, 0, vec![param(0), param(1), param(2)], param(2)),
sym::simd_masked_store => (3, 0, vec![param(0), param(1), param(2)], Ty::new_unit(tcx)),
sym::simd_scatter => (3, 0, vec![param(0), param(1), param(2)], Ty::new_unit(tcx)),
sym::simd_masked_store => (3, 0, vec![param(0), param(1), param(2)], tcx.types.unit),
sym::simd_scatter => (3, 0, vec![param(0), param(1), param(2)], tcx.types.unit),
sym::simd_insert => (2, 0, vec![param(0), tcx.types.u32, param(1)], param(0)),
sym::simd_extract => (2, 0, vec![param(0), tcx.types.u32], param(1)),
sym::simd_cast
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2370,7 +2370,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
self.lower_ty(output)
}
}
hir::FnRetTy::DefaultReturn(..) => Ty::new_unit(tcx),
hir::FnRetTy::DefaultReturn(..) => tcx.types.unit,
};

debug!(?output_ty);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// us to give better error messages (pointing to a usually better
// arm for inconsistent arms or to the whole match when a `()` type
// is required).
Expectation::ExpectHasType(ety) if ety != Ty::new_unit(self.tcx) => ety,
Expectation::ExpectHasType(ety) if ety != tcx.types.unit => ety,
_ => self.next_ty_var(TypeVariableOrigin { param_def_id: None, span: expr.span }),
};
CoerceMany::with_coercion_sites(coerce_first, arms)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
fcx,
cause,
None,
Ty::new_unit(fcx.tcx),
fcx.tcx.types.unit,
augment_error,
label_unit_as_expected,
)
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
// Otherwise, this is a break *without* a value. That's
// always legal, and is equivalent to `break ()`.
e_ty = Ty::new_unit(tcx);
e_ty = tcx.types.unit;
cause = self.misc(expr.span);
}

Expand Down Expand Up @@ -1133,7 +1133,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// The expected type is `bool` but this will result in `()` so we can reasonably
// say that the user intended to write `lhs == rhs` instead of `lhs = rhs`.
// The likely cause of this is `if foo = bar { .. }`.
let actual_ty = Ty::new_unit(self.tcx);
let actual_ty = self.tcx.types.unit;
let mut err = self.demand_suptype_diag(expr.span, expected_ty, actual_ty).unwrap();
let lhs_ty = self.check_expr(lhs);
let rhs_ty = self.check_expr(rhs);
Expand Down Expand Up @@ -1256,7 +1256,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Err(guar) = (lhs_ty, rhs_ty).error_reported() {
Ty::new_error(self.tcx, guar)
} else {
Ty::new_unit(self.tcx)
self.tcx.types.unit
}
}

Expand Down Expand Up @@ -1319,7 +1319,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if ctxt.coerce.is_none() && !ctxt.may_break {
self.dcx().span_bug(body.span, "no coercion, but loop may not break");
}
ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| Ty::new_unit(self.tcx))
ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| self.tcx.types.unit)
}

/// Checks a method call.
Expand Down Expand Up @@ -3174,7 +3174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.dcx().emit_err(YieldExprOutsideOfCoroutine { span: expr.span });
// Avoid expressions without types during writeback (#78653).
self.check_expr(value);
Ty::new_unit(self.tcx)
self.tcx.types.unit
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir::StmtKind::Item(_) => {}
hir::StmtKind::Expr(ref expr) => {
// Check with expected type of `()`.
self.check_expr_has_type_or_error(expr, Ty::new_unit(self.tcx), |err| {
self.check_expr_has_type_or_error(expr, self.tcx.types.unit, |err| {
if expr.can_have_side_effects() {
self.suggest_semicolon_at_end(expr.span, err);
}
Expand All @@ -1676,7 +1676,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

pub fn check_block_no_value(&self, blk: &'tcx hir::Block<'tcx>) {
let unit = Ty::new_unit(self.tcx);
let unit = self.tcx.types.unit;
let ty = self.check_block_with_expected(blk, ExpectHasType(unit));

// if the block produces a `!` value, that can always be
Expand Down Expand Up @@ -1794,7 +1794,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
blk.span,
blk.hir_id,
expected_ty,
Ty::new_unit(self.tcx),
self.tcx.types.unit,
);
}
if !self.err_ctxt().consider_removing_semicolon(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty =
if !lhs_ty.is_ty_var() && !rhs_ty.is_ty_var() && is_builtin_binop(lhs_ty, rhs_ty, op) {
self.enforce_builtin_binop_types(lhs.span, lhs_ty, rhs.span, rhs_ty, op);
Ty::new_unit(self.tcx)
self.tcx.types.unit
} else {
return_ty
};
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_lint/src/unit_bindings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::lints::UnitBindingsDiag;
use crate::{LateLintPass, LintContext};
use rustc_hir as hir;
use rustc_middle::ty::Ty;
use rustc_session::{declare_lint, declare_lint_pass};

declare_lint! {
Expand Down Expand Up @@ -57,8 +56,8 @@ impl<'tcx> LateLintPass<'tcx> for UnitBindings {
&& let Some(init) = local.init
&& let init_ty = tyck_results.expr_ty(init)
&& let local_ty = tyck_results.node_type(local.hir_id)
&& init_ty == Ty::new_unit(cx.tcx)
&& local_ty == Ty::new_unit(cx.tcx)
&& init_ty == cx.tcx.types.unit
&& local_ty == cx.tcx.types.unit
&& local.ty.is_none()
&& !matches!(init.kind, hir::ExprKind::Tup([]))
&& !matches!(local.pat.kind, hir::PatKind::Tuple([], ..))
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Primitive {
F64 => tcx.types.f64,
F128 => tcx.types.f128,
// FIXME(erikdesjardins): handle non-default addrspace ptr sizes
Pointer(_) => Ty::new_mut_ptr(tcx, Ty::new_unit(tcx)),
Pointer(_) => Ty::new_mut_ptr(tcx, tcx.types.unit),
}
}

Expand Down Expand Up @@ -775,7 +775,7 @@ where
// (which may have no non-DST form), and will work as long
// as the `Abi` or `FieldsShape` is checked by users.
if i == 0 {
let nil = Ty::new_unit(tcx);
let nil = tcx.types.unit;
let unit_ptr_ty = if this.ty.is_unsafe_ptr() {
Ty::new_mut_ptr(tcx, nil)
} else {
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1750,11 +1750,6 @@ impl<'tcx> Ty<'tcx> {

// misc

#[inline]
pub fn new_unit(tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
tcx.types.unit
}

#[inline]
pub fn new_static_str(tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
Ty::new_imm_ref(tcx, tcx.lifetimes.re_static, tcx.types.str_)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
match self.unit_temp {
Some(tmp) => tmp,
None => {
let ty = Ty::new_unit(self.tcx);
let ty = self.tcx.types.unit;
let fn_span = self.fn_span;
let tmp = self.temp(ty, fn_span);
self.unit_temp = Some(tmp);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/thir/cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_hir::HirId;
use rustc_hir::Node;
use rustc_middle::middle::region;
use rustc_middle::thir::*;
use rustc_middle::ty::{self, RvalueScopes, Ty, TyCtxt};
use rustc_middle::ty::{self, RvalueScopes, TyCtxt};

pub(crate) fn thir_body(
tcx: TyCtxt<'_>,
Expand All @@ -39,7 +39,7 @@ pub(crate) fn thir_body(
// It will always be `()` in this case.
if tcx.is_coroutine(owner_def.to_def_id()) && body.params.is_empty() {
cx.thir.params.push(Param {
ty: Ty::new_unit(tcx),
ty: tcx.types.unit,
pat: None,
ty_span: None,
self_kind: None,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_dataflow/src/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ where

let ref_ty = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, ty);
let ref_place = self.new_temp(ref_ty);
let unit_temp = Place::from(self.new_temp(Ty::new_unit(tcx)));
let unit_temp = Place::from(self.new_temp(tcx.types.unit));

let result = BasicBlockData {
statements: vec![self.assign(
Expand Down
Loading
Loading