Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates > by-pkgid > 4e2dbb669434a7691662cb2f0ad38972 > files > 11451

rust-doc-1.28.0-1.mga6.armv7hl.rpm

<!DOCTYPE HTML>
<html lang="en" class="sidebar-visible no-js">
    <head>
        <!-- Book generated using mdBook -->
        <meta charset="UTF-8">
        <title>Allowed-by-default lints - The rustc book</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="theme-color" content="#ffffff" />

        <base href="../../">

        <link rel="stylesheet" href="book.css">
        <link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500" rel="stylesheet" type="text/css">

        <link rel="shortcut icon" href="favicon.png">

        <!-- Font Awesome -->
        <link rel="stylesheet" href="_FontAwesome/css/font-awesome.css">

        <link rel="stylesheet" href="highlight.css">
        <link rel="stylesheet" href="tomorrow-night.css">
        <link rel="stylesheet" href="ayu-highlight.css">

        <!-- Custom theme stylesheets -->
        

        

    </head>
    <body class="light">
        <!-- Work around some values being stored in localStorage wrapped in quotes -->
        <script type="text/javascript">
            try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }
        </script>

        <!-- Set the theme before any content is loaded, prevents flash -->
        <script type="text/javascript">
            var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { } 
            if (theme === null || theme === undefined) { theme = 'light'; }
            document.body.className = theme;
            document.querySelector('html').className = theme + ' js';
        </script>

        <!-- Hide / unhide sidebar before it is displayed -->
        <script type="text/javascript">
            var html = document.querySelector('html');
            var sidebar = 'hidden';
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            }
            html.classList.remove('sidebar-visible');
            html.classList.add("sidebar-" + sidebar);
        </script>

        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
            <ol class="chapter"><li><a href="what-is-rustc.html"><strong aria-hidden="true">1.</strong> What is rustc?</a></li><li><a href="command-line-arguments.html"><strong aria-hidden="true">2.</strong> Command-line arguments</a></li><li><a href="lints/index.html"><strong aria-hidden="true">3.</strong> Lints</a></li><li><ol class="section"><li><a href="lints/levels.html"><strong aria-hidden="true">3.1.</strong> Lint levels</a></li><li><a href="lints/groups.html"><strong aria-hidden="true">3.2.</strong> Lint Groups</a></li><li><a href="lints/listing/index.html"><strong aria-hidden="true">3.3.</strong> Lint listing</a></li><li><ol class="section"><li><a href="lints/listing/allowed-by-default.html" class="active"><strong aria-hidden="true">3.3.1.</strong> Allowed-by-default lints</a></li><li><a href="lints/listing/warn-by-default.html"><strong aria-hidden="true">3.3.2.</strong> Warn-by-default lints</a></li><li><a href="lints/listing/deny-by-default.html"><strong aria-hidden="true">3.3.3.</strong> Deny-by-default lints</a></li></ol></li></ol></li><li><a href="codegen-options/index.html"><strong aria-hidden="true">4.</strong> Codegen options</a></li><li><a href="targets/index.html"><strong aria-hidden="true">5.</strong> Targets</a></li><li><ol class="section"><li><a href="targets/built-in.html"><strong aria-hidden="true">5.1.</strong> Built-in Targets</a></li><li><a href="targets/custom.html"><strong aria-hidden="true">5.2.</strong> Custom Targets</a></li></ol></li><li><a href="contributing.html"><strong aria-hidden="true">6.</strong> Contributing to rustc</a></li></ol>
        </nav>

        <div id="page-wrapper" class="page-wrapper">

            <div class="page">
                
                <div id="menu-bar" class="menu-bar">
                    <div id="menu-bar-sticky-container">
                        <div class="left-buttons">
                            <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
                                <i class="fa fa-bars"></i>
                            </button>
                            <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
                                <i class="fa fa-paint-brush"></i>
                            </button>
                            <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
                                <li role="none"><button role="menuitem" class="theme" id="light">Light <span class="default">(default)</span></button></li>
                                <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
                                <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
                                <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
                                <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
                            </ul>
                            
                            <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
                                <i class="fa fa-search"></i>
                            </button>
                            
                        </div>

                        <h1 class="menu-title">The rustc book</h1> 

                        <div class="right-buttons">
                            <a href="print.html" title="Print this book" aria-label="Print this book">
                                <i id="print-button" class="fa fa-print"></i>
                            </a>
                        </div>
                    </div>
                </div>

                
                <div id="search-wrapper" class="hidden">
                    <form id="searchbar-outer" class="searchbar-outer">
                        <input type="search" name="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
                    </form>
                    <div id="searchresults-outer" class="searchresults-outer hidden">
                        <div id="searchresults-header" class="searchresults-header"></div>
                        <ul id="searchresults">
                        </ul>
                    </div>
                </div>
                

                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
                <script type="text/javascript">
                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });
                </script>

                <div id="content" class="content">
                    <main>
                        <a class="header" href="lints/listing/allowed-by-default.html#allowed-by-default-lints" id="allowed-by-default-lints"><h1>Allowed-by-default lints</h1></a>
<p>These lints are all set to the 'allow' level by default. As such, they won't show up
unless you set them to a higher lint level with a flag or attribute.</p>
<a class="header" href="lints/listing/allowed-by-default.html#anonymous-parameters" id="anonymous-parameters"><h2>anonymous-parameters</h2></a>
<p>This lint detects anonymous parameters. Some example code that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#fn main() {
trait Foo {
    fn foo(usize);
}
#}</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: use of deprecated anonymous parameter
 --&gt; src/lib.rs:5:11
  |
5 |     fn foo(usize);
  |           ^
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #41686 &lt;https://github.com/rust-lang/rust/issues/41686&gt;
</code></pre>
<p>This syntax is mostly a historical accident, and can be worked around quite
easily:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#fn main() {
trait Foo {
    fn foo(_: usize);
}
#}</code></pre></pre>
<a class="header" href="lints/listing/allowed-by-default.html#bare-trait-object" id="bare-trait-object"><h2>bare-trait-object</h2></a>
<p>This lint suggests using <code>dyn Trait</code> for trait objects. Some example code
that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#![feature(dyn_trait)]

#fn main() {
trait Trait { }

fn takes_trait_object(_: Box&lt;Trait&gt;) {
}
#}</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: trait objects without an explicit `dyn` are deprecated
 --&gt; src/lib.rs:7:30
  |
7 | fn takes_trait_object(_: Box&lt;Trait&gt;) {
  |                              ^^^^^ help: use `dyn`: `dyn Trait`
  |
</code></pre>
<p>To fix it, do as the help message suggests:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#![feature(dyn_trait)]
#![deny(bare_trait_objects)]

#fn main() {
trait Trait { }

fn takes_trait_object(_: Box&lt;dyn Trait&gt;) {
}
#}</code></pre></pre>
<a class="header" href="lints/listing/allowed-by-default.html#box-pointers" id="box-pointers"><h2>box-pointers</h2></a>
<p>This lints use of the Box type. Some example code that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#fn main() {
struct Foo {
    x: Box&lt;isize&gt;,
}
#}</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: type uses owned (Box type) pointers: std::boxed::Box&lt;isize&gt;
 --&gt; src/lib.rs:6:5
  |
6 |     x: Box&lt;isize&gt; //~ ERROR type uses owned
  |     ^^^^^^^^^^^^^
  |
</code></pre>
<p>This lint is mostly historical, and not particularly useful. <code>Box&lt;T&gt;</code> used to
be built into the language, and the only way to do heap allocation. Today's
Rust can call into other allocators, etc.</p>
<a class="header" href="lints/listing/allowed-by-default.html#elided-lifetime-in-path" id="elided-lifetime-in-path"><h2>elided-lifetime-in-path</h2></a>
<p>This lint detects the use of hidden lifetime parameters. Some example code
that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#fn main() {
struct Foo&lt;'a&gt; {
    x: &amp;'a u32
}

fn foo(x: &amp;Foo) {
}
#}</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: hidden lifetime parameters are deprecated, try `Foo&lt;'_&gt;`
 --&gt; src/lib.rs:5:12
  |
5 | fn foo(x: &amp;Foo) {
  |            ^^^
  |
</code></pre>
<p>Lifetime elision elides this lifetime, but that is being deprecated.</p>
<a class="header" href="lints/listing/allowed-by-default.html#missing-copy-implementations" id="missing-copy-implementations"><h2>missing-copy-implementations</h2></a>
<p>This lint detects potentially-forgotten implementations of <code>Copy</code>. Some
example code that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#fn main() {
pub struct Foo {
    pub field: i32
}
#}</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: type could implement `Copy`; consider adding `impl Copy`
 --&gt; src/main.rs:3:1
  |
3 | / pub struct Foo { //~ ERROR type could implement `Copy`; consider adding `impl Copy`
4 | |     pub field: i32
5 | | }
  | |_^
  |
</code></pre>
<p>You can fix the lint by deriving <code>Copy</code>.</p>
<p>This lint is set to 'allow' because this code isn't bad; it's common to write
newtypes like this specifically so that a <code>Copy</code> type is no longer <code>Copy</code>.</p>
<a class="header" href="lints/listing/allowed-by-default.html#missing-debug-implementations" id="missing-debug-implementations"><h2>missing-debug-implementations</h2></a>
<p>This lint detects missing implementations of <code>fmt::Debug</code>. Some example code
that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#fn main() {
pub struct Foo;
#}</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: type does not implement `fmt::Debug`; consider adding #[derive(Debug)] or a manual implementation
 --&gt; src/main.rs:3:1
  |
3 | pub struct Foo;
  | ^^^^^^^^^^^^^^^
  |
</code></pre>
<p>You can fix the lint by deriving <code>Debug</code>.</p>
<a class="header" href="lints/listing/allowed-by-default.html#missing-docs" id="missing-docs"><h2>missing-docs</h2></a>
<p>This lint detects missing documentation for public items. Some example code
that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#fn main() {
pub fn foo() {}
#}</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: missing documentation for crate
 --&gt; src/main.rs:1:1
  |
1 | / #![deny(missing_docs)]
2 | |
3 | | pub fn foo() {}
4 | |
5 | | fn main() {}
  | |____________^
  |

error: missing documentation for a function
 --&gt; src/main.rs:3:1
  |
3 | pub fn foo() {}
  | ^^^^^^^^^^^^

</code></pre>
<p>To fix the lint, add documentation to all items.</p>
<a class="header" href="lints/listing/allowed-by-default.html#single-use-lifetime" id="single-use-lifetime"><h2>single-use-lifetime</h2></a>
<p>This lint detects lifetimes that are only used once. Some example code that
triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#fn main() {
struct Foo&lt;'x&gt; {
    x: &amp;'x u32
}
#}</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: lifetime name `'x` only used once
 --&gt; src/main.rs:3:12
  |
3 | struct Foo&lt;'x&gt; {
  |            ^^
  |
</code></pre>
<a class="header" href="lints/listing/allowed-by-default.html#trivial-casts" id="trivial-casts"><h2>trivial-casts</h2></a>
<p>This lint detects trivial casts which could be removed. Some example code
that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#fn main() {
let x: &amp;u32 = &amp;42;
let _ = x as *const u32;
#}</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: trivial cast: `&amp;u32` as `*const u32`. Cast can be replaced by coercion, this might require type ascription or a temporary variable
 --&gt; src/main.rs:5:13
  |
5 |     let _ = x as *const u32;
  |             ^^^^^^^^^^^^^^^
  |
note: lint level defined here
 --&gt; src/main.rs:1:9
  |
1 | #![deny(trivial_casts)]
  |         ^^^^^^^^^^^^^
</code></pre>
<a class="header" href="lints/listing/allowed-by-default.html#trivial-numeric-casts" id="trivial-numeric-casts"><h2>trivial-numeric-casts</h2></a>
<p>This lint detects trivial casts of numeric types which could be removed. Some
example code that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#fn main() {
let x = 42i32 as i32;
#}</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: trivial numeric cast: `i32` as `i32`. Cast can be replaced by coercion, this might require type ascription or a temporary variable
 --&gt; src/main.rs:4:13
  |
4 |     let x = 42i32 as i32;
  |             ^^^^^^^^^^^^
  |
</code></pre>
<a class="header" href="lints/listing/allowed-by-default.html#unreachable-pub" id="unreachable-pub"><h2>unreachable-pub</h2></a>
<p>This lint triggers for <code>pub</code> items not reachable from the crate root. Some
example code that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#fn main() {
mod foo {
    pub mod bar {
        
    }
}
#}</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: unreachable `pub` item
 --&gt; src/main.rs:4:5
  |
4 |     pub mod bar {
  |     ---^^^^^^^^
  |     |
  |     help: consider restricting its visibility: `pub(crate)`
  |
</code></pre>
<a class="header" href="lints/listing/allowed-by-default.html#unsafe-code" id="unsafe-code"><h2>unsafe-code</h2></a>
<p>This lint catches usage of <code>unsafe</code> code. Some example code that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">fn main() {
    unsafe {

    }
}
</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: usage of an `unsafe` block
 --&gt; src/main.rs:4:5
  |
4 | /     unsafe {
5 | |         
6 | |     }
  | |_____^
  |
</code></pre>
<a class="header" href="lints/listing/allowed-by-default.html#unstable-features" id="unstable-features"><h2>unstable-features</h2></a>
<p>This lint is deprecated and no longer used.</p>
<a class="header" href="lints/listing/allowed-by-default.html#unused-extern-crates" id="unused-extern-crates"><h2>unused-extern-crates</h2></a>
<p>This lint guards against <code>extern crate</code> items that are never used. Some
example code that triggers this lint:</p>
<pre><code class="language-rust ignore">extern crate semver;
</code></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: unused extern crate
 --&gt; src/main.rs:3:1
  |
3 | extern crate semver;
  | ^^^^^^^^^^^^^^^^^^^^
  |
</code></pre>
<a class="header" href="lints/listing/allowed-by-default.html#unused-import-braces" id="unused-import-braces"><h2>unused-import-braces</h2></a>
<p>This lint catches unnecessary braces around an imported item. Some example
code that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">use test::{A};

pub mod test {
    pub struct A;
}
# fn main() {}
</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: braces around A is unnecessary
 --&gt; src/main.rs:3:1
  |
3 | use test::{A};
  | ^^^^^^^^^^^^^^
  |
</code></pre>
<p>To fix it, <code>use test::A;</code></p>
<a class="header" href="lints/listing/allowed-by-default.html#unused-qualifications" id="unused-qualifications"><h2>unused-qualifications</h2></a>
<p>This lint detects unnecessarily qualified names. Some example code that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">mod foo {
    pub fn bar() {}
}

fn main() {
    use foo::bar;
    foo::bar();
}
</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: unnecessary qualification
 --&gt; src/main.rs:9:5
  |
9 |     foo::bar();
  |     ^^^^^^^^
  |
</code></pre>
<p>You can call <code>bar()</code> directly, without the <code>foo::</code>.</p>
<a class="header" href="lints/listing/allowed-by-default.html#unused-results" id="unused-results"><h2>unused-results</h2></a>
<p>This lint checks for the unused result of an expression in a statement. Some
example code that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust no_run">fn foo&lt;T&gt;() -&gt; T { panic!() }

fn main() {
    foo::&lt;usize&gt;();
}
</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: unused result
 --&gt; src/main.rs:6:5
  |
6 |     foo::&lt;usize&gt;();
  |     ^^^^^^^^^^^^^^^
  |
</code></pre>
<a class="header" href="lints/listing/allowed-by-default.html#variant-size-differences" id="variant-size-differences"><h2>variant-size-differences</h2></a>
<p>This lint detects enums with widely varying variant sizes. Some example code that triggers this lint:</p>
<pre><pre class="playpen"><code class="language-rust">
# #![allow(unused_variables)]
#fn main() {
enum En {
    V0(u8),
    VBig([u8; 1024]),
}
#}</code></pre></pre>
<p>When set to 'deny', this will produce:</p>
<pre><code class="language-text">error: enum variant is more than three times larger (1024 bytes) than the next largest
 --&gt; src/main.rs:5:5
  |
5 |     VBig([u8; 1024]),   //~ ERROR variant is more than three times larger
  |     ^^^^^^^^^^^^^^^^
  |
</code></pre>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->
                        
                            <a rel="prev" href="lints/listing/index.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                                <i class="fa fa-angle-left"></i>
                            </a>
                        

                        
                            <a rel="next" href="lints/listing/warn-by-default.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                                <i class="fa fa-angle-right"></i>
                            </a>
                        

                        <div style="clear: both"></div>
                    </nav>
                </div>
            </div>

            <nav class="nav-wide-wrapper" aria-label="Page navigation">
                
                    <a href="lints/listing/index.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                        <i class="fa fa-angle-left"></i>
                    </a>
                

                
                    <a href="lints/listing/warn-by-default.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                        <i class="fa fa-angle-right"></i>
                    </a>
                
            </nav>

        </div>

        

        

        

        

        
        <script src="searchindex.js" type="text/javascript" charset="utf-8"></script>
        
        
        <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
        

        <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
        <script src="book.js" type="text/javascript" charset="utf-8"></script>

        <!-- Custom JS scripts -->
        

    </body>
</html>