@@ -864,13 +864,15 @@ fn check_opaque_types<'fcx, 'tcx>(
864
864
trace ! ( "check_opaque_types: opaque_ty, {:?}, {:?}" , def_id, substs) ;
865
865
let generics = tcx. generics_of ( def_id) ;
866
866
// 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.
867
869
if generics. parent . is_none ( ) && def_id. is_local ( ) {
868
870
let opaque_hir_id = tcx. hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ;
869
871
if may_define_opaque_type ( tcx, fn_def_id, opaque_hir_id) {
870
872
trace ! ( "check_opaque_types: may define, generics={:#?}" , generics) ;
871
873
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 ( ) {
874
876
ty:: subst:: GenericArgKind :: Type ( ty) => match ty. kind {
875
877
ty:: Param ( ..) => { }
876
878
// Prevent `fn foo() -> Foo<u32>` from being defining.
@@ -882,9 +884,9 @@ fn check_opaque_types<'fcx, 'tcx>(
882
884
in defining scope",
883
885
)
884
886
. span_note (
885
- tcx. def_span ( param . def_id ) ,
887
+ tcx. def_span ( generics . param_at ( i , tcx ) . def_id ) ,
886
888
& format ! (
887
- "used non-generic type {} for \
889
+ "used non-generic type `{}` for \
888
890
generic parameter",
889
891
ty,
890
892
) ,
@@ -894,7 +896,6 @@ fn check_opaque_types<'fcx, 'tcx>(
894
896
} ,
895
897
896
898
ty:: subst:: GenericArgKind :: Lifetime ( region) => {
897
- let param_span = tcx. def_span ( param. def_id ) ;
898
899
if let ty:: ReStatic = region {
899
900
tcx. sess
900
901
. struct_span_err (
@@ -903,14 +904,14 @@ fn check_opaque_types<'fcx, 'tcx>(
903
904
in defining scope",
904
905
)
905
906
. span_label (
906
- param_span ,
907
+ tcx . def_span ( generics . param_at ( i , tcx ) . def_id ) ,
907
908
"cannot use static lifetime; use a bound lifetime \
908
909
instead or remove the lifetime parameter from the \
909
910
opaque type",
910
911
)
911
912
. emit ( ) ;
912
913
} else {
913
- seen. entry ( region) . or_default ( ) . push ( param_span ) ;
914
+ seen. entry ( region) . or_default ( ) . push ( i ) ;
914
915
}
915
916
}
916
917
@@ -924,20 +925,24 @@ fn check_opaque_types<'fcx, 'tcx>(
924
925
in defining scope",
925
926
)
926
927
. span_note (
927
- tcx. def_span ( param . def_id ) ,
928
+ tcx. def_span ( generics . param_at ( i , tcx ) . def_id ) ,
928
929
& format ! (
929
- "used non-generic const {} for \
930
+ "used non-generic const `{}` for \
930
931
generic parameter",
931
- ty ,
932
+ ct ,
932
933
) ,
933
934
)
934
935
. emit ( ) ;
935
936
}
936
937
} ,
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 ( ) ;
941
946
tcx. sess
942
947
. struct_span_err (
943
948
span,
0 commit comments