mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
add is_host_effect
to GenericParamDefKind::Const
and address review
This commit is contained in:
parent
84a490712a
commit
9654d5ceaf
@ -523,7 +523,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
Ty::new_misc_error(tcx).into()
|
||||
}
|
||||
}
|
||||
GenericParamDefKind::Const { has_default } => {
|
||||
GenericParamDefKind::Const { has_default, .. } => {
|
||||
let ty = tcx
|
||||
.at(self.span)
|
||||
.type_of(param.def_id)
|
||||
|
@ -1255,7 +1255,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
|
||||
|
||||
let is_our_default = |def: &ty::GenericParamDef| match def.kind {
|
||||
GenericParamDefKind::Type { has_default, .. }
|
||||
| GenericParamDefKind::Const { has_default } => {
|
||||
| GenericParamDefKind::Const { has_default, .. } => {
|
||||
has_default && def.index >= generics.parent_count as u32
|
||||
}
|
||||
GenericParamDefKind::Lifetime => unreachable!(),
|
||||
|
@ -328,7 +328,10 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
|
||||
name: param.name.ident().name,
|
||||
def_id: param.def_id.to_def_id(),
|
||||
pure_wrt_drop: param.pure_wrt_drop,
|
||||
kind: ty::GenericParamDefKind::Const { has_default: default.is_some() },
|
||||
kind: ty::GenericParamDefKind::Const {
|
||||
has_default: default.is_some(),
|
||||
is_host_effect: is_host_param,
|
||||
},
|
||||
})
|
||||
}
|
||||
}));
|
||||
|
@ -1295,10 +1295,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
(GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => {
|
||||
self.fcx.ty_infer(Some(param), inf.span).into()
|
||||
}
|
||||
(&GenericParamDefKind::Const { has_default }, GenericArg::Infer(inf)) => {
|
||||
(
|
||||
&GenericParamDefKind::Const { has_default, is_host_effect },
|
||||
GenericArg::Infer(inf),
|
||||
) => {
|
||||
let tcx = self.fcx.tcx();
|
||||
|
||||
if has_default && tcx.has_attr(param.def_id, sym::rustc_host) {
|
||||
if has_default && is_host_effect {
|
||||
self.fcx.var_for_effect(param)
|
||||
} else {
|
||||
self.fcx
|
||||
@ -1341,7 +1344,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
self.fcx.var_for_def(self.span, param)
|
||||
}
|
||||
}
|
||||
GenericParamDefKind::Const { has_default } => {
|
||||
GenericParamDefKind::Const { has_default, is_host_effect } => {
|
||||
if has_default {
|
||||
// N.B. this is a bit of a hack. `infer_args` is passed depending on
|
||||
// whether the user has provided generic args. E.g. for `Vec::new`
|
||||
@ -1352,7 +1355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// it before falling back to default, such that a `const fn` such as
|
||||
// `needs_drop::<()>` can still be called in const contexts. (if we defaulted
|
||||
// instead of inferred, typeck would error)
|
||||
if tcx.has_attr(param.def_id, sym::rustc_host) {
|
||||
if is_host_effect {
|
||||
return self.fcx.var_for_effect(param);
|
||||
} else if !infer_args {
|
||||
return tcx
|
||||
|
@ -20,7 +20,7 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin
|
||||
use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::{self, sym, Span, DUMMY_SP};
|
||||
use rustc_span::{self, Span, DUMMY_SP};
|
||||
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode, ObligationCtxt};
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
@ -268,9 +268,12 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
|
||||
) -> Const<'tcx> {
|
||||
// FIXME ideally this shouldn't use unwrap
|
||||
match param {
|
||||
Some(param) if self.tcx.has_attr(param.def_id, sym::rustc_host) => {
|
||||
self.var_for_effect(param).as_const().unwrap()
|
||||
}
|
||||
Some(
|
||||
param @ ty::GenericParamDef {
|
||||
kind: ty::GenericParamDefKind::Const { is_host_effect: true, .. },
|
||||
..
|
||||
},
|
||||
) => self.var_for_effect(param).as_const().unwrap(),
|
||||
Some(param) => self.var_for_def(span, param).as_const().unwrap(),
|
||||
None => self.next_const_var(
|
||||
ty,
|
||||
|
@ -546,9 +546,9 @@ fn float_unification_error<'tcx>(
|
||||
}
|
||||
|
||||
fn effect_unification_error<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
a_is_expected: bool,
|
||||
(a, b): (EffectVarValue<'tcx>, EffectVarValue<'tcx>),
|
||||
_tcx: TyCtxt<'tcx>,
|
||||
_a_is_expected: bool,
|
||||
(_a, _b): (EffectVarValue<'tcx>, EffectVarValue<'tcx>),
|
||||
) -> TypeError<'tcx> {
|
||||
TypeError::ConstMismatch(ExpectedFound::new(a_is_expected, a.as_const(tcx), b.as_const(tcx)))
|
||||
bug!("unexpected effect unification error")
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ use rustc_middle::ty::{self, GenericParamDefKind, InferConst, InferTy, Ty, TyCtx
|
||||
use rustc_middle::ty::{ConstVid, EffectVid, FloatVid, IntVid, TyVid};
|
||||
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_span::Span;
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::fmt;
|
||||
@ -1181,9 +1181,8 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
|
||||
Ty::new_var(self.tcx, ty_var_id).into()
|
||||
}
|
||||
GenericParamDefKind::Const { .. } => {
|
||||
// todo what about using effect var here
|
||||
if self.tcx.has_attr(param.def_id, sym::rustc_host) {
|
||||
GenericParamDefKind::Const { is_host_effect, .. } => {
|
||||
if is_host_effect {
|
||||
return self.var_for_effect(param);
|
||||
}
|
||||
let origin = ConstVariableOrigin {
|
||||
|
@ -873,14 +873,14 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Macro(_)
|
||||
| DefKind::Field
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::ConstParam => true,
|
||||
| DefKind::Impl { .. } => true,
|
||||
// Tools may want to be able to detect their tool lints on
|
||||
// closures from upstream crates, too. This is used by
|
||||
// https://github.com/model-checking/kani and is not a performance
|
||||
// or maintenance issue for us.
|
||||
DefKind::Closure => true,
|
||||
DefKind::TyParam
|
||||
| DefKind::ConstParam
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::ExternCrate
|
||||
| DefKind::Use
|
||||
|
@ -448,7 +448,6 @@ impl<'tcx> CanonicalVarValues<'tcx> {
|
||||
};
|
||||
ty::Region::new_late_bound(tcx, ty::INNERMOST, br).into()
|
||||
}
|
||||
// todo eh?
|
||||
CanonicalVarKind::Effect => ty::Const::new_bound(
|
||||
tcx,
|
||||
ty::INNERMOST,
|
||||
|
@ -12,7 +12,7 @@ use super::{Clause, EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamT
|
||||
pub enum GenericParamDefKind {
|
||||
Lifetime,
|
||||
Type { has_default: bool, synthetic: bool },
|
||||
Const { has_default: bool },
|
||||
Const { has_default: bool, is_host_effect: bool },
|
||||
}
|
||||
|
||||
impl GenericParamDefKind {
|
||||
@ -87,7 +87,7 @@ impl GenericParamDef {
|
||||
GenericParamDefKind::Type { has_default, .. } if has_default => {
|
||||
Some(tcx.type_of(self.def_id).map_bound(|t| t.into()))
|
||||
}
|
||||
GenericParamDefKind::Const { has_default } if has_default => {
|
||||
GenericParamDefKind::Const { has_default, .. } if has_default => {
|
||||
Some(tcx.const_param_default(self.def_id).map_bound(|c| c.into()))
|
||||
}
|
||||
_ => None,
|
||||
@ -187,7 +187,7 @@ impl<'tcx> Generics {
|
||||
GenericParamDefKind::Type { has_default, .. } => {
|
||||
own_defaults.types += has_default as usize;
|
||||
}
|
||||
GenericParamDefKind::Const { has_default } => {
|
||||
GenericParamDefKind::Const { has_default, .. } => {
|
||||
own_defaults.consts += has_default as usize;
|
||||
}
|
||||
}
|
||||
|
@ -836,7 +836,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
|
||||
self.visit(self.ev.tcx.type_of(param.def_id).instantiate_identity());
|
||||
}
|
||||
}
|
||||
GenericParamDefKind::Const { has_default } => {
|
||||
GenericParamDefKind::Const { has_default, .. } => {
|
||||
self.visit(self.ev.tcx.type_of(param.def_id).instantiate_identity());
|
||||
if has_default {
|
||||
self.visit(
|
||||
|
@ -1242,7 +1242,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind {
|
||||
ty::GenericParamDefKind::Type { has_default, synthetic } => {
|
||||
GenericParamDefKind::Type { has_default: *has_default, synthetic: *synthetic }
|
||||
}
|
||||
ty::GenericParamDefKind::Const { has_default } => {
|
||||
ty::GenericParamDefKind::Const { has_default, is_host_effect: _ } => {
|
||||
GenericParamDefKind::Const { has_default: *has_default }
|
||||
}
|
||||
}
|
||||
|
@ -541,7 +541,7 @@ fn clean_generic_param_def<'tcx>(
|
||||
},
|
||||
)
|
||||
}
|
||||
ty::GenericParamDefKind::Const { has_default } => (
|
||||
ty::GenericParamDefKind::Const { has_default, .. } => (
|
||||
def.name,
|
||||
GenericParamDefKind::Const {
|
||||
ty: Box::new(clean_middle_ty(
|
||||
|
Loading…
Reference in New Issue
Block a user