@@ -21,7 +21,7 @@ use crate::{
21
21
type_:: {
22
22
self , FieldMap , ModuleValueConstructor , Type , TypeVar , TypedCallArg , ValueConstructor ,
23
23
error:: { ModuleSuggestion , VariableDeclaration , VariableOrigin } ,
24
- printer:: { Names , Printer } ,
24
+ printer:: Printer ,
25
25
} ,
26
26
} ;
27
27
use ecow:: { EcoString , eco_format} ;
@@ -1310,7 +1310,7 @@ impl<'a> AddAnnotations<'a> {
1310
1310
edits : TextEdits :: new ( line_numbers) ,
1311
1311
// We need to use the same printer for all the edits because otherwise
1312
1312
// we could get duplicate type variable names.
1313
- printer : Printer :: new ( & module. ast . names ) ,
1313
+ printer : Printer :: new_without_type_variables ( & module. ast . names ) ,
1314
1314
}
1315
1315
}
1316
1316
@@ -3545,7 +3545,9 @@ impl<'a> GenerateDynamicDecoder<'a> {
3545
3545
params : & ' a CodeActionParams ,
3546
3546
actions : & ' a mut Vec < CodeAction > ,
3547
3547
) -> Self {
3548
- let printer = Printer :: new ( & module. ast . names ) ;
3548
+ // Since we are generating a new function, type variables from other
3549
+ // functions and constants are irrelevant to the types we print.
3550
+ let printer = Printer :: new_without_type_variables ( & module. ast . names ) ;
3549
3551
Self {
3550
3552
module,
3551
3553
params,
@@ -3633,7 +3635,7 @@ impl<'a> GenerateDynamicDecoder<'a> {
3633
3635
}
3634
3636
3635
3637
let mut decoder_printer = DecoderPrinter :: new (
3636
- & self . module . ast . names ,
3638
+ & mut self . printer ,
3637
3639
custom_type. name . clone ( ) ,
3638
3640
self . module . name . clone ( ) ,
3639
3641
) ;
@@ -3741,8 +3743,8 @@ fn maybe_import(edits: &mut TextEdits<'_>, module: &Module, module_name: &str) {
3741
3743
) ) ;
3742
3744
}
3743
3745
3744
- struct DecoderPrinter < ' a > {
3745
- printer : Printer < ' a > ,
3746
+ struct DecoderPrinter < ' a , ' b > {
3747
+ printer : & ' a mut Printer < ' b > ,
3746
3748
/// The name of the root type we are printing a decoder for
3747
3749
type_name : EcoString ,
3748
3750
/// The module name of the root type we are printing a decoder for
@@ -3792,12 +3794,12 @@ impl RecordLabel<'_> {
3792
3794
}
3793
3795
}
3794
3796
3795
- impl < ' a > DecoderPrinter < ' a > {
3796
- fn new ( names : & ' a Names , type_name : EcoString , type_module : EcoString ) -> Self {
3797
+ impl < ' a , ' b > DecoderPrinter < ' a , ' b > {
3798
+ fn new ( printer : & ' a mut Printer < ' b > , type_name : EcoString , type_module : EcoString ) -> Self {
3797
3799
Self {
3798
3800
type_name,
3799
3801
type_module,
3800
- printer : Printer :: new ( names ) ,
3802
+ printer,
3801
3803
}
3802
3804
}
3803
3805
@@ -3937,7 +3939,9 @@ impl<'a> GenerateJsonEncoder<'a> {
3937
3939
actions : & ' a mut Vec < CodeAction > ,
3938
3940
config : & ' a PackageConfig ,
3939
3941
) -> Self {
3940
- let printer = Printer :: new ( & module. ast . names ) ;
3942
+ // Since we are generating a new function, type variables from other
3943
+ // functions and constants are irrelevant to the types we print.
3944
+ let printer = Printer :: new_without_type_variables ( & module. ast . names ) ;
3941
3945
Self {
3942
3946
module,
3943
3947
params,
@@ -4041,7 +4045,7 @@ impl<'a> GenerateJsonEncoder<'a> {
4041
4045
4042
4046
// Otherwise we turn it into an object with a `type` tag field.
4043
4047
let mut encoder_printer =
4044
- JsonEncoderPrinter :: new ( & self . module . ast . names , type_name, self . module . name . clone ( ) ) ;
4048
+ JsonEncoderPrinter :: new ( & mut self . printer , type_name, self . module . name . clone ( ) ) ;
4045
4049
4046
4050
// These are the fields of the json object to encode.
4047
4051
let mut fields = Vec :: with_capacity ( constructor. arguments . len ( ) ) ;
@@ -4126,20 +4130,20 @@ fn {name}({record_name}: {type_}) -> {json_type} {{
4126
4130
}
4127
4131
}
4128
4132
4129
- struct JsonEncoderPrinter < ' a > {
4130
- printer : Printer < ' a > ,
4133
+ struct JsonEncoderPrinter < ' a , ' b > {
4134
+ printer : & ' a mut Printer < ' b > ,
4131
4135
/// The name of the root type we are printing an encoder for
4132
4136
type_name : EcoString ,
4133
4137
/// The module name of the root type we are printing an encoder for
4134
4138
type_module : EcoString ,
4135
4139
}
4136
4140
4137
- impl < ' a > JsonEncoderPrinter < ' a > {
4138
- fn new ( names : & ' a Names , type_name : EcoString , type_module : EcoString ) -> Self {
4141
+ impl < ' a , ' b > JsonEncoderPrinter < ' a , ' b > {
4142
+ fn new ( printer : & ' a mut Printer < ' b > , type_name : EcoString , type_module : EcoString ) -> Self {
4139
4143
Self {
4140
4144
type_name,
4141
4145
type_module,
4142
- printer : Printer :: new ( names ) ,
4146
+ printer,
4143
4147
}
4144
4148
}
4145
4149
@@ -4982,7 +4986,10 @@ impl<'a> GenerateFunction<'a> {
4982
4986
// generators to avoid renaming a label in case it shares a name with an argument.
4983
4987
let mut label_names = NameGenerator :: new ( ) ;
4984
4988
let mut argument_names = NameGenerator :: new ( ) ;
4985
- let mut printer = Printer :: new ( & self . module . ast . names ) ;
4989
+
4990
+ // Since we are generating a new function, type variables from other
4991
+ // functions and constants are irrelevant to the types we print.
4992
+ let mut printer = Printer :: new_without_type_variables ( & self . module . ast . names ) ;
4986
4993
let arguments = arguments_types
4987
4994
. iter ( )
4988
4995
. enumerate ( )
0 commit comments