-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
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 (
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a9f72fe
to
fecdcdc
Compare
This comment has been minimized.
This comment has been minimized.
fecdcdc
to
a427c6a
Compare
This comment has been minimized.
This comment has been minimized.
a427c6a
to
a4dfd7c
Compare
This comment has been minimized.
This comment has been minimized.
a4dfd7c
to
f5651dd
Compare
This comment has been minimized.
This comment has been minimized.
f5651dd
to
5a7be2e
Compare
This comment has been minimized.
This comment has been minimized.
5a7be2e
to
e479c63
Compare
This comment has been minimized.
This comment has been minimized.
e479c63
to
c6aa569
Compare
?Sized
when param type has default
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.
Please address my suggestions, then we are good to go unless you'd also like to fix the other bug I just found.
tests/ui/traits/issue-120878.rs
Outdated
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.
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.
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 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)!
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.
Thank you for the review and for suggesting interesting assignments.
I think I can fix it, so I'll give it a try.
c6aa569
to
09e2f77
Compare
This comment has been minimized.
This comment has been minimized.
09e2f77
to
7b8033f
Compare
This comment has been minimized.
This comment has been minimized.
when param type has default and type in trait is generic.
7b8033f
to
4ac90e2
Compare
@@ -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(), ":") |
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.
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 👍
Great, thanks a lot! |
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
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`
Fixes #120878
Diagnostic suggests adding
: ?Sized
in an incorrect place if a type parameter default is presentr? @fmease