@@ -864,13 +864,15 @@ fn check_opaque_types<'fcx, 'tcx>(
864864 trace ! ( "check_opaque_types: opaque_ty, {:?}, {:?}" , def_id, substs) ;
865865 let generics = tcx. generics_of ( def_id) ;
866866 // Only check named `impl Trait` types defined in this crate.
867+ // FIXME(eddyb) is `generics.parent.is_none()` correct? It seems
868+ // potentially risky wrt associated types in `impl`s.
867869 if generics. parent . is_none ( ) && def_id. is_local ( ) {
868870 let opaque_hir_id = tcx. hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ;
869871 if may_define_opaque_type ( tcx, fn_def_id, opaque_hir_id) {
870872 trace ! ( "check_opaque_types: may define, generics={:#?}" , generics) ;
871873 let mut seen: FxHashMap < _ , Vec < _ > > = FxHashMap :: default ( ) ;
872- for ( subst , param ) in substs. iter ( ) . zip ( & generics . params ) {
873- match subst . unpack ( ) {
874+ for ( i , & arg ) in substs. iter ( ) . enumerate ( ) {
875+ match arg . unpack ( ) {
874876 ty:: subst:: GenericArgKind :: Type ( ty) => match ty. kind {
875877 ty:: Param ( ..) => { }
876878 // Prevent `fn foo() -> Foo<u32>` from being defining.
@@ -882,9 +884,9 @@ fn check_opaque_types<'fcx, 'tcx>(
882884 in defining scope",
883885 )
884886 . span_note (
885- tcx. def_span ( param . def_id ) ,
887+ tcx. def_span ( generics . param_at ( i , tcx ) . def_id ) ,
886888 & format ! (
887- "used non-generic type {} for \
889+ "used non-generic type `{}` for \
888890 generic parameter",
889891 ty,
890892 ) ,
@@ -894,7 +896,6 @@ fn check_opaque_types<'fcx, 'tcx>(
894896 } ,
895897
896898 ty:: subst:: GenericArgKind :: Lifetime ( region) => {
897- let param_span = tcx. def_span ( param. def_id ) ;
898899 if let ty:: ReStatic = region {
899900 tcx. sess
900901 . struct_span_err (
@@ -903,14 +904,14 @@ fn check_opaque_types<'fcx, 'tcx>(
903904 in defining scope",
904905 )
905906 . span_label (
906- param_span ,
907+ tcx . def_span ( generics . param_at ( i , tcx ) . def_id ) ,
907908 "cannot use static lifetime; use a bound lifetime \
908909 instead or remove the lifetime parameter from the \
909910 opaque type",
910911 )
911912 . emit ( ) ;
912913 } else {
913- seen. entry ( region) . or_default ( ) . push ( param_span ) ;
914+ seen. entry ( region) . or_default ( ) . push ( i ) ;
914915 }
915916 }
916917
@@ -924,20 +925,24 @@ fn check_opaque_types<'fcx, 'tcx>(
924925 in defining scope",
925926 )
926927 . span_note (
927- tcx. def_span ( param . def_id ) ,
928+ tcx. def_span ( generics . param_at ( i , tcx ) . def_id ) ,
928929 & format ! (
929- "used non-generic const {} for \
930+ "used non-generic const `{}` for \
930931 generic parameter",
931- ty ,
932+ ct ,
932933 ) ,
933934 )
934935 . emit ( ) ;
935936 }
936937 } ,
937- } // match subst
938- } // for (subst, param)
939- for ( _, spans) in seen {
940- if spans. len ( ) > 1 {
938+ } // match arg
939+ } // for (arg, param)
940+ for ( _, indices) in seen {
941+ if indices. len ( ) > 1 {
942+ let spans: Vec < _ > = indices
943+ . into_iter ( )
944+ . map ( |i| tcx. def_span ( generics. param_at ( i, tcx) . def_id ) )
945+ . collect ( ) ;
941946 tcx. sess
942947 . struct_span_err (
943948 span,
0 commit comments