Skip to content

Rollup of 8 pull requests #104983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
68d9530
notify lcnr on changes to `ObligationCtxt`
lcnr Nov 25, 2022
1dc88ff
Allow non-org members to label `requires-debug-assertions`
compiler-errors Nov 26, 2022
c256bd2
Remove redundant `all` in cfg
ChrisDenton Nov 26, 2022
2ab3f76
Remove more redundant `all`s
ChrisDenton Nov 26, 2022
e06b61c
explain how to get the discriminant out of a `#[repr(T)] enum`
Nov 25, 2022
4b2a1eb
Support unit tests for jsondoclint
aDotInTheVoid Nov 26, 2022
946d51e
fix broken link fragment
Nov 26, 2022
09818a8
Add a test that makes sense
aDotInTheVoid Nov 26, 2022
74de78a
rustdoc: improve popover focus handling JS
notriddle Nov 26, 2022
c96d888
Pretty-print generators with their `generator_kind`
Swatinem Nov 25, 2022
c26074a
rustdoc: pass "true" to reset focus for notable traits
notriddle Nov 26, 2022
353cef9
Use target exe_suffix for doctests
workingjubilee Apr 9, 2022
47ddca6
Attempt to solve problem with globs
workingjubilee Nov 27, 2022
7ce937f
Rollup merge of #95836 - workingjubilee:doctest-exe, r=notriddle
matthiaskrgr Nov 27, 2022
5d05cf8
Rollup merge of #104882 - lcnr:notify-ocx, r=Mark-Simulacrum
matthiaskrgr Nov 27, 2022
9ba78ac
Rollup merge of #104892 - lukas-code:discriminant, r=scottmcm
matthiaskrgr Nov 27, 2022
9ebffb7
Rollup merge of #104917 - compiler-errors:requires-debug-assertions, …
matthiaskrgr Nov 27, 2022
6e6c42c
Rollup merge of #104931 - Swatinem:async-pretty, r=eholk
matthiaskrgr Nov 27, 2022
8d90647
Rollup merge of #104934 - ChrisDenton:all-anybody-wants, r=thomcc
matthiaskrgr Nov 27, 2022
e3165a3
Rollup merge of #104944 - aDotInTheVoid:jsondoclint-unit-tests, r=jyn514
matthiaskrgr Nov 27, 2022
55cf566
Rollup merge of #104946 - notriddle:notriddle/popover-menu-focus, r=G…
matthiaskrgr Nov 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_gcc/example/alloc_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

// The minimum alignment guaranteed by the architecture. This value is used to
// add fast paths for low alignment values.
#[cfg(all(any(target_arch = "x86",
#[cfg(any(target_arch = "x86",
target_arch = "arm",
target_arch = "mips",
target_arch = "powerpc",
target_arch = "powerpc64")))]
target_arch = "powerpc64"))]
const MIN_ALIGN: usize = 8;
#[cfg(all(any(target_arch = "x86_64",
#[cfg(any(target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "mips64",
target_arch = "s390x",
target_arch = "sparc64")))]
target_arch = "sparc64"))]
const MIN_ALIGN: usize = 16;

pub struct System;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl<'tcx> NonConstOp<'tcx> for Generator {
ccx: &ConstCx<'_, 'tcx>,
span: Span,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let msg = format!("{}s are not allowed in {}s", self.0, ccx.const_kind());
let msg = format!("{}s are not allowed in {}s", self.0.descr(), ccx.const_kind());
if let hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) = self.0 {
ccx.tcx.sess.create_feature_err(
UnallowedOpInConstContext { span, msg },
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,9 +1514,9 @@ pub enum AsyncGeneratorKind {
impl fmt::Display for AsyncGeneratorKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
AsyncGeneratorKind::Block => "`async` block",
AsyncGeneratorKind::Closure => "`async` closure body",
AsyncGeneratorKind::Fn => "`async fn` body",
AsyncGeneratorKind::Block => "async block",
AsyncGeneratorKind::Closure => "async closure body",
AsyncGeneratorKind::Fn => "async fn body",
})
}
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_typeck/src/generator_interior/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
} else {
let note = format!(
"the type is part of the {} because of this {}",
self.kind, yield_data.source
self.kind.descr(),
yield_data.source
);

self.fcx
Expand Down
25 changes: 10 additions & 15 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,25 +681,20 @@ pub trait PrettyPrinter<'tcx>:
}
ty::Str => p!("str"),
ty::Generator(did, substs, movability) => {
// FIXME(swatinem): async constructs used to be pretty printed
// as `impl Future` previously due to the `from_generator` wrapping.
// lets special case this here for now to avoid churn in diagnostics.
let generator_kind = self.tcx().generator_kind(did);
if matches!(generator_kind, Some(hir::GeneratorKind::Async(..))) {
let return_ty = substs.as_generator().return_ty();
p!(write("impl Future<Output = {}>", return_ty));

return Ok(self);
}

p!(write("["));
match movability {
hir::Movability::Movable => {}
hir::Movability::Static => p!("static "),
let generator_kind = self.tcx().generator_kind(did).unwrap();
let should_print_movability =
self.should_print_verbose() || generator_kind == hir::GeneratorKind::Gen;

if should_print_movability {
match movability {
hir::Movability::Movable => {}
hir::Movability::Static => p!("static "),
}
}

if !self.should_print_verbose() {
p!("generator");
p!(write("{}", generator_kind));
// FIXME(eddyb) should use `def_span`.
if let Some(did) = did.as_local() {
let span = self.tcx().def_span(did);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/analyze_source_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn analyze_source_file(
}

cfg_if::cfg_if! {
if #[cfg(all(any(target_arch = "x86", target_arch = "x86_64")))] {
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
fn analyze_source_file_dispatch(src: &str,
source_file_start_pos: BytePos,
lines: &mut Vec<BytePos>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2673,7 +2673,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let sp = self.tcx.def_span(def_id);

// Special-case this to say "async block" instead of `[static generator]`.
let kind = tcx.generator_kind(def_id).unwrap();
let kind = tcx.generator_kind(def_id).unwrap().descr();
err.span_note(
sp,
&format!("required because it's used within this {}", kind),
Expand Down
61 changes: 60 additions & 1 deletion library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,10 @@ impl<T> fmt::Debug for Discriminant<T> {
/// # Stability
///
/// The discriminant of an enum variant may change if the enum definition changes. A discriminant
/// of some variant will not change between compilations with the same compiler.
/// of some variant will not change between compilations with the same compiler. See the [Reference]
/// for more information.
///
/// [Reference]: ../../reference/items/enumerations.html#custom-discriminant-values-for-fieldless-enumerations
///
/// # Examples
///
Expand All @@ -1129,6 +1132,62 @@ impl<T> fmt::Debug for Discriminant<T> {
/// assert_eq!(mem::discriminant(&Foo::B(1)), mem::discriminant(&Foo::B(2)));
/// assert_ne!(mem::discriminant(&Foo::B(3)), mem::discriminant(&Foo::C(3)));
/// ```
///
/// ## Accessing the numeric value of the discriminant
///
/// Note that it is *undefined behavior* to [`transmute`] from [`Discriminant`] to a primitive!
///
/// If an enum has only unit variants, then the numeric value of the discriminant can be accessed
/// with an [`as`] cast:
///
/// ```
/// enum Enum {
/// Foo,
/// Bar,
/// Baz,
/// }
///
/// assert_eq!(0, Enum::Foo as isize);
/// assert_eq!(1, Enum::Bar as isize);
/// assert_eq!(2, Enum::Baz as isize);
/// ```
///
/// If an enum has opted-in to having a [primitive representation] for its discriminant,
/// then it's possible to use pointers to read the memory location storing the discriminant.
/// That **cannot** be done for enums using the [default representation], however, as it's
/// undefined what layout the discriminant has and where it's stored — it might not even be
/// stored at all!
///
/// [`as`]: ../../std/keyword.as.html
/// [primitive representation]: ../../reference/type-layout.html#primitive-representations
/// [default representation]: ../../reference/type-layout.html#the-default-representation
/// ```
/// #[repr(u8)]
/// enum Enum {
/// Unit,
/// Tuple(bool),
/// Struct { a: bool },
/// }
///
/// impl Enum {
/// fn discriminant(&self) -> u8 {
/// // SAFETY: Because `Self` is marked `repr(u8)`, its layout is a `repr(C)` `union`
/// // between `repr(C)` structs, each of which has the `u8` discriminant as its first
/// // field, so we can read the discriminant without offsetting the pointer.
/// unsafe { *<*const _>::from(self).cast::<u8>() }
/// }
/// }
///
/// let unit_like = Enum::Unit;
/// let tuple_like = Enum::Tuple(true);
/// let struct_like = Enum::Struct { a: false };
/// assert_eq!(0, unit_like.discriminant());
/// assert_eq!(1, tuple_like.discriminant());
/// assert_eq!(2, struct_like.discriminant());
///
/// // ⚠️ This is undefined behavior. Don't do this. ⚠️
/// // assert_eq!(0, unsafe { std::mem::transmute::<_, u8>(std::mem::discriminant(&unit_like)) });
/// ```
#[stable(feature = "discriminant_value", since = "1.21.0")]
#[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_discriminant")]
Expand Down
12 changes: 6 additions & 6 deletions library/std/src/sys/common/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::ptr;

// The minimum alignment guaranteed by the architecture. This value is used to
// add fast paths for low alignment values.
#[cfg(all(any(
#[cfg(any(
target_arch = "x86",
target_arch = "arm",
target_arch = "mips",
Expand All @@ -16,23 +16,23 @@ use crate::ptr;
target_arch = "hexagon",
all(target_arch = "riscv32", not(target_os = "espidf")),
all(target_arch = "xtensa", not(target_os = "espidf")),
)))]
))]
pub const MIN_ALIGN: usize = 8;
#[cfg(all(any(
#[cfg(any(
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "mips64",
target_arch = "s390x",
target_arch = "sparc64",
target_arch = "riscv64",
target_arch = "wasm64",
)))]
))]
pub const MIN_ALIGN: usize = 16;
// The allocator on the esp-idf platform guarantees 4 byte alignment.
#[cfg(all(any(
#[cfg(any(
all(target_arch = "riscv32", target_os = "espidf"),
all(target_arch = "xtensa", target_os = "espidf"),
)))]
))]
pub const MIN_ALIGN: usize = 4;

pub unsafe fn realloc_fallback(
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ impl<'a> Builder<'a> {
test::CrateLibrustc,
test::CrateRustdoc,
test::CrateRustdocJsonTypes,
test::CrateJsonDocLint,
test::Linkcheck,
test::TierCheck,
test::ReplacePlaceholderTest,
Expand Down
36 changes: 36 additions & 0 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,42 @@ fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
true
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct CrateJsonDocLint {
host: TargetSelection,
}

impl Step for CrateJsonDocLint {
type Output = ();
const ONLY_HOSTS: bool = true;
const DEFAULT: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/tools/jsondoclint")
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(CrateJsonDocLint { host: run.target });
}

fn run(self, builder: &Builder<'_>) {
let bootstrap_host = builder.config.build;
let compiler = builder.compiler(0, bootstrap_host);

let cargo = tool::prepare_tool_cargo(
builder,
compiler,
Mode::ToolBootstrap,
bootstrap_host,
"test",
"src/tools/jsondoclint",
SourceType::InTree,
&[],
);
try_run(builder, &mut cargo.into());
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Linkcheck {
host: TargetSelection,
Expand Down
16 changes: 14 additions & 2 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_span::edition::Edition;
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::sym;
use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP};
use rustc_target::spec::TargetTriple;
use rustc_target::spec::{Target, TargetTriple};
use tempfile::Builder as TempFileBuilder;

use std::env;
Expand Down Expand Up @@ -293,6 +293,16 @@ struct UnusedExterns {
unused_extern_names: Vec<String>,
}

fn add_exe_suffix(input: String, target: &TargetTriple) -> String {
let exe_suffix = match target {
TargetTriple::TargetTriple(_) => Target::expect_builtin(target).options.exe_suffix,
TargetTriple::TargetJson { contents, .. } => {
Target::from_json(contents.parse().unwrap()).unwrap().0.options.exe_suffix
}
};
input + &exe_suffix
}

fn run_test(
test: &str,
crate_name: &str,
Expand All @@ -313,7 +323,9 @@ fn run_test(
let (test, line_offset, supports_color) =
make_test(test, Some(crate_name), lang_string.test_harness, opts, edition, Some(test_id));

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

let rustc_binary = rustdoc_options
.test_builder
Expand Down
20 changes: 16 additions & 4 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ function loadCss(cssUrl) {
if (event.ctrlKey || event.altKey || event.metaKey) {
return;
}
window.hideAllModals(false);
addClass(getSettingsButton(), "rotate");
event.preventDefault();
// Sending request for the CSS and the JS files at the same time so it will
Expand Down Expand Up @@ -377,7 +378,7 @@ function loadCss(cssUrl) {
}
ev.preventDefault();
searchState.defocus();
window.hidePopoverMenus();
window.hideAllModals(true); // true = reset focus for notable traits
}

function handleShortcut(ev) {
Expand Down Expand Up @@ -767,6 +768,7 @@ function loadCss(cssUrl) {
};

function showSidebar() {
window.hideAllModals(false);
window.rustdocMobileScrollLock();
const sidebar = document.getElementsByClassName("sidebar")[0];
addClass(sidebar, "shown");
Expand Down Expand Up @@ -843,7 +845,7 @@ function loadCss(cssUrl) {
// Make this function idempotent.
return;
}
hideNotable(false);
window.hideAllModals(false);
const ty = e.getAttribute("data-ty");
const wrapper = document.createElement("div");
wrapper.innerHTML = "<div class=\"docblock\">" + window.NOTABLE_TRAITS[ty] + "</div>";
Expand Down Expand Up @@ -1049,14 +1051,24 @@ function loadCss(cssUrl) {
return container;
}

/**
* Hide popover menus, notable trait tooltips, and the sidebar (if applicable).
*
* Pass "true" to reset focus for notable traits.
*/
window.hideAllModals = function(switchFocus) {
hideSidebar();
window.hidePopoverMenus();
hideNotable(switchFocus);
};

/**
* Hide all the popover menus.
*/
window.hidePopoverMenus = function() {
onEachLazy(document.querySelectorAll(".search-form .popover"), elem => {
elem.style.display = "none";
});
hideNotable(false);
};

/**
Expand All @@ -1081,7 +1093,7 @@ function loadCss(cssUrl) {
function showHelp() {
const menu = getHelpMenu(true);
if (menu.style.display === "none") {
window.hidePopoverMenus();
window.hideAllModals();
menu.style.display = "";
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
event.preventDefault();
const shouldDisplaySettings = settingsMenu.style.display === "none";

window.hidePopoverMenus();
window.hideAllModals();
if (shouldDisplaySettings) {
displaySettings();
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make/coverage-reports/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ include clear_expected_if_blessed
--instr-profile="$(TMPDIR)"/$@.profdata \
$(call BIN,"$(TMPDIR)"/$@) \
$$( \
for file in $(TMPDIR)/rustdoc-$@/*/rust_out; do \
for file in $(TMPDIR)/rustdoc-$@/*/rust_out*; do \
[ -x "$$file" ] && printf "%s %s " -object $$file; \
done \
) \
Expand Down
Loading