@@ -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:: {
@@ -720,7 +720,7 @@ impl<'db> AnyDiagnostic<'db> {
720720 d : & ' db InferenceDiagnostic ,
721721 source_map : & hir_def:: expr_store:: BodySourceMap ,
722722 sig_map : & hir_def:: expr_store:: ExpressionStoreSourceMap ,
723- env : ParamEnvAndCrate < ' db > ,
723+ type_owner : TypeOwnerId ,
724724 ) -> Option < AnyDiagnostic < ' db > > {
725725 let expr_syntax = |expr| {
726726 source_map
@@ -744,6 +744,7 @@ impl<'db> AnyDiagnostic<'db> {
744744 ExprOrPatId :: ExprId ( expr) => expr_syntax ( expr) ,
745745 ExprOrPatId :: PatId ( pat) => pat_syntax ( pat) ,
746746 } ;
747+ let generic_def = || def. generic_def ( db) ;
747748 let span_syntax = |span| match span {
748749 hir_ty:: Span :: ExprId ( idx) => expr_syntax ( idx) . map ( |it| it. upcast ( ) ) ,
749750 hir_ty:: Span :: PatId ( idx) => pat_syntax ( idx) . map ( |it| it. upcast ( ) ) ,
@@ -795,8 +796,11 @@ impl<'db> AnyDiagnostic<'db> {
795796 }
796797 InferenceDiagnostic :: ExpectedFunction { call_expr, found } => {
797798 let call_expr = expr_syntax ( * call_expr) ?;
798- ExpectedFunction { call : call_expr, found : Type :: new ( db, def, found. as_ref ( ) ) }
799- . into ( )
799+ ExpectedFunction {
800+ call : call_expr,
801+ found : Type :: new ( generic_def ( ) , found. as_ref ( ) ) ,
802+ }
803+ . into ( )
800804 }
801805 InferenceDiagnostic :: UnresolvedField {
802806 expr,
@@ -808,7 +812,7 @@ impl<'db> AnyDiagnostic<'db> {
808812 UnresolvedField {
809813 expr,
810814 name : name. clone ( ) ,
811- receiver : Type :: new ( db , def , receiver. as_ref ( ) ) ,
815+ receiver : Type :: new ( generic_def ( ) , receiver. as_ref ( ) ) ,
812816 method_with_same_name_exists : * method_with_same_name_exists,
813817 }
814818 . into ( )
@@ -824,10 +828,10 @@ impl<'db> AnyDiagnostic<'db> {
824828 UnresolvedMethodCall {
825829 expr,
826830 name : name. clone ( ) ,
827- receiver : Type :: new ( db , def , receiver. as_ref ( ) ) ,
831+ receiver : Type :: new ( generic_def ( ) , receiver. as_ref ( ) ) ,
828832 field_with_same_name : field_with_same_name
829833 . as_ref ( )
830- . map ( |ty| Type :: new ( db , def , ty. as_ref ( ) ) ) ,
834+ . map ( |ty| Type :: new ( generic_def ( ) , ty. as_ref ( ) ) ) ,
831835 assoc_func_with_same_name : assoc_func_with_same_name. map ( Into :: into) ,
832836 }
833837 . into ( )
@@ -857,7 +861,7 @@ impl<'db> AnyDiagnostic<'db> {
857861 }
858862 InferenceDiagnostic :: TypedHole { expr, expected } => {
859863 let expr = expr_syntax ( * expr) ?;
860- TypedHole { expr, expected : Type :: new ( db , def , expected. as_ref ( ) ) } . into ( )
864+ TypedHole { expr, expected : Type :: new ( generic_def ( ) , expected. as_ref ( ) ) } . into ( )
861865 }
862866 & InferenceDiagnostic :: MismatchedTupleStructPatArgCount { pat, expected, found } => {
863867 let InFile { file_id, value } = pat_syntax ( pat) ?;
@@ -868,12 +872,12 @@ impl<'db> AnyDiagnostic<'db> {
868872 }
869873 InferenceDiagnostic :: CastToUnsized { expr, cast_ty } => {
870874 let expr = expr_syntax ( * expr) ?;
871- CastToUnsized { expr, cast_ty : Type :: new ( db , def , cast_ty. as_ref ( ) ) } . into ( )
875+ CastToUnsized { expr, cast_ty : Type :: new ( generic_def ( ) , cast_ty. as_ref ( ) ) } . into ( )
872876 }
873877 InferenceDiagnostic :: InvalidCast { expr, error, expr_ty, cast_ty } => {
874878 let expr = expr_syntax ( * expr) ?;
875- let expr_ty = Type :: new ( db , def , expr_ty. as_ref ( ) ) ;
876- let cast_ty = Type :: new ( db , def , cast_ty. as_ref ( ) ) ;
879+ let expr_ty = Type :: new ( generic_def ( ) , expr_ty. as_ref ( ) ) ;
880+ let cast_ty = Type :: new ( generic_def ( ) , cast_ty. as_ref ( ) ) ;
877881 InvalidCast { expr, error : * error, expr_ty, cast_ty } . into ( )
878882 }
879883 InferenceDiagnostic :: TyDiagnostic { source, diag } => {
@@ -946,10 +950,9 @@ impl<'db> AnyDiagnostic<'db> {
946950 & InferenceDiagnostic :: TypeMustBeKnown { at_point, ref top_term } => {
947951 let at_point = span_syntax ( at_point) ?;
948952 let top_term = top_term. as_ref ( ) . map ( |top_term| match top_term. as_ref ( ) . kind ( ) {
949- rustc_type_ir:: GenericArgKind :: Type ( ty) => Either :: Left ( Type {
950- ty,
951- env : crate :: body_param_env_from_has_crate ( db, def) ,
952- } ) ,
953+ rustc_type_ir:: GenericArgKind :: Type ( ty) => {
954+ Either :: Left ( Type :: new ( generic_def ( ) , ty) )
955+ }
953956 // FIXME: Printing the const to string is definitely not the correct thing to do here.
954957 rustc_type_ir:: GenericArgKind :: Const ( konst) => Either :: Right (
955958 konst. display ( db, DisplayTarget :: from_crate ( db, def. krate ( db) ) ) . to_string ( ) ,
@@ -968,14 +971,14 @@ impl<'db> AnyDiagnostic<'db> {
968971 let expr_or_pat = expr_or_pat_syntax ( * node) ?;
969972 TypeMismatch {
970973 expr_or_pat,
971- expected : Type { env , ty : expected. as_ref ( ) } ,
972- actual : Type { env , ty : found. as_ref ( ) } ,
974+ expected : Type { owner : type_owner , ty : EarlyBinder :: bind ( expected. as_ref ( ) ) } ,
975+ actual : Type { owner : type_owner , ty : EarlyBinder :: bind ( found. as_ref ( ) ) } ,
973976 }
974977 . into ( )
975978 }
976979 InferenceDiagnostic :: SolverDiagnostic ( d) => {
977980 let span = span_syntax ( d. span ) ?;
978- Self :: solver_diagnostic ( db, & d. kind , span, env ) ?
981+ Self :: solver_diagnostic ( db, & d. kind , span, type_owner ) ?
979982 }
980983 } )
981984 }
@@ -984,16 +987,21 @@ impl<'db> AnyDiagnostic<'db> {
984987 db : & ' db dyn HirDatabase ,
985988 d : & ' db SolverDiagnosticKind ,
986989 span : SpanSyntax ,
987- env : ParamEnvAndCrate < ' db > ,
990+ type_owner : TypeOwnerId ,
988991 ) -> Option < AnyDiagnostic < ' db > > {
989992 let interner = DbInterner :: new_no_crate ( db) ;
990993 Some ( match d {
991994 SolverDiagnosticKind :: TraitUnimplemented { trait_predicate, root_trait_predicate } => {
992- let trait_predicate =
993- crate :: TraitPredicate { inner : trait_predicate. get ( interner) , env } ;
995+ let trait_predicate = crate :: TraitPredicate {
996+ inner : trait_predicate. get ( interner) ,
997+ owner : type_owner,
998+ } ;
994999 let root_trait_predicate =
9951000 root_trait_predicate. as_ref ( ) . map ( |root_trait_predicate| {
996- crate :: TraitPredicate { inner : root_trait_predicate. get ( interner) , env }
1001+ crate :: TraitPredicate {
1002+ inner : root_trait_predicate. get ( interner) ,
1003+ owner : type_owner,
1004+ }
9971005 } ) ;
9981006 UnimplementedTrait { span, trait_predicate, root_trait_predicate } . into ( )
9991007 }
0 commit comments