-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Parsing issues around qualifiers and modifiers #146122
Copy link
Copy link
Open
Labels
A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.Category: This is a bug.F-const_trait_impl`#![feature(const_trait_impl)]``#![feature(const_trait_impl)]`PG-const-traitsProject group: Const traitsProject group: Const traitsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.Category: This is a bug.F-const_trait_impl`#![feature(const_trait_impl)]``#![feature(const_trait_impl)]`PG-const-traitsProject group: Const traitsProject group: Const traitsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Fn vs. trait qualifiers
We fail to parse
and
even though
check_trait_front_matterwould returntruehere in theory. That's because inparse_item_kindwecheck_fn_front_matterfirst which returnstrueonce there are >=2 "fn" qualifiers (†) which most notably includes the sequenceconst unsafe. Two basic solutions:check_fn_front_matteralready contains certain exceptions likeunsafe extern {,async gen {andasync gen move {; we could extend this with!self.is_trait_front_matter()but that's kind of awful because we would basically check the sequenceconst unsafethree times over. Moreover, we gonna wanna have bothis_*(&self) andcheck_*(&mut self) variants but that means bad duplication.check_trait_front_mattercheck above/before the fn one since it's more strict. However, I wonder if this breaks some soft invariants:check_trait_front_matteris also used elsewhere to determine whether a fn item follows. With this change, it would have "false positives". Likely not a problem in practice though.Fn ptr ty qualifiers vs. trait bound modifiers in bare trait object tys
What's more, we also use
check_fn_front_matterinsideparse_ty_commonfor fn ptr tys but later rejectconstandasyncqualifiers inparse_fn_front_matter. Now, since that happens before we checkcan_begin_boundwe incorrectly reject bare trait object tys that start with >=2 trait bound modifiers if they coincide with "fn" qualifiers (thanks tocheck_fn_front_matteryet again), i.e.,async constbare trait object tys:Array/slice ty vs. conditional constness inside bare trait object tys
For consistency, the following should get parsed as a bare trait object ty with a conditionally-const trait bound. However, we commit to parsing an array/slice ty before that: