@@ -444,6 +444,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
444444 }
445445
446446 self . suggest_bare_struct_literal ( & mut err) ;
447+ self . suggest_changing_type_to_const_param ( & mut err, res, source, span) ;
447448
448449 if self . suggest_pattern_match_with_let ( & mut err, source, span) {
449450 // Fallback label.
@@ -1138,6 +1139,55 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
11381139 }
11391140 }
11401141
1142+ fn suggest_changing_type_to_const_param (
1143+ & mut self ,
1144+ err : & mut Diagnostic ,
1145+ res : Option < Res > ,
1146+ source : PathSource < ' _ > ,
1147+ span : Span ,
1148+ ) {
1149+ let PathSource :: Trait ( _) = source else { return } ;
1150+
1151+ // We don't include `DefKind::Str` and `DefKind::AssocKind` as they can't be reached here anyway.
1152+ let applicability = match res {
1153+ Some ( Res :: PrimTy ( PrimTy :: Int ( _) | PrimTy :: Uint ( _) | PrimTy :: Bool | PrimTy :: Char ) ) => {
1154+ Applicability :: MachineApplicable
1155+ }
1156+ // FIXME(const_generics): Add `DefKind::TyParam` and `SelfTyParam` once we support generic
1157+ // const generics. Of course, `Struct` and `Enum` may contain ty params, too, but the
1158+ // benefits of including them here outweighs the small number of false positives.
1159+ Some ( Res :: Def ( DefKind :: Struct | DefKind :: Enum , _) )
1160+ if self . r . tcx . features ( ) . adt_const_params =>
1161+ {
1162+ Applicability :: MaybeIncorrect
1163+ }
1164+ _ => return ,
1165+ } ;
1166+
1167+ let Some ( item) = self . diagnostic_metadata . current_item else { return } ;
1168+ let Some ( generics) = item. kind . generics ( ) else { return } ;
1169+
1170+ let param = generics. params . iter ( ) . find_map ( |param| {
1171+ // Only consider type params with exactly one trait bound.
1172+ if let [ bound] = & * param. bounds
1173+ && let ast:: GenericBound :: Trait ( tref, ast:: TraitBoundModifiers :: NONE ) = bound
1174+ && tref. span == span
1175+ && param. ident . span . eq_ctxt ( span)
1176+ {
1177+ Some ( param. ident . span )
1178+ } else {
1179+ None
1180+ }
1181+ } ) ;
1182+
1183+ if let Some ( param) = param {
1184+ err. subdiagnostic ( errors:: UnexpectedResChangeTyToConstParamSugg {
1185+ span : param. shrink_to_lo ( ) ,
1186+ applicability,
1187+ } ) ;
1188+ }
1189+ }
1190+
11411191 fn suggest_pattern_match_with_let (
11421192 & mut self ,
11431193 err : & mut Diagnostic ,
0 commit comments