Skip to content

Commit 1eb62b1

Browse files
committed
Auto merge of rust-lang#104983 - matthiaskrgr:rollup-018sk73, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#95836 (Use `rust_out{exe_suffix}` for doctests) - rust-lang#104882 (notify lcnr on changes to `ObligationCtxt`) - rust-lang#104892 (Explain how to get the discriminant out of a `#[repr(T)] enum` with payload) - rust-lang#104917 (Allow non-org members to label `requires-debug-assertions`) - rust-lang#104931 (Pretty-print generators with their `generator_kind`) - rust-lang#104934 (Remove redundant `all` in cfg) - rust-lang#104944 (Support unit tests for jsondoclint) - rust-lang#104946 (rustdoc: improve popover focus handling JS) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 454784a + 55cf566 commit 1eb62b1

File tree

37 files changed

+318
-114
lines changed

37 files changed

+318
-114
lines changed

compiler/rustc_codegen_gcc/example/alloc_system.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313

1414
// The minimum alignment guaranteed by the architecture. This value is used to
1515
// add fast paths for low alignment values.
16-
#[cfg(all(any(target_arch = "x86",
16+
#[cfg(any(target_arch = "x86",
1717
target_arch = "arm",
1818
target_arch = "mips",
1919
target_arch = "powerpc",
20-
target_arch = "powerpc64")))]
20+
target_arch = "powerpc64"))]
2121
const MIN_ALIGN: usize = 8;
22-
#[cfg(all(any(target_arch = "x86_64",
22+
#[cfg(any(target_arch = "x86_64",
2323
target_arch = "aarch64",
2424
target_arch = "mips64",
2525
target_arch = "s390x",
26-
target_arch = "sparc64")))]
26+
target_arch = "sparc64"))]
2727
const MIN_ALIGN: usize = 16;
2828

2929
pub struct System;

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl<'tcx> NonConstOp<'tcx> for Generator {
376376
ccx: &ConstCx<'_, 'tcx>,
377377
span: Span,
378378
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
379-
let msg = format!("{}s are not allowed in {}s", self.0, ccx.const_kind());
379+
let msg = format!("{}s are not allowed in {}s", self.0.descr(), ccx.const_kind());
380380
if let hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) = self.0 {
381381
ccx.tcx.sess.create_feature_err(
382382
UnallowedOpInConstContext { span, msg },

compiler/rustc_hir/src/hir.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1526,9 +1526,9 @@ pub enum AsyncGeneratorKind {
15261526
impl fmt::Display for AsyncGeneratorKind {
15271527
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15281528
f.write_str(match self {
1529-
AsyncGeneratorKind::Block => "`async` block",
1530-
AsyncGeneratorKind::Closure => "`async` closure body",
1531-
AsyncGeneratorKind::Fn => "`async fn` body",
1529+
AsyncGeneratorKind::Block => "async block",
1530+
AsyncGeneratorKind::Closure => "async closure body",
1531+
AsyncGeneratorKind::Fn => "async fn body",
15321532
})
15331533
}
15341534
}

compiler/rustc_hir_typeck/src/generator_interior/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
118118
} else {
119119
let note = format!(
120120
"the type is part of the {} because of this {}",
121-
self.kind, yield_data.source
121+
self.kind.descr(),
122+
yield_data.source
122123
);
123124

124125
self.fcx

compiler/rustc_middle/src/ty/print/pretty.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -681,25 +681,20 @@ pub trait PrettyPrinter<'tcx>:
681681
}
682682
ty::Str => p!("str"),
683683
ty::Generator(did, substs, movability) => {
684-
// FIXME(swatinem): async constructs used to be pretty printed
685-
// as `impl Future` previously due to the `from_generator` wrapping.
686-
// lets special case this here for now to avoid churn in diagnostics.
687-
let generator_kind = self.tcx().generator_kind(did);
688-
if matches!(generator_kind, Some(hir::GeneratorKind::Async(..))) {
689-
let return_ty = substs.as_generator().return_ty();
690-
p!(write("impl Future<Output = {}>", return_ty));
691-
692-
return Ok(self);
693-
}
694-
695684
p!(write("["));
696-
match movability {
697-
hir::Movability::Movable => {}
698-
hir::Movability::Static => p!("static "),
685+
let generator_kind = self.tcx().generator_kind(did).unwrap();
686+
let should_print_movability =
687+
self.should_print_verbose() || generator_kind == hir::GeneratorKind::Gen;
688+
689+
if should_print_movability {
690+
match movability {
691+
hir::Movability::Movable => {}
692+
hir::Movability::Static => p!("static "),
693+
}
699694
}
700695

701696
if !self.should_print_verbose() {
702-
p!("generator");
697+
p!(write("{}", generator_kind));
703698
// FIXME(eddyb) should use `def_span`.
704699
if let Some(did) = did.as_local() {
705700
let span = self.tcx().def_span(did);

compiler/rustc_span/src/analyze_source_file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn analyze_source_file(
4141
}
4242

4343
cfg_if::cfg_if! {
44-
if #[cfg(all(any(target_arch = "x86", target_arch = "x86_64")))] {
44+
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
4545
fn analyze_source_file_dispatch(src: &str,
4646
source_file_start_pos: BytePos,
4747
lines: &mut Vec<BytePos>,

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2673,7 +2673,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
26732673
let sp = self.tcx.def_span(def_id);
26742674

26752675
// Special-case this to say "async block" instead of `[static generator]`.
2676-
let kind = tcx.generator_kind(def_id).unwrap();
2676+
let kind = tcx.generator_kind(def_id).unwrap().descr();
26772677
err.span_note(
26782678
sp,
26792679
&format!("required because it's used within this {}", kind),

library/core/src/mem/mod.rs

+60-1
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,10 @@ impl<T> fmt::Debug for Discriminant<T> {
11131113
/// # Stability
11141114
///
11151115
/// The discriminant of an enum variant may change if the enum definition changes. A discriminant
1116-
/// of some variant will not change between compilations with the same compiler.
1116+
/// of some variant will not change between compilations with the same compiler. See the [Reference]
1117+
/// for more information.
1118+
///
1119+
/// [Reference]: ../../reference/items/enumerations.html#custom-discriminant-values-for-fieldless-enumerations
11171120
///
11181121
/// # Examples
11191122
///
@@ -1129,6 +1132,62 @@ impl<T> fmt::Debug for Discriminant<T> {
11291132
/// assert_eq!(mem::discriminant(&Foo::B(1)), mem::discriminant(&Foo::B(2)));
11301133
/// assert_ne!(mem::discriminant(&Foo::B(3)), mem::discriminant(&Foo::C(3)));
11311134
/// ```
1135+
///
1136+
/// ## Accessing the numeric value of the discriminant
1137+
///
1138+
/// Note that it is *undefined behavior* to [`transmute`] from [`Discriminant`] to a primitive!
1139+
///
1140+
/// If an enum has only unit variants, then the numeric value of the discriminant can be accessed
1141+
/// with an [`as`] cast:
1142+
///
1143+
/// ```
1144+
/// enum Enum {
1145+
/// Foo,
1146+
/// Bar,
1147+
/// Baz,
1148+
/// }
1149+
///
1150+
/// assert_eq!(0, Enum::Foo as isize);
1151+
/// assert_eq!(1, Enum::Bar as isize);
1152+
/// assert_eq!(2, Enum::Baz as isize);
1153+
/// ```
1154+
///
1155+
/// If an enum has opted-in to having a [primitive representation] for its discriminant,
1156+
/// then it's possible to use pointers to read the memory location storing the discriminant.
1157+
/// That **cannot** be done for enums using the [default representation], however, as it's
1158+
/// undefined what layout the discriminant has and where it's stored — it might not even be
1159+
/// stored at all!
1160+
///
1161+
/// [`as`]: ../../std/keyword.as.html
1162+
/// [primitive representation]: ../../reference/type-layout.html#primitive-representations
1163+
/// [default representation]: ../../reference/type-layout.html#the-default-representation
1164+
/// ```
1165+
/// #[repr(u8)]
1166+
/// enum Enum {
1167+
/// Unit,
1168+
/// Tuple(bool),
1169+
/// Struct { a: bool },
1170+
/// }
1171+
///
1172+
/// impl Enum {
1173+
/// fn discriminant(&self) -> u8 {
1174+
/// // SAFETY: Because `Self` is marked `repr(u8)`, its layout is a `repr(C)` `union`
1175+
/// // between `repr(C)` structs, each of which has the `u8` discriminant as its first
1176+
/// // field, so we can read the discriminant without offsetting the pointer.
1177+
/// unsafe { *<*const _>::from(self).cast::<u8>() }
1178+
/// }
1179+
/// }
1180+
///
1181+
/// let unit_like = Enum::Unit;
1182+
/// let tuple_like = Enum::Tuple(true);
1183+
/// let struct_like = Enum::Struct { a: false };
1184+
/// assert_eq!(0, unit_like.discriminant());
1185+
/// assert_eq!(1, tuple_like.discriminant());
1186+
/// assert_eq!(2, struct_like.discriminant());
1187+
///
1188+
/// // ⚠️ This is undefined behavior. Don't do this. ⚠️
1189+
/// // assert_eq!(0, unsafe { std::mem::transmute::<_, u8>(std::mem::discriminant(&unit_like)) });
1190+
/// ```
11321191
#[stable(feature = "discriminant_value", since = "1.21.0")]
11331192
#[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
11341193
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_discriminant")]

library/std/src/sys/common/alloc.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::ptr;
44

55
// The minimum alignment guaranteed by the architecture. This value is used to
66
// add fast paths for low alignment values.
7-
#[cfg(all(any(
7+
#[cfg(any(
88
target_arch = "x86",
99
target_arch = "arm",
1010
target_arch = "mips",
@@ -16,23 +16,23 @@ use crate::ptr;
1616
target_arch = "hexagon",
1717
all(target_arch = "riscv32", not(target_os = "espidf")),
1818
all(target_arch = "xtensa", not(target_os = "espidf")),
19-
)))]
19+
))]
2020
pub const MIN_ALIGN: usize = 8;
21-
#[cfg(all(any(
21+
#[cfg(any(
2222
target_arch = "x86_64",
2323
target_arch = "aarch64",
2424
target_arch = "mips64",
2525
target_arch = "s390x",
2626
target_arch = "sparc64",
2727
target_arch = "riscv64",
2828
target_arch = "wasm64",
29-
)))]
29+
))]
3030
pub const MIN_ALIGN: usize = 16;
3131
// The allocator on the esp-idf platform guarantees 4 byte alignment.
32-
#[cfg(all(any(
32+
#[cfg(any(
3333
all(target_arch = "riscv32", target_os = "espidf"),
3434
all(target_arch = "xtensa", target_os = "espidf"),
35-
)))]
35+
))]
3636
pub const MIN_ALIGN: usize = 4;
3737

3838
pub unsafe fn realloc_fallback(

src/bootstrap/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ impl<'a> Builder<'a> {
644644
test::CrateLibrustc,
645645
test::CrateRustdoc,
646646
test::CrateRustdocJsonTypes,
647+
test::CrateJsonDocLint,
647648
test::Linkcheck,
648649
test::TierCheck,
649650
test::ReplacePlaceholderTest,

src/bootstrap/test.rs

+36
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,42 @@ fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
9090
true
9191
}
9292

93+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
94+
pub struct CrateJsonDocLint {
95+
host: TargetSelection,
96+
}
97+
98+
impl Step for CrateJsonDocLint {
99+
type Output = ();
100+
const ONLY_HOSTS: bool = true;
101+
const DEFAULT: bool = true;
102+
103+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
104+
run.path("src/tools/jsondoclint")
105+
}
106+
107+
fn make_run(run: RunConfig<'_>) {
108+
run.builder.ensure(CrateJsonDocLint { host: run.target });
109+
}
110+
111+
fn run(self, builder: &Builder<'_>) {
112+
let bootstrap_host = builder.config.build;
113+
let compiler = builder.compiler(0, bootstrap_host);
114+
115+
let cargo = tool::prepare_tool_cargo(
116+
builder,
117+
compiler,
118+
Mode::ToolBootstrap,
119+
bootstrap_host,
120+
"test",
121+
"src/tools/jsondoclint",
122+
SourceType::InTree,
123+
&[],
124+
);
125+
try_run(builder, &mut cargo.into());
126+
}
127+
}
128+
93129
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
94130
pub struct Linkcheck {
95131
host: TargetSelection,

src/librustdoc/doctest.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_span::edition::Edition;
1919
use rustc_span::source_map::SourceMap;
2020
use rustc_span::symbol::sym;
2121
use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP};
22-
use rustc_target::spec::TargetTriple;
22+
use rustc_target::spec::{Target, TargetTriple};
2323
use tempfile::Builder as TempFileBuilder;
2424

2525
use std::env;
@@ -293,6 +293,16 @@ struct UnusedExterns {
293293
unused_extern_names: Vec<String>,
294294
}
295295

296+
fn add_exe_suffix(input: String, target: &TargetTriple) -> String {
297+
let exe_suffix = match target {
298+
TargetTriple::TargetTriple(_) => Target::expect_builtin(target).options.exe_suffix,
299+
TargetTriple::TargetJson { contents, .. } => {
300+
Target::from_json(contents.parse().unwrap()).unwrap().0.options.exe_suffix
301+
}
302+
};
303+
input + &exe_suffix
304+
}
305+
296306
fn run_test(
297307
test: &str,
298308
crate_name: &str,
@@ -313,7 +323,9 @@ fn run_test(
313323
let (test, line_offset, supports_color) =
314324
make_test(test, Some(crate_name), lang_string.test_harness, opts, edition, Some(test_id));
315325

316-
let output_file = outdir.path().join("rust_out");
326+
// Make sure we emit well-formed executable names for our target.
327+
let rust_out = add_exe_suffix("rust_out".to_owned(), &target);
328+
let output_file = outdir.path().join(rust_out);
317329

318330
let rustc_binary = rustdoc_options
319331
.test_builder

src/librustdoc/html/static/js/main.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ function loadCss(cssUrl) {
202202
if (event.ctrlKey || event.altKey || event.metaKey) {
203203
return;
204204
}
205+
window.hideAllModals(false);
205206
addClass(getSettingsButton(), "rotate");
206207
event.preventDefault();
207208
// Sending request for the CSS and the JS files at the same time so it will
@@ -377,7 +378,7 @@ function loadCss(cssUrl) {
377378
}
378379
ev.preventDefault();
379380
searchState.defocus();
380-
window.hidePopoverMenus();
381+
window.hideAllModals(true); // true = reset focus for notable traits
381382
}
382383

383384
function handleShortcut(ev) {
@@ -767,6 +768,7 @@ function loadCss(cssUrl) {
767768
};
768769

769770
function showSidebar() {
771+
window.hideAllModals(false);
770772
window.rustdocMobileScrollLock();
771773
const sidebar = document.getElementsByClassName("sidebar")[0];
772774
addClass(sidebar, "shown");
@@ -843,7 +845,7 @@ function loadCss(cssUrl) {
843845
// Make this function idempotent.
844846
return;
845847
}
846-
hideNotable(false);
848+
window.hideAllModals(false);
847849
const ty = e.getAttribute("data-ty");
848850
const wrapper = document.createElement("div");
849851
wrapper.innerHTML = "<div class=\"docblock\">" + window.NOTABLE_TRAITS[ty] + "</div>";
@@ -1049,14 +1051,24 @@ function loadCss(cssUrl) {
10491051
return container;
10501052
}
10511053

1054+
/**
1055+
* Hide popover menus, notable trait tooltips, and the sidebar (if applicable).
1056+
*
1057+
* Pass "true" to reset focus for notable traits.
1058+
*/
1059+
window.hideAllModals = function(switchFocus) {
1060+
hideSidebar();
1061+
window.hidePopoverMenus();
1062+
hideNotable(switchFocus);
1063+
};
1064+
10521065
/**
10531066
* Hide all the popover menus.
10541067
*/
10551068
window.hidePopoverMenus = function() {
10561069
onEachLazy(document.querySelectorAll(".search-form .popover"), elem => {
10571070
elem.style.display = "none";
10581071
});
1059-
hideNotable(false);
10601072
};
10611073

10621074
/**
@@ -1081,7 +1093,7 @@ function loadCss(cssUrl) {
10811093
function showHelp() {
10821094
const menu = getHelpMenu(true);
10831095
if (menu.style.display === "none") {
1084-
window.hidePopoverMenus();
1096+
window.hideAllModals();
10851097
menu.style.display = "";
10861098
}
10871099
}

src/librustdoc/html/static/js/settings.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
event.preventDefault();
269269
const shouldDisplaySettings = settingsMenu.style.display === "none";
270270

271-
window.hidePopoverMenus();
271+
window.hideAllModals();
272272
if (shouldDisplaySettings) {
273273
displaySettings();
274274
}

src/test/run-make/coverage-reports/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ include clear_expected_if_blessed
132132
--instr-profile="$(TMPDIR)"/[email protected] \
133133
$(call BIN,"$(TMPDIR)"/$@) \
134134
$$( \
135-
for file in $(TMPDIR)/rustdoc-$@/*/rust_out; do \
135+
for file in $(TMPDIR)/rustdoc-$@/*/rust_out*; do \
136136
[ -x "$$file" ] && printf "%s %s " -object $$file; \
137137
done \
138138
) \

0 commit comments

Comments
 (0)