- matches!(walk_ptrs_ty(cx.tcx.expr_ty(&args[0])).sty, ty::TyStr)
-}
-
-/// **What it does:** This lint checks for getting the remainder of a division by one.
-///
-/// **Why is this bad?** The result can only ever be zero. No one will write such code deliberately, unless trying to win an Underhanded Rust Contest. Even for that contest, it's probably a bad idea. Use something more underhanded.
-///
-/// **Known problems:** None
-///
-/// **Example:** `x % 1`
-declare_lint!(pub MODULO_ONE, Warn, "taking a number modulo 1, which always returns 0");
-
-#[derive(Copy,Clone)]
-pub struct ModuloOne;
-
-impl LintPass for ModuloOne {
- fn get_lints(&self) -> LintArray {
- lint_array!(MODULO_ONE)
- }
-}
-
-impl LateLintPass for ModuloOne {
- fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
- if let ExprBinary(ref cmp, _, ref right) = expr.node {
- if let Spanned { node: BinOp_::BiRem, .. } = *cmp {
- if is_integer_literal(right, 1) {
- span_lint(cx, MODULO_ONE, expr.span, "any number modulo 1 will be 0");
- }
- }
- }
- }
-}
-
-/// **What it does:** This lint checks for patterns in the form `name @ _`.
-///
-/// **Why is this bad?** It's almost always more readable to just use direct bindings.
-///
-/// **Known problems:** None
-///
-/// **Example**:
-/// ```
-/// match v {
-/// Some(x) => (),
-/// y @ _ => (), // easier written as `y`,
-/// }
-/// ```
-declare_lint!(pub REDUNDANT_PATTERN, Warn, "using `name @ _` in a pattern");
-
-#[derive(Copy,Clone)]
-pub struct PatternPass;
-
-impl LintPass for PatternPass {
- fn get_lints(&self) -> LintArray {
- lint_array!(REDUNDANT_PATTERN)
- }
-}
-
-impl LateLintPass for PatternPass {
- fn check_pat(&mut self, cx: &LateContext, pat: &Pat) {
- if let PatKind::Binding(_, ref ident, Some(ref right)) = pat.node {
- if right.node == PatKind::Wild {
- span_lint(cx,
- REDUNDANT_PATTERN,
- pat.span,
- &format!("the `{} @ _` pattern can be written as just `{}`",
- ident.node,
- ident.node));
- }
- }
- }
-}
-
-
-/// **What it does:** This lint checks for the use of bindings with a single leading underscore
-///
-/// **Why is this bad?** A single leading underscore is usually used to indicate that a binding
-/// will not be used. Using such a binding breaks this expectation.
-///
-/// **Known problems:** The lint does not work properly with desugaring and macro, it has been
-/// allowed in the mean time.
-///
-/// **Example**:
-/// ```
-/// let _x = 0;
-/// let y = _x + 1; // Here we are using `_x`, even though it has a leading underscore.
-/// // We should rename `_x` to `x`
-/// ```
-declare_lint!(pub USED_UNDERSCORE_BINDING, Allow,
- "using a binding which is prefixed with an underscore");
-
-#[derive(Copy, Clone)]
-pub struct UsedUnderscoreBinding;
-
-impl LintPass for UsedUnderscoreBinding {
- fn get_lints(&self) -> LintArray {
- lint_array!(USED_UNDERSCORE_BINDING)
- }
-}
-
-impl LateLintPass for UsedUnderscoreBinding {
- #[cfg_attr(rustfmt, rustfmt_skip)]
- fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
- if in_attributes_expansion(cx, expr) {
- // Don't lint things expanded by #[derive(...)], etc
- return;
- }
- let binding = match expr.node {
- ExprPath(_, ref path) => {
- let segment = path.segments
- .last()
- .expect("path should always have at least one segment")
- .name;
- if segment.as_str().starts_with('_') &&
- !segment.as_str().starts_with("__") &&
- segment != segment.unhygienize() && // not in bang macro
- is_used(cx, expr) {
- Some(segment.as_str())
- } else {
- None
- }
- }
- ExprField(_, spanned) => {
- let name = spanned.node.as_str();
- if name.starts_with('_') && !name.starts_with("__") {
- Some(name)
- } else {
- None
- }
- }
- _ => None,
- };
- if let Some(binding) = binding {
- if binding != "_result" { // FIXME: #944
- span_lint(cx,
- USED_UNDERSCORE_BINDING,
- expr.span,
- &format!("used binding `{}` which is prefixed with an underscore. A leading \
- underscore signals that a binding will not be used.", binding));
- }
- }
- }