@@ -10,7 +10,7 @@ use crate::strings::{to_snake_case, to_upper_camel_case};
1010use crate :: type_:: collapse_links;
1111use crate :: type_:: error:: {
1212 IncorrectArityContext , InvalidImportKind , MissingAnnotation , ModuleValueUsageContext , Named ,
13- UnknownField , UnknownTypeHint , UnsafeRecordUpdateReason ,
13+ RecordUpdateInvalidReason , UnknownField , UnknownTypeHint , UnsafeRecordUpdateReason ,
1414} ;
1515use crate :: type_:: printer:: { Names , Printer } ;
1616use crate :: type_:: { FieldAccessUsage , error:: PatternMatchKind } ;
@@ -3096,21 +3096,43 @@ UTF-codepoint pattern matching."
30963096 } ) ,
30973097 }
30983098 }
3099- TypeError :: RecordUpdateInvalidConstructor { location } => Diagnostic {
3100- title : "Invalid record constructor" . into ( ) ,
3101- text : "Only record constructors can be used with the update syntax." . into ( ) ,
3102- hint : None ,
3103- level : Level :: Error ,
3104- location : Some ( Location {
3105- label : Label {
3106- text : Some ( "This is not a record constructor" . into ( ) ) ,
3107- span : * location,
3108- } ,
3109- path : path. clone ( ) ,
3110- src : src. clone ( ) ,
3111- extra_labels : vec ! [ ] ,
3112- } ) ,
3113- } ,
3099+ TypeError :: RecordUpdateInvalidConstructor { location, reason } => {
3100+ let ( title, text, label_text) = match reason {
3101+ RecordUpdateInvalidReason :: NoFields => (
3102+ "Invalid record update" . into ( ) ,
3103+ "This constructor has no fields to update." . into ( ) ,
3104+ "This constructor has no fields" . into ( ) ,
3105+ ) ,
3106+ RecordUpdateInvalidReason :: UnlabelledFields => (
3107+ "Invalid record update" . into ( ) ,
3108+ "Only constructors with labelled fields can be used with the update syntax." . into ( ) ,
3109+ "This constructor has no labelled fields" . into ( ) ,
3110+ ) ,
3111+ RecordUpdateInvalidReason :: WrongVariant { expected, given } => (
3112+ "Type mismatch" . into ( ) ,
3113+ wrap ( & format ! (
3114+ "The record being spread is a `{}` but you are trying to construct a `{}`." ,
3115+ given, expected
3116+ ) ) ,
3117+ format ! ( "This is a `{}`, not a `{}`" , given, expected) ,
3118+ ) ,
3119+ } ;
3120+ Diagnostic {
3121+ title,
3122+ text,
3123+ hint : None ,
3124+ level : Level :: Error ,
3125+ location : Some ( Location {
3126+ label : Label {
3127+ text : Some ( label_text) ,
3128+ span : * location,
3129+ } ,
3130+ path : path. clone ( ) ,
3131+ src : src. clone ( ) ,
3132+ extra_labels : vec ! [ ] ,
3133+ } ) ,
3134+ }
3135+ }
31143136
31153137 TypeError :: UnexpectedTypeHole { location } => Diagnostic {
31163138 title : "Unexpected type hole" . into ( ) ,
0 commit comments