Auto merge of #118605 - fee1-dead-contrib:rm-rustc_host, r=compiler-errors
Remove `#[rustc_host]`, use internal desugaring Also removed a way for users to explicitly specify the host param since that isn't particularly useful. This should eliminate any pain with encoding attributes across crates and etc. r? `@compiler-errors`
This commit is contained in:
commit
f32d29837d
@ -565,11 +565,10 @@ fn lower_assoc_item(
|
|||||||
.params
|
.params
|
||||||
.iter()
|
.iter()
|
||||||
.find(|param| {
|
.find(|param| {
|
||||||
parent_hir
|
matches!(
|
||||||
.attrs
|
param.kind,
|
||||||
.get(param.hir_id.local_id)
|
hir::GenericParamKind::Const { is_host_effect: true, .. }
|
||||||
.iter()
|
)
|
||||||
.any(|attr| attr.has_name(sym::rustc_host))
|
|
||||||
})
|
})
|
||||||
.map(|param| param.def_id);
|
.map(|param| param.def_id);
|
||||||
}
|
}
|
||||||
@ -1372,27 +1371,17 @@ fn lower_generics<T>(
|
|||||||
let host_param_parts = if let Const::Yes(span) = constness
|
let host_param_parts = if let Const::Yes(span) = constness
|
||||||
&& self.tcx.features().effects
|
&& self.tcx.features().effects
|
||||||
{
|
{
|
||||||
if let Some(param) =
|
let param_node_id = self.next_node_id();
|
||||||
generics.params.iter().find(|x| x.attrs.iter().any(|x| x.has_name(sym::rustc_host)))
|
let hir_id = self.next_id();
|
||||||
{
|
let def_id = self.create_def(
|
||||||
// user has manually specified a `rustc_host` param, in this case, we set
|
self.local_def_id(parent_node_id),
|
||||||
// the param id so that lowering logic can use that. But we don't create
|
param_node_id,
|
||||||
// another host param, so this gives `None`.
|
sym::host,
|
||||||
self.host_param_id = Some(self.local_def_id(param.id));
|
DefKind::ConstParam,
|
||||||
None
|
span,
|
||||||
} else {
|
);
|
||||||
let param_node_id = self.next_node_id();
|
self.host_param_id = Some(def_id);
|
||||||
let hir_id = self.next_id();
|
Some((span, hir_id, def_id))
|
||||||
let def_id = self.create_def(
|
|
||||||
self.local_def_id(parent_node_id),
|
|
||||||
param_node_id,
|
|
||||||
sym::host,
|
|
||||||
DefKind::ConstParam,
|
|
||||||
span,
|
|
||||||
);
|
|
||||||
self.host_param_id = Some(def_id);
|
|
||||||
Some((span, hir_id, def_id))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@ -1456,19 +1445,6 @@ fn lower_generics<T>(
|
|||||||
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
|
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
|
||||||
self.children.push((anon_const, hir::MaybeOwner::NonOwner(const_id)));
|
self.children.push((anon_const, hir::MaybeOwner::NonOwner(const_id)));
|
||||||
|
|
||||||
let attr_id = self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id();
|
|
||||||
|
|
||||||
let attrs = self.arena.alloc_from_iter([Attribute {
|
|
||||||
kind: AttrKind::Normal(P(NormalAttr::from_ident(Ident::new(
|
|
||||||
sym::rustc_host,
|
|
||||||
span,
|
|
||||||
)))),
|
|
||||||
span,
|
|
||||||
id: attr_id,
|
|
||||||
style: AttrStyle::Outer,
|
|
||||||
}]);
|
|
||||||
self.attrs.insert(hir_id.local_id, attrs);
|
|
||||||
|
|
||||||
let const_body = self.lower_body(|this| {
|
let const_body = self.lower_body(|this| {
|
||||||
(
|
(
|
||||||
&[],
|
&[],
|
||||||
@ -1510,6 +1486,7 @@ fn lower_generics<T>(
|
|||||||
hir_id: const_id,
|
hir_id: const_id,
|
||||||
body: const_body,
|
body: const_body,
|
||||||
}),
|
}),
|
||||||
|
is_host_effect: true,
|
||||||
},
|
},
|
||||||
colon_span: None,
|
colon_span: None,
|
||||||
pure_wrt_drop: false,
|
pure_wrt_drop: false,
|
||||||
|
@ -2122,7 +2122,7 @@ fn lower_generic_param_kind(
|
|||||||
let default = default.as_ref().map(|def| self.lower_anon_const(def));
|
let default = default.as_ref().map(|def| self.lower_anon_const(def));
|
||||||
(
|
(
|
||||||
hir::ParamName::Plain(self.lower_ident(param.ident)),
|
hir::ParamName::Plain(self.lower_ident(param.ident)),
|
||||||
hir::GenericParamKind::Const { ty, default },
|
hir::GenericParamKind::Const { ty, default, is_host_effect: false },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2550,15 +2550,6 @@ fn push_constness(&mut self, lcx: &mut LoweringContext<'_, 'hir>, constness: ast
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let attr_id = lcx.tcx.sess.parse_sess.attr_id_generator.mk_attr_id();
|
|
||||||
let attr = lcx.arena.alloc(Attribute {
|
|
||||||
kind: AttrKind::Normal(P(NormalAttr::from_ident(Ident::new(sym::rustc_host, span)))),
|
|
||||||
span,
|
|
||||||
id: attr_id,
|
|
||||||
style: AttrStyle::Outer,
|
|
||||||
});
|
|
||||||
lcx.attrs.insert(hir_id.local_id, std::slice::from_ref(attr));
|
|
||||||
|
|
||||||
let def_id = lcx.create_def(
|
let def_id = lcx.create_def(
|
||||||
lcx.current_hir_id_owner.def_id,
|
lcx.current_hir_id_owner.def_id,
|
||||||
id,
|
id,
|
||||||
@ -2566,6 +2557,7 @@ fn push_constness(&mut self, lcx: &mut LoweringContext<'_, 'hir>, constness: ast
|
|||||||
DefKind::AnonConst,
|
DefKind::AnonConst,
|
||||||
span,
|
span,
|
||||||
);
|
);
|
||||||
|
|
||||||
lcx.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
|
lcx.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
|
||||||
self.args.push(hir::GenericArg::Const(hir::ConstArg {
|
self.args.push(hir::GenericArg::Const(hir::ConstArg {
|
||||||
value: hir::AnonConst { def_id, hir_id, body },
|
value: hir::AnonConst { def_id, hir_id, body },
|
||||||
|
@ -719,12 +719,6 @@ pub struct BuiltinAttribute {
|
|||||||
and it is only intended to be used in `alloc`."
|
and it is only intended to be used in `alloc`."
|
||||||
),
|
),
|
||||||
|
|
||||||
rustc_attr!(
|
|
||||||
rustc_host, AttributeType::Normal, template!(Word), ErrorFollowing,
|
|
||||||
"#[rustc_host] annotates const generic parameters as the `host` effect param, \
|
|
||||||
and it is only intended for internal use and as a desugaring."
|
|
||||||
),
|
|
||||||
|
|
||||||
BuiltinAttribute {
|
BuiltinAttribute {
|
||||||
name: sym::rustc_diagnostic_item,
|
name: sym::rustc_diagnostic_item,
|
||||||
// FIXME: This can be `true` once we always use `tcx.is_diagnostic_item`.
|
// FIXME: This can be `true` once we always use `tcx.is_diagnostic_item`.
|
||||||
|
@ -487,6 +487,7 @@ pub enum GenericParamKind<'hir> {
|
|||||||
ty: &'hir Ty<'hir>,
|
ty: &'hir Ty<'hir>,
|
||||||
/// Optional default value for the const generic param
|
/// Optional default value for the const generic param
|
||||||
default: Option<AnonConst>,
|
default: Option<AnonConst>,
|
||||||
|
is_host_effect: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -874,7 +874,7 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi
|
|||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamKind::Lifetime { .. } => {}
|
GenericParamKind::Lifetime { .. } => {}
|
||||||
GenericParamKind::Type { ref default, .. } => walk_list!(visitor, visit_ty, default),
|
GenericParamKind::Type { ref default, .. } => walk_list!(visitor, visit_ty, default),
|
||||||
GenericParamKind::Const { ref ty, ref default } => {
|
GenericParamKind::Const { ref ty, ref default, is_host_effect: _ } => {
|
||||||
visitor.visit_ty(ty);
|
visitor.visit_ty(ty);
|
||||||
if let Some(ref default) = default {
|
if let Some(ref default) = default {
|
||||||
visitor.visit_const_param_default(param.hir_id, default);
|
visitor.visit_const_param_default(param.hir_id, default);
|
||||||
|
@ -859,7 +859,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
|
|||||||
hir::GenericParamKind::Lifetime { .. } | hir::GenericParamKind::Type { .. } => Ok(()),
|
hir::GenericParamKind::Lifetime { .. } | hir::GenericParamKind::Type { .. } => Ok(()),
|
||||||
|
|
||||||
// Const parameters are well formed if their type is structural match.
|
// Const parameters are well formed if their type is structural match.
|
||||||
hir::GenericParamKind::Const { ty: hir_ty, default: _ } => {
|
hir::GenericParamKind::Const { ty: hir_ty, default: _, is_host_effect: _ } => {
|
||||||
let ty = tcx.type_of(param.def_id).instantiate_identity();
|
let ty = tcx.type_of(param.def_id).instantiate_identity();
|
||||||
|
|
||||||
if tcx.features().adt_const_params {
|
if tcx.features().adt_const_params {
|
||||||
|
@ -1383,7 +1383,7 @@ fn impl_trait_ref(
|
|||||||
let last_segment = path_segments.len() - 1;
|
let last_segment = path_segments.len() - 1;
|
||||||
let mut args = *path_segments[last_segment].args();
|
let mut args = *path_segments[last_segment].args();
|
||||||
let last_arg = args.args.len() - 1;
|
let last_arg = args.args.len() - 1;
|
||||||
assert!(matches!(args.args[last_arg], hir::GenericArg::Const(anon_const) if tcx.has_attr(anon_const.value.def_id, sym::rustc_host)));
|
assert!(matches!(args.args[last_arg], hir::GenericArg::Const(anon_const) if anon_const.is_desugared_from_effects));
|
||||||
args.args = &args.args[..args.args.len() - 1];
|
args.args = &args.args[..args.args.len() - 1];
|
||||||
path_segments[last_segment].args = Some(&args);
|
path_segments[last_segment].args = Some(&args);
|
||||||
let path = hir::Path {
|
let path = hir::Path {
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
use rustc_session::lint;
|
use rustc_session::lint;
|
||||||
use rustc_span::symbol::{kw, Symbol};
|
use rustc_span::symbol::{kw, Symbol};
|
||||||
use rustc_span::{sym, Span};
|
use rustc_span::Span;
|
||||||
|
|
||||||
pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
|
pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
|
||||||
use rustc_hir::*;
|
use rustc_hir::*;
|
||||||
@ -298,13 +298,11 @@ enum Defaults {
|
|||||||
kind,
|
kind,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
GenericParamKind::Const { default, .. } => {
|
GenericParamKind::Const { ty: _, default, is_host_effect } => {
|
||||||
let is_host_param = tcx.has_attr(param.def_id, sym::rustc_host);
|
|
||||||
|
|
||||||
if !matches!(allow_defaults, Defaults::Allowed)
|
if !matches!(allow_defaults, Defaults::Allowed)
|
||||||
&& default.is_some()
|
&& default.is_some()
|
||||||
// `rustc_host` effect params are allowed to have defaults.
|
// `host` effect params are allowed to have defaults.
|
||||||
&& !is_host_param
|
&& !is_host_effect
|
||||||
{
|
{
|
||||||
tcx.sess.span_err(
|
tcx.sess.span_err(
|
||||||
param.span,
|
param.span,
|
||||||
@ -315,7 +313,7 @@ enum Defaults {
|
|||||||
|
|
||||||
let index = next_index();
|
let index = next_index();
|
||||||
|
|
||||||
if is_host_param {
|
if is_host_effect {
|
||||||
if let Some(idx) = host_effect_index {
|
if let Some(idx) = host_effect_index {
|
||||||
bug!("parent also has host effect param? index: {idx}, def: {def_id:?}");
|
bug!("parent also has host effect param? index: {idx}, def: {def_id:?}");
|
||||||
}
|
}
|
||||||
@ -330,7 +328,7 @@ enum Defaults {
|
|||||||
pure_wrt_drop: param.pure_wrt_drop,
|
pure_wrt_drop: param.pure_wrt_drop,
|
||||||
kind: ty::GenericParamDefKind::Const {
|
kind: ty::GenericParamDefKind::Const {
|
||||||
has_default: default.is_some(),
|
has_default: default.is_some(),
|
||||||
is_host_effect: is_host_param,
|
is_host_effect,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -489,7 +487,7 @@ struct AnonConstInParamTyDetector {
|
|||||||
|
|
||||||
impl<'v> Visitor<'v> for AnonConstInParamTyDetector {
|
impl<'v> Visitor<'v> for AnonConstInParamTyDetector {
|
||||||
fn visit_generic_param(&mut self, p: &'v hir::GenericParam<'v>) {
|
fn visit_generic_param(&mut self, p: &'v hir::GenericParam<'v>) {
|
||||||
if let GenericParamKind::Const { ty, default: _ } = p.kind {
|
if let GenericParamKind::Const { ty, default: _, is_host_effect: _ } = p.kind {
|
||||||
let prev = self.in_param_ty;
|
let prev = self.in_param_ty;
|
||||||
self.in_param_ty = true;
|
self.in_param_ty = true;
|
||||||
self.visit_ty(ty);
|
self.visit_ty(ty);
|
||||||
|
@ -992,7 +992,7 @@ fn visit_generic_param(&mut self, p: &'tcx GenericParam<'tcx>) {
|
|||||||
self.visit_ty(ty);
|
self.visit_ty(ty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GenericParamKind::Const { ty, default } => {
|
GenericParamKind::Const { ty, default, is_host_effect: _ } => {
|
||||||
self.visit_ty(ty);
|
self.visit_ty(ty);
|
||||||
if let Some(default) = default {
|
if let Some(default) = default {
|
||||||
self.visit_body(self.tcx.hir().body(default.body));
|
self.visit_body(self.tcx.hir().body(default.body));
|
||||||
|
@ -2126,7 +2126,7 @@ fn print_generic_param(&mut self, param: &GenericParam<'_>) {
|
|||||||
self.print_type(default);
|
self.print_type(default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GenericParamKind::Const { ty, ref default } => {
|
GenericParamKind::Const { ty, ref default, is_host_effect: _ } => {
|
||||||
self.word_space(":");
|
self.word_space(":");
|
||||||
self.print_type(ty);
|
self.print_type(ty);
|
||||||
if let Some(default) = default {
|
if let Some(default) = default {
|
||||||
|
@ -534,9 +534,9 @@ fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_generic_param(&mut self, cx: &LateContext<'_>, param: &hir::GenericParam<'_>) {
|
fn check_generic_param(&mut self, cx: &LateContext<'_>, param: &hir::GenericParam<'_>) {
|
||||||
if let GenericParamKind::Const { .. } = param.kind {
|
if let GenericParamKind::Const { is_host_effect, .. } = param.kind {
|
||||||
// `rustc_host` params are explicitly allowed to be lowercase.
|
// `host` params are explicitly allowed to be lowercase.
|
||||||
if cx.tcx.has_attr(param.def_id, sym::rustc_host) {
|
if is_host_effect {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NonUpperCaseGlobals::check_upper_case(cx, "const parameter", ¶m.name.ident());
|
NonUpperCaseGlobals::check_upper_case(cx, "const parameter", ¶m.name.ident());
|
||||||
|
@ -2186,7 +2186,7 @@ pub fn is_const_trait_impl_raw(self, def_id: DefId) -> bool {
|
|||||||
hir::Node::Item(hir::Item {
|
hir::Node::Item(hir::Item {
|
||||||
kind: hir::ItemKind::Impl(hir::Impl { generics, .. }),
|
kind: hir::ItemKind::Impl(hir::Impl { generics, .. }),
|
||||||
..
|
..
|
||||||
}) if generics.params.iter().any(|p| self.has_attr(p.def_id, sym::rustc_host))
|
}) if generics.params.iter().any(|p| matches!(p.kind, hir::GenericParamKind::Const { is_host_effect: true, .. }))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::cstore::ExternCrate;
|
use rustc_session::cstore::ExternCrate;
|
||||||
use rustc_span::symbol::kw::Empty;
|
use rustc_span::symbol::kw::Empty;
|
||||||
use rustc_span::{sym, Span};
|
use rustc_span::Span;
|
||||||
|
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
|
|
||||||
@ -162,7 +162,12 @@ fn collect_item_extended(&mut self, lang_item: LangItem, item_def_id: LocalDefId
|
|||||||
generics
|
generics
|
||||||
.params
|
.params
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|p| !self.tcx.has_attr(p.def_id, sym::rustc_host))
|
.filter(|p| {
|
||||||
|
!matches!(
|
||||||
|
p.kind,
|
||||||
|
hir::GenericParamKind::Const { is_host_effect: true, .. }
|
||||||
|
)
|
||||||
|
})
|
||||||
.count(),
|
.count(),
|
||||||
generics.span,
|
generics.span,
|
||||||
),
|
),
|
||||||
|
@ -1393,7 +1393,6 @@
|
|||||||
rustc_expected_cgu_reuse,
|
rustc_expected_cgu_reuse,
|
||||||
rustc_has_incoherent_inherent_impls,
|
rustc_has_incoherent_inherent_impls,
|
||||||
rustc_hidden_type_of_opaques,
|
rustc_hidden_type_of_opaques,
|
||||||
rustc_host,
|
|
||||||
rustc_if_this_changed,
|
rustc_if_this_changed,
|
||||||
rustc_inherit_overflow_checks,
|
rustc_inherit_overflow_checks,
|
||||||
rustc_insignificant_dtor,
|
rustc_insignificant_dtor,
|
||||||
|
@ -595,13 +595,13 @@ fn clean_generic_param<'tcx>(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
hir::GenericParamKind::Const { ty, default } => (
|
hir::GenericParamKind::Const { ty, default, is_host_effect } => (
|
||||||
param.name.ident().name,
|
param.name.ident().name,
|
||||||
GenericParamDefKind::Const {
|
GenericParamDefKind::Const {
|
||||||
ty: Box::new(clean_ty(ty, cx)),
|
ty: Box::new(clean_ty(ty, cx)),
|
||||||
default: default
|
default: default
|
||||||
.map(|ct| Box::new(ty::Const::from_anon_const(cx.tcx, ct.def_id).to_string())),
|
.map(|ct| Box::new(ty::Const::from_anon_const(cx.tcx, ct.def_id).to_string())),
|
||||||
is_host_effect: cx.tcx.has_attr(param.def_id, sym::rustc_host),
|
is_host_effect,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
@ -2536,11 +2536,12 @@ fn clean_generic_args<'tcx>(
|
|||||||
}
|
}
|
||||||
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
|
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
|
||||||
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
|
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
|
||||||
// Checking for `#[rustc_host]` on the `AnonConst` not only accounts for the case
|
// Checking for `is_desugared_from_effects` on the `AnonConst` not only accounts for the case
|
||||||
// where the argument is `host` but for all possible cases (e.g., `true`, `false`).
|
// where the argument is `host` but for all possible cases (e.g., `true`, `false`).
|
||||||
hir::GenericArg::Const(ct)
|
hir::GenericArg::Const(hir::ConstArg {
|
||||||
if cx.tcx.has_attr(ct.value.def_id, sym::rustc_host) =>
|
is_desugared_from_effects: true,
|
||||||
{
|
..
|
||||||
|
}) => {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))),
|
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))),
|
||||||
|
@ -3,15 +3,16 @@
|
|||||||
// gate-test-effects
|
// gate-test-effects
|
||||||
// ^ effects doesn't have a gate so we will trick tidy into thinking this is a gate test
|
// ^ effects doesn't have a gate so we will trick tidy into thinking this is a gate test
|
||||||
|
|
||||||
#![feature(const_trait_impl, effects, rustc_attrs)]
|
#![feature(const_trait_impl, effects, core_intrinsics, const_eval_select)]
|
||||||
|
|
||||||
// ensure we are passing in the correct host effect in always const contexts.
|
// ensure we are passing in the correct host effect in always const contexts.
|
||||||
|
|
||||||
pub const fn hmm<T, #[rustc_host] const host: bool = true>() -> usize {
|
pub const fn hmm<T>() -> usize {
|
||||||
if host {
|
// FIXME(const_trait_impl): maybe we should have a way to refer to the (hidden) effect param
|
||||||
1
|
fn one() -> usize { 1 }
|
||||||
} else {
|
const fn zero() -> usize { 0 }
|
||||||
0
|
unsafe {
|
||||||
|
std::intrinsics::const_eval_select((), zero, one)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user