Skip to content

rustc: add item name to deprecated lint warning #45707

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

Merged
merged 1 commit into from
Nov 11, 2017

Conversation

Ryman
Copy link
Contributor

@Ryman Ryman commented Nov 2, 2017

It can sometimes be difficult to know what is actually deprecated when you have foo.bar() and bar comes from a trait in another crate.

@rust-highfive
Copy link
Contributor

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@@ -516,11 +516,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
return;
}

let lint_deprecated = |note: Option<Symbol>| {
let lint_deprecated = |def_id: DefId, note: Option<Symbol>| {
let name = self.item_path_str(def_id);
Copy link
Member

Choose a reason for hiding this comment

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

This variable should be named path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed, thanks.

let data = cur_def_key.disambiguated_data.data;
let symbol =
data.get_opt_name().unwrap_or_else(|| Symbol::intern("<unnamed>").as_str());
cur_path.push(symbol);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@eddyb what specifically are you unsure about? The use of <unnamed>? I wonder if/when this can ever arise. Perhaps some cases like this?

struct Foo;
impl Foo {
    #[deprecated]
    fn bar(&self); // referenced like `Foo::bar`
}

also maybe something like this

fn foo() {
    let x = || {
        #[deprecated]
        fn bar() { }
        bar();
    };
}

It'd definitely be good to include those two cases in the test harness, if nothing else.

Copy link
Contributor Author

@Ryman Ryman Nov 2, 2017

Choose a reason for hiding this comment

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

The first should already addressed by MethodTester in deprecation-lint.rs which includes testing all the UFCS forms.

I've added a test for the latter, which prints use of deprecated item 'this_crate::test_fn_closure_body::{{closure}}::bar which seems okay?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see that the <unnamed> only applies at the tip (and that it was here anyway). I guess @eddyb was likely complaining more about the fact that it now skips to the parent of a StructCtor. That made me nervous too, except that it is part of push_visible_item_path, which seems like it's a "user-facing printout" function, and in that case this does strike me as the right behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, but my premise is totally false. We invoke try_push_visible_item_path from the normal item_path.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, I might rather do this "skip to parent of struct ctor" in the caller.

Copy link
Contributor

Choose a reason for hiding this comment

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

Though really this is more evidence that item_path_str is just serving too many clients right now. Let me go do some ripgrep around -- I may be remembering wrong -- but I feel like it's used in a lot of places, some of which may want precision and some of which do not.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, I might rather do this "skip to parent of struct ctor" in the caller.

@Ryman do you see what I mean by this? thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nikomatsakis Yeah, I understand, I was waiting for a followup to 'Let me go do some ripgrep around' incase you had other ideas :P I think adding it to the caller could make sense here as we already do so in other cases in the only caller that I can find see here.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be honest I found it hard to assess all the places that it's being used. Still, that case you showed seems to suggest that we're already doing a similar amount of suppression.

@eddyb
Copy link
Member

eddyb commented Nov 2, 2017

r? @nikomatsakis for the item path changes

@rust-highfive rust-highfive assigned nikomatsakis and unassigned eddyb Nov 2, 2017
@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 2, 2017
@Ryman Ryman force-pushed the deprecated-item-name branch from 40f410b to bdcddd8 Compare November 2, 2017 15:10
@Ryman Ryman force-pushed the deprecated-item-name branch from bdcddd8 to 725ddb4 Compare November 2, 2017 16:10
@nikomatsakis
Copy link
Contributor

@bors r+

The worrisome case seems like it already exists (other parts of that same code skip over steps) -- clearly we need to rework item_path_str.

@bors
Copy link
Collaborator

bors commented Nov 10, 2017

📌 Commit 725ddb4 has been approved by nikomatsakis

@kennytm kennytm 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 Nov 10, 2017
@bors
Copy link
Collaborator

bors commented Nov 10, 2017

⌛ Testing commit 725ddb4 with merge 25cc4a8...

bors added a commit that referenced this pull request Nov 10, 2017
rustc: add item name to deprecated lint warning

It can sometimes be difficult to know what is actually deprecated when you have `foo.bar()` and `bar` comes from a trait in another crate.
@bors
Copy link
Collaborator

bors commented Nov 11, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 25cc4a8 to master...

@bors bors merged commit 725ddb4 into rust-lang:master Nov 11, 2017
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.

6 participants