@@ -14,6 +14,7 @@ use syn::Token;
14
14
15
15
pub struct RustColumn {
16
16
pub ( super ) ident : Ident ,
17
+ pub ( super ) var_name : Ident ,
17
18
pub ( super ) type_ : ColumnType ,
18
19
}
19
20
@@ -114,6 +115,9 @@ fn column_to_rust<DB: DatabaseExt>(describe: &Describe<DB>, i: usize) -> crate::
114
115
} ;
115
116
116
117
Ok ( RustColumn {
118
+ // prefix the variable name we use in `quote_query_as!()` so it doesn't conflict
119
+ // https://github.com/launchbadge/sqlx/issues/1322
120
+ var_name : quote:: format_ident!( "sqlx_query_as_{}" , decl. ident) ,
117
121
ident : decl. ident ,
118
122
type_,
119
123
} )
@@ -129,7 +133,7 @@ pub fn quote_query_as<DB: DatabaseExt>(
129
133
|(
130
134
i,
131
135
& RustColumn {
132
- ref ident ,
136
+ ref var_name ,
133
137
ref type_,
134
138
..
135
139
} ,
@@ -140,20 +144,21 @@ pub fn quote_query_as<DB: DatabaseExt>(
140
144
// binding to a `let` avoids confusing errors about
141
145
// "try expression alternatives have incompatible types"
142
146
// it doesn't seem to hurt inference in the other branches
143
- let #ident = row. try_get_unchecked:: <#type_, _>( #i) ?;
147
+ let #var_name = row. try_get_unchecked:: <#type_, _>( #i) ?;
144
148
} ,
145
149
// type was overridden to be a wildcard so we fallback to the runtime check
146
- ( true , ColumnType :: Wildcard ) => quote ! ( let #ident = row. try_get( #i) ?; ) ,
150
+ ( true , ColumnType :: Wildcard ) => quote ! ( let #var_name = row. try_get( #i) ?; ) ,
147
151
( true , ColumnType :: OptWildcard ) => {
148
- quote ! ( let #ident = row. try_get:: <:: std:: option:: Option <_>, _>( #i) ?; )
152
+ quote ! ( let #var_name = row. try_get:: <:: std:: option:: Option <_>, _>( #i) ?; )
149
153
}
150
154
// macro is the `_unchecked!()` variant so this will die in decoding if it's wrong
151
- ( false , _) => quote ! ( let #ident = row. try_get_unchecked( #i) ?; ) ,
155
+ ( false , _) => quote ! ( let #var_name = row. try_get_unchecked( #i) ?; ) ,
152
156
}
153
157
} ,
154
158
) ;
155
159
156
160
let ident = columns. iter ( ) . map ( |col| & col. ident ) ;
161
+ let var_name = columns. iter ( ) . map ( |col| & col. var_name ) ;
157
162
158
163
let db_path = DB :: db_path ( ) ;
159
164
let row_path = DB :: row_path ( ) ;
@@ -172,7 +177,7 @@ pub fn quote_query_as<DB: DatabaseExt>(
172
177
173
178
#( #instantiations) *
174
179
175
- Ok ( #out_ty { #( #ident: #ident ) , * } )
180
+ Ok ( #out_ty { #( #ident: #var_name ) , * } )
176
181
} )
177
182
}
178
183
}
0 commit comments