Skip to content

Commit f04c372

Browse files
Merge pull request #22265 from A4-Tacks/suggest-impl-type-question
fix: don't panic on `impl ?Sized` for introduce_named_type_parameter
2 parents d8e4858 + 765be20 commit f04c372

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

crates/ide-assists/src/handlers/introduce_named_type_parameter.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ fn foo<
182182
);
183183
}
184184

185+
#[test]
186+
fn replace_impl_question_bounds() {
187+
check_assist(
188+
introduce_named_type_parameter,
189+
r#"fn foo(bar: &$0impl ?Sized) {}"#,
190+
r#"fn foo<$0S: ?Sized>(bar: &S) {}"#,
191+
);
192+
}
193+
185194
#[test]
186195
fn replace_impl_with_mut() {
187196
check_assist(

crates/ide-db/src/syntax_helpers/suggest_name.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ impl NameGenerator {
193193
pub fn for_impl_trait_as_generic(&mut self, ty: &ast::ImplTraitType) -> SmolStr {
194194
let c = ty
195195
.type_bound_list()
196-
.and_then(|bounds| bounds.syntax().text().char_at(0.into()))
196+
.and_then(|bounds| {
197+
let ty = bounds.bounds().next()?.ty()?;
198+
ty.syntax().text().char_at(0.into()).filter(|ch| ch.is_alphabetic())
199+
})
197200
.unwrap_or('T');
198201

199202
self.suggest_name(&c.to_string())

0 commit comments

Comments
 (0)