@@ -15,12 +15,12 @@ use hir_def::{
1515} ;
1616use hir_expand:: { HirFileId , InFile , mod_path:: ModPath , name:: Name } ;
1717use hir_ty:: {
18- CastError , InferenceDiagnostic , InferenceTyDiagnosticSource , ParamEnvAndCrate ,
19- PathGenericsSource , PathLoweringDiagnostic , TyLoweringDiagnostic , TyLoweringDiagnosticKind ,
18+ CastError , InferenceDiagnostic , InferenceTyDiagnosticSource , PathGenericsSource ,
19+ PathLoweringDiagnostic , TyLoweringDiagnostic , TyLoweringDiagnosticKind ,
2020 db:: HirDatabase ,
2121 diagnostics:: { BodyValidationDiagnostic , UnsafetyReason } ,
2222 display:: { DisplayTarget , HirDisplay } ,
23- next_solver:: DbInterner ,
23+ next_solver:: { DbInterner , EarlyBinder } ,
2424 solver_errors:: SolverDiagnosticKind ,
2525} ;
2626use stdx:: { impl_from, never} ;
@@ -31,7 +31,7 @@ use syntax::{
3131} ;
3232use triomphe:: Arc ;
3333
34- use crate :: { AssocItem , Field , Function , GenericDef , Local , Trait , Type , Variant } ;
34+ use crate :: { AssocItem , Field , Function , GenericDef , Local , Trait , Type , TypeOwnerId , Variant } ;
3535
3636pub use hir_def:: VariantId ;
3737pub use hir_ty:: {
@@ -733,7 +733,7 @@ impl<'db> AnyDiagnostic<'db> {
733733 d : & ' db InferenceDiagnostic ,
734734 source_map : & hir_def:: expr_store:: BodySourceMap ,
735735 sig_map : & hir_def:: expr_store:: ExpressionStoreSourceMap ,
736- env : ParamEnvAndCrate < ' db > ,
736+ type_owner : TypeOwnerId ,
737737 ) -> Option < AnyDiagnostic < ' db > > {
738738 let expr_syntax = |expr| {
739739 source_map
@@ -757,6 +757,7 @@ impl<'db> AnyDiagnostic<'db> {
757757 ExprOrPatId :: ExprId ( expr) => expr_syntax ( expr) ,
758758 ExprOrPatId :: PatId ( pat) => pat_syntax ( pat) ,
759759 } ;
760+ let generic_def = || def. generic_def ( db) ;
760761 let span_syntax = |span| match span {
761762 hir_ty:: Span :: ExprId ( idx) => expr_syntax ( idx) . map ( |it| it. upcast ( ) ) ,
762763 hir_ty:: Span :: PatId ( idx) => pat_syntax ( idx) . map ( |it| it. upcast ( ) ) ,
@@ -786,7 +787,11 @@ impl<'db> AnyDiagnostic<'db> {
786787 }
787788 InferenceDiagnostic :: ExpectedArrayOrSlicePat { pat, found } => {
788789 let pat = pat_syntax ( * pat) ?. map ( Into :: into) ;
789- ExpectedArrayOrSlicePat { pat, found : Type :: new ( db, def, found. as_ref ( ) ) } . into ( )
790+ ExpectedArrayOrSlicePat {
791+ pat,
792+ found : Type { owner : type_owner, ty : EarlyBinder :: bind ( found. as_ref ( ) ) } ,
793+ }
794+ . into ( )
790795 }
791796 & InferenceDiagnostic :: DuplicateField { field : expr, variant } => {
792797 let expr_or_pat = match expr {
@@ -812,8 +817,11 @@ impl<'db> AnyDiagnostic<'db> {
812817 }
813818 InferenceDiagnostic :: ExpectedFunction { call_expr, found } => {
814819 let call_expr = expr_syntax ( * call_expr) ?;
815- ExpectedFunction { call : call_expr, found : Type :: new ( db, def, found. as_ref ( ) ) }
816- . into ( )
820+ ExpectedFunction {
821+ call : call_expr,
822+ found : Type :: new ( generic_def ( ) , found. as_ref ( ) ) ,
823+ }
824+ . into ( )
817825 }
818826 InferenceDiagnostic :: UnresolvedField {
819827 expr,
@@ -825,7 +833,7 @@ impl<'db> AnyDiagnostic<'db> {
825833 UnresolvedField {
826834 expr,
827835 name : name. clone ( ) ,
828- receiver : Type :: new ( db , def , receiver. as_ref ( ) ) ,
836+ receiver : Type :: new ( generic_def ( ) , receiver. as_ref ( ) ) ,
829837 method_with_same_name_exists : * method_with_same_name_exists,
830838 }
831839 . into ( )
@@ -841,10 +849,10 @@ impl<'db> AnyDiagnostic<'db> {
841849 UnresolvedMethodCall {
842850 expr,
843851 name : name. clone ( ) ,
844- receiver : Type :: new ( db , def , receiver. as_ref ( ) ) ,
852+ receiver : Type :: new ( generic_def ( ) , receiver. as_ref ( ) ) ,
845853 field_with_same_name : field_with_same_name
846854 . as_ref ( )
847- . map ( |ty| Type :: new ( db , def , ty. as_ref ( ) ) ) ,
855+ . map ( |ty| Type :: new ( generic_def ( ) , ty. as_ref ( ) ) ) ,
848856 assoc_func_with_same_name : assoc_func_with_same_name. map ( Into :: into) ,
849857 }
850858 . into ( )
@@ -877,7 +885,7 @@ impl<'db> AnyDiagnostic<'db> {
877885 }
878886 InferenceDiagnostic :: TypedHole { expr, expected } => {
879887 let expr = expr_syntax ( * expr) ?;
880- TypedHole { expr, expected : Type :: new ( db , def , expected. as_ref ( ) ) } . into ( )
888+ TypedHole { expr, expected : Type :: new ( generic_def ( ) , expected. as_ref ( ) ) } . into ( )
881889 }
882890 & InferenceDiagnostic :: MismatchedTupleStructPatArgCount { pat, expected, found } => {
883891 let InFile { file_id, value } = pat_syntax ( pat) ?;
@@ -888,12 +896,12 @@ impl<'db> AnyDiagnostic<'db> {
888896 }
889897 InferenceDiagnostic :: CastToUnsized { expr, cast_ty } => {
890898 let expr = expr_syntax ( * expr) ?;
891- CastToUnsized { expr, cast_ty : Type :: new ( db , def , cast_ty. as_ref ( ) ) } . into ( )
899+ CastToUnsized { expr, cast_ty : Type :: new ( generic_def ( ) , cast_ty. as_ref ( ) ) } . into ( )
892900 }
893901 InferenceDiagnostic :: InvalidCast { expr, error, expr_ty, cast_ty } => {
894902 let expr = expr_syntax ( * expr) ?;
895- let expr_ty = Type :: new ( db , def , expr_ty. as_ref ( ) ) ;
896- let cast_ty = Type :: new ( db , def , cast_ty. as_ref ( ) ) ;
903+ let expr_ty = Type :: new ( generic_def ( ) , expr_ty. as_ref ( ) ) ;
904+ let cast_ty = Type :: new ( generic_def ( ) , cast_ty. as_ref ( ) ) ;
897905 InvalidCast { expr, error : * error, expr_ty, cast_ty } . into ( )
898906 }
899907 InferenceDiagnostic :: TyDiagnostic { source, diag } => {
@@ -966,10 +974,9 @@ impl<'db> AnyDiagnostic<'db> {
966974 & InferenceDiagnostic :: TypeMustBeKnown { at_point, ref top_term } => {
967975 let at_point = span_syntax ( at_point) ?;
968976 let top_term = top_term. as_ref ( ) . map ( |top_term| match top_term. as_ref ( ) . kind ( ) {
969- rustc_type_ir:: GenericArgKind :: Type ( ty) => Either :: Left ( Type {
970- ty,
971- env : crate :: body_param_env_from_has_crate ( db, def) ,
972- } ) ,
977+ rustc_type_ir:: GenericArgKind :: Type ( ty) => {
978+ Either :: Left ( Type :: new ( generic_def ( ) , ty) )
979+ }
973980 // FIXME: Printing the const to string is definitely not the correct thing to do here.
974981 rustc_type_ir:: GenericArgKind :: Const ( konst) => Either :: Right (
975982 konst. display ( db, DisplayTarget :: from_crate ( db, def. krate ( db) ) ) . to_string ( ) ,
@@ -988,14 +995,14 @@ impl<'db> AnyDiagnostic<'db> {
988995 let expr_or_pat = expr_or_pat_syntax ( * node) ?;
989996 TypeMismatch {
990997 expr_or_pat,
991- expected : Type { env , ty : expected. as_ref ( ) } ,
992- actual : Type { env , ty : found. as_ref ( ) } ,
998+ expected : Type { owner : type_owner , ty : EarlyBinder :: bind ( expected. as_ref ( ) ) } ,
999+ actual : Type { owner : type_owner , ty : EarlyBinder :: bind ( found. as_ref ( ) ) } ,
9931000 }
9941001 . into ( )
9951002 }
9961003 InferenceDiagnostic :: SolverDiagnostic ( d) => {
9971004 let span = span_syntax ( d. span ) ?;
998- Self :: solver_diagnostic ( db, & d. kind , span, env ) ?
1005+ Self :: solver_diagnostic ( db, & d. kind , span, type_owner ) ?
9991006 }
10001007 } )
10011008 }
@@ -1004,16 +1011,21 @@ impl<'db> AnyDiagnostic<'db> {
10041011 db : & ' db dyn HirDatabase ,
10051012 d : & ' db SolverDiagnosticKind ,
10061013 span : SpanSyntax ,
1007- env : ParamEnvAndCrate < ' db > ,
1014+ type_owner : TypeOwnerId ,
10081015 ) -> Option < AnyDiagnostic < ' db > > {
10091016 let interner = DbInterner :: new_no_crate ( db) ;
10101017 Some ( match d {
10111018 SolverDiagnosticKind :: TraitUnimplemented { trait_predicate, root_trait_predicate } => {
1012- let trait_predicate =
1013- crate :: TraitPredicate { inner : trait_predicate. get ( interner) , env } ;
1019+ let trait_predicate = crate :: TraitPredicate {
1020+ inner : trait_predicate. get ( interner) ,
1021+ owner : type_owner,
1022+ } ;
10141023 let root_trait_predicate =
10151024 root_trait_predicate. as_ref ( ) . map ( |root_trait_predicate| {
1016- crate :: TraitPredicate { inner : root_trait_predicate. get ( interner) , env }
1025+ crate :: TraitPredicate {
1026+ inner : root_trait_predicate. get ( interner) ,
1027+ owner : type_owner,
1028+ }
10171029 } ) ;
10181030 UnimplementedTrait { span, trait_predicate, root_trait_predicate } . into ( )
10191031 }
0 commit comments