-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
refactor the BorrowckErrors
trait to take fn(self)
#48902
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
pub trait BorrowckErrors { | ||
fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self, | ||
pub trait BorrowckErrors<'cx> { | ||
fn struct_span_err_with_code<S: Into<MultiSpan>>(self, | ||
sp: S, | ||
msg: &str, |
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.
Formatting is broken here in in few other places.
LGTM, r=me after fixing formatting |
r @petrochenkov |
@bors r+ |
📌 Commit cb5ac97 has been approved by |
…lf, r=petrochenkov refactor the `BorrowckErrors` trait to take `fn(self)` Fixes rust-lang#48783
sp: S, | ||
msg: &str) | ||
-> DiagnosticBuilder<'cx> | ||
where Self: Sized + Copy |
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.
Wait -- this where clause should not be needed, right? (I would have probably moved it into the trait, in any case, but it shouldn't be needed in the impls...)
diag: DiagnosticBuilder<'cx>, | ||
o: Origin) | ||
-> DiagnosticBuilder<'cx> | ||
where Self: Sized + Copy; |
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.
Nit: I would move these into the trait definition, as the trait is meant to be implemented for references.
@@ -284,22 +298,25 @@ pub trait BorrowckErrors { | |||
self.cancel_if_wrong_origin(err, o) | |||
} | |||
|
|||
fn cannot_assign(&self, span: Span, desc: &str, o: Origin) -> DiagnosticBuilder | |||
fn cannot_assign(self, span: Span, desc: &str, o: Origin) -> DiagnosticBuilder<'cx> | |||
where Self: Sized + Copy |
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.
...then you could remove them from all these places
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.
it seems the where clause cannot be removed here:
error[E0277]: the trait bound `Self: std::marker::Sized` is not satisfied
--> librustc_mir/util/borrowck_errors.rs:287:22
|
287 | fn cannot_assign(self, span: Span, desc: &str, o: Origin) -> DiagnosticBuilder<'cx>
| ^^^^ `Self` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `Self`
= help: consider adding a `where Self: std::marker::Sized` bound
= note: all local variables must have a statically known size
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.
@nikomatsakis
the compiler complained that the self
in trait should be Sized + Copy
, and I found that TyCtxt
already #[derive(Copy, Clone)]
, so I rewrote pub trait BorrowckError<'tcx>: Sized + Copy {}
instead of appending where
clause in every method. Is this make sense?
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.
Yep! That's what I was proposing, in fact.
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 @csmoe -- left one more nit :)
813c57d
to
4d24236
Compare
4d24236
to
5511624
Compare
@bors r+ rollup |
📌 Commit 5511624 has been approved by |
…lf, r=nikomatsakis refactor the `BorrowckErrors` trait to take `fn(self)` Fixes rust-lang#48783
Fixes #48783