Skip to content

Commit b21cc36

Browse files
committed
hotfix: add help dialog for PermissionExt
1 parent e1d3c1e commit b21cc36

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::span_lint_and_note;
1+
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::paths;
33
use clippy_utils::ty::match_type;
44
use rustc_ast::ast::LitKind;
@@ -8,11 +8,11 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
88

99
declare_clippy_lint! {
1010
/// ### What it does
11-
/// Checks for calls to `std::fs::Permissions.set_readonly` with argument `false`
11+
/// Checks for calls to `std::fs::Permissions.set_readonly` with argument `false`.
1212
///
1313
/// ### Why is this bad?
14-
/// On Unix platforms this results in the file being world writable
15-
///
14+
/// On Unix platforms this results in the file being world writable,
15+
/// equivalent to `chmod a+w <file>`.
1616
/// ### Example
1717
/// ```rust
1818
/// use std::fs::File;
@@ -32,18 +32,21 @@ impl<'tcx> LateLintPass<'tcx> for PermissionsSetReadonlyFalse {
3232
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
3333
if let ExprKind::MethodCall(path, receiver, [arg], _) = &expr.kind
3434
&& match_type(cx, cx.typeck_results().expr_ty(receiver), &paths::PERMISSIONS)
35-
&& path.ident.name == sym!(set_readonly)
36-
&& let ExprKind::Lit(lit) = &arg.kind
37-
&& LitKind::Bool(false) == lit.node
35+
&& path.ident.name == sym!(set_readonly)
36+
&& let ExprKind::Lit(lit) = &arg.kind
37+
&& LitKind::Bool(false) == lit.node
3838
{
39-
span_lint_and_note(
40-
cx,
41-
PERMISSIONS_SET_READONLY_FALSE,
42-
expr.span,
43-
"call to `set_readonly` with argument `false`",
44-
None,
45-
"on Unix platforms this results in the file being world writable",
46-
);
39+
span_lint_and_then(
40+
cx,
41+
PERMISSIONS_SET_READONLY_FALSE,
42+
expr.span,
43+
"call to `set_readonly` with argument `false`",
44+
|diag| {
45+
diag.note("on Unix platforms this results in the file being world writable");
46+
diag.help("you can set the desired permissions using `PermissionsExt`. For more information, see\n\
47+
https://doc.rust-lang.org/std/os/unix/fs/trait.PermissionsExt.html");
48+
}
49+
);
4750
}
4851
}
4952
}

tests/ui/permissions_set_readonly_false.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ LL | permissions.set_readonly(false);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: on Unix platforms this results in the file being world writable
8+
= help: you can set the desired permissions using `PermissionsExt`. For more information, see
9+
https://doc.rust-lang.org/std/os/unix/fs/trait.PermissionsExt.html
810
= note: `-D clippy::permissions-set-readonly-false` implied by `-D warnings`
911

1012
error: aborting due to previous error

0 commit comments

Comments
 (0)