Skip to content

Commit de238ea

Browse files
authored
Merge branch 'master' into issue142386
2 parents 3ef14d0 + df4ad9e commit de238ea

File tree

191 files changed

+10164
-1305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+10164
-1305
lines changed

.github/ISSUE_TEMPLATE/rustdoc.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
name: Problem with rustdoc
3+
about: Report an issue with how docs get generated.
4+
labels: C-bug, T-rustdoc
5+
---
6+
<!--
7+
Thank you for filing a rustdoc issue! Rustdoc is the tool that handles the generation of docs. It is usually invoked via `cargo doc`, but can also be used directly.
8+
9+
If you have an issue with the actual content of the docs, use the "Documentation problem" template instead.
10+
-->
11+
12+
# Code
13+
<!-- problematic snippet and/or link to repo and/or full path of standard library function -->
14+
15+
```rust
16+
<code>
17+
```
18+
19+
# Reproduction Steps
20+
<!--
21+
* command(s) to run, if any
22+
* permalink to hosted documentation, if any
23+
* search query, if any
24+
-->
25+
26+
# Expected Outcome
27+
<!--
28+
What did you want to happen?
29+
30+
For GUI issues, feel free to provide a mockup image of what you want it to look like.
31+
32+
For diagnostics, please provide a mockup of the desired output in a code block.
33+
-->
34+
35+
# Actual Output
36+
<!--
37+
* rustdoc console output
38+
* browser screenshot of generated html
39+
* rustdoc json (prettify by running through `jq` or running thorugh an online formatter)
40+
-->
41+
```console
42+
<code>
43+
```
44+
45+
46+
# Version
47+
<!--
48+
Available via `rustdoc --version` or under the "Help" menu.
49+
50+
If the issue involves opening the documentation in a browser, please also provide the name and version of the browser used.
51+
-->
52+
53+
# Additional Details
54+
<!-- Anything else you think is relevant -->

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,3 +698,4 @@ Zach Pomerantz <[email protected]>
698698
699699
Zack Slayton <[email protected]>
700700
Zbigniew Siciarz <[email protected]> Zbigniew Siciarz <[email protected]>
701+

Cargo.lock

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,6 +2983,15 @@ dependencies = [
29832983
"getrandom 0.3.3",
29842984
]
29852985

2986+
[[package]]
2987+
name = "rand_xorshift"
2988+
version = "0.4.0"
2989+
source = "registry+https://github.com/rust-lang/crates.io-index"
2990+
checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
2991+
dependencies = [
2992+
"rand_core 0.9.3",
2993+
]
2994+
29862995
[[package]]
29872996
name = "rand_xoshiro"
29882997
version = "0.7.0"
@@ -3182,16 +3191,6 @@ dependencies = [
31823191
"tikv-jemalloc-sys",
31833192
]
31843193

3185-
[[package]]
3186-
name = "rustc-rayon-core"
3187-
version = "0.5.1"
3188-
source = "registry+https://github.com/rust-lang/crates.io-index"
3189-
checksum = "2f42932dcd3bcbe484b38a3ccf79b7906fac41c02d408b5b1bac26da3416efdb"
3190-
dependencies = [
3191-
"crossbeam-deque",
3192-
"crossbeam-utils",
3193-
]
3194-
31953194
[[package]]
31963195
name = "rustc-semver"
31973196
version = "1.1.0"
@@ -3558,14 +3557,14 @@ dependencies = [
35583557
"parking_lot",
35593558
"portable-atomic",
35603559
"rustc-hash 2.1.1",
3561-
"rustc-rayon-core",
35623560
"rustc-stable-hash",
35633561
"rustc_arena",
35643562
"rustc_graphviz",
35653563
"rustc_hashes",
35663564
"rustc_index",
35673565
"rustc_macros",
35683566
"rustc_serialize",
3567+
"rustc_thread_pool",
35693568
"smallvec",
35703569
"stacker",
35713570
"tempfile",
@@ -3913,7 +3912,6 @@ dependencies = [
39133912
name = "rustc_interface"
39143913
version = "0.0.0"
39153914
dependencies = [
3916-
"rustc-rayon-core",
39173915
"rustc_abi",
39183916
"rustc_ast",
39193917
"rustc_ast_lowering",
@@ -3952,6 +3950,7 @@ dependencies = [
39523950
"rustc_span",
39533951
"rustc_symbol_mangling",
39543952
"rustc_target",
3953+
"rustc_thread_pool",
39553954
"rustc_trait_selection",
39563955
"rustc_traits",
39573956
"rustc_ty_utils",
@@ -4079,7 +4078,6 @@ dependencies = [
40794078
"either",
40804079
"gsgdt",
40814080
"polonius-engine",
4082-
"rustc-rayon-core",
40834081
"rustc_abi",
40844082
"rustc_apfloat",
40854083
"rustc_arena",
@@ -4103,6 +4101,7 @@ dependencies = [
41034101
"rustc_session",
41044102
"rustc_span",
41054103
"rustc_target",
4104+
"rustc_thread_pool",
41064105
"rustc_type_ir",
41074106
"smallvec",
41084107
"thin-vec",
@@ -4349,7 +4348,6 @@ version = "0.0.0"
43494348
dependencies = [
43504349
"hashbrown",
43514350
"parking_lot",
4352-
"rustc-rayon-core",
43534351
"rustc_abi",
43544352
"rustc_ast",
43554353
"rustc_attr_data_structures",
@@ -4364,6 +4362,7 @@ dependencies = [
43644362
"rustc_serialize",
43654363
"rustc_session",
43664364
"rustc_span",
4365+
"rustc_thread_pool",
43674366
"smallvec",
43684367
"tracing",
43694368
]
@@ -4525,6 +4524,18 @@ dependencies = [
45254524
"tracing",
45264525
]
45274526

4527+
[[package]]
4528+
name = "rustc_thread_pool"
4529+
version = "0.0.0"
4530+
dependencies = [
4531+
"crossbeam-deque",
4532+
"crossbeam-utils",
4533+
"libc",
4534+
"rand 0.9.1",
4535+
"rand_xorshift",
4536+
"scoped-tls",
4537+
]
4538+
45284539
[[package]]
45294540
name = "rustc_tools_util"
45304541
version = "0.4.2"

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ exclude = [
6060
"obj",
6161
]
6262

63-
[profile.release.package.rustc-rayon-core]
63+
[profile.release.package.rustc_thread_pool]
6464
# The rustc fork of Rayon has deadlock detection code which intermittently
6565
# causes overflows in the CI (see https://github.com/rust-lang/rust/issues/90227)
6666
# so we turn overflow checks off for now.

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,44 @@ impl<'a> State<'a> {
386386

387387
let ib = self.ibox(INDENT_UNIT);
388388

389-
// The Match subexpression in `match x {} - 1` must be parenthesized if
390-
// it is the leftmost subexpression in a statement:
391-
//
392-
// (match x {}) - 1;
393-
//
394-
// But not otherwise:
395-
//
396-
// let _ = match x {} - 1;
397-
//
398-
// Same applies to a small set of other expression kinds which eagerly
399-
// terminate a statement which opens with them.
400-
let needs_par = fixup.would_cause_statement_boundary(expr);
389+
let needs_par = {
390+
// The Match subexpression in `match x {} - 1` must be parenthesized
391+
// if it is the leftmost subexpression in a statement:
392+
//
393+
// (match x {}) - 1;
394+
//
395+
// But not otherwise:
396+
//
397+
// let _ = match x {} - 1;
398+
//
399+
// Same applies to a small set of other expression kinds which
400+
// eagerly terminate a statement which opens with them.
401+
fixup.would_cause_statement_boundary(expr)
402+
} || {
403+
// If a binary operation ends up with an attribute, such as
404+
// resulting from the following macro expansion, then parentheses
405+
// are required so that the attribute encompasses the right
406+
// subexpression and not just the left one.
407+
//
408+
// #![feature(stmt_expr_attributes)]
409+
//
410+
// macro_rules! add_attr {
411+
// ($e:expr) => { #[attr] $e };
412+
// }
413+
//
414+
// let _ = add_attr!(1 + 1);
415+
//
416+
// We must pretty-print `#[attr] (1 + 1)` not `#[attr] 1 + 1`.
417+
!attrs.is_empty()
418+
&& matches!(
419+
expr.kind,
420+
ast::ExprKind::Binary(..)
421+
| ast::ExprKind::Cast(..)
422+
| ast::ExprKind::Assign(..)
423+
| ast::ExprKind::AssignOp(..)
424+
| ast::ExprKind::Range(..)
425+
)
426+
};
401427
if needs_par {
402428
self.popen();
403429
fixup = FixupContext::default();

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ pub enum AttributeKind {
202202
span: Span,
203203
},
204204

205+
/// Represents `#[cold]`.
206+
Cold(Span),
207+
205208
/// Represents `#[rustc_confusables]`.
206209
Confusables {
207210
symbols: ThinVec<Symbol>,

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,21 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
3838
Some(AttributeKind::Optimize(res, cx.attr_span))
3939
}
4040
}
41+
42+
pub(crate) struct ColdParser;
43+
44+
impl<S: Stage> SingleAttributeParser<S> for ColdParser {
45+
const PATH: &[rustc_span::Symbol] = &[sym::cold];
46+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
47+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
48+
const TEMPLATE: AttributeTemplate = template!(Word);
49+
50+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
51+
if !args.no_args() {
52+
cx.expected_no_args(args.span().unwrap_or(cx.attr_span));
53+
return None;
54+
};
55+
56+
Some(AttributeKind::Cold(cx.attr_span))
57+
}
58+
}

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,19 @@ pub(crate) trait AttributeParser<S: Stage>: Default + 'static {
8787
/// [`SingleAttributeParser`] can only convert attributes one-to-one, and cannot combine multiple
8888
/// attributes together like is necessary for `#[stable()]` and `#[unstable()]` for example.
8989
pub(crate) trait SingleAttributeParser<S: Stage>: 'static {
90+
/// The single path of the attribute this parser accepts.
91+
///
92+
/// If you need the parser to accept more than one path, use [`AttributeParser`] instead
9093
const PATH: &[Symbol];
94+
95+
/// Configures the precedence of attributes with the same `PATH` on a syntax node.
9196
const ATTRIBUTE_ORDER: AttributeOrder;
97+
98+
/// Configures what to do when when the same attribute is
99+
/// applied more than once on the same syntax node.
100+
///
101+
/// [`ATTRIBUTE_ORDER`](Self::ATTRIBUTE_ORDER) specified which one is assumed to be correct,
102+
/// and this specified whether to, for example, warn or error on the other one.
92103
const ON_DUPLICATE: OnDuplicate<S>;
93104

94105
/// The template this attribute parser should implement. Used for diagnostics.
@@ -98,6 +109,8 @@ pub(crate) trait SingleAttributeParser<S: Stage>: 'static {
98109
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind>;
99110
}
100111

112+
/// Use in combination with [`SingleAttributeParser`].
113+
/// `Single<T: SingleAttributeParser>` implements [`AttributeParser`].
101114
pub(crate) struct Single<T: SingleAttributeParser<S>, S: Stage>(
102115
PhantomData<(S, T)>,
103116
Option<(AttributeKind, Span)>,
@@ -230,6 +243,10 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static {
230243
const PATH: &[rustc_span::Symbol];
231244

232245
type Item;
246+
/// A function that converts individual items (of type [`Item`](Self::Item)) into the final attribute.
247+
///
248+
/// For example, individual representations fomr `#[repr(...)]` attributes into an `AttributeKind::Repr(x)`,
249+
/// where `x` is a vec of these individual reprs.
233250
const CONVERT: ConvertFn<Self::Item>;
234251

235252
/// The template this attribute parser should implement. Used for diagnostics.
@@ -242,6 +259,8 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static {
242259
) -> impl IntoIterator<Item = Self::Item> + 'c;
243260
}
244261

262+
/// Use in combination with [`CombineAttributeParser`].
263+
/// `Combine<T: CombineAttributeParser>` implements [`AttributeParser`].
245264
pub(crate) struct Combine<T: CombineAttributeParser<S>, S: Stage>(
246265
PhantomData<(S, T)>,
247266
ThinVec<<T as CombineAttributeParser<S>>::Item>,

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ impl<S: Stage> CombineAttributeParser<S> for ReprParser {
2525
const PATH: &[Symbol] = &[sym::repr];
2626
const CONVERT: ConvertFn<Self::Item> = AttributeKind::Repr;
2727
// FIXME(jdonszelmann): never used
28-
const TEMPLATE: AttributeTemplate = template!(List: "C");
28+
const TEMPLATE: AttributeTemplate =
29+
template!(List: "C | Rust | align(...) | packed(...) | <integer type> | transparent");
2930

3031
fn extend<'c>(
3132
cx: &'c mut AcceptContext<'_, '_, S>,
@@ -273,7 +274,7 @@ pub(crate) struct AlignParser(Option<(Align, Span)>);
273274

274275
impl AlignParser {
275276
const PATH: &'static [Symbol] = &[sym::align];
276-
const TEMPLATE: AttributeTemplate = template!(Word, List: "<alignment in bytes>");
277+
const TEMPLATE: AttributeTemplate = template!(List: "<alignment in bytes>");
277278

278279
fn parse<'c, S: Stage>(
279280
&mut self,

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_session::Session;
1515
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1616

1717
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
18-
use crate::attributes::codegen_attrs::OptimizeParser;
18+
use crate::attributes::codegen_attrs::{ColdParser, OptimizeParser};
1919
use crate::attributes::confusables::ConfusablesParser;
2020
use crate::attributes::deprecation::DeprecationParser;
2121
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
@@ -106,6 +106,7 @@ attribute_parsers!(
106106

107107
// tidy-alphabetical-start
108108
Single<AsPtrParser>,
109+
Single<ColdParser>,
109110
Single<ConstStabilityIndirectParser>,
110111
Single<DeprecationParser>,
111112
Single<InlineParser>,
@@ -234,6 +235,16 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
234235
})
235236
}
236237

238+
pub(crate) fn expected_no_args(&self, args_span: Span) -> ErrorGuaranteed {
239+
self.emit_err(AttributeParseError {
240+
span: args_span,
241+
attr_span: self.attr_span,
242+
template: self.template.clone(),
243+
attribute: self.attr_path.clone(),
244+
reason: AttributeParseErrorReason::ExpectedNoArgs,
245+
})
246+
}
247+
237248
/// emit an error that a `name = value` pair was expected at this span. The symbol can be given for
238249
/// a nicer error message talking about the specific name that was found lacking a value.
239250
pub(crate) fn expected_name_value(&self, span: Span, name: Option<Symbol>) -> ErrorGuaranteed {
@@ -422,19 +433,13 @@ impl<'sess> AttributeParser<'sess, Early> {
422433

423434
parsed.pop()
424435
}
425-
426-
pub fn new_early(sess: &'sess Session, features: &'sess Features, tools: Vec<Symbol>) -> Self {
427-
Self { features: Some(features), tools, parse_only: None, sess, stage: PhantomData }
428-
}
429436
}
430437

431-
impl<'sess> AttributeParser<'sess, Late> {
438+
impl<'sess, S: Stage> AttributeParser<'sess, S> {
432439
pub fn new(sess: &'sess Session, features: &'sess Features, tools: Vec<Symbol>) -> Self {
433440
Self { features: Some(features), tools, parse_only: None, sess, stage: PhantomData }
434441
}
435-
}
436442

437-
impl<'sess, S: Stage> AttributeParser<'sess, S> {
438443
pub(crate) fn sess(&self) -> &'sess Session {
439444
&self.sess
440445
}

0 commit comments

Comments
 (0)