@@ -29,7 +29,8 @@ use rustc_errors::{
2929} ;
3030use rustc_hir:: def:: { CtorKind , CtorOf , DefKind , Res } ;
3131use rustc_hir:: def_id:: { DefId , LocalDefId } ;
32- use rustc_hir:: { self as hir, AnonConst , GenericArg , GenericArgs , HirId } ;
32+ use rustc_hir:: { self as hir, find_attr, AnonConst , GenericArg , GenericArgs , HirId } ;
33+ use rustc_hir:: attrs:: AttributeKind ;
3334use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
3435use rustc_infer:: traits:: DynCompatibilityViolation ;
3536use rustc_macros:: { TypeFoldable , TypeVisitable } ;
@@ -1231,7 +1232,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
12311232 LowerTypeRelativePathMode :: Const ,
12321233 ) ? {
12331234 TypeRelativePath :: AssocItem ( def_id, args) => {
1234- if !tcx. associated_item ( def_id) . is_type_const_capable ( tcx ) {
1235+ if !find_attr ! ( self . tcx( ) . get_all_attrs ( def_id) , AttributeKind :: TypeConst ( _ ) ) {
12351236 let mut err = self . dcx ( ) . struct_span_err (
12361237 span,
12371238 "use of trait associated const without `#[type_const]`" ,
@@ -1672,6 +1673,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
16721673 ty:: AssocTag :: Const ,
16731674 ) {
16741675 Ok ( ( item_def_id, item_args) ) => {
1676+ if !find_attr ! ( self . tcx( ) . get_all_attrs( item_def_id) , AttributeKind :: TypeConst ( _) ) {
1677+ let mut err = self . dcx ( ) . struct_span_err (
1678+ span,
1679+ "use of `const` in the type system without `#[type_const]`" ,
1680+ ) ;
1681+ err. note ( "the declaration must be marked with `#[type_const]`" ) ;
1682+ return Const :: new_error ( self . tcx ( ) , err. emit ( ) ) ;
1683+ }
1684+
16751685 let uv = ty:: UnevaluatedConst :: new ( item_def_id, item_args) ;
16761686 Const :: new_unevaluated ( self . tcx ( ) , uv)
16771687 }
0 commit comments