Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMake unrooted_must_root a bit more aggressive. #8073
Conversation
| @@ -18,6 +18,7 @@ pub struct FileList { | |||
| } | |||
|
|
|||
| impl FileList { | |||
| #[allow(unrooted_must_root)] | |||
| fn new_inherited(files: Vec<JS<File>>) -> FileList { | |||
This comment has been minimized.
This comment has been minimized.
nox
Oct 19, 2015
Member
Anything named new or new_something is supposed to get automatically white-listed, weird that you had to add these.
This comment has been minimized.
This comment has been minimized.
Manishearth
Oct 19, 2015
Member
No, only box unrooted is safe in new, everything else isn't.
In this case it's the pat from the argument list that's being caught. It wasn't caught in the past since check_fn is not run on new_*.
This can be fixed by adding another state to the lint, "in_argument_list", which is set unconditionally by check_fn and turned off by check_block, and bailing in check_pat when in_new_function && in_argument_list
|
r? @Manishearth |
| cx.span_lint(UNROOTED_MUST_ROOT, expr.span, | ||
| &format!("Expression of type {:?} must be rooted", ty)) | ||
| fn check_pat(&mut self, cx: &LateContext, pat: &hir::Pat) { | ||
| if let hir::PatIdent(hir::BindByValue(_), _, _) = pat.node { |
This comment has been minimized.
This comment has been minimized.
Manishearth
Oct 19, 2015
Member
This won't catch let (a, b, c) = foo(); We should allow any pat here I guess?
This comment has been minimized.
This comment has been minimized.
eefriedman
Oct 19, 2015
Author
Contributor
check_pat gets called for every hir::Pat in the tree, so we would end up checking a, b, and c individually. (This also allows us to avoid false positives involving by-ref matches.)
This comment has been minimized.
This comment has been minimized.
Manishearth
Oct 19, 2015
Member
Oh, right, sorry.
But then, this would catch let ref a = b. It shouldn't.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
eefriedman
Oct 19, 2015
Author
Contributor
pat_ty_opt returns the type of the variable in let ref a = b, so it works correctly.
|
Mostly looks good. Just need to add the second state variable for ignoring function arguments, and make the pat check handle all pats. The alternative to the state variable is to keep |
|
Came up with a different solution for ignoring function arguments: using a nested visitor. This is a bit more convenient for a couple reasons: it makes it easier to ensure the lint only sees patterns which actually represent variables, and it handles nested function definitions more correctly. |
|
Note that this might affect compile times. The regular lint is implemented as a visitor which runs threaded together with the other lints. A separate visitor might make things slower. But we're not doing any crazy computations here so we should be fine. |
|
How is |
|
@Ms2ger It's not, but we need to ignore it for |
|
@Manishearth I thought the goal was to suppress the error for return values for such functions; I don't recall any discussion about the function arguments. |
|
Okay, we can turn on warnings for the argument list then. |
|
I'm not exactly sure how the argument list is any worse than the return type? Conceptually, functions should always return a rooted value. Anyway, I'll change it. |
|
Updated. |
|
@eefriedman The exception for the return value for |
|
@Manishearth Ping. |
|
|
|
Rebased. |
|
Reviewed 4 of 8 files at r1, 4 of 4 files at r2, 5 of 5 files at r3. components/plugins/lints/unrooted_must_root.rs, line 40 [r2] (raw file): Comments from the review on Reviewable.io |
|
Review status: all files reviewed at latest revision, 2 unresolved discussions, all commit checks successful. components/plugins/lints/unrooted_must_root.rs, line 40 [r2] (raw file): Comments from the review on Reviewable.io |
|
@bors-servo retry It's asking for a license fix. Tried to ssh and fix it, but it seems like the admin password was updated. |
Make unrooted_must_root a bit more aggressive. Basically, instead of trying to check for specific kinds of statements, just check the types of all local variables. Also included are some commented-out proposals for some slightly more aggressive lints which might be useful (but trigger a little too frequently at the moment). <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8073) <!-- Reviewable:end -->
|
|
|
@bors-servo retry |
Make unrooted_must_root a bit more aggressive. Basically, instead of trying to check for specific kinds of statements, just check the types of all local variables. Also included are some commented-out proposals for some slightly more aggressive lints which might be useful (but trigger a little too frequently at the moment). <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8073) <!-- Reviewable:end -->
|
|
|
@bors-servo retry #7791 |
Make unrooted_must_root a bit more aggressive. Basically, instead of trying to check for specific kinds of statements, just check the types of all local variables. Also included are some commented-out proposals for some slightly more aggressive lints which might be useful (but trigger a little too frequently at the moment). <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8073) <!-- Reviewable:end -->
|
@frewsxcv Nothing's going to work till the builders come back |
Make unrooted_must_root a bit more aggressive. Basically, instead of trying to check for specific kinds of statements, just check the types of all local variables. Also included are some commented-out proposals for some slightly more aggressive lints which might be useful (but trigger a little too frequently at the moment). <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8073) <!-- Reviewable:end -->
|
|
eefriedman commentedOct 18, 2015
Basically, instead of trying to check for specific kinds of statements,
just check the types of all local variables.
Also included are some commented-out proposals for some slightly more
aggressive lints which might be useful (but trigger a little too
frequently at the moment).