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

librustc: Can mark functions as deprecated. #4643

Closed
wants to merge 1 commit into from

Conversation

luqmana
Copy link
Member

@luqmana luqmana commented Jan 26, 2013

#723 - Add a deprecated items check to lint.

So far it actually only works for functions. I'm not exactly sure how to go about doing it for things like types, structs etc and catching only their uses.

@brson
Copy link
Contributor

brson commented Jan 28, 2013

Awesome. Can you add a test? Here's an example: https://github.com/mozilla/rust/blob/incoming/src/test/compile-fail/lint-deprecated-self.rs

Checking use of deprecated types will require either looking through the types of all the nodes in the type context, or possibly adding a new table of 'used types' to the type context. Types would be added to this table by the type checker during unification.

@luqmana
Copy link
Member Author

luqmana commented Jan 28, 2013

Hmm ok. Also, are methods handled differently than regular fn's in the def_map? There's def_fn and def_static_method.

@brson
Copy link
Contributor

brson commented Jan 29, 2013

I am not familiar enough with resolve to know what's in def_map, but @pcwalton, @nikomatsakis or @catamorphism might be.

@catamorphism
Copy link
Contributor

@luqmana def_fn is just for functions AFAIK. The compiler treats method access like field access, so (regular) methods don't use def_fn or def_static_method. The exception is static methods (declared with static fn).

This should all be documented, but isn't. Feel free to ask follow-up questions...

@catamorphism
Copy link
Contributor

(see middle::typeck::check::method for the gory details)

@luqmana
Copy link
Member Author

luqmana commented Jan 29, 2013

So how could I get the ast::def_id associated with a ast::expr_method_call to lookup the ast::item?

@catamorphism
Copy link
Contributor

@luqmana You can't, because the method you're actually calling isn't known until trans time. For example:

trait A { fn f(); }

impl P: A { fn f() {} }
impl Q: A { #[deprecated] fn f() {} }

fn g<T: A>(x: T) {
    x.f();
}

Does g call the deprecated Q method, or the non-deprecated P method? There's no way to know until monomorphization, which is part of trans.

So you could do this check as part of trans (as a sort of link-time lint check) or just punt on allowing impl methods to have a #[deprecated] attribute.

@catamorphism
Copy link
Contributor

I'm not sure what the status of this is; closing. @luqmana -- feel free to open a new pull requests, or ask questions on IRC if you're blocked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants