Resolve lifetimes in associated types

Fix #18790.
Fix #19862.