Skip to content

Rollup of 4 pull requests #140845

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

Closed
wants to merge 10 commits into from
Closed
14 changes: 12 additions & 2 deletions compiler/rustc_hir_typeck/src/gather_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,26 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
}

fn assign(&mut self, span: Span, nid: HirId, ty_opt: Option<Ty<'tcx>>) -> Ty<'tcx> {
// We evaluate expressions twice occasionally in diagnostics for better
// type information or because it needs type information out-of-order.
// In order to not ICE and not lead to knock-on ambiguity errors, if we
// try to re-assign a type to a local, then just take out the previous
// type and delay a bug.
if let Some(&local) = self.fcx.locals.borrow_mut().get(&nid) {
self.fcx.dcx().span_delayed_bug(span, "evaluated expression more than once");
return local;
}

match ty_opt {
None => {
// Infer the variable's type.
let var_ty = self.fcx.next_ty_var(span);
assert_eq!(self.fcx.locals.borrow_mut().insert(nid, var_ty), None);
self.fcx.locals.borrow_mut().insert(nid, var_ty);
var_ty
}
Some(typ) => {
// Take type that the user specified.
assert_eq!(self.fcx.locals.borrow_mut().insert(nid, typ), None);
self.fcx.locals.borrow_mut().insert(nid, typ);
typ
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub(crate) struct Options {
pub(crate) expanded_args: Vec<String>,

/// Arguments to be used when compiling doctests.
pub(crate) doctest_compilation_args: Vec<String>,
pub(crate) doctest_build_args: Vec<String>,
}

impl fmt::Debug for Options {
Expand Down Expand Up @@ -802,7 +802,7 @@ impl Options {
let scrape_examples_options = ScrapeExamplesOptions::new(matches, dcx);
let with_examples = matches.opt_strs("with-examples");
let call_locations = crate::scrape_examples::load_call_locations(with_examples, dcx);
let doctest_compilation_args = matches.opt_strs("doctest-compilation-args");
let doctest_build_args = matches.opt_strs("doctest-build-arg");

let unstable_features =
rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
Expand Down Expand Up @@ -851,7 +851,7 @@ impl Options {
scrape_examples_options,
unstable_features,
expanded_args: args,
doctest_compilation_args,
doctest_build_args,
};
let render_options = RenderOptions {
output,
Expand Down
44 changes: 1 addition & 43 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,46 +51,6 @@ pub(crate) struct GlobalTestOptions {
pub(crate) args_file: PathBuf,
}

/// Function used to split command line arguments just like a shell would.
fn split_args(args: &str) -> Vec<String> {
let mut out = Vec::new();
let mut iter = args.chars();
let mut current = String::new();

while let Some(c) = iter.next() {
if c == '\\' {
if let Some(c) = iter.next() {
// If it's escaped, even a quote or a whitespace will be ignored.
current.push(c);
}
} else if c == '"' || c == '\'' {
while let Some(new_c) = iter.next() {
if new_c == c {
break;
} else if new_c == '\\' {
if let Some(c) = iter.next() {
// If it's escaped, even a quote will be ignored.
current.push(c);
}
} else {
current.push(new_c);
}
}
} else if " \n\t\r".contains(c) {
if !current.is_empty() {
out.push(current.clone());
current.clear();
}
} else {
current.push(c);
}
}
if !current.is_empty() {
out.push(current);
}
out
}

pub(crate) fn generate_args_file(file_path: &Path, options: &RustdocOptions) -> Result<(), String> {
let mut file = File::create(file_path)
.map_err(|error| format!("failed to create args file: {error:?}"))?;
Expand Down Expand Up @@ -119,9 +79,7 @@ pub(crate) fn generate_args_file(file_path: &Path, options: &RustdocOptions) ->
content.push(format!("-Z{unstable_option_str}"));
}

for compilation_args in &options.doctest_compilation_args {
content.extend(split_args(compilation_args));
}
content.extend(options.doctest_build_args.clone());

let content = content.join("\n");

Expand Down
22 changes: 0 additions & 22 deletions src/librustdoc/doctest/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,28 +381,6 @@ fn main() {
assert_eq!((output, len), (expected, 1));
}

#[test]
fn check_split_args() {
fn compare(input: &str, expected: &[&str]) {
let output = super::split_args(input);
let expected = expected.iter().map(|s| s.to_string()).collect::<Vec<_>>();
assert_eq!(expected, output, "test failed for {input:?}");
}

compare("'a' \"b\"c", &["a", "bc"]);
compare("'a' \"b \"c d", &["a", "b c", "d"]);
compare("'a' \"b\\\"c\"", &["a", "b\"c"]);
compare("'a\"'", &["a\""]);
compare("\"a'\"", &["a'"]);
compare("\\ a", &[" a"]);
compare("\\\\", &["\\"]);
compare("a'", &["a"]);
compare("a ", &["a"]);
compare("a b", &["a", "b"]);
compare("a\n\t \rb", &["a", "b"]);
compare("a\n\t1 \rb", &["a", "1", "b"]);
}

#[test]
fn comment_in_attrs() {
// If there is an inline code comment after attributes, we need to ensure that
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/html/static/css/noscript.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ nav.sub {
--settings-button-border-focus: #717171;
--sidebar-background-color: #f5f5f5;
--sidebar-background-color-hover: #e0e0e0;
--sidebar-border-color: #ddd;
--code-block-background-color: #f5f5f5;
--scrollbar-track-background-color: #dcdcdc;
--scrollbar-thumb-background-color: rgba(36, 37, 39, 0.6);
Expand Down Expand Up @@ -135,6 +136,7 @@ nav.sub {
--scrape-example-code-wrapper-background-end: rgba(255, 255, 255, 0);
--sidebar-resizer-hover: hsl(207, 90%, 66%);
--sidebar-resizer-active: hsl(207, 90%, 54%);
--sidebar-resizer-shadow: #ccc;
}
/* End theme: light */

Expand All @@ -149,6 +151,7 @@ nav.sub {
--settings-button-border-focus: #ffb900;
--sidebar-background-color: #505050;
--sidebar-background-color-hover: #676767;
--sidebar-border-color: #2A2A2A;
--code-block-background-color: #2A2A2A;
--scrollbar-track-background-color: #717171;
--scrollbar-thumb-background-color: rgba(32, 34, 37, .6);
Expand Down Expand Up @@ -244,6 +247,7 @@ nav.sub {
--scrape-example-code-wrapper-background-end: rgba(53, 53, 53, 0);
--sidebar-resizer-hover: hsl(207, 30%, 54%);
--sidebar-resizer-active: hsl(207, 90%, 54%);
--sidebar-resizer-shadow: #000;
}
/* End theme: dark */
}
57 changes: 50 additions & 7 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* When static files are updated, their suffixes need to be updated.
/* ignore-tidy-filelength */
/*
When static files are updated, their suffixes need to be updated.
1. In the top directory run:
./x.py doc --stage 1 library/core
2. Find the directory containing files named with updated suffixes:
Expand Down Expand Up @@ -496,12 +498,13 @@ img {
top: 0;
left: 0;
z-index: var(--desktop-sidebar-z-index);
/* resize indicator: hide this when on touch or mobile */
border-right: solid 1px var(--sidebar-border-color);
}

.rustdoc.src .sidebar {
flex-basis: 50px;
width: 50px;
border-right: 1px solid;
overflow-x: hidden;
/* The sidebar is by default hidden */
overflow-y: hidden;
Expand All @@ -515,12 +518,40 @@ img {
.sidebar-resizer {
touch-action: none;
width: 9px;
cursor: col-resize;
cursor: ew-resize;
z-index: calc(var(--desktop-sidebar-z-index) + 1);
position: fixed;
height: 100%;
/* make sure there's a 1px gap between the scrollbar and resize handle */
left: calc(var(--desktop-sidebar-width) + 1px);
left: var(--desktop-sidebar-width);
display: flex;
align-items: center;
justify-content: flex-start;
}
.sidebar-resizer::after {
content: "";
background: linear-gradient(
0.25turn,
transparent 0px,
transparent 2px,
var(--sidebar-border-color) 2px,
var(--sidebar-border-color) 3px,
var(--sidebar-resizer-shadow) 3px,
var(--sidebar-resizer-shadow) 4px,
transparent 4px,
transparent 6px,
var(--sidebar-border-color) 6px,
var(--sidebar-border-color) 7px,
var(--sidebar-resizer-shadow) 7px,
var(--sidebar-resizer-shadow) 8px,
transparent 8px
);
border: solid 1px var(--sidebar-border-color);
border-left: none;
border-right: solid 1px var(--sidebar-resizer-shadow);
border-bottom: solid 1px var(--sidebar-resizer-shadow);
width: 8px;
height: 24px;
image-rendering: crisp-edges;
}

.rustdoc.src .sidebar-resizer {
Expand All @@ -543,7 +574,7 @@ img {
}

.sidebar-resizing * {
cursor: col-resize !important;
cursor: ew-resize !important;
}

.sidebar-resizing .sidebar {
Expand All @@ -561,7 +592,7 @@ img {
margin: 0;
/* when active or hovered, place resizer glow on top of the sidebar (right next to, or even
on top of, the scrollbar) */
left: var(--desktop-sidebar-width);
left: calc(var(--desktop-sidebar-width) - 1px);
border-left: solid 1px var(--sidebar-resizer-hover);
}

Expand All @@ -578,6 +609,10 @@ img {
/* too easy to hit the resizer while trying to hit the [-] toggle */
display: none !important;
}
.sidebar {
/* resize indicator: hide this when on touch or mobile */
border-right: none;
}
}

.sidebar-resizer.active {
Expand Down Expand Up @@ -2509,6 +2544,8 @@ in src-script.js and main.js
/* Reduce height slightly to account for mobile topbar. */
height: calc(100vh - 45px);
width: 200px;
/* resize indicator: hide this when on touch or mobile */
border-right: none;
}

/* The source view uses a different design for the sidebar toggle, and doesn't have a topbar,
Expand Down Expand Up @@ -2897,6 +2934,7 @@ by default.
--settings-button-border-focus: #717171;
--sidebar-background-color: #f5f5f5;
--sidebar-background-color-hover: #e0e0e0;
--sidebar-border-color: #ddd;
--code-block-background-color: #f5f5f5;
--scrollbar-track-background-color: #dcdcdc;
--scrollbar-thumb-background-color: rgba(36, 37, 39, 0.6);
Expand Down Expand Up @@ -2989,6 +3027,7 @@ by default.
--scrape-example-code-wrapper-background-end: rgba(255, 255, 255, 0);
--sidebar-resizer-hover: hsl(207, 90%, 66%);
--sidebar-resizer-active: hsl(207, 90%, 54%);
--sidebar-resizer-shadow: #ccc;
}
/* End theme: light */

Expand All @@ -3002,6 +3041,7 @@ by default.
--settings-button-border-focus: #ffb900;
--sidebar-background-color: #505050;
--sidebar-background-color-hover: #676767;
--sidebar-border-color: #999;
--code-block-background-color: #2A2A2A;
--scrollbar-track-background-color: #717171;
--scrollbar-thumb-background-color: rgba(32, 34, 37, .6);
Expand Down Expand Up @@ -3097,6 +3137,7 @@ by default.
--scrape-example-code-wrapper-background-end: rgba(53, 53, 53, 0);
--sidebar-resizer-hover: hsl(207, 30%, 54%);
--sidebar-resizer-active: hsl(207, 90%, 54%);
--sidebar-resizer-shadow: #000;
}
/* End theme: dark */

Expand All @@ -3114,6 +3155,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
--settings-button-border-focus: #e0e0e0;
--sidebar-background-color: #14191f;
--sidebar-background-color-hover: rgba(70, 70, 70, 0.33);
--sidebar-border-color: #5c6773;
--code-block-background-color: #191f26;
--scrollbar-track-background-color: transparent;
--scrollbar-thumb-background-color: #5c6773;
Expand Down Expand Up @@ -3209,6 +3251,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
--scrape-example-code-wrapper-background-end: rgba(15, 20, 25, 0);
--sidebar-resizer-hover: hsl(34, 50%, 33%);
--sidebar-resizer-active: hsl(34, 100%, 66%);
--sidebar-resizer-shadow: #000;
}

:root[data-theme="ayu"] h1,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ <h2>Files</h2> {# #}
{% endif %}
{{ sidebar|safe }}
</nav> {# #}
<div class="sidebar-resizer"></div> {# #}
<div class="sidebar-resizer" title="Drag to resize sidebar"></div> {# #}
<main>
{% if page.css_class != "src" %}<div class="width-limiter">{% endif %}
{# defined in storage.js to avoid duplicating complex UI across every page #}
Expand Down
25 changes: 22 additions & 3 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ extern crate tikv_jemalloc_sys as jemalloc_sys;

use std::env::{self, VarError};
use std::io::{self, IsTerminal};
use std::path::Path;
use std::process;

use rustc_errors::DiagCtxtHandle;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_interface::interface;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{ErrorOutputType, RustcOptGroup, make_crate_type_option};
Expand Down Expand Up @@ -654,9 +656,9 @@ fn opts() -> Vec<RustcOptGroup> {
Unstable,
Multi,
"",
"doctest-compilation-args",
"",
"add arguments to be used when compiling doctests",
"doctest-build-arg",
"One argument (of possibly many) to be used when compiling doctests",
"ARG",
),
opt(
Unstable,
Expand Down Expand Up @@ -904,6 +906,10 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
rustc_interface::passes::write_dep_info(tcx);
}

if let Some(metrics_dir) = &sess.opts.unstable_opts.metrics_dir {
dump_feature_usage_metrics(tcx, metrics_dir);
}

if run_check {
// Since we're in "check" mode, no need to generate anything beyond this point.
return;
Expand All @@ -923,3 +929,16 @@ fn main_args(early_dcx: &mut EarlyDiagCtxt, at_args: &[String]) {
})
})
}

fn dump_feature_usage_metrics(tcxt: TyCtxt<'_>, metrics_dir: &Path) {
let hash = tcxt.crate_hash(LOCAL_CRATE);
let crate_name = tcxt.crate_name(LOCAL_CRATE);
let metrics_file_name = format!("unstable_feature_usage_metrics-{crate_name}-{hash}.json");
let metrics_path = metrics_dir.join(metrics_file_name);
if let Err(error) = tcxt.features().dump_feature_usage_metrics(metrics_path) {
// FIXME(yaahc): once metrics can be enabled by default we will want "failure to emit
// default metrics" to only produce a warning when metrics are enabled by default and emit
// an error only when the user manually enables metrics
tcxt.dcx().err(format!("cannot emit feature usage metrics: {error}"));
}
}
Loading