-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Modernize diagnostic for indeterminate trait object lifetime bounds #152226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modernize diagnostic for indeterminate trait object lifetime bounds #152226
Conversation
fmease
commented
Feb 6, 2026
- remove suggestion from the diagnostic message (bad style, too long) and turn it into a structured suggestion
- replace object type with trait object type since the former is an outdated term
|
r? @chenyukang rustbot has assigned @chenyukang. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| // FIXME: Account for trailing plus `dyn Trait+`, the need of parens in | ||
| // `*const dyn Trait` and `Fn() -> *const dyn Trait`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've decided against fixing these ~minor issues in this PR because it's a rabbit hole I didn't want to pursue at the moment:
Most diagnostics in the compiler that suggest adding + /* bound */ to a type don't consider both last cases mentioned in the FIXME above (and I bet none properly account for trailing pluses1). E.g., suggest_new_region_bound (see FIXME).
We do have some helpers in place for cases like this like hir::Generics::bounds_span_for_suggestions but it's not general enough (e.g., I can't use it here) & it doesn't account for everything (like raw pointers).
I hope this paints a clear enough picture. I'd rather fix a bunch of these diagnostic suggestions at once in a separate future PR by providing better HIR helpers for these cases. I'm already tracking this in my internal issue tracker (and I might upstream this issue to r-l/r if I won't get to write a PR soon-ish). From a technical standpoint, it shouldn't be hard at all, you just need to check the parent & the child of the HIR type. I just really want to avoid duplicating code for this.
Footnotes
-
Since trailing pluses aren't represented in the AST, HIR etc. and you can't just trim &
contains('+')-check the relevant part of the source text as obtained viasource_map()since it wouldn't account for source code comments; you'd actually need to re-lex the snippet (which is overkill for such a niche issue) ↩
|
This PR conflicts with #152076 which I'm assigned to and which I'll hopefully review today. Can't tell yet which one's more likely to get merged first. |
|
@bors r=chenyukang |
…ect-lifetime-diag, r=chenyukang Modernize diagnostic for indeterminate trait object lifetime bounds * remove suggestion from the diagnostic message (bad style, too long) and turn it into a structured suggestion * replace *object type* with *trait object type* since the former is an outdated term
Rollup of 7 pull requests Successful merges: - #151152 (Add FCW for derive helper attributes that will conflict with built-in attributes) - #151954 (Add help message suggesting explicit reference cast for From/TryFrom) - #152148 (Move `impl Interner for TyCtxt` to its own submodule) - #152226 (Modernize diagnostic for indeterminate trait object lifetime bounds) - #150688 (typeck: Make it clearer that `check_pat_lit` only handles literal patterns) - #152293 (Format heterogeneous try blocks) - #152396 (Uplift `Predicate::allow_normalization` to `rustc_type_ir`)
…ect-lifetime-diag, r=chenyukang Modernize diagnostic for indeterminate trait object lifetime bounds * remove suggestion from the diagnostic message (bad style, too long) and turn it into a structured suggestion * replace *object type* with *trait object type* since the former is an outdated term
…ect-lifetime-diag, r=chenyukang Modernize diagnostic for indeterminate trait object lifetime bounds * remove suggestion from the diagnostic message (bad style, too long) and turn it into a structured suggestion * replace *object type* with *trait object type* since the former is an outdated term
…ect-lifetime-diag, r=chenyukang Modernize diagnostic for indeterminate trait object lifetime bounds * remove suggestion from the diagnostic message (bad style, too long) and turn it into a structured suggestion * replace *object type* with *trait object type* since the former is an outdated term
…uwer Rollup of 11 pull requests Successful merges: - #152364 (Port a lot of attributes to the new parser) - #151954 (Add help message suggesting explicit reference cast for From/TryFrom) - #152148 (Move `impl Interner for TyCtxt` to its own submodule) - #152226 (Modernize diagnostic for indeterminate trait object lifetime bounds) - #152351 (Remove `SubdiagMessage` in favour of the identical `DiagMessage`) - #152417 (Move the needs-drop check for `arena_cache` queries out of macro code) - #150688 (typeck: Make it clearer that `check_pat_lit` only handles literal patterns) - #152293 (Format heterogeneous try blocks) - #152355 (Update documentation of rustc_macros) - #152396 (Uplift `Predicate::allow_normalization` to `rustc_type_ir`) - #152425 (Port #![test_runner] to the attribute parser)
…uwer Rollup of 10 pull requests Successful merges: - #152364 (Port a lot of attributes to the new parser) - #151954 (Add help message suggesting explicit reference cast for From/TryFrom) - #152148 (Move `impl Interner for TyCtxt` to its own submodule) - #152226 (Modernize diagnostic for indeterminate trait object lifetime bounds) - #152351 (Remove `SubdiagMessage` in favour of the identical `DiagMessage`) - #152417 (Move the needs-drop check for `arena_cache` queries out of macro code) - #150688 (typeck: Make it clearer that `check_pat_lit` only handles literal patterns) - #152293 (Format heterogeneous try blocks) - #152355 (Update documentation of rustc_macros) - #152396 (Uplift `Predicate::allow_normalization` to `rustc_type_ir`)