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

Rustup to rust-lang/rust#64874 #4628

Merged
merged 6 commits into from
Oct 8, 2019
Merged

Rustup to rust-lang/rust#64874 #4628

merged 6 commits into from
Oct 8, 2019

Conversation

flip1995
Copy link
Member

@flip1995 flip1995 commented Oct 4, 2019

TODO:

  • replace rvalue_promotable_map in [1]
  • fix [2] according to this comment Simplify ExprUseVisitor rust#64874 (comment) this should be merged with consume, but I didn't figure out how to merge them, yet.
  • fix [3]; What to do with LoanCause?

[2]+[3] probably have to be resolved by a rewrite of the lint. #4628 (comment)

[1]

let promotable = self
.cx
.tcx
.rvalue_promotable_map(owner_def)
.contains(&expr.hir_id.local_id);
if !promotable {
self.found |= true;
}

[2]

fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {

[3]

fn borrow(
&mut self,
_: HirId,
_: Span,
cmt: &cmt_<'tcx>,
_: ty::Region<'_>,
_: ty::BorrowKind,
loan_cause: LoanCause,
) {
if let Categorization::Local(lid) = cmt.cat {
match loan_cause {

I could need some help with [1]. The purpose of this is to "don't lint for constant values". cc @matthewjasper

For now I see what I can do with [2].

changelog: Temporary break boxed_local lint.

@flip1995 flip1995 force-pushed the rustup branch 2 times, most recently from ab95b45 to 65a52ba Compare October 4, 2019 13:33
Episode 1 - The simple cases
This also accidentally improved the spans of the suggestions
let cmt = unwrap_downcast_or_interior(cmt);

if let mc::Categorization::Local(vid) = cmt.cat {
self.moved_vars.insert(vid);
}
}

fn non_moving_pat(&mut self, matched_pat: &Pat, cmt: &mc::cmt_<'tcx>) {
Copy link
Member Author

@flip1995 flip1995 Oct 4, 2019

Choose a reason for hiding this comment

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

Is removing this completely ok? It didn't break anything in the tests 🤔 cc @sinkuu since you added this function in 627d24c

Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing is inserted to spans_need_deref after this change, so the suggestions to add * should be broken, but idk.

Anyway, Rust has gained default binding mode and this suggestion became useless. I think it's OK to remove it.

@flip1995 flip1995 added the E-help-wanted Call for participation: Help is requested to fix this issue. label Oct 4, 2019
@tesuji

This comment has been minimized.

@flip1995
Copy link
Member Author

flip1995 commented Oct 4, 2019

Update: I won't get to this until tomorrow. It would be great if someone could take over :)

@matthewjasper
Copy link
Contributor

[1] Change is_ctor_function to check for promotable functions as well (and give it a different name). It would look something like

// ...
match cx.tables.qpath_res(qp, fun.hir_id) {
    def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _) => true,
    // Maybe consider `is_const_fn`, but there's less guarantee of cheapness there.
    def::Ref::Def(DefKind::Fn, def_id) => cx.tcx.is_promotable_const_fn(def_id),
    _ => false,
}

[2] and [3] Looking into this lint some more, it's hopelessly broken and needs a rewrite. That said, to roughly keep the current behavior:

[2]:

  • Move the if is_argument part into consume, using cmt.hir_id instead of consume_pat.hir_id.
  • Remove the if let Categorization::Rvalue(..) = ... block, it doesn't appear to work.
  • Move the if let Categorization::Local(lid) = ... block into consume adding a check that checking that map.find(cmt.hir_id) is Some(Node::Binding(_))

[3]: Unconditionally call self.set.remove(&lid); - this slightly changes the behavior of this lint around closures.

FIXME: This doesn't work and probably needs a rewrite of the lint

See rust-lang#4628 (comment)
@flip1995
Copy link
Member Author

flip1995 commented Oct 5, 2019

Thanks a lot for the hints @matthewjasper!

Oh nevermind...

u32::max_value() (and so on) is a DefKind::Method, not DefKind::Fn

[1] That doesn't work, because the PathSegment of a const fn call like u32::max_value() always has res: Some(Err), e.g.

let _ = 1u32.checked_add(1).unwrap_or(u32::max_value());

dbg!(qpath):

[clippy_lints/src/utils/mod.rs:809] qp = TypeRelative(
    type(u32),
    PathSegment {
        ident: max_value#0,
        hir_id: Some(
            HirId {
                owner: DefIndex(17),
                local_id: 43,
            },
        ),
        res: Some(
            Err,
        ),
        args: None,
        infer_args: true,
    },
)

I'm still curious about this though:

What does Res::Err mean? That the resolution errored or that no resolution is known at this point? (Does Res even stand for Resolution?) Sorry if that's a stupid question, but def::Res is completely undocumented and I couldn't find anything in the rustc-guide.


it's hopelessly broken and needs a rewrite

That's what I was afraid of. I propably won't have the time of doing a rewrite, so I'd suggest to just adapt the tests, since this only introduces FNs. We then can get a working Clippy faster and work on this later. cc @rust-lang/clippy

[2]+[3] I did this is in b7d4735, but the result is, that all tests fail for this lint

@flip1995 flip1995 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed E-help-wanted Call for participation: Help is requested to fix this issue. labels Oct 5, 2019
@flip1995 flip1995 changed the title WIP: Rustup to rust-lang/rust#64874 Rustup to rust-lang/rust#64874 Oct 5, 2019
@flip1995
Copy link
Member Author

flip1995 commented Oct 5, 2019

On another note: I think it's time to Nuke the clippy plugin interface

warning: use of deprecated attribute `plugin_registrar`: compiler plugins are deprecated. See https://github.com/rust-lang/rust/issues/29597
  --> src/lib.rs:12:1
   |
12 | #[plugin_registrar]
   | ^^^^^^^^^^^^^^^^^^^ help: remove this attribute
   |
   = note: `#[warn(deprecated)]` on by default

https://travis-ci.com/rust-lang/rust-clippy/jobs/242398220#L890-L896

@flip1995 flip1995 mentioned this pull request Oct 5, 2019
@flip1995
Copy link
Member Author

flip1995 commented Oct 5, 2019

As suggested in #4616 (comment)

@bors treeclosed=10 p=10

@matthewjasper
Copy link
Contributor

What does Res::Err mean? That the resolution errored or that no resolution is known at this point? (Does Res even stand for Resolution?) Sorry if that's a stupid question, but def::Res is completely undocumented and I couldn't find anything in the rustc-guide.

Res::Err usually means that name resolution errored, but it's also used here because the name won't be resolved until type checking is done.

[2]+[3] I did this is in b7d4735, but the result is, that all tests fail for this lint

I've had a look at this, moving the is_argument check to mutate fixes this (only the error that I expected to go is now gone).

@@ -12,11 +12,5 @@ error: local variable doesn't need to be boxed here
LL | pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
| ^^^^^^^^^^^

error: local variable doesn't need to be boxed here
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only remaining FN introduced in this PR now. So ping @rust-lang/clippy for review.

Copy link
Member

Choose a reason for hiding this comment

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

file an issue for it and refer to it in the test file and we can land tis

@phansch
Copy link
Member

phansch commented Oct 8, 2019

@bors r+ p=10

@bors
Copy link
Contributor

bors commented Oct 8, 2019

📌 Commit 3d39379 has been approved by phansch

@bors
Copy link
Contributor

bors commented Oct 8, 2019

⌛ Testing commit 3d39379 with merge df80193...

bors added a commit that referenced this pull request Oct 8, 2019
Rustup to rust-lang/rust#64874

TODO:
- [x] replace `rvalue_promotable_map` in [1]
- [ ] ~~fix [2] according to this comment rust-lang/rust#64874 (comment) this should be merged with `consume`, but I didn't figure out how to merge them, yet.~~
- [ ] ~~fix [3]; What to do with `LoanCause`?~~

[2]+[3] probably have to be resolved by a rewrite of the lint. #4628 (comment)

[1]
https://github.com/rust-lang/rust-clippy/blob/54bf4ffd626970e831bb80c037f804a3b3450835/clippy_lints/src/methods/mod.rs#L1292-L1299

[2]
https://github.com/rust-lang/rust-clippy/blob/54bf4ffd626970e831bb80c037f804a3b3450835/clippy_lints/src/escape.rs#L126

[3]
https://github.com/rust-lang/rust-clippy/blob/54bf4ffd626970e831bb80c037f804a3b3450835/clippy_lints/src/escape.rs#L166-L176

I could need some help with [1]. The purpose of this is to "don't lint for constant values". cc @matthewjasper

For now I see what I can do with [2].

changelog: Temporary break `boxed_local` lint.
@bors
Copy link
Contributor

bors commented Oct 8, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: phansch
Pushing df80193 to master...

@bors bors merged commit 3d39379 into rust-lang:master Oct 8, 2019
@phansch
Copy link
Member

phansch commented Oct 8, 2019

@bors treeclosed-

@flip1995 flip1995 deleted the rustup branch October 8, 2019 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants