You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
suggested fix for undeclared hrtb lifetimes in where clauses in produces error "[E0316] nested quantification of lifetimes" when specified just before the trait #122714
error[E0261]: use of undeclared lifetime name `'b` --> src/lib.rs:2:31 |2 | where T: for<'a> Trait<T> + 'b { } | ^^ undeclared lifetime | = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.htmlhelp: consider making the bound lifetime-generic with a new `'b` lifetime
|
2 | where for<'b> T: for<'a> Trait<T> + 'b { } | +++++++help: consider introducing lifetime `'b` here|1 | trait Trait<'b, T> | +++
Desired output
error[E0261]: use of undeclared lifetime name `'b` --> src/lib.rs:2:31 |2 | where T: for<'a> Trait<T> + 'b { } | ^^ undeclared lifetime | = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.htmlhelp: consider making the bound lifetime-generic with a new `'b` lifetime
|
2 | where T: for<'a, 'b> Trait<T> + 'b { } | ++++help: consider introducing lifetime `'b` here|1 | trait Trait<'b, T> | +++
Rationale and extra context
HRTB lifetimes can be put not only before the constrained type (for<...> T: ...), but also just before the constraining trait (T: for<...> Trait ...). When in this position, compiler suggests code which produces error "[E0316] nested quantification of lifetimes" as it ignores the existing HRTB just before the trait and only looks at constraint HRTB.
changed the title [-]suggested fix for undeclared hrtb lifetimes in where clause in produces error "[E0316] nested quantification of lifetimes" when specified just before the trait[/-][+]suggested fix for undeclared hrtb lifetimes in where clauses in produces error "[E0316] nested quantification of lifetimes" when specified just before the trait[/+]on Mar 18, 2024
where T: for<'a, 'b> Trait<T> + 'b isn't valid either tho b/c for<> after : only universally quantifies (i.e., introduces universal parameters for) the trait ref immediately following the binder meaning 'b in + 'b is still undefined / unbound.
We should keep the preexisting trait Trait<'b, T> suggestion (which can lead to follow-up errors unfortunately) and maybe suggest:
- where T: for<'a> Trait<T> + 'b+ where for<'a, 'b> T: Trait<T> + 'b
removing the inner binder (which might be a bit harder to do). The outer binder to the left of the : quantifies the entire bound.
Activity
[-]suggested fix for undeclared hrtb lifetimes in where clause in produces error "[E0316] nested quantification of lifetimes" when specified just before the trait[/-][+]suggested fix for undeclared hrtb lifetimes in where clauses in produces error "[E0316] nested quantification of lifetimes" when specified just before the trait[/+]surechen commentedon Mar 19, 2024
I think this should suggest :
Because
'bis bound forTsurechen commentedon Mar 19, 2024
@rustbot claim
polina4096 commentedon Mar 19, 2024
It already does suggest that, I think. There are two suggestions.
fmease commentedon Mar 19, 2024
where T: for<'a, 'b> Trait<T> + 'bisn't valid either tho b/cfor<>after:only universally quantifies (i.e., introduces universal parameters for) the trait ref immediately following the binder meaning'bin+ 'bis still undefined / unbound.We should keep the preexisting
trait Trait<'b, T>suggestion (which can lead to follow-up errors unfortunately) and maybe suggest:removing the inner binder (which might be a bit harder to do). The outer binder to the left of the
:quantifies the entire bound.Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses.
Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses.
Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses.
Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses.
Fpoly_trait_refix incorrect suggestion for undeclared hrtb lifetimes …
Fpoly_trait_refix incorrect suggestion for undeclared hrtb lifetimes …
Fpoly_trait_refix incorrect suggestion for undeclared hrtb lifetimes …
Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses.
Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses.
Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses.
Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses.
Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses.
Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses.
Rollup merge of rust-lang#123122 - surechen:fix_122714, r=fmease
Rollup merge of rust-lang#123122 - surechen:fix_122714, r=fmease
Rollup merge of rust-lang#123122 - surechen:fix_122714, r=fmease
Unrolled build for rust-lang#123122