@@ -2955,45 +2955,39 @@ impl Analyzer<'_> {
29552955 "Remove `pure`, or change the parameter to `read` if the function does not mutate it." ,
29562956 ) ,
29572957 } ;
2958- self . diagnostics . push (
2959- Diagnostic :: error (
2960- code:: INVALID_PURE_EFFECT ,
2961- format ! (
2962- "`{}` is declared pure but parameter `{}` uses `{}`." ,
2963- function. name,
2964- param. name,
2965- param. effect. map_or( "unknown" , data_effect_name)
2966- ) ,
2967- param. span . clone ( ) ,
2968- label,
2969- )
2970- . with_cause ( cause)
2971- . with_fix ( "remove_pure_or_use_read" , fix, "manual" ) ,
2972- ) ;
2958+ self . diagnostics . push ( checks:: diagnostic_helpers:: error_cause_manual_fix (
2959+ code:: INVALID_PURE_EFFECT ,
2960+ format ! (
2961+ "`{}` is declared pure but parameter `{}` uses `{}`." ,
2962+ function. name,
2963+ param. name,
2964+ param. effect. map_or( "unknown" , data_effect_name)
2965+ ) ,
2966+ param. span . clone ( ) ,
2967+ label,
2968+ cause,
2969+ "remove_pure_or_use_read" ,
2970+ fix,
2971+ ) ) ;
29732972 }
29742973
29752974 for effect in function
29762975 . effects
29772976 . iter ( )
29782977 . filter ( |effect| matches ! ( effect, EffectDecl :: Retains ( _) ) )
29792978 {
2980- self . diagnostics . push (
2981- Diagnostic :: error (
2982- code:: INVALID_PURE_EFFECT ,
2983- format ! (
2984- "`{}` is declared pure but also retains a parameter." ,
2985- function. name
2986- ) ,
2987- function. span . clone ( ) ,
2988- "retention in pure function" ,
2989- )
2990- . with_cause ( "A `pure` function must not retain parameters after returning." )
2991- . with_fix (
2992- "remove_pure_or_retains" ,
2993- format ! ( "Remove `pure` or remove `{}`." , effect_display( effect) ) ,
2994- "manual" ,
2979+ self . diagnostics . push ( checks:: diagnostic_helpers:: error_cause_manual_fix (
2980+ code:: INVALID_PURE_EFFECT ,
2981+ format ! (
2982+ "`{}` is declared pure but also retains a parameter." ,
2983+ function. name
29952984 ) ,
2996- ) ;
2985+ function. span . clone ( ) ,
2986+ "retention in pure function" ,
2987+ "A `pure` function must not retain parameters after returning." ,
2988+ "remove_pure_or_retains" ,
2989+ format ! ( "Remove `pure` or remove `{}`." , effect_display( effect) ) ,
2990+ ) ) ;
29972991 }
29982992 }
29992993 }
@@ -4728,67 +4722,46 @@ impl Analyzer<'_> {
47284722 callee : & Callee ,
47294723 span : & crate :: diagnostic:: Span ,
47304724 ) {
4731- self . diagnostics . push (
4732- Diagnostic :: error (
4733- code:: INVALID_PURE_EFFECT ,
4734- format ! (
4735- "`{function_name}` is declared pure but calls non-pure function `{}`." ,
4736- callee_display( callee)
4737- ) ,
4738- span. clone ( ) ,
4739- "non-pure call in pure function" ,
4740- )
4741- . with_cause (
4742- "A `pure` function may only call constructors, enum variants, or functions also declared `effects(pure)`." ,
4743- )
4744- . with_fix (
4745- "remove_pure_or_call_pure" ,
4746- "Remove `pure`, or call only APIs whose signatures are declared `effects(pure)`." ,
4747- "manual" ,
4725+ self . diagnostics . push ( checks:: diagnostic_helpers:: error_cause_manual_fix (
4726+ code:: INVALID_PURE_EFFECT ,
4727+ format ! (
4728+ "`{function_name}` is declared pure but calls non-pure function `{}`." ,
4729+ callee_display( callee)
47484730 ) ,
4749- ) ;
4731+ span. clone ( ) ,
4732+ "non-pure call in pure function" ,
4733+ "A `pure` function may only call constructors, enum variants, or functions also declared `effects(pure)`." ,
4734+ "remove_pure_or_call_pure" ,
4735+ "Remove `pure`, or call only APIs whose signatures are declared `effects(pure)`." ,
4736+ ) ) ;
47504737 }
47514738
47524739 fn pure_manage_diagnostic ( & mut self , function_name : & str , span : & crate :: diagnostic:: Span ) {
4753- self . diagnostics . push (
4754- Diagnostic :: error (
4755- code:: INVALID_PURE_EFFECT ,
4756- format ! ( "`{function_name}` is declared pure but uses `manage`." ) ,
4757- span. clone ( ) ,
4758- "manage in pure function" ,
4759- )
4760- . with_cause (
4761- "`manage` consumes a local value and changes its ownership boundary; `pure` functions may observe inputs but must not consume local values." ,
4762- )
4763- . with_fix (
4764- "remove_manage_or_pure" ,
4765- "Move the `manage` operation outside the pure function, or remove `pure`." ,
4766- "manual" ,
4767- ) ,
4768- ) ;
4740+ self . diagnostics . push ( checks:: diagnostic_helpers:: error_cause_manual_fix (
4741+ code:: INVALID_PURE_EFFECT ,
4742+ format ! ( "`{function_name}` is declared pure but uses `manage`." ) ,
4743+ span. clone ( ) ,
4744+ "manage in pure function" ,
4745+ "`manage` consumes a local value and changes its ownership boundary; `pure` functions may observe inputs but must not consume local values." ,
4746+ "remove_manage_or_pure" ,
4747+ "Move the `manage` operation outside the pure function, or remove `pure`." ,
4748+ ) ) ;
47694749 }
47704750
47714751 fn pure_with_resource_diagnostic (
47724752 & mut self ,
47734753 function_name : & str ,
47744754 span : & crate :: diagnostic:: Span ,
47754755 ) {
4776- self . diagnostics . push (
4777- Diagnostic :: error (
4778- code:: INVALID_PURE_EFFECT ,
4779- format ! ( "`{function_name}` is declared pure but opens a resource scope." ) ,
4780- span. clone ( ) ,
4781- "resource scope in pure function" ,
4782- )
4783- . with_cause (
4784- "`with` introduces deterministic resource lifetime behavior; `pure` functions may observe inputs but must not open resource scopes." ,
4785- )
4786- . with_fix (
4787- "remove_with_or_pure" ,
4788- "Move resource handling outside the pure function, or remove `pure`." ,
4789- "manual" ,
4790- ) ,
4791- ) ;
4756+ self . diagnostics . push ( checks:: diagnostic_helpers:: error_cause_manual_fix (
4757+ code:: INVALID_PURE_EFFECT ,
4758+ format ! ( "`{function_name}` is declared pure but opens a resource scope." ) ,
4759+ span. clone ( ) ,
4760+ "resource scope in pure function" ,
4761+ "`with` introduces deterministic resource lifetime behavior; `pure` functions may observe inputs but must not open resource scopes." ,
4762+ "remove_with_or_pure" ,
4763+ "Move resource handling outside the pure function, or remove `pure`." ,
4764+ ) ) ;
47924765 }
47934766
47944767 fn pure_resource_return_diagnostic (
@@ -4797,24 +4770,17 @@ impl Analyzer<'_> {
47974770 span : crate :: diagnostic:: Span ,
47984771 resource_name : & str ,
47994772 ) {
4800- self . diagnostics . push (
4801- Diagnostic :: error (
4802- code:: INVALID_PURE_EFFECT ,
4803- format ! (
4804- "`{function_name}` is declared pure but returns resource `{resource_name}`."
4805- ) ,
4806- span,
4807- "resource return in pure function" ,
4808- )
4809- . with_cause (
4810- "Returning a resource creates a lifetime boundary; `pure` functions must not open or return resources." ,
4811- )
4812- . with_fix (
4813- "remove_resource_return_or_pure" ,
4814- "Return an ordinary value, or remove `pure` from the resource-producing function." ,
4815- "manual" ,
4773+ self . diagnostics . push ( checks:: diagnostic_helpers:: error_cause_manual_fix (
4774+ code:: INVALID_PURE_EFFECT ,
4775+ format ! (
4776+ "`{function_name}` is declared pure but returns resource `{resource_name}`."
48164777 ) ,
4817- ) ;
4778+ span,
4779+ "resource return in pure function" ,
4780+ "Returning a resource creates a lifetime boundary; `pure` functions must not open or return resources." ,
4781+ "remove_resource_return_or_pure" ,
4782+ "Return an ordinary value, or remove `pure` from the resource-producing function." ,
4783+ ) ) ;
48184784 }
48194785
48204786 fn resource_return_type_name < ' a > ( & self , ty : & ' a TypeRef ) -> Option < & ' a str > {
0 commit comments