Skip to content

Commit

Permalink
Auto merge of #66323 - JohnTitor:rollup-jl8xdk4, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 11 pull requests

Successful merges:

 - #65965 (Clean up librustc_typeck error_codes file)
 - #66230 (remove vestigial comments referring to defunct numeric trait hierarchy)
 - #66241 (bump openssl version)
 - #66257 (Drop long-section-names linker workaround for windows-gnu)
 - #66263 (make the error message more readable)
 - #66267 (Add rustdoc doc)
 - #66276 (Move lock into CodeStats)
 - #66278 (Fix error message about exported symbols from proc-macro crates)
 - #66280 (Fix HashSet::union performance)
 - #66299 (support issue = "none" in unstable attributes )
 - #66309 (Tiny cleanup to size assertions)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Nov 12, 2019
2 parents e3d9984 + 420f926 commit a19f934
Show file tree
Hide file tree
Showing 29 changed files with 458 additions and 190 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2252,9 +2252,9 @@ dependencies = [

[[package]]
name = "openssl"
version = "0.10.16"
version = "0.10.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec7bd7ca4cce6dbdc77e7c1230682740d307d1218a87fb0349a571272be749f9"
checksum = "2f372b2b53ce10fb823a337aaa674e3a7d072b957c6264d0f4ff0bd86e657449"
dependencies = [
"bitflags",
"cfg-if",
Expand All @@ -2281,15 +2281,15 @@ dependencies = [

[[package]]
name = "openssl-sys"
version = "0.9.43"
version = "0.9.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33c86834957dd5b915623e94f2f4ab2c70dd8f6b70679824155d5ae21dbd495d"
checksum = "c977d08e1312e2f7e4b86f9ebaa0ed3b19d1daff75fae88bbb88108afbd801fc"
dependencies = [
"autocfg",
"cc",
"libc",
"openssl-src",
"pkg-config",
"rustc_version",
"vcpkg",
]

Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,12 @@ Arguments:

Flags {
verbose: matches.opt_count("verbose"),
stage: matches.opt_str("stage").map(|j| j.parse().unwrap()),
stage: matches.opt_str("stage").map(|j| j.parse().expect("`stage` should be a number")),
dry_run: matches.opt_present("dry-run"),
on_fail: matches.opt_str("on-fail"),
rustc_error_format: matches.opt_str("error-format"),
keep_stage: matches.opt_strs("keep-stage")
.into_iter().map(|j| j.parse().unwrap())
.into_iter().map(|j| j.parse().expect("`keep-stage` should be a number"))
.collect(),
host: split(&matches.opt_strs("host"))
.into_iter()
Expand All @@ -464,7 +464,7 @@ Arguments:
.map(|x| INTERNER.intern_string(x))
.collect::<Vec<_>>(),
config: cfg_file,
jobs: matches.opt_str("jobs").map(|j| j.parse().unwrap()),
jobs: matches.opt_str("jobs").map(|j| j.parse().expect("`jobs` should be a number")),
cmd,
incremental: matches.opt_present("incremental"),
exclude: split(&matches.opt_strs("exclude"))
Expand Down
2 changes: 2 additions & 0 deletions src/doc/rustdoc/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# The Rustdoc Book

- [What is rustdoc?](what-is-rustdoc.md)
- [How to write documentation](how-to-write-documentation.md)
- [Command-line arguments](command-line-arguments.md)
- [The `#[doc]` attribute](the-doc-attribute.md)
- [Documentation tests](documentation-tests.md)
- [Lints](lints.md)
- [Passes](passes.md)
- [Unstable features](unstable-features.md)
82 changes: 82 additions & 0 deletions src/doc/rustdoc/src/how-to-write-documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# How to write documentation

This chapter covers not only how to write documentation but specifically
how to write **good** documentation. Something to keep in mind when
writing documentation is that your audience is not just yourself but others
who simply don't have the context you do. It is important to be as clear
as you can, and as complete as possible. As a rule of thumb: the more
documentation you write for your crate the better. If an item is public
then it should be documented.

## Basic structure

It is recommended that each item's documentation follows this basic structure:

```text
[short sentence explaining what it is]
[more detailed explanation]
[at least one code example that users can copy/paste to try it]
[even more advanced explanations if necessary]
```

This basic structure should be straightforward to follow when writing your
documentation and, while you might think that a code example is trivial,
the examples are really important because they can help your users to
understand what an item is, how it is used, and for what purpose it exists.

Let's see an example coming from the [standard library] by taking a look at the
[`std::env::args()`][env::args] function:

``````text
Returns the arguments which this program was started with (normally passed
via the command line).
The first element is traditionally the path of the executable, but it can be
set to arbitrary text, and may not even exist. This means this property should
not be relied upon for security purposes.
On Unix systems shell usually expands unquoted arguments with glob patterns
(such as `*` and `?`). On Windows this is not done, and such arguments are
passed as-is.
# Panics
The returned iterator will panic during iteration if any argument to the
process is not valid unicode. If this is not desired,
use the [`args_os`] function instead.
# Examples
```
use std::env;
// Prints each argument on a separate line
for argument in env::args() {
println!("{}", argument);
}
```
[`args_os`]: ./fn.args_os.html
``````

As you can see, it follows the structure detailed above: it starts with a short
sentence explaining what the functions does, then it provides more information
and finally provides a code example.

## Markdown

`rustdoc` is using the [commonmark markdown specification]. You might be
interested into taking a look at their website to see what's possible to do.

## Lints

To be sure that you didn't miss any item without documentation or code examples,
you can take a look at the rustdoc lints [here][rustdoc-lints].

[standard library]: https://doc.rust-lang.org/stable/std/index.html
[env::args]: https://doc.rust-lang.org/stable/std/env/fn.args.html
[commonmark markdown specification]: https://commonmark.org/
[rustdoc-lints]: lints.md
119 changes: 119 additions & 0 deletions src/doc/rustdoc/src/lints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Lints

`rustdoc` provides lints to help you writing and testing your documentation. You
can use them like any other lints by doing this:

```rust,ignore
#![allow(missing_docs)] // allowing the lint, no message
#![warn(missing_docs)] // warn if there is missing docs
#![deny(missing_docs)] // rustdoc will fail if there is missing docs
```

Here is the list of the lints provided by `rustdoc`:

## intra_doc_link_resolution_failure

This lint **warns by default** and is **nightly-only**. This lint detects when
an intra-doc link fails to get resolved. For example:

```rust
/// I want to link to [`Inexistent`] but it doesn't exist!
pub fn foo() {}
```

You'll get a warning saying:

```text
error: `[`Inexistent`]` cannot be resolved, ignoring it...
```

## missing_docs

This lint is **allowed by default**. It detects items missing documentation.
For example:

```rust
#![warn(missing_docs)]

pub fn undocumented() {}
# fn main() {}
```

The `undocumented` function will then have the following warning:

```text
warning: missing documentation for a function
--> your-crate/lib.rs:3:1
|
3 | pub fn undocumented() {}
| ^^^^^^^^^^^^^^^^^^^^^
```

## missing_doc_code_examples

This lint is **allowed by default**. It detects when a documentation block
is missing a code example. For example:

```rust
#![warn(missing_doc_code_examples)]

/// There is no code example!
pub fn no_code_example() {}
# fn main() {}
```

The `no_code_example` function will then have the following warning:

```text
warning: Missing code example in this documentation
--> your-crate/lib.rs:3:1
|
LL | /// There is no code example!
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

To fix the lint, you need to add a code example into the documentation block:

```rust
/// There is no code example!
///
/// ```
/// println!("calling no_code_example...");
/// no_code_example();
/// println!("we called no_code_example!");
/// ```
pub fn no_code_example() {}
```

## private_doc_tests

This lint is **allowed by default**. It detects documentation tests when they
are on a private item. For example:

```rust
#![warn(private_doc_tests)]

mod foo {
/// private doc test
///
/// ```
/// assert!(false);
/// ```
fn bar() {}
}
# fn main() {}
```

Which will give:

```text
warning: Documentation test in private item
--> your-crate/lib.rs:4:1
|
4 | / /// private doc test
5 | | ///
6 | | /// ```
7 | | /// assert!(false);
8 | | /// ```
| |___________^
```
2 changes: 0 additions & 2 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ depending on the target pointer size.
"}
}

// `Int` + `SignedInt` implemented for signed integers
macro_rules! int_impl {
($SelfT:ty, $ActualT:ident, $UnsignedT:ty, $BITS:expr, $Min:expr, $Max:expr, $Feature:expr,
$EndFeature:expr, $rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr,
Expand Down Expand Up @@ -2303,7 +2302,6 @@ impl isize {
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
}

// `Int` + `UnsignedInt` implemented for unsigned integers
macro_rules! uint_impl {
($SelfT:ty, $ActualT:ty, $BITS:expr, $MaxV:expr, $Feature:expr, $EndFeature:expr,
$rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr,
Expand Down
13 changes: 7 additions & 6 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ use syntax::attr::{self, Stability, Deprecation, RustcDeprecation};
use crate::ty::{self, TyCtxt};
use crate::util::nodemap::{FxHashSet, FxHashMap};

use std::mem::replace;
use std::cmp::Ordering;
use std::mem::replace;
use std::num::NonZeroU32;

#[derive(PartialEq, Clone, Copy, Debug)]
pub enum StabilityLevel {
Expand Down Expand Up @@ -441,7 +442,7 @@ impl<'tcx> Index<'tcx> {
let stability = tcx.intern_stability(Stability {
level: attr::StabilityLevel::Unstable {
reason: Some(Symbol::intern(reason)),
issue: 27812,
issue: NonZeroU32::new(27812),
is_soft: false,
},
feature: sym::rustc_private,
Expand Down Expand Up @@ -488,7 +489,7 @@ pub fn report_unstable(
sess: &Session,
feature: Symbol,
reason: Option<Symbol>,
issue: u32,
issue: Option<NonZeroU32>,
is_soft: bool,
span: Span,
soft_handler: impl FnOnce(&'static lint::Lint, Span, &str),
Expand Down Expand Up @@ -520,7 +521,7 @@ pub fn report_unstable(
soft_handler(lint::builtin::SOFT_UNSTABLE, span, &msg)
} else {
emit_feature_err(
&sess.parse_sess, feature, span, GateIssue::Library(Some(issue)), &msg
&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg
);
}
}
Expand Down Expand Up @@ -637,7 +638,7 @@ pub enum EvalResult {
Deny {
feature: Symbol,
reason: Option<Symbol>,
issue: u32,
issue: Option<NonZeroU32>,
is_soft: bool,
},
/// The item does not have the `#[stable]` or `#[unstable]` marker assigned.
Expand Down Expand Up @@ -758,7 +759,7 @@ impl<'tcx> TyCtxt<'tcx> {
// the `-Z force-unstable-if-unmarked` flag present (we're
// compiling a compiler crate), then let this missing feature
// annotation slide.
if feature == sym::rustc_private && issue == 27812 {
if feature == sym::rustc_private && issue == NonZeroU32::new(27812) {
if self.sess.opts.debugging_opts.force_unstable_if_unmarked {
return EvalResult::Allow;
}
Expand Down
12 changes: 7 additions & 5 deletions src/librustc/session/code_stats.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rustc_target::abi::{Align, Size};
use rustc_data_structures::fx::{FxHashSet};
use std::cmp::{self, Ordering};
use rustc_data_structures::sync::Lock;

#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub struct VariantInfo {
Expand Down Expand Up @@ -44,13 +45,13 @@ pub struct TypeSizeInfo {
pub variants: Vec<VariantInfo>,
}

#[derive(PartialEq, Eq, Debug, Default)]
#[derive(Default)]
pub struct CodeStats {
type_sizes: FxHashSet<TypeSizeInfo>,
type_sizes: Lock<FxHashSet<TypeSizeInfo>>,
}

impl CodeStats {
pub fn record_type_size<S: ToString>(&mut self,
pub fn record_type_size<S: ToString>(&self,
kind: DataTypeKind,
type_desc: S,
align: Align,
Expand All @@ -73,11 +74,12 @@ impl CodeStats {
opt_discr_size: opt_discr_size.map(|s| s.bytes()),
variants,
};
self.type_sizes.insert(info);
self.type_sizes.borrow_mut().insert(info);
}

pub fn print_type_sizes(&self) {
let mut sorted: Vec<_> = self.type_sizes.iter().collect();
let type_sizes = self.type_sizes.borrow();
let mut sorted: Vec<_> = type_sizes.iter().collect();

// Primary sort: large-to-small.
// Secondary sort: description (dictionary order)
Expand Down
Loading

0 comments on commit a19f934

Please sign in to comment.