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.
This commit is contained in:
parent
0c2ebbd412
commit
e9a0c429c5
145 changed files with 519 additions and 531 deletions
|
@ -2324,7 +2324,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
// This is also case 2 from above but for functions, return type is still an
|
||||
// anonymous reference so we select the first argument.
|
||||
let argument_span = fn_decl.inputs.first()?.span;
|
||||
let argument_ty = sig.inputs().skip_binder().first()?;
|
||||
let argument_ty = *sig.inputs().skip_binder().first()?;
|
||||
|
||||
let return_span = fn_decl.output.span();
|
||||
let return_ty = sig.output().skip_binder();
|
||||
|
@ -2379,27 +2379,27 @@ impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
|
|||
diag: &mut DiagnosticBuilder<'_>,
|
||||
) -> String {
|
||||
match self {
|
||||
AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span } => {
|
||||
&AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span } => {
|
||||
diag.span_label(
|
||||
*argument_span,
|
||||
argument_span,
|
||||
format!("has type `{}`", cx.get_name_for_ty(argument_ty, 0)),
|
||||
);
|
||||
|
||||
cx.get_region_name_for_ty(argument_ty, 0)
|
||||
}
|
||||
AnnotatedBorrowFnSignature::AnonymousFunction {
|
||||
&AnnotatedBorrowFnSignature::AnonymousFunction {
|
||||
argument_ty,
|
||||
argument_span,
|
||||
return_ty,
|
||||
return_span,
|
||||
} => {
|
||||
let argument_ty_name = cx.get_name_for_ty(argument_ty, 0);
|
||||
diag.span_label(*argument_span, format!("has type `{}`", argument_ty_name));
|
||||
diag.span_label(argument_span, format!("has type `{}`", argument_ty_name));
|
||||
|
||||
let return_ty_name = cx.get_name_for_ty(return_ty, 0);
|
||||
let types_equal = return_ty_name == argument_ty_name;
|
||||
diag.span_label(
|
||||
*return_span,
|
||||
return_span,
|
||||
format!(
|
||||
"{}has type `{}`",
|
||||
if types_equal { "also " } else { "" },
|
||||
|
@ -2419,7 +2419,7 @@ impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
|
|||
}
|
||||
AnnotatedBorrowFnSignature::NamedFunction { arguments, return_ty, return_span } => {
|
||||
// Region of return type and arguments checked to be the same earlier.
|
||||
let region_name = cx.get_region_name_for_ty(return_ty, 0);
|
||||
let region_name = cx.get_region_name_for_ty(*return_ty, 0);
|
||||
for (_, argument_span) in arguments {
|
||||
diag.span_label(*argument_span, format!("has lifetime `{}`", region_name));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue