@@ -16,12 +16,11 @@ use hir_def::{
1616use hir_expand:: { HirFileId , InFile , mod_path:: ModPath , name:: Name } ;
1717use hir_ty:: {
1818 CastError , ExplicitDropMethodUseKind , InferenceDiagnostic , InferenceTyDiagnosticSource ,
19- ParamEnvAndCrate , PathGenericsSource , PathLoweringDiagnostic , TyLoweringDiagnostic ,
20- TyLoweringDiagnosticKind ,
19+ PathGenericsSource , PathLoweringDiagnostic , TyLoweringDiagnostic , TyLoweringDiagnosticKind ,
2120 db:: HirDatabase ,
2221 diagnostics:: { BodyValidationDiagnostic , UnsafetyReason } ,
2322 display:: { DisplayTarget , HirDisplay } ,
24- next_solver:: DbInterner ,
23+ next_solver:: { DbInterner , EarlyBinder } ,
2524 solver_errors:: SolverDiagnosticKind ,
2625} ;
2726use stdx:: { impl_from, never} ;
@@ -32,7 +31,7 @@ use syntax::{
3231} ;
3332use triomphe:: Arc ;
3433
35- use crate :: { AssocItem , Field , Function , GenericDef , Local , Trait , Type , Variant } ;
34+ use crate :: { AssocItem , Field , Function , GenericDef , Local , Trait , Type , TypeOwnerId , Variant } ;
3635
3736pub use hir_def:: VariantId ;
3837pub use hir_ty:: {
@@ -772,7 +771,7 @@ impl<'db> AnyDiagnostic<'db> {
772771 d : & ' db InferenceDiagnostic ,
773772 source_map : & hir_def:: expr_store:: BodySourceMap ,
774773 sig_map : & hir_def:: expr_store:: ExpressionStoreSourceMap ,
775- env : ParamEnvAndCrate < ' db > ,
774+ type_owner : TypeOwnerId ,
776775 ) -> Option < AnyDiagnostic < ' db > > {
777776 let expr_syntax = |expr| {
778777 source_map
@@ -796,6 +795,7 @@ impl<'db> AnyDiagnostic<'db> {
796795 ExprOrPatId :: ExprId ( expr) => expr_syntax ( expr) ,
797796 ExprOrPatId :: PatId ( pat) => pat_syntax ( pat) ,
798797 } ;
798+ let new_ty = |ty| Type { owner : type_owner, ty : EarlyBinder :: bind ( ty) } ;
799799 let span_syntax = |span| match span {
800800 hir_ty:: Span :: ExprId ( idx) => expr_syntax ( idx) . map ( |it| it. upcast ( ) ) ,
801801 hir_ty:: Span :: PatId ( idx) => pat_syntax ( idx) . map ( |it| it. upcast ( ) ) ,
@@ -825,7 +825,11 @@ impl<'db> AnyDiagnostic<'db> {
825825 }
826826 InferenceDiagnostic :: ExpectedArrayOrSlicePat { pat, found } => {
827827 let pat = pat_syntax ( * pat) ?. map ( Into :: into) ;
828- ExpectedArrayOrSlicePat { pat, found : Type :: new ( db, def, found. as_ref ( ) ) } . into ( )
828+ ExpectedArrayOrSlicePat {
829+ pat,
830+ found : Type { owner : type_owner, ty : EarlyBinder :: bind ( found. as_ref ( ) ) } ,
831+ }
832+ . into ( )
829833 }
830834 & InferenceDiagnostic :: InvalidRangePatType { pat } => {
831835 let pat = pat_syntax ( pat) ?. map ( Into :: into) ;
@@ -855,8 +859,7 @@ impl<'db> AnyDiagnostic<'db> {
855859 }
856860 InferenceDiagnostic :: ExpectedFunction { call_expr, found } => {
857861 let call_expr = expr_syntax ( * call_expr) ?;
858- ExpectedFunction { call : call_expr, found : Type :: new ( db, def, found. as_ref ( ) ) }
859- . into ( )
862+ ExpectedFunction { call : call_expr, found : new_ty ( found. as_ref ( ) ) } . into ( )
860863 }
861864 InferenceDiagnostic :: UnresolvedField {
862865 expr,
@@ -868,7 +871,7 @@ impl<'db> AnyDiagnostic<'db> {
868871 UnresolvedField {
869872 expr,
870873 name : name. clone ( ) ,
871- receiver : Type :: new ( db , def , receiver. as_ref ( ) ) ,
874+ receiver : new_ty ( receiver. as_ref ( ) ) ,
872875 method_with_same_name_exists : * method_with_same_name_exists,
873876 }
874877 . into ( )
@@ -884,10 +887,10 @@ impl<'db> AnyDiagnostic<'db> {
884887 UnresolvedMethodCall {
885888 expr,
886889 name : name. clone ( ) ,
887- receiver : Type :: new ( db , def , receiver. as_ref ( ) ) ,
890+ receiver : new_ty ( receiver. as_ref ( ) ) ,
888891 field_with_same_name : field_with_same_name
889892 . as_ref ( )
890- . map ( |ty| Type :: new ( db , def , ty. as_ref ( ) ) ) ,
893+ . map ( |ty| new_ty ( ty. as_ref ( ) ) ) ,
891894 assoc_func_with_same_name : assoc_func_with_same_name. map ( Into :: into) ,
892895 }
893896 . into ( )
@@ -924,7 +927,7 @@ impl<'db> AnyDiagnostic<'db> {
924927 }
925928 InferenceDiagnostic :: TypedHole { expr, expected } => {
926929 let expr = expr_syntax ( * expr) ?;
927- TypedHole { expr, expected : Type :: new ( db , def , expected. as_ref ( ) ) } . into ( )
930+ TypedHole { expr, expected : new_ty ( expected. as_ref ( ) ) } . into ( )
928931 }
929932 & InferenceDiagnostic :: MismatchedTupleStructPatArgCount { pat, expected, found } => {
930933 let InFile { file_id, value } = pat_syntax ( pat) ?;
@@ -935,17 +938,17 @@ impl<'db> AnyDiagnostic<'db> {
935938 }
936939 InferenceDiagnostic :: CastToUnsized { expr, cast_ty } => {
937940 let expr = expr_syntax ( * expr) ?;
938- CastToUnsized { expr, cast_ty : Type :: new ( db , def , cast_ty. as_ref ( ) ) } . into ( )
941+ CastToUnsized { expr, cast_ty : new_ty ( cast_ty. as_ref ( ) ) } . into ( )
939942 }
940943 InferenceDiagnostic :: InvalidCast { expr, error, expr_ty, cast_ty } => {
941944 let expr = expr_syntax ( * expr) ?;
942- let expr_ty = Type :: new ( db , def , expr_ty. as_ref ( ) ) ;
943- let cast_ty = Type :: new ( db , def , cast_ty. as_ref ( ) ) ;
945+ let expr_ty = new_ty ( expr_ty. as_ref ( ) ) ;
946+ let cast_ty = new_ty ( cast_ty. as_ref ( ) ) ;
944947 InvalidCast { expr, error : * error, expr_ty, cast_ty } . into ( )
945948 }
946949 InferenceDiagnostic :: CannotBeDereferenced { expr, found } => {
947950 let expr = expr_syntax ( * expr) ?;
948- CannotBeDereferenced { expr, found : Type :: new ( db , def , found. as_ref ( ) ) } . into ( )
951+ CannotBeDereferenced { expr, found : new_ty ( found. as_ref ( ) ) } . into ( )
949952 }
950953 InferenceDiagnostic :: TyDiagnostic { source, diag } => {
951954 let source_map = match source {
@@ -1020,10 +1023,7 @@ impl<'db> AnyDiagnostic<'db> {
10201023 & InferenceDiagnostic :: TypeMustBeKnown { at_point, ref top_term } => {
10211024 let at_point = span_syntax ( at_point) ?;
10221025 let top_term = top_term. as_ref ( ) . map ( |top_term| match top_term. as_ref ( ) . kind ( ) {
1023- rustc_type_ir:: GenericArgKind :: Type ( ty) => Either :: Left ( Type {
1024- ty,
1025- env : crate :: body_param_env_from_has_crate ( db, def) ,
1026- } ) ,
1026+ rustc_type_ir:: GenericArgKind :: Type ( ty) => Either :: Left ( new_ty ( ty) ) ,
10271027 // FIXME: Printing the const to string is definitely not the correct thing to do here.
10281028 rustc_type_ir:: GenericArgKind :: Const ( konst) => Either :: Right (
10291029 konst. display ( db, DisplayTarget :: from_crate ( db, def. krate ( db) ) ) . to_string ( ) ,
@@ -1042,14 +1042,14 @@ impl<'db> AnyDiagnostic<'db> {
10421042 let expr_or_pat = expr_or_pat_syntax ( * node) ?;
10431043 TypeMismatch {
10441044 expr_or_pat,
1045- expected : Type { env , ty : expected. as_ref ( ) } ,
1046- actual : Type { env , ty : found. as_ref ( ) } ,
1045+ expected : Type { owner : type_owner , ty : EarlyBinder :: bind ( expected. as_ref ( ) ) } ,
1046+ actual : Type { owner : type_owner , ty : EarlyBinder :: bind ( found. as_ref ( ) ) } ,
10471047 }
10481048 . into ( )
10491049 }
10501050 InferenceDiagnostic :: SolverDiagnostic ( d) => {
10511051 let span = span_syntax ( d. span ) ?;
1052- Self :: solver_diagnostic ( db, & d. kind , span, env ) ?
1052+ Self :: solver_diagnostic ( db, & d. kind , span, type_owner ) ?
10531053 }
10541054 InferenceDiagnostic :: ExplicitDropMethodUse { kind } => {
10551055 let expr_or_path = match kind {
@@ -1077,16 +1077,21 @@ impl<'db> AnyDiagnostic<'db> {
10771077 db : & ' db dyn HirDatabase ,
10781078 d : & ' db SolverDiagnosticKind ,
10791079 span : SpanSyntax ,
1080- env : ParamEnvAndCrate < ' db > ,
1080+ type_owner : TypeOwnerId ,
10811081 ) -> Option < AnyDiagnostic < ' db > > {
10821082 let interner = DbInterner :: new_no_crate ( db) ;
10831083 Some ( match d {
10841084 SolverDiagnosticKind :: TraitUnimplemented { trait_predicate, root_trait_predicate } => {
1085- let trait_predicate =
1086- crate :: TraitPredicate { inner : trait_predicate. get ( interner) , env } ;
1085+ let trait_predicate = crate :: TraitPredicate {
1086+ inner : trait_predicate. get ( interner) ,
1087+ owner : type_owner,
1088+ } ;
10871089 let root_trait_predicate =
10881090 root_trait_predicate. as_ref ( ) . map ( |root_trait_predicate| {
1089- crate :: TraitPredicate { inner : root_trait_predicate. get ( interner) , env }
1091+ crate :: TraitPredicate {
1092+ inner : root_trait_predicate. get ( interner) ,
1093+ owner : type_owner,
1094+ }
10901095 } ) ;
10911096 UnimplementedTrait { span, trait_predicate, root_trait_predicate } . into ( )
10921097 }
0 commit comments