mgca: Lower all const paths as ConstArgKind::Path
When `#![feature(min_generic_const_args)]` is enabled, we now lower all const paths in generic arg position to `hir::ConstArgKind::Path`. We then lower assoc const paths to `ty::ConstKind::Unevaluated` since we can no longer use the anon const expression lowering machinery. In the process of implementing this, I factored out `hir_ty_lowering` code that is now shared between lowering assoc types and assoc consts. This PR also introduces a `#[type_const]` attribute for trait assoc consts that are allowed as const args. However, we still need to implement code to check that assoc const definitions satisfy `#[type_const]` if present (basically is it a const path or a monomorphic anon const).
This commit is contained in:
parent
2010bba886
commit
177e7ff548
35 changed files with 602 additions and 148 deletions
|
@ -14,6 +14,7 @@ use rustc_attr_parsing::{AttributeKind, ReprAttr, find_attr};
|
|||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{Applicability, DiagCtxtHandle, IntoDiagArg, MultiSpan, StashKey};
|
||||
use rustc_feature::{AttributeDuplicates, AttributeType, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute};
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::LocalModDefId;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::{
|
||||
|
@ -257,6 +258,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
[sym::coroutine, ..] => {
|
||||
self.check_coroutine(attr, target);
|
||||
}
|
||||
[sym::type_const, ..] => {
|
||||
self.check_type_const(hir_id,attr, target);
|
||||
}
|
||||
[sym::linkage, ..] => self.check_linkage(attr, span, target),
|
||||
[sym::rustc_pub_transparent, ..] => self.check_rustc_pub_transparent(attr.span(), span, attrs),
|
||||
[
|
||||
|
@ -2519,6 +2523,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_type_const(&self, hir_id: HirId, attr: &Attribute, target: Target) {
|
||||
let tcx = self.tcx;
|
||||
if target == Target::AssocConst
|
||||
&& let parent = tcx.parent(hir_id.expect_owner().to_def_id())
|
||||
&& self.tcx.def_kind(parent) == DefKind::Trait
|
||||
{
|
||||
return;
|
||||
} else {
|
||||
self.dcx()
|
||||
.struct_span_err(
|
||||
attr.span(),
|
||||
"`#[type_const]` must only be applied to trait associated constants",
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
|
||||
fn check_linkage(&self, attr: &Attribute, span: Span, target: Target) {
|
||||
match target {
|
||||
Target::Fn
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue