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
This commit is contained in:
bors 2021-05-19 04:44:09 +00:00
commit 9f8012e3aa
29 changed files with 226 additions and 100 deletions

View File

@ -712,10 +712,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
gate_all!(const_trait_impl, "const trait impls are experimental");
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
gate_all!(inline_const, "inline-const is experimental");
gate_all!(
extended_key_value_attributes,
"arbitrary expressions in key-value attributes are unstable"
);
gate_all!(
const_generics_defaults,
"default values for const generic parameters are experimental"

View File

@ -8,7 +8,7 @@
#![feature(bool_to_option)]
#![feature(const_cstr_unchecked)]
#![feature(crate_visibility_modifier)]
#![feature(extended_key_value_attributes)]
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
#![feature(extern_types)]
#![feature(in_band_lifetimes)]
#![feature(iter_zip)]

View File

@ -281,8 +281,11 @@ impl<'a> Linker for GccLinker<'a> {
}
}
LinkOutputKind::DynamicPicExe => {
// `-pie` works for both gcc wrapper and ld.
self.cmd.arg("-pie");
// noop on windows w/ gcc & ld, error w/ lld
if !self.sess.target.is_like_windows {
// `-pie` works for both gcc wrapper and ld.
self.cmd.arg("-pie");
}
}
LinkOutputKind::StaticNoPicExe => {
// `-static` works for both gcc wrapper and ld.
@ -347,7 +350,7 @@ impl<'a> Linker for GccLinker<'a> {
// has -needed-l{} / -needed_library {}
// but we have no way to detect that here.
self.sess.warn("`as-needed` modifier not implemented yet for ld64");
} else if self.sess.target.linker_is_gnu {
} else if self.sess.target.linker_is_gnu && !self.sess.target.is_like_windows {
self.linker_arg("--no-as-needed");
} else {
self.sess.warn("`as-needed` modifier not supported for current linker");
@ -358,7 +361,7 @@ impl<'a> Linker for GccLinker<'a> {
if !as_needed {
if self.sess.target.is_like_osx {
// See above FIXME comment
} else if self.sess.target.linker_is_gnu {
} else if self.sess.target.linker_is_gnu && !self.sess.target.is_like_windows {
self.linker_arg("--as-needed");
}
}
@ -469,7 +472,7 @@ impl<'a> Linker for GccLinker<'a> {
// eliminate the metadata. If we're building an executable, however,
// --gc-sections drops the size of hello world from 1.8MB to 597K, a 67%
// reduction.
} else if !keep_metadata {
} else if self.sess.target.linker_is_gnu && !keep_metadata {
self.linker_arg("--gc-sections");
}
}
@ -477,9 +480,7 @@ impl<'a> Linker for GccLinker<'a> {
fn no_gc_sections(&mut self) {
if self.sess.target.is_like_osx {
self.linker_arg("-no_dead_strip");
} else if self.sess.target.is_like_solaris {
self.linker_arg("-zrecord");
} else {
} else if self.sess.target.linker_is_gnu {
self.linker_arg("--no-gc-sections");
}
}
@ -692,7 +693,7 @@ impl<'a> Linker for GccLinker<'a> {
}
fn add_as_needed(&mut self) {
if self.sess.target.linker_is_gnu {
if self.sess.target.linker_is_gnu && !self.sess.target.is_like_windows {
self.linker_arg("--as-needed");
} else if self.sess.target.is_like_solaris {
// -z ignore is the Solaris equivalent to the GNU ld --as-needed option

View File

@ -5,7 +5,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(crate_visibility_modifier)]
#![feature(backtrace)]
#![feature(extended_key_value_attributes)]
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
#![feature(format_args_capture)]
#![feature(iter_zip)]
#![feature(nll)]

View File

@ -281,6 +281,8 @@ declare_features! (
(accepted, or_patterns, "1.53.0", Some(54883), None),
/// Allows defining identifiers beyond ASCII.
(accepted, non_ascii_idents, "1.53.0", Some(55467), None),
/// Allows arbitrary expressions in key-value attributes at parse time.
(accepted, extended_key_value_attributes, "1.54.0", Some(78835), None),
// -------------------------------------------------------------------------
// feature-group-end: accepted features

View File

@ -601,9 +601,6 @@ declare_features! (
/// Allows capturing disjoint fields in a closure/generator (RFC 2229).
(active, capture_disjoint_fields, "1.49.0", Some(53488), None),
/// Allows arbitrary expressions in key-value attributes at parse time.
(active, extended_key_value_attributes, "1.50.0", Some(78835), None),
/// Allows const generics to have default values (e.g. `struct Foo<const N: usize = 3>(...);`).
(active, const_generics_defaults, "1.51.0", Some(44580), None),

View File

@ -4,7 +4,7 @@
#![feature(crate_visibility_modifier)]
#![feature(const_panic)]
#![feature(extended_key_value_attributes)]
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
#![feature(in_band_lifetimes)]
#![feature(once_cell)]
#![cfg_attr(bootstrap, feature(or_patterns))]

View File

@ -1065,24 +1065,11 @@ impl<'a> Parser<'a> {
} else if !delimited_only {
if self.eat(&token::Eq) {
let eq_span = self.prev_token.span;
let mut is_interpolated_expr = false;
if let token::Interpolated(nt) = &self.token.kind {
if let token::NtExpr(..) = **nt {
is_interpolated_expr = true;
}
}
// Collect tokens because they are used during lowering to HIR.
let expr = self.parse_expr_force_collect()?;
let span = expr.span;
match &expr.kind {
// Not gated to support things like `doc = $expr` that work on stable.
_ if is_interpolated_expr => {}
ExprKind::Lit(lit) if lit.kind.is_unsuffixed() => {}
_ => self.sess.gated_spans.gate(sym::extended_key_value_attributes, span),
}
let token_kind = token::Interpolated(Lrc::new(token::NtExpr(expr)));
MacArgs::Eq(eq_span, Token::new(token_kind, span))
} else {

View File

@ -485,9 +485,39 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
mut self,
predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>,
) -> Result<Self::DynExistential, Self::Error> {
for predicate in predicates {
self = self.in_binder(&predicate, |mut cx, predicate| {
match predicate {
// Okay, so this is a bit tricky. Imagine we have a trait object like
// `dyn for<'a> Foo<'a, Bar = &'a ()>`. When we mangle this, the
// output looks really close to the syntax, where the `Bar = &'a ()` bit
// is under the same binders (`['a]`) as the `Foo<'a>` bit. However, we
// actually desugar these into two separate `ExistentialPredicate`s. We
// can't enter/exit the "binder scope" twice though, because then we
// would mangle the binders twice. (Also, side note, we merging these
// two is kind of difficult, because of potential HRTBs in the Projection
// predicate.)
//
// Also worth mentioning: imagine that we instead had
// `dyn for<'a> Foo<'a, Bar = &'a ()> + Send`. In this case, `Send` is
// under the same binders as `Foo`. Currently, this doesn't matter,
// because only *auto traits* are allowed other than the principal trait
// and all auto traits don't have any generics. Two things could
// make this not an "okay" mangling:
// 1) Instead of mangling only *used*
// bound vars, we want to mangle *all* bound vars (`for<'b> Send` is a
// valid trait predicate);
// 2) We allow multiple "principal" traits in the future, or at least
// allow in any form another trait predicate that can take generics.
//
// Here we assume that predicates have the following structure:
// [<Trait> [{<Projection>}]] [{<Auto>}]
// Since any predicates after the first one shouldn't change the binders,
// just put them all in the binders of the first.
self = self.in_binder(&predicates[0], |mut cx, _| {
for predicate in predicates.iter() {
// It would be nice to be able to validate bound vars here, but
// projections can actually include bound vars from super traits
// because of HRTBs (only in the `Self` type). Also, auto traits
// could have different bound vars *anyways*.
match predicate.as_ref().skip_binder() {
ty::ExistentialPredicate::Trait(trait_ref) => {
// Use a type that can't appear in defaults of type parameters.
let dummy_self = cx.tcx.mk_ty_infer(ty::FreshTy(0));
@ -504,9 +534,10 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
cx = cx.print_def_path(*def_id, &[])?;
}
}
Ok(cx)
})?;
}
}
Ok(cx)
})?;
self.push("E");
Ok(self)
}

View File

@ -66,6 +66,7 @@ pub fn opts() -> TargetOptions {
// FIXME(#13846) this should be enabled for windows
function_sections: false,
linker: Some("gcc".to_string()),
linker_is_gnu: true,
dynamic_linking: true,
executables: true,
dll_prefix: String::new(),

View File

@ -1394,11 +1394,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let auto_trait_predicates = auto_traits.into_iter().map(|trait_ref| {
ty::Binder::dummy(ty::ExistentialPredicate::AutoTrait(trait_ref.trait_ref().def_id()))
});
// N.b. principal, projections, auto traits
// FIXME: This is actually wrong with multiple principals in regards to symbol mangling
let mut v = regular_trait_predicates
.chain(auto_trait_predicates)
.chain(
existential_projections.map(|x| x.map_bound(ty::ExistentialPredicate::Projection)),
)
.chain(auto_trait_predicates)
.collect::<SmallVec<[_; 8]>>();
v.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder()));
v.dedup();

View File

@ -113,7 +113,7 @@
#![cfg_attr(bootstrap, feature(doc_spotlight))]
#![cfg_attr(not(bootstrap), feature(doc_notable_trait))]
#![feature(duration_consts_2)]
#![feature(extended_key_value_attributes)]
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
#![feature(extern_types)]
#![feature(fundamental)]
#![feature(intra_doc_pointers)]

View File

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

View File

@ -268,7 +268,7 @@
#![feature(exact_size_is_empty)]
#![feature(exhaustive_patterns)]
#![feature(extend_one)]
#![feature(extended_key_value_attributes)]
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
#![feature(fn_traits)]
#![feature(format_args_nl)]
#![feature(gen_future)]

View File

@ -593,7 +593,14 @@ impl Step for Cargo {
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
let builder = run.builder;
run.path("src/tools/cargo").default_condition(builder.config.extended)
run.path("src/tools/cargo").default_condition(
builder.config.extended
&& builder.config.tools.as_ref().map_or(
true,
// If `tools` is set, search list for this tool.
|tools| tools.iter().any(|tool| tool == "cargo"),
),
)
}
fn make_run(run: RunConfig<'_>) {

View File

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

View File

@ -35,6 +35,13 @@ Which can feel more flexible. Note that this would generate this:
but given that docs are rendered via Markdown, it will remove these newlines.
Another use case is for including external files as documentation:
```rust,no_run
#[doc = include_str!("../README.md")]
# fn f() {}
```
The `doc` attribute has more options though! These don't involve the text of
the output, but instead, various aspects of the presentation of the output.
We've split them into two kinds below: attributes that are useful at the

View File

@ -425,9 +425,9 @@ function hideThemeButtonState() {
function handleEscape(ev) {
var help = getHelpElement(false);
var search = searchState.outputElement();
if (!hasClass(help, "hidden")) {
if (help && !hasClass(help, "hidden")) {
displayHelp(false, ev, help);
} else if (!hasClass(search, "hidden")) {
} else if (search && !hasClass(search, "hidden")) {
searchState.clearInputTimeout();
ev.preventDefault();
searchState.hideResults(search);

View File

@ -427,9 +427,13 @@ nav.sub {
border-bottom: 1px solid;
}
#main > .docblock h1 { font-size: 1.3em; }
#main > .docblock h2 { font-size: 1.15em; }
#main > .docblock h3, #main > .docblock h4, #main > .docblock h5 { font-size: 1em; }
.top-doc .docblock h1 { font-size: 1.3em; }
.top-doc .docblock h2 { font-size: 1.15em; }
.top-doc .docblock h3,
.top-doc .docblock h4,
.top-doc .docblock h5 {
font-size: 1em;
}
.docblock h1 { font-size: 1em; }
.docblock h2 { font-size: 0.95em; }

View File

@ -0,0 +1,27 @@
goto: file://|DOC_PATH|/test_docs/index.html
// First, we check that the search results are hidden when the Escape key is pressed.
write: (".search-input", "test")
wait-for: "#search > h1" // The search element is empty before the first search
assert: ("#search", "class", "content")
assert: ("#main", "class", "content hidden")
press-key: "Escape"
assert: ("#search", "class", "content hidden")
assert: ("#main", "class", "content")
// Check that focusing the search input brings back the search results
focus: ".search-input"
assert: ("#search", "class", "content")
assert: ("#main", "class", "content hidden")
// Now let's check that when the help popup is displayed and we press Escape, it doesn't
// hide the search results too.
click: "#help-button"
assert: ("#help", "class", "")
press-key: "Escape"
assert: ("#help", "class", "hidden")
assert: ("#search", "class", "content")
assert: ("#main", "class", "content hidden")
// FIXME: Once https://github.com/rust-lang/rust/pull/84462 is merged, add check to ensure
// that Escape hides the search results when a result is focused.
// press-key: "ArrowDown"

View File

@ -1,5 +1,4 @@
#![feature(external_doc)]
#![feature(extended_key_value_attributes)]
// @has external_doc/struct.CanHasDocs.html
// @has - '//h1' 'External Docs'

View File

@ -1,4 +1,3 @@
#![feature(extended_key_value_attributes)]
#![feature(rustc_attrs)]
#[rustc_dummy = stringify!(a)] // OK

View File

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

View File

@ -1,8 +0,0 @@
#[cfg(FALSE)]
#[attr = multi::segment::path] //~ ERROR arbitrary expressions in key-value attributes are unstable
#[attr = macro_call!()] //~ ERROR arbitrary expressions in key-value attributes are unstable
#[attr = 1 + 2] //~ ERROR arbitrary expressions in key-value attributes are unstable
#[attr = what?] //~ ERROR arbitrary expressions in key-value attributes are unstable
struct S;
fn main() {}

View File

@ -1,39 +0,0 @@
error[E0658]: arbitrary expressions in key-value attributes are unstable
--> $DIR/feature-gate-extended_key_value_attributes.rs:2:10
|
LL | #[attr = multi::segment::path]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #78835 <https://github.com/rust-lang/rust/issues/78835> for more information
= help: add `#![feature(extended_key_value_attributes)]` to the crate attributes to enable
error[E0658]: arbitrary expressions in key-value attributes are unstable
--> $DIR/feature-gate-extended_key_value_attributes.rs:3:10
|
LL | #[attr = macro_call!()]
| ^^^^^^^^^^^^^
|
= note: see issue #78835 <https://github.com/rust-lang/rust/issues/78835> for more information
= help: add `#![feature(extended_key_value_attributes)]` to the crate attributes to enable
error[E0658]: arbitrary expressions in key-value attributes are unstable
--> $DIR/feature-gate-extended_key_value_attributes.rs:4:10
|
LL | #[attr = 1 + 2]
| ^^^^^
|
= note: see issue #78835 <https://github.com/rust-lang/rust/issues/78835> for more information
= help: add `#![feature(extended_key_value_attributes)]` to the crate attributes to enable
error[E0658]: arbitrary expressions in key-value attributes are unstable
--> $DIR/feature-gate-extended_key_value_attributes.rs:5:10
|
LL | #[attr = what?]
| ^^^^^
|
= note: see issue #78835 <https://github.com/rust-lang/rust/issues/78835> for more information
= help: add `#![feature(extended_key_value_attributes)]` to the crate attributes to enable
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,4 +1,4 @@
#![feature(rustc_attrs, extended_key_value_attributes)]
#![feature(rustc_attrs)]
#[rustc_dummy = 1usize] //~ ERROR: suffixed literals are not allowed in attributes
#[rustc_dummy = 1u8] //~ ERROR: suffixed literals are not allowed in attributes

View File

@ -0,0 +1,48 @@
// Ensure that trait objects don't include more than one binder. See #83611
// build-fail
// revisions: v0
//[v0]compile-flags: -Z symbol-mangling-version=v0
//[v0]normalize-stderr-test: "Cs.*?_" -> "CRATE_HASH"
//[v0]normalize-stderr-test: "core\[.*?\]" -> "core[HASH]"
#![feature(rustc_attrs)]
trait Bar {
fn method(&self) {}
}
impl Bar for &dyn FnMut(&u8) {
#[rustc_symbol_name]
//[v0]~^ ERROR symbol-name
//[v0]~| ERROR demangling
//[v0]~| ERROR demangling-alt
fn method(&self) {}
}
trait Foo {
fn method(&self) {}
}
impl Foo for &(dyn FnMut(&u8) + for<'b> Send) {
#[rustc_symbol_name]
//[v0]~^ ERROR symbol-name
//[v0]~| ERROR demangling
//[v0]~| ERROR demangling-alt
fn method(&self) {}
}
trait Baz {
fn method(&self) {}
}
impl Baz for &(dyn for<'b> Send + FnMut(&u8)) {
#[rustc_symbol_name]
//[v0]~^ ERROR symbol-name
//[v0]~| ERROR demangling
//[v0]~| ERROR demangling-alt
fn method(&self) {}
}
fn main() {
}

View File

@ -0,0 +1,56 @@
error: symbol-name(_RNvXCRATE_HASH13trait_objectsRDG_INtNtNtCRATE_HASH4core3ops8function5FnMutTRL0_hEEp6OutputuEL_NtB2_3Bar6method)
--> $DIR/trait-objects.rs:16:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(<&dyn for<'a> core[HASH]::ops::function::FnMut<(&'a u8,), Output = ()> as trait_objects[17891616a171812d]::Bar>::method)
--> $DIR/trait-objects.rs:16:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(<&dyn for<'a> core::ops::function::FnMut<(&'a u8,), Output = ()> as trait_objects::Bar>::method)
--> $DIR/trait-objects.rs:16:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_RNvXs_CRATE_HASH13trait_objectsRDG_INtNtNtCRATE_HASH4core3ops8function5FnMutTRL0_hEEp6OutputuNtNtBI_6marker4SendEL_NtB4_3Foo6method)
--> $DIR/trait-objects.rs:28:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(<&dyn for<'a> core[HASH]::ops::function::FnMut<(&'a u8,), Output = ()> + core[HASH]::marker::Send as trait_objects[17891616a171812d]::Foo>::method)
--> $DIR/trait-objects.rs:28:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(<&dyn for<'a> core::ops::function::FnMut<(&'a u8,), Output = ()> + core::marker::Send as trait_objects::Foo>::method)
--> $DIR/trait-objects.rs:28:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_RNvXs0_CRATE_HASH13trait_objectsRDG_INtNtNtCRATE_HASH4core3ops8function5FnMutTRL0_hEEp6OutputuNtNtBJ_6marker4SendEL_NtB5_3Baz6method)
--> $DIR/trait-objects.rs:40:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(<&dyn for<'a> core[HASH]::ops::function::FnMut<(&'a u8,), Output = ()> + core[HASH]::marker::Send as trait_objects[17891616a171812d]::Baz>::method)
--> $DIR/trait-objects.rs:40:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(<&dyn for<'a> core::ops::function::FnMut<(&'a u8,), Output = ()> + core::marker::Send as trait_objects::Baz>::method)
--> $DIR/trait-objects.rs:40:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to 9 previous errors

View File

@ -2327,7 +2327,11 @@ impl<'test> TestCx<'test> {
// For now, though…
if let Some(rev) = self.revision {
let prefixes = format!("CHECK,{}", rev);
filecheck.args(&["--check-prefixes", &prefixes]);
if self.config.llvm_version.unwrap_or(0) >= 130000 {
filecheck.args(&["--allow-unused-prefixes", "--check-prefixes", &prefixes]);
} else {
filecheck.args(&["--check-prefixes", &prefixes]);
}
}
self.compose_and_run(filecheck, "", None, None)
}