@@ -227,9 +227,8 @@ fn get_transformed_assoc_item(
227227 assoc_item : ast:: AssocItem ,
228228 impl_def : hir:: Impl ,
229229) -> Option < ast:: AssocItem > {
230- let assoc_item = assoc_item. clone_for_update ( ) ;
231230 let trait_ = impl_def. trait_ ( ctx. db ) ?;
232- let source_scope = & ctx. sema . scope_for_def ( trait_ ) ;
231+ let source_scope = & ctx. sema . scope ( assoc_item . syntax ( ) ) ? ;
233232 let target_scope = & ctx. sema . scope ( ctx. sema . source ( impl_def) ?. syntax ( ) . value ) ?;
234233 let transform = PathTransform :: trait_impl (
235234 target_scope,
@@ -238,6 +237,9 @@ fn get_transformed_assoc_item(
238237 ctx. sema . source ( impl_def) ?. value ,
239238 ) ;
240239
240+ let assoc_item = assoc_item. clone_for_update ( ) ;
241+ // FIXME: Paths in nested macros are not handled well. See
242+ // `macro_generated_assoc_item2` test.
241243 transform. apply ( assoc_item. syntax ( ) ) ;
242244 assoc_item. remove_attrs_and_docs ( ) ;
243245 Some ( assoc_item)
@@ -1220,6 +1222,81 @@ impl Foo for Test {
12201222 ) ;
12211223 }
12221224
1225+ #[ test]
1226+ fn macro_generated_assoc_item ( ) {
1227+ check_edit (
1228+ "fn method" ,
1229+ r#"
1230+ macro_rules! ty { () => { i32 } }
1231+ trait SomeTrait { type Output; }
1232+ impl SomeTrait for i32 { type Output = i64; }
1233+ macro_rules! define_method {
1234+ () => {
1235+ fn method(&mut self, params: <ty!() as SomeTrait>::Output);
1236+ };
1237+ }
1238+ trait AnotherTrait { define_method!(); }
1239+ impl AnotherTrait for () {
1240+ $0
1241+ }
1242+ "# ,
1243+ r#"
1244+ macro_rules! ty { () => { i32 } }
1245+ trait SomeTrait { type Output; }
1246+ impl SomeTrait for i32 { type Output = i64; }
1247+ macro_rules! define_method {
1248+ () => {
1249+ fn method(&mut self, params: <ty!() as SomeTrait>::Output);
1250+ };
1251+ }
1252+ trait AnotherTrait { define_method!(); }
1253+ impl AnotherTrait for () {
1254+ fn method(&mut self,params: <ty!()as SomeTrait>::Output) {
1255+ $0
1256+ }
1257+ }
1258+ "# ,
1259+ ) ;
1260+ }
1261+
1262+ // FIXME: `T` in `ty!(T)` should be replaced by `PathTransform`.
1263+ #[ test]
1264+ fn macro_generated_assoc_item2 ( ) {
1265+ check_edit (
1266+ "fn method" ,
1267+ r#"
1268+ macro_rules! ty { ($me:ty) => { $me } }
1269+ trait SomeTrait { type Output; }
1270+ impl SomeTrait for i32 { type Output = i64; }
1271+ macro_rules! define_method {
1272+ ($t:ty) => {
1273+ fn method(&mut self, params: <ty!($t) as SomeTrait>::Output);
1274+ };
1275+ }
1276+ trait AnotherTrait<T: SomeTrait> { define_method!(T); }
1277+ impl AnotherTrait<i32> for () {
1278+ $0
1279+ }
1280+ "# ,
1281+ r#"
1282+ macro_rules! ty { ($me:ty) => { $me } }
1283+ trait SomeTrait { type Output; }
1284+ impl SomeTrait for i32 { type Output = i64; }
1285+ macro_rules! define_method {
1286+ ($t:ty) => {
1287+ fn method(&mut self, params: <ty!($t) as SomeTrait>::Output);
1288+ };
1289+ }
1290+ trait AnotherTrait<T: SomeTrait> { define_method!(T); }
1291+ impl AnotherTrait<i32> for () {
1292+ fn method(&mut self,params: <ty!(T)as SomeTrait>::Output) {
1293+ $0
1294+ }
1295+ }
1296+ "# ,
1297+ ) ;
1298+ }
1299+
12231300 #[ test]
12241301 fn includes_gat_generics ( ) {
12251302 check_edit (
0 commit comments