Skip to content

Commit 9654d5c

Browse files
committed
add is_host_effect to GenericParamDefKind::Const and address review
1 parent 84a4907 commit 9654d5c

File tree

13 files changed

+35
-28
lines changed

13 files changed

+35
-28
lines changed

Diff for: compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
523523
Ty::new_misc_error(tcx).into()
524524
}
525525
}
526-
GenericParamDefKind::Const { has_default } => {
526+
GenericParamDefKind::Const { has_default, .. } => {
527527
let ty = tcx
528528
.at(self.span)
529529
.type_of(param.def_id)

Diff for: compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
12551255

12561256
let is_our_default = |def: &ty::GenericParamDef| match def.kind {
12571257
GenericParamDefKind::Type { has_default, .. }
1258-
| GenericParamDefKind::Const { has_default } => {
1258+
| GenericParamDefKind::Const { has_default, .. } => {
12591259
has_default && def.index >= generics.parent_count as u32
12601260
}
12611261
GenericParamDefKind::Lifetime => unreachable!(),

Diff for: compiler/rustc_hir_analysis/src/collect/generics_of.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,10 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
328328
name: param.name.ident().name,
329329
def_id: param.def_id.to_def_id(),
330330
pure_wrt_drop: param.pure_wrt_drop,
331-
kind: ty::GenericParamDefKind::Const { has_default: default.is_some() },
331+
kind: ty::GenericParamDefKind::Const {
332+
has_default: default.is_some(),
333+
is_host_effect: is_host_param,
334+
},
332335
})
333336
}
334337
}));

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1295,10 +1295,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12951295
(GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => {
12961296
self.fcx.ty_infer(Some(param), inf.span).into()
12971297
}
1298-
(&GenericParamDefKind::Const { has_default }, GenericArg::Infer(inf)) => {
1298+
(
1299+
&GenericParamDefKind::Const { has_default, is_host_effect },
1300+
GenericArg::Infer(inf),
1301+
) => {
12991302
let tcx = self.fcx.tcx();
13001303

1301-
if has_default && tcx.has_attr(param.def_id, sym::rustc_host) {
1304+
if has_default && is_host_effect {
13021305
self.fcx.var_for_effect(param)
13031306
} else {
13041307
self.fcx
@@ -1341,7 +1344,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13411344
self.fcx.var_for_def(self.span, param)
13421345
}
13431346
}
1344-
GenericParamDefKind::Const { has_default } => {
1347+
GenericParamDefKind::Const { has_default, is_host_effect } => {
13451348
if has_default {
13461349
// N.B. this is a bit of a hack. `infer_args` is passed depending on
13471350
// whether the user has provided generic args. E.g. for `Vec::new`
@@ -1352,7 +1355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13521355
// it before falling back to default, such that a `const fn` such as
13531356
// `needs_drop::<()>` can still be called in const contexts. (if we defaulted
13541357
// instead of inferred, typeck would error)
1355-
if tcx.has_attr(param.def_id, sym::rustc_host) {
1358+
if is_host_effect {
13561359
return self.fcx.var_for_effect(param);
13571360
} else if !infer_args {
13581361
return tcx

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin
2020
use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitableExt};
2121
use rustc_session::Session;
2222
use rustc_span::symbol::Ident;
23-
use rustc_span::{self, sym, Span, DUMMY_SP};
23+
use rustc_span::{self, Span, DUMMY_SP};
2424
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode, ObligationCtxt};
2525

2626
use std::cell::{Cell, RefCell};
@@ -268,9 +268,12 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
268268
) -> Const<'tcx> {
269269
// FIXME ideally this shouldn't use unwrap
270270
match param {
271-
Some(param) if self.tcx.has_attr(param.def_id, sym::rustc_host) => {
272-
self.var_for_effect(param).as_const().unwrap()
273-
}
271+
Some(
272+
param @ ty::GenericParamDef {
273+
kind: ty::GenericParamDefKind::Const { is_host_effect: true, .. },
274+
..
275+
},
276+
) => self.var_for_effect(param).as_const().unwrap(),
274277
Some(param) => self.var_for_def(span, param).as_const().unwrap(),
275278
None => self.next_const_var(
276279
ty,

Diff for: compiler/rustc_infer/src/infer/combine.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,9 @@ fn float_unification_error<'tcx>(
546546
}
547547

548548
fn effect_unification_error<'tcx>(
549-
tcx: TyCtxt<'tcx>,
550-
a_is_expected: bool,
551-
(a, b): (EffectVarValue<'tcx>, EffectVarValue<'tcx>),
549+
_tcx: TyCtxt<'tcx>,
550+
_a_is_expected: bool,
551+
(_a, _b): (EffectVarValue<'tcx>, EffectVarValue<'tcx>),
552552
) -> TypeError<'tcx> {
553-
TypeError::ConstMismatch(ExpectedFound::new(a_is_expected, a.as_const(tcx), b.as_const(tcx)))
553+
bug!("unexpected effect unification error")
554554
}

Diff for: compiler/rustc_infer/src/infer/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_middle::ty::{self, GenericParamDefKind, InferConst, InferTy, Ty, TyCtx
3636
use rustc_middle::ty::{ConstVid, EffectVid, FloatVid, IntVid, TyVid};
3737
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef};
3838
use rustc_span::symbol::Symbol;
39-
use rustc_span::{sym, Span};
39+
use rustc_span::Span;
4040

4141
use std::cell::{Cell, RefCell};
4242
use std::fmt;
@@ -1181,9 +1181,8 @@ impl<'tcx> InferCtxt<'tcx> {
11811181

11821182
Ty::new_var(self.tcx, ty_var_id).into()
11831183
}
1184-
GenericParamDefKind::Const { .. } => {
1185-
// todo what about using effect var here
1186-
if self.tcx.has_attr(param.def_id, sym::rustc_host) {
1184+
GenericParamDefKind::Const { is_host_effect, .. } => {
1185+
if is_host_effect {
11871186
return self.var_for_effect(param);
11881187
}
11891188
let origin = ConstVariableOrigin {

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -873,14 +873,14 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
873873
| DefKind::AssocConst
874874
| DefKind::Macro(_)
875875
| DefKind::Field
876-
| DefKind::Impl { .. }
877-
| DefKind::ConstParam => true,
876+
| DefKind::Impl { .. } => true,
878877
// Tools may want to be able to detect their tool lints on
879878
// closures from upstream crates, too. This is used by
880879
// https://github.com/model-checking/kani and is not a performance
881880
// or maintenance issue for us.
882881
DefKind::Closure => true,
883882
DefKind::TyParam
883+
| DefKind::ConstParam
884884
| DefKind::Ctor(..)
885885
| DefKind::ExternCrate
886886
| DefKind::Use

Diff for: compiler/rustc_middle/src/infer/canonical.rs

-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ impl<'tcx> CanonicalVarValues<'tcx> {
448448
};
449449
ty::Region::new_late_bound(tcx, ty::INNERMOST, br).into()
450450
}
451-
// todo eh?
452451
CanonicalVarKind::Effect => ty::Const::new_bound(
453452
tcx,
454453
ty::INNERMOST,

Diff for: compiler/rustc_middle/src/ty/generics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::{Clause, EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamT
1212
pub enum GenericParamDefKind {
1313
Lifetime,
1414
Type { has_default: bool, synthetic: bool },
15-
Const { has_default: bool },
15+
Const { has_default: bool, is_host_effect: bool },
1616
}
1717

1818
impl GenericParamDefKind {
@@ -87,7 +87,7 @@ impl GenericParamDef {
8787
GenericParamDefKind::Type { has_default, .. } if has_default => {
8888
Some(tcx.type_of(self.def_id).map_bound(|t| t.into()))
8989
}
90-
GenericParamDefKind::Const { has_default } if has_default => {
90+
GenericParamDefKind::Const { has_default, .. } if has_default => {
9191
Some(tcx.const_param_default(self.def_id).map_bound(|c| c.into()))
9292
}
9393
_ => None,
@@ -187,7 +187,7 @@ impl<'tcx> Generics {
187187
GenericParamDefKind::Type { has_default, .. } => {
188188
own_defaults.types += has_default as usize;
189189
}
190-
GenericParamDefKind::Const { has_default } => {
190+
GenericParamDefKind::Const { has_default, .. } => {
191191
own_defaults.consts += has_default as usize;
192192
}
193193
}

Diff for: compiler/rustc_privacy/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
836836
self.visit(self.ev.tcx.type_of(param.def_id).instantiate_identity());
837837
}
838838
}
839-
GenericParamDefKind::Const { has_default } => {
839+
GenericParamDefKind::Const { has_default, .. } => {
840840
self.visit(self.ev.tcx.type_of(param.def_id).instantiate_identity());
841841
if has_default {
842842
self.visit(

Diff for: compiler/rustc_smir/src/rustc_smir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind {
12421242
ty::GenericParamDefKind::Type { has_default, synthetic } => {
12431243
GenericParamDefKind::Type { has_default: *has_default, synthetic: *synthetic }
12441244
}
1245-
ty::GenericParamDefKind::Const { has_default } => {
1245+
ty::GenericParamDefKind::Const { has_default, is_host_effect: _ } => {
12461246
GenericParamDefKind::Const { has_default: *has_default }
12471247
}
12481248
}

Diff for: src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ fn clean_generic_param_def<'tcx>(
541541
},
542542
)
543543
}
544-
ty::GenericParamDefKind::Const { has_default } => (
544+
ty::GenericParamDefKind::Const { has_default, .. } => (
545545
def.name,
546546
GenericParamDefKind::Const {
547547
ty: Box::new(clean_middle_ty(

0 commit comments

Comments
 (0)