@@ -287,6 +287,7 @@ pub struct InferenceDiagnosticsData {
287
287
pub struct InferenceDiagnosticsParentData {
288
288
pub prefix : & ' static str ,
289
289
pub name : String ,
290
+ pub def_id : DefId ,
290
291
}
291
292
292
293
pub enum UnderspecifiedArgKind {
@@ -328,6 +329,7 @@ impl InferenceDiagnosticsParentData {
328
329
Some ( InferenceDiagnosticsParentData {
329
330
prefix : tcx. def_kind ( parent_def_id) . descr ( parent_def_id) ,
330
331
name : parent_name,
332
+ def_id : parent_def_id,
331
333
} )
332
334
}
333
335
}
@@ -754,12 +756,30 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
754
756
if let ( UnderspecifiedArgKind :: Const { .. } , Some ( parent_data) ) =
755
757
( & arg_data. kind , & arg_data. parent )
756
758
{
757
- err. span_suggestion_verbose (
758
- span,
759
- "consider specifying the const argument" ,
760
- format ! ( "{}::<{}>" , parent_data. name, arg_data. name) ,
761
- Applicability :: MaybeIncorrect ,
762
- ) ;
759
+ let has_impl_trait =
760
+ self . tcx . generics_of ( parent_data. def_id ) . params . iter ( ) . any ( |param| {
761
+ matches ! (
762
+ param. kind,
763
+ ty:: GenericParamDefKind :: Type {
764
+ synthetic: Some (
765
+ hir:: SyntheticTyParamKind :: ImplTrait
766
+ | hir:: SyntheticTyParamKind :: FromAttr ,
767
+ ) ,
768
+ ..
769
+ }
770
+ )
771
+ } ) ;
772
+
773
+ // (#83606): Do not emit a suggestion if the parent has an `impl Trait`
774
+ // as an argument otherwise it will cause the E0282 error.
775
+ if !has_impl_trait {
776
+ err. span_suggestion_verbose (
777
+ span,
778
+ "consider specifying the const argument" ,
779
+ format ! ( "{}::<{}>" , parent_data. name, arg_data. name) ,
780
+ Applicability :: MaybeIncorrect ,
781
+ ) ;
782
+ }
763
783
}
764
784
765
785
err. span_label (
0 commit comments