Skip to content

Commit 42e5f41

Browse files
authored
Rollup merge of #116870 - compiler-errors:host-param-by-name, r=fee1-dead
Don't compare host param by name Seems sketchy to be searching for `sym::host` by name, especially when we can get the actual index with not very much work. r? fee1-dead
2 parents d69cdb2 + 9917ef9 commit 42e5f41

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

compiler/rustc_hir_analysis/src/bounds.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ impl<'tcx> Bounds<'tcx> {
4646
) {
4747
self.push_trait_bound_inner(tcx, trait_ref, span, polarity);
4848

49-
// if we have a host param, we push an unconst trait bound in addition
50-
// to the const one.
51-
// FIXME(effects) we should find a better way than name matching
52-
if tcx.features().effects && trait_ref.skip_binder().args.host_effect_param().is_some() {
49+
// push a non-const (`host = true`) version of the bound if it is `~const`.
50+
if tcx.features().effects
51+
&& let Some(host_effect_idx) = tcx.generics_of(trait_ref.def_id()).host_effect_index
52+
&& trait_ref.skip_binder().args.const_at(host_effect_idx) != tcx.consts.true_
53+
{
5354
let generics = tcx.generics_of(trait_ref.def_id());
5455
let Some(host_index) = generics.host_effect_index else { return };
5556
let trait_ref = trait_ref.map_bound(|mut trait_ref| {

compiler/rustc_hir_typeck/src/callee.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
786786
tcx.consts.false_
787787
}
788788
Some(hir::ConstContext::ConstFn) => {
789-
let args = ty::GenericArgs::identity_for_item(tcx, context);
790-
args.host_effect_param().expect("ConstContext::Maybe must have host effect param")
789+
let host_idx = tcx
790+
.generics_of(context)
791+
.host_effect_index
792+
.expect("ConstContext::Maybe must have host effect param");
793+
ty::GenericArgs::identity_for_item(tcx, context).const_at(host_idx)
791794
}
792795
None => tcx.consts.true_,
793796
};

compiler/rustc_middle/src/ty/generic_args.rs

-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
1111
use rustc_hir::def_id::DefId;
1212
use rustc_macros::HashStable;
1313
use rustc_serialize::{self, Decodable, Encodable};
14-
use rustc_span::sym;
1514
use rustc_type_ir::WithCachedTypeInfo;
1615
use smallvec::SmallVec;
1716

@@ -452,10 +451,6 @@ impl<'tcx> GenericArgs<'tcx> {
452451
tcx.mk_args_from_iter(self.iter().take(generics.count()))
453452
}
454453

455-
pub fn host_effect_param(&'tcx self) -> Option<ty::Const<'tcx>> {
456-
self.consts().rfind(|x| matches!(x.kind(), ty::ConstKind::Param(p) if p.name == sym::host))
457-
}
458-
459454
pub fn print_as_list(&self) -> String {
460455
let v = self.iter().map(|arg| arg.to_string()).collect::<Vec<_>>();
461456
format!("[{}]", v.join(", "))

0 commit comments

Comments
 (0)