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:
533 type SendVec<T: Send> = Vec<T>;
539 warning: bounds on generic parameters are not enforced in type aliases
542 2 | type SendVec<T: Send> = Vec<T>;
545 = note: #[warn(type_alias_bounds)] on by default
546 = help: the bound will not be checked when the type alias is used, and should be removed
549 ## tyvar-behind-raw-pointer
551 This lint detects raw pointer to an inference variable. Some
552 example code that triggers this lint:
555 let data = std::ptr::null();
556 let _ = &data as *const *const ();
564 warning: type annotations needed
567 4 | if data.is_null() {}
570 = note: #[warn(tyvar_behind_raw_pointer)] on by default
571 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
572 = note: for more information, see issue #46906 <https://github.com/rust-lang/rust/issues/46906>
575 ## unconditional-recursion
577 This lint detects functions that cannot return without calling themselves.
578 Some example code that triggers this lint:
589 warning: function cannot return without recursing
593 | ^^^^^^^^ cannot return without recursing
595 | ----- recursive call site
599 ## unions-with-drop-fields
601 This lint detects use of unions that contain fields with possibly non-trivial drop code. Some
602 example code that triggers this lint:
605 #![feature(untagged_unions)]
615 warning: union contains a field with possibly non-trivial drop code, drop code of union fields is ignored when dropping the union
625 This lint detects unrecognized lint attribute. Some
626 example code that triggers this lint:
629 #[allow(not_a_real_lint)]
635 warning: unknown lint: `not_a_real_lint`
638 1 | #![allow(not_a_real_lint)]
645 This lint detects unreachable code paths. Some example code that
649 panic!("we never go past here!");
657 warning: unreachable statement
665 ## unreachable-patterns
667 This lint detects unreachable patterns. Some
668 example code that triggers this lint:
681 warning: unreachable pattern
689 The `y` pattern will always match, so the five is impossible to reach.
690 Remember, match arms match in order, you probably wanted to put the `5` case
693 ## unstable-name-collision
695 This lint detects that you've used a name that the standard library plans to
696 add in the future, which means that your code may fail to compile without
697 additional type annotations in the future. Either rename, or add those
702 This lint detects unnecessary allocations that can be eliminated.
704 ## unused-assignments
706 This lint detects assignments that will never be read. Some
707 example code that triggers this lint:
717 warning: value assigned to `x` is never read
727 This lint detects attributes that were not used by the compiler. Some
728 example code that triggers this lint:
731 #![feature(custom_attribute)]
739 warning: unused attribute
747 ## unused-comparisons
749 This lint detects comparisons made useless by limits of the types involved. Some
750 example code that triggers this lint:
761 warning: comparison is useless due to type limits
769 ## unused-doc-comment
771 This lint detects doc comments that aren't used by rustdoc. Some
772 example code that triggers this lint:
782 warning: doc comment not used by rustdoc
792 This lint detects unused or unknown features found in crate-level #[feature] directives.
793 To fix this, simply remove the feature flag.
797 This lint detects imports that are never used. Some
798 example code that triggers this lint:
801 use std::collections::HashMap;
807 warning: unused import: `std::collections::HashMap`
810 1 | use std::collections::HashMap;
811 | ^^^^^^^^^^^^^^^^^^^^^^^^^
817 This lint detects macros that were not used. Some example code that
821 macro_rules! unused {
832 warning: unused macro definition
835 1 | / macro_rules! unused {
844 This lint detects unused result of a type flagged as #[must_use]. Some
845 example code that triggers this lint:
848 fn returns_result() -> Result<(), ()> {
860 warning: unused `std::result::Result` that must be used
863 6 | returns_result();
870 This lint detects mut variables which don't need to be mutable. Some
871 example code that triggers this lint:
880 warning: variable does not need to be mutable
886 | help: remove this `mut`
892 This lint detects `if`, `match`, `while` and `return` with parentheses; they
893 do not need them. Some example code that triggers this lint:
902 warning: unnecessary parentheses around `if` condition
906 | ^^^^^^ help: remove these parentheses
912 This lint detects unnecessary use of an `unsafe` block. Some
913 example code that triggers this lint:
922 warning: unnecessary `unsafe` block
926 | ^^^^^^ unnecessary `unsafe` block
932 This lint detects variables which are not used in any way. Some
933 example code that triggers this lint:
942 warning: unused variable: `x`
946 | ^ help: consider using `_x` instead
952 This lint is a bit special; by changing its level, you change every other warning
953 that would produce a warning to whatever value you'd like:
959 As such, you won't ever trigger this lint in your code directly.
963 This lint detects `while true { }`. Some example code that triggers this
975 warning: denote infinite loops with `loop { ... }`
979 | ^^^^^^^^^^ help: use `loop`