Emit an error when RTN is used in an incorrect place

We miss one place: associated type bindings aka. `impl Trait<Type(..): Send>`, but we also miss it for Fn-style parenthesizes error so I left it out for now.
This commit is contained in:
Chayim Refael Friedman 2025-03-08 20:56:54 +02:00
parent eaa0a39831
commit 5076ef7d9b
4 changed files with 80 additions and 2 deletions

View file

@ -607,8 +607,14 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
) -> Substitution {
let prohibit_parens = match def {
GenericDefId::TraitId(trait_) => {
let trait_data = self.ctx.db.trait_data(trait_);
!trait_data.flags.contains(TraitFlags::RUSTC_PAREN_SUGAR)
// RTN is prohibited anyways if we got here.
let is_rtn =
self.current_or_prev_segment.args_and_bindings.is_some_and(|generics| {
generics.parenthesized == GenericArgsParentheses::ReturnTypeNotation
});
let is_fn_trait =
!self.ctx.db.trait_data(trait_).flags.contains(TraitFlags::RUSTC_PAREN_SUGAR);
is_rtn || is_fn_trait
}
_ => true,
};