Rollup merge of #112340 - lcnr:tyctxt-cleanup, r=compiler-errors

remove `TyCtxt::has_error_field` helper method
This commit is contained in:
Matthias Krüger 2023-06-06 22:00:20 +02:00 committed by GitHub
commit e937fa49dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 40 deletions

View File

@ -1745,9 +1745,11 @@ fn check_variances_for_type_defn<'tcx>(
item: &hir::Item<'tcx>,
hir_generics: &hir::Generics<'_>,
) {
let ty = tcx.type_of(item.owner_id).subst_identity();
if tcx.has_error_field(ty) {
return;
let identity_substs = ty::InternalSubsts::identity_for_item(tcx, item.owner_id);
for field in tcx.adt_def(item.owner_id).all_fields() {
if field.ty(tcx, identity_substs).references_error() {
return;
}
}
let ty_predicates = tcx.predicates_of(item.owner_id);

View File

@ -173,18 +173,6 @@ impl<'tcx> TyCtxt<'tcx> {
}
}
pub fn has_error_field(self, ty: Ty<'tcx>) -> bool {
if let ty::Adt(def, substs) = *ty.kind() {
for field in def.all_fields() {
let field_ty = field.ty(self, substs);
if let ty::Error(_) = field_ty.kind() {
return true;
}
}
}
false
}
/// Attempts to returns the deeply last field of nested structures, but
/// does not apply any normalization in its search. Returns the same type
/// if input `ty` is not a structure at all.

View File

@ -6,16 +6,6 @@ LL | pub struct Dependent<T, const X: T>([(); X]);
|
= note: type parameters may not be used in the type of const parameters
error[E0392]: parameter `T` is never used
--> $DIR/const-param-type-depends-on-type-param.rs:11:22
|
LL | pub struct Dependent<T, const X: T>([(); X]);
| ^ unused parameter
|
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
= help: if you intended `T` to be a const parameter, use `const T: usize` instead
error: aborting due to previous error
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0392, E0770.
For more information about an error, try `rustc --explain E0392`.
For more information about this error, try `rustc --explain E0770`.

View File

@ -6,16 +6,6 @@ LL | pub struct Dependent<T, const X: T>([(); X]);
|
= note: type parameters may not be used in the type of const parameters
error[E0392]: parameter `T` is never used
--> $DIR/const-param-type-depends-on-type-param.rs:11:22
|
LL | pub struct Dependent<T, const X: T>([(); X]);
| ^ unused parameter
|
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
= help: if you intended `T` to be a const parameter, use `const T: usize` instead
error: aborting due to previous error
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0392, E0770.
For more information about an error, try `rustc --explain E0392`.
For more information about this error, try `rustc --explain E0770`.

View File

@ -10,6 +10,5 @@
pub struct Dependent<T, const X: T>([(); X]);
//~^ ERROR: the type of const parameters must not depend on other generic parameters
//~| ERROR: parameter `T` is never used
fn main() {}