Fix a panic in ast::TypeBound::kind()
This commit is contained in:
parent
0adc11b534
commit
901ab2b4a8
3 changed files with 21 additions and 5 deletions
|
|
@ -949,7 +949,8 @@ impl<'db> ExprCollector<'db> {
|
|||
node: ast::TypeBound,
|
||||
impl_trait_lower_fn: ImplTraitLowerFn<'_>,
|
||||
) -> TypeBound {
|
||||
match node.kind() {
|
||||
let Some(kind) = node.kind() else { return TypeBound::Error };
|
||||
match kind {
|
||||
ast::TypeBoundKind::PathType(binder, path_type) => {
|
||||
let binder = match binder.and_then(|it| it.generic_param_list()) {
|
||||
Some(gpl) => gpl
|
||||
|
|
|
|||
|
|
@ -197,3 +197,15 @@ fn allowed3(baz: impl Baz<Assoc = Qux<impl Foo>>) {}
|
|||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn regression_21138() {
|
||||
lower_and_print(
|
||||
r#"
|
||||
fn foo(v: for<'a> Trait1 + Trait2) {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
fn foo(dyn for<'a> Trait1 + Trait2) {...}
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -813,13 +813,16 @@ pub enum TypeBoundKind {
|
|||
}
|
||||
|
||||
impl ast::TypeBound {
|
||||
pub fn kind(&self) -> TypeBoundKind {
|
||||
pub fn kind(&self) -> Option<TypeBoundKind> {
|
||||
if let Some(path_type) = support::children(self.syntax()).next() {
|
||||
TypeBoundKind::PathType(self.for_binder(), path_type)
|
||||
Some(TypeBoundKind::PathType(self.for_binder(), path_type))
|
||||
} else if let Some(for_binder) = support::children::<ast::ForType>(&self.syntax).next() {
|
||||
let Some(ast::Type::PathType(path_type)) = for_binder.ty() else { return None };
|
||||
Some(TypeBoundKind::PathType(for_binder.for_binder(), path_type))
|
||||
} else if let Some(args) = self.use_bound_generic_args() {
|
||||
TypeBoundKind::Use(args)
|
||||
Some(TypeBoundKind::Use(args))
|
||||
} else if let Some(lifetime) = self.lifetime() {
|
||||
TypeBoundKind::Lifetime(lifetime)
|
||||
Some(TypeBoundKind::Lifetime(lifetime))
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue