Skip to content

Commit 9f8012e

Browse files
committed
Auto merge of #85458 - jackh726:rollup-zvvybmt, r=jackh726
Rollup of 8 pull requests Successful merges: - #83366 (Stabilize extended_key_value_attributes) - #83767 (Fix v0 symbol mangling bug) - #84883 (compiletest: "fix" FileCheck with --allow-unused-prefixes) - #85274 (Only pass --[no-]gc-sections if linker is GNU ld.) - #85297 (bootstrap: build cargo only if requested in tools) - #85396 (rustdoc: restore header sizes) - #85425 (Fix must_use on `Option::is_none`) - #85438 (Fix escape handling) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3d31363 + 6cfcbf7 commit 9f8012e

File tree

29 files changed

+226
-100
lines changed

29 files changed

+226
-100
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

-4
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
712712
gate_all!(const_trait_impl, "const trait impls are experimental");
713713
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
714714
gate_all!(inline_const, "inline-const is experimental");
715-
gate_all!(
716-
extended_key_value_attributes,
717-
"arbitrary expressions in key-value attributes are unstable"
718-
);
719715
gate_all!(
720716
const_generics_defaults,
721717
"default values for const generic parameters are experimental"

compiler/rustc_codegen_llvm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#![feature(bool_to_option)]
99
#![feature(const_cstr_unchecked)]
1010
#![feature(crate_visibility_modifier)]
11-
#![feature(extended_key_value_attributes)]
11+
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
1212
#![feature(extern_types)]
1313
#![feature(in_band_lifetimes)]
1414
#![feature(iter_zip)]

compiler/rustc_codegen_ssa/src/back/linker.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,11 @@ impl<'a> Linker for GccLinker<'a> {
281281
}
282282
}
283283
LinkOutputKind::DynamicPicExe => {
284-
// `-pie` works for both gcc wrapper and ld.
285-
self.cmd.arg("-pie");
284+
// noop on windows w/ gcc & ld, error w/ lld
285+
if !self.sess.target.is_like_windows {
286+
// `-pie` works for both gcc wrapper and ld.
287+
self.cmd.arg("-pie");
288+
}
286289
}
287290
LinkOutputKind::StaticNoPicExe => {
288291
// `-static` works for both gcc wrapper and ld.
@@ -347,7 +350,7 @@ impl<'a> Linker for GccLinker<'a> {
347350
// has -needed-l{} / -needed_library {}
348351
// but we have no way to detect that here.
349352
self.sess.warn("`as-needed` modifier not implemented yet for ld64");
350-
} else if self.sess.target.linker_is_gnu {
353+
} else if self.sess.target.linker_is_gnu && !self.sess.target.is_like_windows {
351354
self.linker_arg("--no-as-needed");
352355
} else {
353356
self.sess.warn("`as-needed` modifier not supported for current linker");
@@ -358,7 +361,7 @@ impl<'a> Linker for GccLinker<'a> {
358361
if !as_needed {
359362
if self.sess.target.is_like_osx {
360363
// See above FIXME comment
361-
} else if self.sess.target.linker_is_gnu {
364+
} else if self.sess.target.linker_is_gnu && !self.sess.target.is_like_windows {
362365
self.linker_arg("--as-needed");
363366
}
364367
}
@@ -469,17 +472,15 @@ impl<'a> Linker for GccLinker<'a> {
469472
// eliminate the metadata. If we're building an executable, however,
470473
// --gc-sections drops the size of hello world from 1.8MB to 597K, a 67%
471474
// reduction.
472-
} else if !keep_metadata {
475+
} else if self.sess.target.linker_is_gnu && !keep_metadata {
473476
self.linker_arg("--gc-sections");
474477
}
475478
}
476479

477480
fn no_gc_sections(&mut self) {
478481
if self.sess.target.is_like_osx {
479482
self.linker_arg("-no_dead_strip");
480-
} else if self.sess.target.is_like_solaris {
481-
self.linker_arg("-zrecord");
482-
} else {
483+
} else if self.sess.target.linker_is_gnu {
483484
self.linker_arg("--no-gc-sections");
484485
}
485486
}
@@ -692,7 +693,7 @@ impl<'a> Linker for GccLinker<'a> {
692693
}
693694

694695
fn add_as_needed(&mut self) {
695-
if self.sess.target.linker_is_gnu {
696+
if self.sess.target.linker_is_gnu && !self.sess.target.is_like_windows {
696697
self.linker_arg("--as-needed");
697698
} else if self.sess.target.is_like_solaris {
698699
// -z ignore is the Solaris equivalent to the GNU ld --as-needed option

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
66
#![feature(crate_visibility_modifier)]
77
#![feature(backtrace)]
8-
#![feature(extended_key_value_attributes)]
8+
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
99
#![feature(format_args_capture)]
1010
#![feature(iter_zip)]
1111
#![feature(nll)]

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ declare_features! (
281281
(accepted, or_patterns, "1.53.0", Some(54883), None),
282282
/// Allows defining identifiers beyond ASCII.
283283
(accepted, non_ascii_idents, "1.53.0", Some(55467), None),
284+
/// Allows arbitrary expressions in key-value attributes at parse time.
285+
(accepted, extended_key_value_attributes, "1.54.0", Some(78835), None),
284286

285287
// -------------------------------------------------------------------------
286288
// feature-group-end: accepted features

compiler/rustc_feature/src/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,6 @@ declare_features! (
601601
/// Allows capturing disjoint fields in a closure/generator (RFC 2229).
602602
(active, capture_disjoint_fields, "1.49.0", Some(53488), None),
603603

604-
/// Allows arbitrary expressions in key-value attributes at parse time.
605-
(active, extended_key_value_attributes, "1.50.0", Some(78835), None),
606-
607604
/// Allows const generics to have default values (e.g. `struct Foo<const N: usize = 3>(...);`).
608605
(active, const_generics_defaults, "1.51.0", Some(44580), None),
609606

compiler/rustc_hir/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
#![feature(crate_visibility_modifier)]
66
#![feature(const_panic)]
7-
#![feature(extended_key_value_attributes)]
7+
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
88
#![feature(in_band_lifetimes)]
99
#![feature(once_cell)]
1010
#![cfg_attr(bootstrap, feature(or_patterns))]

compiler/rustc_parse/src/parser/mod.rs

-13
Original file line numberDiff line numberDiff line change
@@ -1065,24 +1065,11 @@ impl<'a> Parser<'a> {
10651065
} else if !delimited_only {
10661066
if self.eat(&token::Eq) {
10671067
let eq_span = self.prev_token.span;
1068-
let mut is_interpolated_expr = false;
1069-
if let token::Interpolated(nt) = &self.token.kind {
1070-
if let token::NtExpr(..) = **nt {
1071-
is_interpolated_expr = true;
1072-
}
1073-
}
10741068

10751069
// Collect tokens because they are used during lowering to HIR.
10761070
let expr = self.parse_expr_force_collect()?;
10771071
let span = expr.span;
10781072

1079-
match &expr.kind {
1080-
// Not gated to support things like `doc = $expr` that work on stable.
1081-
_ if is_interpolated_expr => {}
1082-
ExprKind::Lit(lit) if lit.kind.is_unsuffixed() => {}
1083-
_ => self.sess.gated_spans.gate(sym::extended_key_value_attributes, span),
1084-
}
1085-
10861073
let token_kind = token::Interpolated(Lrc::new(token::NtExpr(expr)));
10871074
MacArgs::Eq(eq_span, Token::new(token_kind, span))
10881075
} else {

compiler/rustc_symbol_mangling/src/v0.rs

+37-6
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,39 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
485485
mut self,
486486
predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>,
487487
) -> Result<Self::DynExistential, Self::Error> {
488-
for predicate in predicates {
489-
self = self.in_binder(&predicate, |mut cx, predicate| {
490-
match predicate {
488+
// Okay, so this is a bit tricky. Imagine we have a trait object like
489+
// `dyn for<'a> Foo<'a, Bar = &'a ()>`. When we mangle this, the
490+
// output looks really close to the syntax, where the `Bar = &'a ()` bit
491+
// is under the same binders (`['a]`) as the `Foo<'a>` bit. However, we
492+
// actually desugar these into two separate `ExistentialPredicate`s. We
493+
// can't enter/exit the "binder scope" twice though, because then we
494+
// would mangle the binders twice. (Also, side note, we merging these
495+
// two is kind of difficult, because of potential HRTBs in the Projection
496+
// predicate.)
497+
//
498+
// Also worth mentioning: imagine that we instead had
499+
// `dyn for<'a> Foo<'a, Bar = &'a ()> + Send`. In this case, `Send` is
500+
// under the same binders as `Foo`. Currently, this doesn't matter,
501+
// because only *auto traits* are allowed other than the principal trait
502+
// and all auto traits don't have any generics. Two things could
503+
// make this not an "okay" mangling:
504+
// 1) Instead of mangling only *used*
505+
// bound vars, we want to mangle *all* bound vars (`for<'b> Send` is a
506+
// valid trait predicate);
507+
// 2) We allow multiple "principal" traits in the future, or at least
508+
// allow in any form another trait predicate that can take generics.
509+
//
510+
// Here we assume that predicates have the following structure:
511+
// [<Trait> [{<Projection>}]] [{<Auto>}]
512+
// Since any predicates after the first one shouldn't change the binders,
513+
// just put them all in the binders of the first.
514+
self = self.in_binder(&predicates[0], |mut cx, _| {
515+
for predicate in predicates.iter() {
516+
// It would be nice to be able to validate bound vars here, but
517+
// projections can actually include bound vars from super traits
518+
// because of HRTBs (only in the `Self` type). Also, auto traits
519+
// could have different bound vars *anyways*.
520+
match predicate.as_ref().skip_binder() {
491521
ty::ExistentialPredicate::Trait(trait_ref) => {
492522
// Use a type that can't appear in defaults of type parameters.
493523
let dummy_self = cx.tcx.mk_ty_infer(ty::FreshTy(0));
@@ -504,9 +534,10 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
504534
cx = cx.print_def_path(*def_id, &[])?;
505535
}
506536
}
507-
Ok(cx)
508-
})?;
509-
}
537+
}
538+
Ok(cx)
539+
})?;
540+
510541
self.push("E");
511542
Ok(self)
512543
}

compiler/rustc_target/src/spec/windows_gnu_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub fn opts() -> TargetOptions {
6666
// FIXME(#13846) this should be enabled for windows
6767
function_sections: false,
6868
linker: Some("gcc".to_string()),
69+
linker_is_gnu: true,
6970
dynamic_linking: true,
7071
executables: true,
7172
dll_prefix: String::new(),

compiler/rustc_typeck/src/astconv/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1394,11 +1394,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13941394
let auto_trait_predicates = auto_traits.into_iter().map(|trait_ref| {
13951395
ty::Binder::dummy(ty::ExistentialPredicate::AutoTrait(trait_ref.trait_ref().def_id()))
13961396
});
1397+
// N.b. principal, projections, auto traits
1398+
// FIXME: This is actually wrong with multiple principals in regards to symbol mangling
13971399
let mut v = regular_trait_predicates
1398-
.chain(auto_trait_predicates)
13991400
.chain(
14001401
existential_projections.map(|x| x.map_bound(ty::ExistentialPredicate::Projection)),
14011402
)
1403+
.chain(auto_trait_predicates)
14021404
.collect::<SmallVec<[_; 8]>>();
14031405
v.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder()));
14041406
v.dedup();

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
#![cfg_attr(bootstrap, feature(doc_spotlight))]
114114
#![cfg_attr(not(bootstrap), feature(doc_notable_trait))]
115115
#![feature(duration_consts_2)]
116-
#![feature(extended_key_value_attributes)]
116+
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
117117
#![feature(extern_types)]
118118
#![feature(fundamental)]
119119
#![feature(intra_doc_pointers)]

library/core/src/option.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<T> Option<T> {
209209
/// assert_eq!(x.is_none(), true);
210210
/// ```
211211
#[must_use = "if you intended to assert that this doesn't have a value, consider \
212-
`.and_then(|| panic!(\"`Option` had a value when expected `None`\"))` instead"]
212+
`.and_then(|_| panic!(\"`Option` had a value when expected `None`\"))` instead"]
213213
#[inline]
214214
#[rustc_const_stable(feature = "const_option", since = "1.48.0")]
215215
#[stable(feature = "rust1", since = "1.0.0")]

library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
#![feature(exact_size_is_empty)]
269269
#![feature(exhaustive_patterns)]
270270
#![feature(extend_one)]
271-
#![feature(extended_key_value_attributes)]
271+
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
272272
#![feature(fn_traits)]
273273
#![feature(format_args_nl)]
274274
#![feature(gen_future)]

src/bootstrap/tool.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,14 @@ impl Step for Cargo {
593593

594594
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
595595
let builder = run.builder;
596-
run.path("src/tools/cargo").default_condition(builder.config.extended)
596+
run.path("src/tools/cargo").default_condition(
597+
builder.config.extended
598+
&& builder.config.tools.as_ref().map_or(
599+
true,
600+
// If `tools` is set, search list for this tool.
601+
|tools| tools.iter().any(|tool| tool == "cargo"),
602+
),
603+
)
597604
}
598605

599606
fn make_run(run: RunConfig<'_>) {

src/doc/rustdoc/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Rustdoc
2+
3+
This is documentation for rustdoc itself, written in mdbook format.
4+
To build the book, use `x.py doc src/doc/rustdoc`.
5+
To run doctests, use `x.py test src/doc/rustdoc`.

src/doc/rustdoc/src/the-doc-attribute.md

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ Which can feel more flexible. Note that this would generate this:
3535

3636
but given that docs are rendered via Markdown, it will remove these newlines.
3737

38+
Another use case is for including external files as documentation:
39+
40+
```rust,no_run
41+
#[doc = include_str!("../README.md")]
42+
# fn f() {}
43+
```
44+
3845
The `doc` attribute has more options though! These don't involve the text of
3946
the output, but instead, various aspects of the presentation of the output.
4047
We've split them into two kinds below: attributes that are useful at the

src/librustdoc/html/static/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,9 @@ function hideThemeButtonState() {
425425
function handleEscape(ev) {
426426
var help = getHelpElement(false);
427427
var search = searchState.outputElement();
428-
if (!hasClass(help, "hidden")) {
428+
if (help && !hasClass(help, "hidden")) {
429429
displayHelp(false, ev, help);
430-
} else if (!hasClass(search, "hidden")) {
430+
} else if (search && !hasClass(search, "hidden")) {
431431
searchState.clearInputTimeout();
432432
ev.preventDefault();
433433
searchState.hideResults(search);

src/librustdoc/html/static/rustdoc.css

+7-3
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,13 @@ nav.sub {
427427
border-bottom: 1px solid;
428428
}
429429

430-
#main > .docblock h1 { font-size: 1.3em; }
431-
#main > .docblock h2 { font-size: 1.15em; }
432-
#main > .docblock h3, #main > .docblock h4, #main > .docblock h5 { font-size: 1em; }
430+
.top-doc .docblock h1 { font-size: 1.3em; }
431+
.top-doc .docblock h2 { font-size: 1.15em; }
432+
.top-doc .docblock h3,
433+
.top-doc .docblock h4,
434+
.top-doc .docblock h5 {
435+
font-size: 1em;
436+
}
433437

434438
.docblock h1 { font-size: 1em; }
435439
.docblock h2 { font-size: 0.95em; }

src/test/rustdoc-gui/escape-key.goml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
goto: file://|DOC_PATH|/test_docs/index.html
2+
// First, we check that the search results are hidden when the Escape key is pressed.
3+
write: (".search-input", "test")
4+
wait-for: "#search > h1" // The search element is empty before the first search
5+
assert: ("#search", "class", "content")
6+
assert: ("#main", "class", "content hidden")
7+
press-key: "Escape"
8+
assert: ("#search", "class", "content hidden")
9+
assert: ("#main", "class", "content")
10+
11+
// Check that focusing the search input brings back the search results
12+
focus: ".search-input"
13+
assert: ("#search", "class", "content")
14+
assert: ("#main", "class", "content hidden")
15+
16+
// Now let's check that when the help popup is displayed and we press Escape, it doesn't
17+
// hide the search results too.
18+
click: "#help-button"
19+
assert: ("#help", "class", "")
20+
press-key: "Escape"
21+
assert: ("#help", "class", "hidden")
22+
assert: ("#search", "class", "content")
23+
assert: ("#main", "class", "content hidden")
24+
25+
// FIXME: Once https://github.com/rust-lang/rust/pull/84462 is merged, add check to ensure
26+
// that Escape hides the search results when a result is focused.
27+
// press-key: "ArrowDown"

src/test/rustdoc/external-doc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(external_doc)]
2-
#![feature(extended_key_value_attributes)]
32

43
// @has external_doc/struct.CanHasDocs.html
54
// @has - '//h1' 'External Docs'

src/test/ui/attributes/key-value-expansion-on-mac.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(extended_key_value_attributes)]
21
#![feature(rustc_attrs)]
32

43
#[rustc_dummy = stringify!(a)] // OK

src/test/ui/attributes/key-value-expansion-on-mac.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unexpected token: `stringify!(b)`
2-
--> $DIR/key-value-expansion-on-mac.rs:12:17
2+
--> $DIR/key-value-expansion-on-mac.rs:11:17
33
|
44
LL | #[rustc_dummy = stringify!(b)]
55
| ^^^^^^^^^^^^^

src/test/ui/feature-gates/feature-gate-extended_key_value_attributes.rs

-8
This file was deleted.

0 commit comments

Comments
 (0)