1 # Warn-by-default lints
3 These lints are all set to the 'warn' level by default.
7 This lint detects an erroneous expression while doing constant evaluation. Some
8 example code that triggers this lint:
11 let b = 200u8 + 200u8;
17 warning: attempt to add with overflow
20 2 | let b = 200u8 + 200u8;
27 This lint detects unused, unexported items. Some
28 example code that triggers this lint:
37 warning: function is never used: `foo`
47 This lint detects use of deprecated items. Some
48 example code that triggers this lint:
62 warning: use of deprecated item 'foo'
70 ## illegal-floating-point-literal-pattern
72 This lint detects floating-point literals used in patterns. Some example code
73 that triggers this lint:
87 warning: floating-point literals cannot be used in patterns
93 = note: #[warn(illegal_floating_point_literal_pattern)] on by default
94 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
95 = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
100 This lint detects proper use of libc types in foreign modules. Some
101 example code that triggers this lint:
105 static STATIC: String;
112 warning: found struct without foreign-function-safe representation annotation in foreign module, consider adding a #[repr(C)] attribute to the type
115 2 | static STATIC: String;
120 ## late-bound-lifetime-arguments
122 This lint detects generic lifetime arguments in path segments with
123 late bound lifetime parameters. Some example code that triggers this lint:
129 fn late<'a, 'b>(self, _: &'a u8, _: &'b u8) {}
133 S.late::<'static>(&0, &0);
140 warning: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
143 4 | fn late<'a, 'b>(self, _: &'a u8, _: &'b u8) {}
144 | -- the late bound lifetime parameter is introduced here
146 8 | S.late::<'static>(&0, &0);
149 = note: #[warn(late_bound_lifetime_arguments)] on by default
150 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
151 = note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
154 ## non-camel-case-types
156 This lint detects types, variants, traits and type parameters that don't have
157 camel case names. Some example code that triggers this lint:
166 warning: type `s` should have a camel case name such as `S`
174 ## non-shorthand-field-patterns
176 This lint detects using `Struct { x: x }` instead of `Struct { x }` in a pattern. Some
177 example code that triggers this lint:
193 Point { x: x, y: y } => (),
201 warning: the `x:` in this pattern is redundant
202 --> src/main.rs:14:17
204 14 | Point { x: x, y: y } => (),
210 warning: the `y:` in this pattern is redundant
211 --> src/main.rs:14:23
213 14 | Point { x: x, y: y } => (),
222 This lint detects variables, methods, functions, lifetime parameters and
223 modules that don't have snake case names. Some example code that triggers
233 warning: variable `X` should have a snake case name such as `x`
241 ## non-upper-case-globals
243 This lint detects static constants that don't have uppercase identifiers.
244 Some example code that triggers this lint:
253 warning: static variable `x` should have an upper case name such as `X`
256 1 | static x: i32 = 5;
261 ## no-mangle-generic-items
263 This lint detects generic items must be mangled. Some
264 example code that triggers this lint:
276 warning: functions generic over types must be mangled
280 | ------------ help: remove this attribute
281 2 | / fn foo<T>(t: T) {
290 This lint detects path statements with no effect. Some example code that
302 warning: path statement with no effect
310 ## patterns-in-fns-without-body
312 This lint detects patterns in functions without body were that were
313 previously erroneously allowed. Some example code that triggers this lint:
324 warning: patterns aren't allowed in methods without bodies
327 2 | fn foo(mut arg: u8);
330 = note: #[warn(patterns_in_fns_without_body)] on by default
331 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
332 = note: for more information, see issue #35203 <https://github.com/rust-lang/rust/issues/35203>
335 To fix this, remove the pattern; it can be used in the implementation without
336 being used in the definition. That is:
344 fn foo(mut arg: u8) {
352 This lint detects when compiler plugins are used as ordinary library in
353 non-plugin crate. Some example code that triggers this lint:
357 #![plugin(macro_crate_test)]
359 extern crate macro_crate_test;
364 This lint detects private items in public interfaces not caught by the old implementation. Some
365 example code that triggers this lint:
377 impl ::Trait for ::S {
387 error[E0446]: private type `foo::Z` in public interface
391 | ^^^^^^^^^^^ can't leak private type
394 ## private-no-mangle-fns
396 This lint detects functions marked `#[no_mangle]` that are also private.
397 Given that private functions aren't exposed publicly, and `#[no_mangle]`
398 controls the public symbol, this combination is erroneous. Some example code
399 that triggers this lint:
409 warning: function is marked #[no_mangle], but not exported
415 | help: try making it public: `pub`
419 To fix this, either make it public or remove the `#[no_mangle]`.
421 ## private-no-mangle-statics
423 This lint detects any statics marked `#[no_mangle]` that are private.
424 Given that private statics aren't exposed publicly, and `#[no_mangle]`
425 controls the public symbol, this combination is erroneous. Some example code
426 that triggers this lint:
436 warning: static is marked #[no_mangle], but not exported
439 2 | static X: i32 = 4;
442 | help: try making it public: `pub`
446 To fix this, either make it public or remove the `#[no_mangle]`.
448 ## renamed-and-removed-lints
450 This lint detects lints that have been renamed or removed. Some
451 example code that triggers this lint:
454 #![deny(raw_pointer_derive)]
460 warning: lint raw_pointer_derive has been removed: using derive with raw pointers is ok
463 1 | #![deny(raw_pointer_derive)]
468 To fix this, either remove the lint or use the new name.
470 ## safe-packed-borrows
472 This lint detects borrowing a field in the interior of a packed structure
473 with alignment other than 1. Some example code that triggers this lint:
477 pub struct Unaligned<T>(pub T);
481 data: Unaligned<u32>,
485 let x = Foo { start: 0, data: Unaligned(1) };
493 warning: borrow of packed field requires unsafe function or block (error E0133)
494 --> src/main.rs:11:13
496 11 | let y = &x.data.0;
499 = note: #[warn(safe_packed_borrows)] on by default
500 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
501 = note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
506 This lint detects a `#[feature]` attribute that's since been made stable. Some
507 example code that triggers this lint:
510 #![feature(test_accepted_feature)]
516 warning: this feature has been stable since 1.0.0. Attribute no longer needed
519 1 | #![feature(test_accepted_feature)]
520 | ^^^^^^^^^^^^^^^^^^^^^
524 To fix, simply remove the `#![feature]` attribute, as it's no longer needed.
528 This lint detects bounds in type aliases. These are not currently enforced.
529 Some example code that triggers this lint:
532 type SendVec<T: Send> = Vec<T>;
538 warning: type alias is never used: `SendVec`
541 1 | type SendVec<T: Send> = Vec<T>;
542 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
546 ## tyvar-behind-raw-pointer
548 This lint detects raw pointer to an inference variable. Some
549 example code that triggers this lint:
552 let data = std::ptr::null();
553 let _ = &data as *const *const ();
561 warning: type annotations needed
564 4 | if data.is_null() {}
567 = note: #[warn(tyvar_behind_raw_pointer)] on by default
568 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
569 = note: for more information, see issue #46906 <https://github.com/rust-lang/rust/issues/46906>
572 ## unconditional-recursion
574 This lint detects functions that cannot return without calling themselves.
575 Some example code that triggers this lint:
586 warning: function cannot return without recursing
590 | ^^^^^^^^ cannot return without recursing
592 | ----- recursive call site
596 ## unions-with-drop-fields
598 This lint detects use of unions that contain fields with possibly non-trivial drop code. Some
599 example code that triggers this lint:
602 #![feature(untagged_unions)]
612 warning: union contains a field with possibly non-trivial drop code, drop code of union fields is ignored when dropping the union
622 This lint detects unrecognized lint attribute. Some
623 example code that triggers this lint:
626 #[allow(not_a_real_lint)]
632 warning: unknown lint: `not_a_real_lint`
635 1 | #![allow(not_a_real_lint)]
642 This lint detects unreachable code paths. Some example code that
646 panic!("we never go past here!");
654 warning: unreachable statement
662 ## unreachable-patterns
664 This lint detects unreachable patterns. Some
665 example code that triggers this lint:
678 warning: unreachable pattern
686 The `y` pattern will always match, so the five is impossible to reach.
687 Remember, match arms match in order, you probably wanted to put the `5` case
690 ## unstable-name-collision
692 This lint detects that you've used a name that the standard library plans to
693 add in the future, which means that your code may fail to compile without
694 additional type annotations in the future. Either rename, or add those
699 This lint detects unnecessary allocations that can be eliminated.
701 ## unused-assignments
703 This lint detects assignments that will never be read. Some
704 example code that triggers this lint:
714 warning: value assigned to `x` is never read
724 This lint detects attributes that were not used by the compiler. Some
725 example code that triggers this lint:
728 #![feature(custom_attribute)]
736 warning: unused attribute
744 ## unused-comparisons
746 This lint detects comparisons made useless by limits of the types involved. Some
747 example code that triggers this lint:
758 warning: comparison is useless due to type limits
766 ## unused-doc-comment
768 This lint detects doc comments that aren't used by rustdoc. Some
769 example code that triggers this lint:
779 warning: doc comment not used by rustdoc
789 This lint detects unused or unknown features found in crate-level #[feature] directives.
790 To fix this, simply remove the feature flag.
794 This lint detects imports that are never used. Some
795 example code that triggers this lint:
798 use std::collections::HashMap;
804 warning: unused import: `std::collections::HashMap`
807 1 | use std::collections::HashMap;
808 | ^^^^^^^^^^^^^^^^^^^^^^^^^
814 This lint detects macros that were not used. Some example code that
818 macro_rules! unused {
829 warning: unused macro definition
832 1 | / macro_rules! unused {
841 This lint detects unused result of a type flagged as #[must_use]. Some
842 example code that triggers this lint:
845 fn returns_result() -> Result<(), ()> {
857 warning: unused `std::result::Result` that must be used
860 6 | returns_result();
867 This lint detects mut variables which don't need to be mutable. Some
868 example code that triggers this lint:
877 warning: variable does not need to be mutable
883 | help: remove this `mut`
889 This lint detects `if`, `match`, `while` and `return` with parentheses; they
890 do not need them. Some example code that triggers this lint:
899 warning: unnecessary parentheses around `if` condition
903 | ^^^^^^ help: remove these parentheses
909 This lint detects unnecessary use of an `unsafe` block. Some
910 example code that triggers this lint:
919 warning: unnecessary `unsafe` block
923 | ^^^^^^ unnecessary `unsafe` block
929 This lint detects variables which are not used in any way. Some
930 example code that triggers this lint:
939 warning: unused variable: `x`
943 | ^ help: consider using `_x` instead
949 This lint is a bit special; by changing its level, you change every other warning
950 that would produce a warning to whatever value you'd like:
956 As such, you won't ever trigger this lint in your code directly.
960 This lint detects `while true { }`. Some example code that triggers this
972 warning: denote infinite loops with `loop { ... }`
976 | ^^^^^^^^^^ help: use `loop`