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

refactor the BorrowckErrors trait to take fn(self) #48902

Merged
merged 3 commits into from
Mar 20, 2018

Conversation

csmoe
Copy link
Member

@csmoe csmoe commented Mar 10, 2018

Fixes #48783

@rust-highfive
Copy link
Collaborator

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 10, 2018
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,
Copy link
Contributor

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.

@petrochenkov
Copy link
Contributor

LGTM, r=me after fixing formatting

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 10, 2018
@csmoe
Copy link
Member Author

csmoe commented Mar 11, 2018

r @petrochenkov
formatting fixed.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Mar 11, 2018

📌 Commit cb5ac97 has been approved by petrochenkov

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 11, 2018
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Mar 12, 2018
…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
Copy link
Contributor

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;
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Member Author

@csmoe csmoe Mar 18, 2018

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?

Copy link
Contributor

@nikomatsakis nikomatsakis Mar 19, 2018

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.

Copy link
Contributor

@nikomatsakis nikomatsakis left a 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 :)

@csmoe csmoe force-pushed the refactor_BorrowckErrors_fn_self branch 2 times, most recently from 813c57d to 4d24236 Compare March 18, 2018 11:16
@csmoe csmoe force-pushed the refactor_BorrowckErrors_fn_self branch from 4d24236 to 5511624 Compare March 18, 2018 12:18
@nikomatsakis
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 19, 2018

📌 Commit 5511624 has been approved by nikomatsakis

kennytm added a commit to kennytm/rust that referenced this pull request Mar 19, 2018
…lf, r=nikomatsakis

refactor the `BorrowckErrors` trait to take `fn(self)`

Fixes rust-lang#48783
bors added a commit that referenced this pull request Mar 20, 2018
Rollup of 17 pull requests

- Successful merges: #46518, #48810, #48834, #48902, #49004, #49092, #49096, #49099, #49104, #49125, #49139, #49152, #49157, #49161, #49166, #49176, #49184
- Failed merges:
@bors bors merged commit 5511624 into rust-lang:master Mar 20, 2018
@csmoe csmoe deleted the refactor_BorrowckErrors_fn_self branch July 13, 2018 08:43
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants