Skip to content
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

Fix suggestion span for ?Sized when param type has default #120915

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

OdenShirataki
Copy link
Contributor

@OdenShirataki OdenShirataki commented Feb 11, 2024

Fixes #120878

Diagnostic suggests adding : ?Sized in an incorrect place if a type parameter default is present

r? @fmease

@rustbot
Copy link
Collaborator

rustbot commented Feb 11, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @fmease (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 11, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@compiler-errors compiler-errors changed the title fix: #120878 Use param.name.indent().span if trait bounds not exists. Fix suggestion span for ?Sized when param type has default Feb 11, 2024
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address my suggestions, then we are good to go unless you'd also like to fix the other bug I just found.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding a test! Could you move it into tests/ui/trait-bounds/ though? I think that'd be a better fit. I would also rename to something more descriptive like suggest-maybe-sized-bound.rs and add the issue number as a comment // issue: 120878.

Note that there already exists trait-bounds/unsized-bound.rs but that one's more about removing ?Sized bounds rather than adding them, so I wouldn't extend it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the following code also leads to an incorrect suggestion although that very likely hits a different code path:

trait Trait { type P<X>; }

impl Trait for () { type P<X> = [u8]; }
trait Trait { type P: ?Sized<X>; }
                    ++++++++

If you have time & interest in fixing this, too, while you're at it, go for it (and just amend the existing test file)!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review and for suggesting interesting assignments.

I think I can fix it, so I'll give it a try.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

when param type has default
and type in trait is generic.
@@ -3054,7 +3054,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let (span, separator) = if let [.., last] = bounds {
(last.span().shrink_to_hi(), " +")
} else {
(ident.span.shrink_to_hi(), ":")
(generics.span.shrink_to_hi(), ":")
Copy link
Member

@fmease fmease Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, and if there are no generic params, this is still correct since the span will be a zero-sized span located directly after the ident 👍

@fmease
Copy link
Member

fmease commented Feb 13, 2024

Great, thanks a lot!
@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 13, 2024

📌 Commit 4ac90e2 has been approved by fmease

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 13, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2024
Rollup of 13 pull requests

Successful merges:

 - rust-lang#116387 (Additional doc links and explanation of `Wake`.)
 - rust-lang#118738 (Netbsd10 update)
 - rust-lang#118890 (Clarify the lifetimes of allocations returned by the `Allocator` trait)
 - rust-lang#120498 (Uplift `TypeVisitableExt` into `rustc_type_ir`)
 - rust-lang#120530 (Be less confident when `dyn` suggestion is not checked for object safety)
 - rust-lang#120915 (Fix suggestion span for `?Sized` when param type has default)
 - rust-lang#121015 (Optimize `delayed_bug` handling.)
 - rust-lang#121024 (implement `Default` for `AsciiChar`)
 - rust-lang#121039 (Correctly compute adjustment casts in GVN)
 - rust-lang#121045 (Fix two UI tests with incorrect directive / invalid revision)
 - rust-lang#121049 (Do not point at `#[allow(_)]` as the reason for compat lint triggering)
 - rust-lang#121071 (Use fewer delayed bugs.)
 - rust-lang#121073 (Fix typos in `OneLock` doc)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f3e66ed into rust-lang:master Feb 14, 2024
11 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Feb 14, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2024
Rollup merge of rust-lang#120915 - OdenShirataki:master, r=fmease

Fix suggestion span for `?Sized` when param type has default

Fixes rust-lang#120878

Diagnostic suggests adding `: ?Sized` in an incorrect place if a type parameter default is present

r? `@fmease`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Diagnostic suggests adding : ?Sized in an incorrect place if a type parameter default is present
5 participants