Skip to content

Commit 158f7e8

Browse files
committed
Directly use LangItem::ConstParamTy when necessary
1 parent 125afc1 commit 158f7e8

File tree

3 files changed

+5
-16
lines changed

3 files changed

+5
-16
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,6 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), Er
870870
tcx,
871871
tcx.param_env(param.def_id),
872872
ty,
873-
LangItem::ConstParamTy,
874873
cause,
875874
) {
876875
// Can never implement `ConstParamTy`, don't suggest anything.

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Check properties that are required by built-in traits and set
22
//! up data structures required by type-checking/codegen.
33
4-
use std::assert_matches::assert_matches;
54
use std::collections::BTreeMap;
65

76
use rustc_data_structures::fx::FxHashSet;
@@ -40,7 +39,7 @@ pub(super) fn check_trait<'tcx>(
4039
checker.check(lang_items.async_drop_trait(), visit_implementation_of_drop)?;
4140
checker.check(lang_items.copy_trait(), visit_implementation_of_copy)?;
4241
checker.check(lang_items.const_param_ty_trait(), |checker| {
43-
visit_implementation_of_const_param_ty(checker, LangItem::ConstParamTy)
42+
visit_implementation_of_const_param_ty(checker)
4443
})?;
4544
checker.check(lang_items.coerce_unsized_trait(), visit_implementation_of_coerce_unsized)?;
4645
checker
@@ -135,12 +134,7 @@ fn visit_implementation_of_copy(checker: &Checker<'_>) -> Result<(), ErrorGuaran
135134
}
136135
}
137136

138-
fn visit_implementation_of_const_param_ty(
139-
checker: &Checker<'_>,
140-
kind: LangItem,
141-
) -> Result<(), ErrorGuaranteed> {
142-
assert_matches!(kind, LangItem::ConstParamTy);
143-
137+
fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
144138
let tcx = checker.tcx;
145139
let header = checker.impl_header;
146140
let impl_did = checker.impl_def_id;
@@ -154,7 +148,7 @@ fn visit_implementation_of_const_param_ty(
154148
}
155149

156150
let cause = traits::ObligationCause::misc(DUMMY_SP, impl_did);
157-
match type_allowed_to_implement_const_param_ty(tcx, param_env, self_type, kind, cause) {
151+
match type_allowed_to_implement_const_param_ty(tcx, param_env, self_type, cause) {
158152
Ok(()) => Ok(()),
159153
Err(ConstParamTyImplementationError::InfrigingFields(fields)) => {
160154
let span = tcx.hir_expect_item(impl_did).expect_impl().self_ty.span;

compiler/rustc_trait_selection/src/traits/misc.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Miscellaneous type-system utilities that are too small to deserve their own modules.
22
3-
use std::assert_matches::assert_matches;
4-
53
use hir::LangItem;
64
use rustc_ast::Mutability;
75
use rustc_hir as hir;
@@ -99,10 +97,8 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
9997
tcx: TyCtxt<'tcx>,
10098
param_env: ty::ParamEnv<'tcx>,
10199
self_type: Ty<'tcx>,
102-
lang_item: LangItem,
103100
parent_cause: ObligationCause<'tcx>,
104101
) -> Result<(), ConstParamTyImplementationError<'tcx>> {
105-
assert_matches!(lang_item, LangItem::ConstParamTy);
106102
let mut need_unstable_feature_bound = false;
107103

108104
let inner_tys: Vec<_> = match *self_type.kind() {
@@ -135,7 +131,7 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
135131
adt,
136132
args,
137133
parent_cause.clone(),
138-
lang_item,
134+
LangItem::ConstParamTy,
139135
)
140136
.map_err(ConstParamTyImplementationError::InfrigingFields)?;
141137

@@ -165,7 +161,7 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
165161
parent_cause.clone(),
166162
param_env,
167163
inner_ty,
168-
tcx.require_lang_item(lang_item, parent_cause.span),
164+
tcx.require_lang_item(LangItem::ConstParamTy, parent_cause.span),
169165
);
170166

171167
let errors = ocx.select_all_or_error();

0 commit comments

Comments
 (0)