Skip to content

Commit a19f934

Browse files
committed
Auto merge of #66323 - JohnTitor:rollup-jl8xdk4, r=JohnTitor
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
2 parents e3d9984 + 420f926 commit a19f934

File tree

29 files changed

+458
-190
lines changed

29 files changed

+458
-190
lines changed

Cargo.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -2252,9 +2252,9 @@ dependencies = [
22522252

22532253
[[package]]
22542254
name = "openssl"
2255-
version = "0.10.16"
2255+
version = "0.10.25"
22562256
source = "registry+https://github.com/rust-lang/crates.io-index"
2257-
checksum = "ec7bd7ca4cce6dbdc77e7c1230682740d307d1218a87fb0349a571272be749f9"
2257+
checksum = "2f372b2b53ce10fb823a337aaa674e3a7d072b957c6264d0f4ff0bd86e657449"
22582258
dependencies = [
22592259
"bitflags",
22602260
"cfg-if",
@@ -2281,15 +2281,15 @@ dependencies = [
22812281

22822282
[[package]]
22832283
name = "openssl-sys"
2284-
version = "0.9.43"
2284+
version = "0.9.52"
22852285
source = "registry+https://github.com/rust-lang/crates.io-index"
2286-
checksum = "33c86834957dd5b915623e94f2f4ab2c70dd8f6b70679824155d5ae21dbd495d"
2286+
checksum = "c977d08e1312e2f7e4b86f9ebaa0ed3b19d1daff75fae88bbb88108afbd801fc"
22872287
dependencies = [
2288+
"autocfg",
22882289
"cc",
22892290
"libc",
22902291
"openssl-src",
22912292
"pkg-config",
2292-
"rustc_version",
22932293
"vcpkg",
22942294
]
22952295

src/bootstrap/flags.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,12 @@ Arguments:
448448

449449
Flags {
450450
verbose: matches.opt_count("verbose"),
451-
stage: matches.opt_str("stage").map(|j| j.parse().unwrap()),
451+
stage: matches.opt_str("stage").map(|j| j.parse().expect("`stage` should be a number")),
452452
dry_run: matches.opt_present("dry-run"),
453453
on_fail: matches.opt_str("on-fail"),
454454
rustc_error_format: matches.opt_str("error-format"),
455455
keep_stage: matches.opt_strs("keep-stage")
456-
.into_iter().map(|j| j.parse().unwrap())
456+
.into_iter().map(|j| j.parse().expect("`keep-stage` should be a number"))
457457
.collect(),
458458
host: split(&matches.opt_strs("host"))
459459
.into_iter()
@@ -464,7 +464,7 @@ Arguments:
464464
.map(|x| INTERNER.intern_string(x))
465465
.collect::<Vec<_>>(),
466466
config: cfg_file,
467-
jobs: matches.opt_str("jobs").map(|j| j.parse().unwrap()),
467+
jobs: matches.opt_str("jobs").map(|j| j.parse().expect("`jobs` should be a number")),
468468
cmd,
469469
incremental: matches.opt_present("incremental"),
470470
exclude: split(&matches.opt_strs("exclude"))

src/doc/rustdoc/src/SUMMARY.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# The Rustdoc Book
22

33
- [What is rustdoc?](what-is-rustdoc.md)
4+
- [How to write documentation](how-to-write-documentation.md)
45
- [Command-line arguments](command-line-arguments.md)
56
- [The `#[doc]` attribute](the-doc-attribute.md)
67
- [Documentation tests](documentation-tests.md)
8+
- [Lints](lints.md)
79
- [Passes](passes.md)
810
- [Unstable features](unstable-features.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# How to write documentation
2+
3+
This chapter covers not only how to write documentation but specifically
4+
how to write **good** documentation. Something to keep in mind when
5+
writing documentation is that your audience is not just yourself but others
6+
who simply don't have the context you do. It is important to be as clear
7+
as you can, and as complete as possible. As a rule of thumb: the more
8+
documentation you write for your crate the better. If an item is public
9+
then it should be documented.
10+
11+
## Basic structure
12+
13+
It is recommended that each item's documentation follows this basic structure:
14+
15+
```text
16+
[short sentence explaining what it is]
17+
18+
[more detailed explanation]
19+
20+
[at least one code example that users can copy/paste to try it]
21+
22+
[even more advanced explanations if necessary]
23+
```
24+
25+
This basic structure should be straightforward to follow when writing your
26+
documentation and, while you might think that a code example is trivial,
27+
the examples are really important because they can help your users to
28+
understand what an item is, how it is used, and for what purpose it exists.
29+
30+
Let's see an example coming from the [standard library] by taking a look at the
31+
[`std::env::args()`][env::args] function:
32+
33+
``````text
34+
Returns the arguments which this program was started with (normally passed
35+
via the command line).
36+
37+
The first element is traditionally the path of the executable, but it can be
38+
set to arbitrary text, and may not even exist. This means this property should
39+
not be relied upon for security purposes.
40+
41+
On Unix systems shell usually expands unquoted arguments with glob patterns
42+
(such as `*` and `?`). On Windows this is not done, and such arguments are
43+
passed as-is.
44+
45+
# Panics
46+
47+
The returned iterator will panic during iteration if any argument to the
48+
process is not valid unicode. If this is not desired,
49+
use the [`args_os`] function instead.
50+
51+
# Examples
52+
53+
```
54+
use std::env;
55+
56+
// Prints each argument on a separate line
57+
for argument in env::args() {
58+
println!("{}", argument);
59+
}
60+
```
61+
62+
[`args_os`]: ./fn.args_os.html
63+
``````
64+
65+
As you can see, it follows the structure detailed above: it starts with a short
66+
sentence explaining what the functions does, then it provides more information
67+
and finally provides a code example.
68+
69+
## Markdown
70+
71+
`rustdoc` is using the [commonmark markdown specification]. You might be
72+
interested into taking a look at their website to see what's possible to do.
73+
74+
## Lints
75+
76+
To be sure that you didn't miss any item without documentation or code examples,
77+
you can take a look at the rustdoc lints [here][rustdoc-lints].
78+
79+
[standard library]: https://doc.rust-lang.org/stable/std/index.html
80+
[env::args]: https://doc.rust-lang.org/stable/std/env/fn.args.html
81+
[commonmark markdown specification]: https://commonmark.org/
82+
[rustdoc-lints]: lints.md

src/doc/rustdoc/src/lints.md

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Lints
2+
3+
`rustdoc` provides lints to help you writing and testing your documentation. You
4+
can use them like any other lints by doing this:
5+
6+
```rust,ignore
7+
#![allow(missing_docs)] // allowing the lint, no message
8+
#![warn(missing_docs)] // warn if there is missing docs
9+
#![deny(missing_docs)] // rustdoc will fail if there is missing docs
10+
```
11+
12+
Here is the list of the lints provided by `rustdoc`:
13+
14+
## intra_doc_link_resolution_failure
15+
16+
This lint **warns by default** and is **nightly-only**. This lint detects when
17+
an intra-doc link fails to get resolved. For example:
18+
19+
```rust
20+
/// I want to link to [`Inexistent`] but it doesn't exist!
21+
pub fn foo() {}
22+
```
23+
24+
You'll get a warning saying:
25+
26+
```text
27+
error: `[`Inexistent`]` cannot be resolved, ignoring it...
28+
```
29+
30+
## missing_docs
31+
32+
This lint is **allowed by default**. It detects items missing documentation.
33+
For example:
34+
35+
```rust
36+
#![warn(missing_docs)]
37+
38+
pub fn undocumented() {}
39+
# fn main() {}
40+
```
41+
42+
The `undocumented` function will then have the following warning:
43+
44+
```text
45+
warning: missing documentation for a function
46+
--> your-crate/lib.rs:3:1
47+
|
48+
3 | pub fn undocumented() {}
49+
| ^^^^^^^^^^^^^^^^^^^^^
50+
```
51+
52+
## missing_doc_code_examples
53+
54+
This lint is **allowed by default**. It detects when a documentation block
55+
is missing a code example. For example:
56+
57+
```rust
58+
#![warn(missing_doc_code_examples)]
59+
60+
/// There is no code example!
61+
pub fn no_code_example() {}
62+
# fn main() {}
63+
```
64+
65+
The `no_code_example` function will then have the following warning:
66+
67+
```text
68+
warning: Missing code example in this documentation
69+
--> your-crate/lib.rs:3:1
70+
|
71+
LL | /// There is no code example!
72+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
73+
```
74+
75+
To fix the lint, you need to add a code example into the documentation block:
76+
77+
```rust
78+
/// There is no code example!
79+
///
80+
/// ```
81+
/// println!("calling no_code_example...");
82+
/// no_code_example();
83+
/// println!("we called no_code_example!");
84+
/// ```
85+
pub fn no_code_example() {}
86+
```
87+
88+
## private_doc_tests
89+
90+
This lint is **allowed by default**. It detects documentation tests when they
91+
are on a private item. For example:
92+
93+
```rust
94+
#![warn(private_doc_tests)]
95+
96+
mod foo {
97+
/// private doc test
98+
///
99+
/// ```
100+
/// assert!(false);
101+
/// ```
102+
fn bar() {}
103+
}
104+
# fn main() {}
105+
```
106+
107+
Which will give:
108+
109+
```text
110+
warning: Documentation test in private item
111+
--> your-crate/lib.rs:4:1
112+
|
113+
4 | / /// private doc test
114+
5 | | ///
115+
6 | | /// ```
116+
7 | | /// assert!(false);
117+
8 | | /// ```
118+
| |___________^
119+
```

src/libcore/num/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ depending on the target pointer size.
235235
"}
236236
}
237237

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

2306-
// `Int` + `UnsignedInt` implemented for unsigned integers
23072305
macro_rules! uint_impl {
23082306
($SelfT:ty, $ActualT:ty, $BITS:expr, $MaxV:expr, $Feature:expr, $EndFeature:expr,
23092307
$rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr,

src/librustc/middle/stability.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ use syntax::attr::{self, Stability, Deprecation, RustcDeprecation};
2222
use crate::ty::{self, TyCtxt};
2323
use crate::util::nodemap::{FxHashSet, FxHashMap};
2424

25-
use std::mem::replace;
2625
use std::cmp::Ordering;
26+
use std::mem::replace;
27+
use std::num::NonZeroU32;
2728

2829
#[derive(PartialEq, Clone, Copy, Debug)]
2930
pub enum StabilityLevel {
@@ -441,7 +442,7 @@ impl<'tcx> Index<'tcx> {
441442
let stability = tcx.intern_stability(Stability {
442443
level: attr::StabilityLevel::Unstable {
443444
reason: Some(Symbol::intern(reason)),
444-
issue: 27812,
445+
issue: NonZeroU32::new(27812),
445446
is_soft: false,
446447
},
447448
feature: sym::rustc_private,
@@ -488,7 +489,7 @@ pub fn report_unstable(
488489
sess: &Session,
489490
feature: Symbol,
490491
reason: Option<Symbol>,
491-
issue: u32,
492+
issue: Option<NonZeroU32>,
492493
is_soft: bool,
493494
span: Span,
494495
soft_handler: impl FnOnce(&'static lint::Lint, Span, &str),
@@ -520,7 +521,7 @@ pub fn report_unstable(
520521
soft_handler(lint::builtin::SOFT_UNSTABLE, span, &msg)
521522
} else {
522523
emit_feature_err(
523-
&sess.parse_sess, feature, span, GateIssue::Library(Some(issue)), &msg
524+
&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg
524525
);
525526
}
526527
}
@@ -637,7 +638,7 @@ pub enum EvalResult {
637638
Deny {
638639
feature: Symbol,
639640
reason: Option<Symbol>,
640-
issue: u32,
641+
issue: Option<NonZeroU32>,
641642
is_soft: bool,
642643
},
643644
/// The item does not have the `#[stable]` or `#[unstable]` marker assigned.
@@ -758,7 +759,7 @@ impl<'tcx> TyCtxt<'tcx> {
758759
// the `-Z force-unstable-if-unmarked` flag present (we're
759760
// compiling a compiler crate), then let this missing feature
760761
// annotation slide.
761-
if feature == sym::rustc_private && issue == 27812 {
762+
if feature == sym::rustc_private && issue == NonZeroU32::new(27812) {
762763
if self.sess.opts.debugging_opts.force_unstable_if_unmarked {
763764
return EvalResult::Allow;
764765
}

src/librustc/session/code_stats.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc_target::abi::{Align, Size};
22
use rustc_data_structures::fx::{FxHashSet};
33
use std::cmp::{self, Ordering};
4+
use rustc_data_structures::sync::Lock;
45

56
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
67
pub struct VariantInfo {
@@ -44,13 +45,13 @@ pub struct TypeSizeInfo {
4445
pub variants: Vec<VariantInfo>,
4546
}
4647

47-
#[derive(PartialEq, Eq, Debug, Default)]
48+
#[derive(Default)]
4849
pub struct CodeStats {
49-
type_sizes: FxHashSet<TypeSizeInfo>,
50+
type_sizes: Lock<FxHashSet<TypeSizeInfo>>,
5051
}
5152

5253
impl CodeStats {
53-
pub fn record_type_size<S: ToString>(&mut self,
54+
pub fn record_type_size<S: ToString>(&self,
5455
kind: DataTypeKind,
5556
type_desc: S,
5657
align: Align,
@@ -73,11 +74,12 @@ impl CodeStats {
7374
opt_discr_size: opt_discr_size.map(|s| s.bytes()),
7475
variants,
7576
};
76-
self.type_sizes.insert(info);
77+
self.type_sizes.borrow_mut().insert(info);
7778
}
7879

7980
pub fn print_type_sizes(&self) {
80-
let mut sorted: Vec<_> = self.type_sizes.iter().collect();
81+
let type_sizes = self.type_sizes.borrow();
82+
let mut sorted: Vec<_> = type_sizes.iter().collect();
8183

8284
// Primary sort: large-to-small.
8385
// Secondary sort: description (dictionary order)

0 commit comments

Comments
 (0)