@@ -44,8 +44,9 @@ use rustc_middle::ty::{
44
44
} ;
45
45
use rustc_middle:: { bug, span_bug} ;
46
46
use rustc_session:: lint:: builtin:: AMBIGUOUS_ASSOCIATED_ITEMS ;
47
+ use rustc_session:: parse:: feature_err;
47
48
use rustc_span:: edit_distance:: find_best_match_for_name;
48
- use rustc_span:: { DUMMY_SP , Ident , Span , Symbol , kw} ;
49
+ use rustc_span:: { DUMMY_SP , Ident , Span , Symbol , kw, sym } ;
49
50
use rustc_trait_selection:: infer:: InferCtxtExt ;
50
51
use rustc_trait_selection:: traits:: wf:: object_region_bounds;
51
52
use rustc_trait_selection:: traits:: { self , ObligationCtxt } ;
@@ -1174,11 +1175,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1174
1175
) ? {
1175
1176
LoweredAssoc :: Term ( def_id, args) => {
1176
1177
let assoc = tcx. associated_item ( def_id) ;
1177
- let ty = if matches ! ( assoc, ty:: AssocItem {
1178
- container: ty:: AssocItemContainer :: Impl ,
1179
- trait_item_def_id: None ,
1180
- ..
1181
- } ) {
1178
+ let ty = if matches ! (
1179
+ assoc,
1180
+ ty:: AssocItem {
1181
+ container: ty:: AssocItemContainer :: Impl ,
1182
+ trait_item_def_id: None ,
1183
+ ..
1184
+ }
1185
+ ) {
1182
1186
Ty :: new_alias ( tcx, ty:: Inherent , ty:: AliasTy :: new_from_args ( tcx, def_id, args) )
1183
1187
} else {
1184
1188
Ty :: new_projection_from_args ( tcx, def_id, args)
@@ -1478,14 +1482,29 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1478
1482
) -> Result < Option < ( DefId , GenericArgsRef < ' tcx > ) > , ErrorGuaranteed > {
1479
1483
let tcx = self . tcx ( ) ;
1480
1484
1481
- // Don't attempt to look up inherent associated types when the feature is not enabled.
1482
- // Theoretically it'd be fine to do so since we feature-gate their definition site.
1483
- // However, due to current limitations of the implementation (caused by us performing
1484
- // selection during HIR ty lowering instead of in the trait solver), IATs can lead to cycle
1485
- // errors (#108491) which mask the feature-gate error, needlessly confusing users
1486
- // who use IATs by accident (#113265).
1487
- if kind == ty:: AssocKind :: Type && !tcx. features ( ) . inherent_associated_types ( ) {
1488
- return Ok ( None ) ;
1485
+ if !tcx. features ( ) . inherent_associated_types ( ) {
1486
+ match kind {
1487
+ // Don't attempt to look up inherent associated types when the feature is not enabled.
1488
+ // Theoretically it'd be fine to do so since we feature-gate their definition site.
1489
+ // However, due to current limitations of the implementation (caused by us performing
1490
+ // selection during HIR ty lowering instead of in the trait solver), IATs can lead to cycle
1491
+ // errors (#108491) which mask the feature-gate error, needlessly confusing users
1492
+ // who use IATs by accident (#113265).
1493
+ ty:: AssocKind :: Type => return Ok ( None ) ,
1494
+ ty:: AssocKind :: Const => {
1495
+ // We also gate the mgca codepath for type-level uses of inherent consts
1496
+ // with the inherent_associated_types feature gate since it relies on the
1497
+ // same machinery and has similar rough edges.
1498
+ return Err ( feature_err (
1499
+ & tcx. sess ,
1500
+ sym:: inherent_associated_types,
1501
+ span,
1502
+ "inherent associated types are unstable" ,
1503
+ )
1504
+ . emit ( ) ) ;
1505
+ }
1506
+ ty:: AssocKind :: Fn => unreachable ! ( ) ,
1507
+ }
1489
1508
}
1490
1509
1491
1510
let name = segment. ident ;
0 commit comments