Skip to content

Commit 5fa961b

Browse files
committed
Overhaul TyS and Ty.
Specifically, change `Ty` from this: ``` pub type Ty<'tcx> = &'tcx TyS<'tcx>; ``` to this ``` pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>); ``` There are two benefits to this. - It's now a first class type, so we can define methods on it. This means we can move a lot of methods away from `TyS`, leaving `TyS` as a barely-used type, which is appropriate given that it's not meant to be used directly. - The uniqueness requirement is now explicit, via the `Interned` type. E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather than via `TyS`, which wasn't obvious at all. Much of this commit is boring churn. The interesting changes are in these files: - compiler/rustc_middle/src/arena.rs - compiler/rustc_middle/src/mir/visit.rs - compiler/rustc_middle/src/ty/context.rs - compiler/rustc_middle/src/ty/mod.rs Specifically: - Most mentions of `TyS` are removed. It's very much a dumb struct now; `Ty` has all the smarts. - `TyS` now has `crate` visibility instead of `pub`. - `TyS::make_for_test` is removed in favour of the static `BOOL_TY`, which just works better with the new structure. - The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned` (pointer-based, for the `Equal` case) and partly on `TyS` (contents-based, for the other cases). - There are many tedious sigil adjustments, i.e. adding or removing `*` or `&`. They seem to be unavoidable.
1 parent fecd216 commit 5fa961b

38 files changed

+78
-77
lines changed

clippy_lints/src/case_sensitive_file_extension_comparisons.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn check_case_sensitive_file_extension_comparison(ctx: &LateContext<'_>, expr: &
4747
then {
4848
let mut ty = ctx.typeck_results().expr_ty(obj);
4949
ty = match ty.kind() {
50-
ty::Ref(_, ty, ..) => ty,
50+
ty::Ref(_, ty, ..) => *ty,
5151
_ => ty
5252
};
5353

clippy_lints/src/default_numeric_fallback.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
123123
if let Some(fn_sig) = fn_sig_opt(self.cx, func.hir_id) {
124124
for (expr, bound) in iter::zip(*args, fn_sig.skip_binder().inputs()) {
125125
// Push found arg type, then visit arg.
126-
self.ty_bounds.push(TyBound::Ty(bound));
126+
self.ty_bounds.push(TyBound::Ty(*bound));
127127
self.visit_expr(expr);
128128
self.ty_bounds.pop();
129129
}
@@ -135,7 +135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
135135
if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) {
136136
let fn_sig = self.cx.tcx.fn_sig(def_id).skip_binder();
137137
for (expr, bound) in iter::zip(*args, fn_sig.inputs()) {
138-
self.ty_bounds.push(TyBound::Ty(bound));
138+
self.ty_bounds.push(TyBound::Ty(*bound));
139139
self.visit_expr(expr);
140140
self.ty_bounds.pop();
141141
}
@@ -210,7 +210,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
210210

211211
fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<PolyFnSig<'tcx>> {
212212
let node_ty = cx.typeck_results().node_type_opt(hir_id)?;
213-
// We can't use `TyS::fn_sig` because it automatically performs substs, this may result in FNs.
213+
// We can't use `Ty::fn_sig` because it automatically performs substs, this may result in FNs.
214214
match node_ty.kind() {
215215
ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id)),
216216
ty::FnPtr(fn_sig) => Some(*fn_sig),

clippy_lints/src/eq_op.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use clippy_utils::{ast_utils::is_useless_with_eq_exprs, eq_expr_value, is_in_tes
77
use if_chain::if_chain;
88
use rustc_errors::Applicability;
99
use rustc_hir::{
10-
def::Res, def_id::DefId, BinOpKind, BorrowKind, Expr, ExprKind, GenericArg, ItemKind, QPath, Ty, TyKind,
10+
def::Res, def_id::DefId, BinOpKind, BorrowKind, Expr, ExprKind, GenericArg, ItemKind, QPath, TyKind,
1111
};
1212
use rustc_lint::{LateContext, LateLintPass};
13-
use rustc_middle::ty::{self, TyS};
13+
use rustc_middle::ty::{self, Ty};
1414
use rustc_session::{declare_lint_pass, declare_tool_lint};
1515

1616
declare_clippy_lint! {
@@ -279,7 +279,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
279279
}
280280
}
281281

282-
fn in_impl<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, bin_op: DefId) -> Option<(&'tcx Ty<'tcx>, &'tcx Ty<'tcx>)> {
282+
fn in_impl<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, bin_op: DefId) -> Option<(&'tcx rustc_hir::Ty<'tcx>, &'tcx rustc_hir::Ty<'tcx>)> {
283283
if_chain! {
284284
if let Some(block) = get_enclosing_block(cx, e.hir_id);
285285
if let Some(impl_def_id) = cx.tcx.impl_of_method(block.hir_id.owner.to_def_id());
@@ -301,7 +301,7 @@ fn in_impl<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, bin_op: DefId) -> Op
301301
}
302302
}
303303

304-
fn are_equal<'tcx>(cx: &LateContext<'tcx>, middle_ty: &TyS<'_>, hir_ty: &Ty<'_>) -> bool {
304+
fn are_equal<'tcx>(cx: &LateContext<'tcx>, middle_ty: Ty<'_>, hir_ty: &rustc_hir::Ty<'_>) -> bool {
305305
if_chain! {
306306
if let ty::Adt(adt_def, _) = middle_ty.kind();
307307
if let Some(local_did) = adt_def.did.as_local();

clippy_lints/src/format_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ where
211211
if overloaded_deref.is_some() {
212212
n_needed = n_total;
213213
}
214-
ty = target;
214+
ty = *target;
215215
} else {
216216
return (n_needed, ty);
217217
}

clippy_lints/src/index_refutable_slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<hir
118118
// The values need to use the `ref` keyword if they can't be copied.
119119
// This will need to be adjusted if the lint want to support multable access in the future
120120
let src_is_ref = bound_ty.is_ref() && binding != hir::BindingAnnotation::Ref;
121-
let needs_ref = !(src_is_ref || is_copy(cx, inner_ty));
121+
let needs_ref = !(src_is_ref || is_copy(cx, *inner_ty));
122122

123123
let slice_info = slices
124124
.entry(value_hir_id)

clippy_lints/src/large_const_arrays.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
5555
if let ty::Array(element_type, cst) = ty.kind();
5656
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val;
5757
if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
58-
if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes());
58+
if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes());
5959
if self.maximum_allowed_size < element_count * element_size;
6060

6161
then {

clippy_lints/src/large_stack_arrays.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays {
4545
if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind();
4646
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val;
4747
if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
48-
if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes());
48+
if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes());
4949
if self.maximum_allowed_size < element_count * element_size;
5050
then {
5151
span_lint_and_help(

clippy_lints/src/len_zero.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl LenOutput<'_> {
294294
/// Checks if the given signature matches the expectations for `is_empty`
295295
fn check_is_empty_sig(sig: FnSig<'_>, self_kind: ImplicitSelfKind, len_output: LenOutput<'_>) -> bool {
296296
match &**sig.inputs_and_output {
297-
[arg, res] if len_output.matches_is_empty_output(res) => {
297+
[arg, res] if len_output.matches_is_empty_output(*res) => {
298298
matches!(
299299
(arg.kind(), self_kind),
300300
(ty::Ref(_, _, Mutability::Not), ImplicitSelfKind::ImmRef)

clippy_lints/src/loops/explicit_counter_loop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_errors::Applicability;
77
use rustc_hir::intravisit::{walk_block, walk_expr};
88
use rustc_hir::{Expr, Pat};
99
use rustc_lint::LateContext;
10-
use rustc_middle::ty::{self, UintTy};
10+
use rustc_middle::ty::{self, Ty, UintTy};
1111

1212
// To trigger the EXPLICIT_COUNTER_LOOP lint, a variable must be
1313
// incremented exactly once in the loop body, and initialized to zero
@@ -36,7 +36,7 @@ pub(super) fn check<'tcx>(
3636
then {
3737
let mut applicability = Applicability::MachineApplicable;
3838

39-
let int_name = match ty.map(ty::TyS::kind) {
39+
let int_name = match ty.map(Ty::kind) {
4040
// usize or inferred
4141
Some(ty::Uint(UintTy::Usize)) | None => {
4242
span_lint_and_sugg(

clippy_lints/src/loops/manual_memcpy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ struct Start<'hir> {
335335
fn get_slice_like_element_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
336336
match ty.kind() {
337337
ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Vec, adt.did) => Some(subs.type_at(0)),
338-
ty::Ref(_, subty, _) => get_slice_like_element_ty(cx, subty),
339-
ty::Slice(ty) | ty::Array(ty, _) => Some(ty),
338+
ty::Ref(_, subty, _) => get_slice_like_element_ty(cx, *subty),
339+
ty::Slice(ty) | ty::Array(ty, _) => Some(*ty),
340340
_ => None,
341341
}
342342
}

0 commit comments

Comments
 (0)