Skip to content

Commit 686e313

Browse files
committed
Auto merge of #91288 - matthiaskrgr:rollup-yp5h41r, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #83791 (Weaken guarantee around advancing underlying iterators in zip) - #90995 (Document non-guarantees for Hash) - #91057 (Expand `available_parallelism` docs in anticipation of cgroup quota support) - #91062 (rustdoc: Consolidate static-file replacement mechanism) - #91208 (Account for incorrect `where T::Assoc = Ty` bound) - #91266 (Use non-generic inner function for pointer formatting) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5fd3a5c + 073b120 commit 686e313

File tree

22 files changed

+307
-161
lines changed

22 files changed

+307
-161
lines changed

Diff for: compiler/rustc_ast_passes/src/ast_validation.rs

+48-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_span::symbol::{kw, sym, Ident};
2323
use rustc_span::Span;
2424
use rustc_target::spec::abi;
2525
use std::mem;
26-
use std::ops::DerefMut;
26+
use std::ops::{Deref, DerefMut};
2727

2828
const MORE_EXTERN: &str =
2929
"for more information, visit https://doc.rust-lang.org/std/keyword.extern.html";
@@ -1714,6 +1714,53 @@ fn deny_equality_constraints(
17141714
}
17151715
}
17161716
}
1717+
// Given `A: Foo, A::Bar = RhsTy`, suggest `A: Foo<Bar = RhsTy>`.
1718+
if let TyKind::Path(None, full_path) = &predicate.lhs_ty.kind {
1719+
if let [potential_param, potential_assoc] = &full_path.segments[..] {
1720+
for param in &generics.params {
1721+
if param.ident == potential_param.ident {
1722+
for bound in &param.bounds {
1723+
if let ast::GenericBound::Trait(trait_ref, TraitBoundModifier::None) = bound
1724+
{
1725+
if let [trait_segment] = &trait_ref.trait_ref.path.segments[..] {
1726+
let assoc = pprust::path_to_string(&ast::Path::from_ident(
1727+
potential_assoc.ident,
1728+
));
1729+
let ty = pprust::ty_to_string(&predicate.rhs_ty);
1730+
let (args, span) = match &trait_segment.args {
1731+
Some(args) => match args.deref() {
1732+
ast::GenericArgs::AngleBracketed(args) => {
1733+
let Some(arg) = args.args.last() else {
1734+
continue;
1735+
};
1736+
(
1737+
format!(", {} = {}", assoc, ty),
1738+
arg.span().shrink_to_hi(),
1739+
)
1740+
}
1741+
_ => continue,
1742+
},
1743+
None => (
1744+
format!("<{} = {}>", assoc, ty),
1745+
trait_segment.span().shrink_to_hi(),
1746+
),
1747+
};
1748+
err.multipart_suggestion(
1749+
&format!(
1750+
"if `{}::{}` is an associated type you're trying to set, \
1751+
use the associated type binding syntax",
1752+
trait_segment.ident, potential_assoc.ident,
1753+
),
1754+
vec![(span, args), (predicate.span, String::new())],
1755+
Applicability::MaybeIncorrect,
1756+
);
1757+
}
1758+
}
1759+
}
1760+
}
1761+
}
1762+
}
1763+
}
17171764
err.note(
17181765
"see issue #20041 <https://github.com/rust-lang/rust/issues/20041> for more information",
17191766
);

Diff for: compiler/rustc_ast_passes/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
#![feature(iter_is_partitioned)]
88
#![feature(box_patterns)]
9+
#![feature(let_else)]
910
#![recursion_limit = "256"]
1011

1112
pub mod ast_validation;

Diff for: library/core/src/fmt/mod.rs

+24-18
Original file line numberDiff line numberDiff line change
@@ -2186,28 +2186,34 @@ impl Display for char {
21862186
#[stable(feature = "rust1", since = "1.0.0")]
21872187
impl<T: ?Sized> Pointer for *const T {
21882188
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
2189-
let old_width = f.width;
2190-
let old_flags = f.flags;
2191-
2192-
// The alternate flag is already treated by LowerHex as being special-
2193-
// it denotes whether to prefix with 0x. We use it to work out whether
2194-
// or not to zero extend, and then unconditionally set it to get the
2195-
// prefix.
2196-
if f.alternate() {
2197-
f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32);
2198-
2199-
if f.width.is_none() {
2200-
f.width = Some((usize::BITS / 4) as usize + 2);
2189+
/// Since the formatting will be identical for all pointer types, use a non-monomorphized
2190+
/// implementation for the actual formatting to reduce the amount of codegen work needed
2191+
fn inner(ptr: *const (), f: &mut Formatter<'_>) -> Result {
2192+
let old_width = f.width;
2193+
let old_flags = f.flags;
2194+
2195+
// The alternate flag is already treated by LowerHex as being special-
2196+
// it denotes whether to prefix with 0x. We use it to work out whether
2197+
// or not to zero extend, and then unconditionally set it to get the
2198+
// prefix.
2199+
if f.alternate() {
2200+
f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32);
2201+
2202+
if f.width.is_none() {
2203+
f.width = Some((usize::BITS / 4) as usize + 2);
2204+
}
22012205
}
2202-
}
2203-
f.flags |= 1 << (FlagV1::Alternate as u32);
2206+
f.flags |= 1 << (FlagV1::Alternate as u32);
2207+
2208+
let ret = LowerHex::fmt(&(ptr as usize), f);
22042209

2205-
let ret = LowerHex::fmt(&(*self as *const () as usize), f);
2210+
f.width = old_width;
2211+
f.flags = old_flags;
22062212

2207-
f.width = old_width;
2208-
f.flags = old_flags;
2213+
ret
2214+
}
22092215

2210-
ret
2216+
inner(*self as *const (), f)
22112217
}
22122218
}
22132219

Diff for: library/core/src/hash/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ mod sip;
164164
/// `0xFF` byte to the `Hasher` so that the values `("ab", "c")` and `("a",
165165
/// "bc")` hash differently.
166166
///
167+
/// ## Portability
168+
///
169+
/// Due to differences in endianness and type sizes, data fed by `Hash` to a `Hasher`
170+
/// should not be considered portable across platforms. Additionally the data passed by most
171+
/// standard library types should not be considered stable between compiler versions.
172+
///
173+
/// This means tests shouldn't probe hard-coded hash values or data fed to a `Hasher` and
174+
/// instead should check consistency with `Eq`.
175+
///
176+
/// Serialization formats intended to be portable between platforms or compiler versions should
177+
/// either avoid encoding hashes or only rely on `Hash` and `Hasher` implementations that
178+
/// provide additional guarantees.
179+
///
167180
/// [`HashMap`]: ../../std/collections/struct.HashMap.html
168181
/// [`HashSet`]: ../../std/collections/struct.HashSet.html
169182
/// [`hash`]: Hash::hash

Diff for: library/core/src/iter/traits/iterator.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,10 @@ pub trait Iterator {
458458
/// In other words, it zips two iterators together, into a single one.
459459
///
460460
/// If either iterator returns [`None`], [`next`] from the zipped iterator
461-
/// will return [`None`]. If the first iterator returns [`None`], `zip` will
462-
/// short-circuit and `next` will not be called on the second iterator.
461+
/// will return [`None`].
462+
/// If the zipped iterator has no more elements to return then each further attempt to advance
463+
/// it will first try to advance the first iterator at most one time and if it still yielded an item
464+
/// try to advance the second iterator at most one time.
463465
///
464466
/// # Examples
465467
///

Diff for: library/std/src/thread/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1460,9 +1460,12 @@ fn _assert_sync_and_send() {
14601460
/// The purpose of this API is to provide an easy and portable way to query
14611461
/// the default amount of parallelism the program should use. Among other things it
14621462
/// does not expose information on NUMA regions, does not account for
1463-
/// differences in (co)processor capabilities, and will not modify the program's
1464-
/// global state in order to more accurately query the amount of available
1465-
/// parallelism.
1463+
/// differences in (co)processor capabilities or current system load,
1464+
/// and will not modify the program's global state in order to more accurately
1465+
/// query the amount of available parallelism.
1466+
///
1467+
/// Where both fixed steady-state and burst limits are available the steady-state
1468+
/// capacity will be used to ensure more predictable latencies.
14661469
///
14671470
/// Resource limits can be changed during the runtime of a program, therefore the value is
14681471
/// not cached and instead recomputed every time this function is called. It should not be

Diff for: src/librustdoc/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ impl Options {
552552
))
553553
.emit();
554554
}
555-
themes.push(StylePath { path: theme_file, disabled: true });
555+
themes.push(StylePath { path: theme_file });
556556
}
557557
}
558558

Diff for: src/librustdoc/error.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ macro_rules! try_none {
3939
match $e {
4040
Some(e) => e,
4141
None => {
42-
return Err(Error::new(io::Error::new(io::ErrorKind::Other, "not found"), $file));
42+
return Err(<crate::error::Error as crate::docfs::PathError>::new(
43+
io::Error::new(io::ErrorKind::Other, "not found"),
44+
$file,
45+
));
4346
}
4447
}
4548
}};

Diff for: src/librustdoc/html/layout.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::path::PathBuf;
22

33
use rustc_data_structures::fx::FxHashMap;
44

5+
use crate::error::Error;
56
use crate::externalfiles::ExternalHtml;
6-
use crate::html::escape::Escape;
77
use crate::html::format::{Buffer, Print};
88
use crate::html::render::{ensure_trailing_slash, StylePath};
99

@@ -50,10 +50,11 @@ struct PageLayout<'a> {
5050
static_root_path: &'a str,
5151
page: &'a Page<'a>,
5252
layout: &'a Layout,
53-
style_files: String,
53+
themes: Vec<String>,
5454
sidebar: String,
5555
content: String,
5656
krate_with_trailing_slash: String,
57+
crate rustdoc_version: &'a str,
5758
}
5859

5960
crate fn render<T: Print, S: Print>(
@@ -66,29 +67,24 @@ crate fn render<T: Print, S: Print>(
6667
) -> String {
6768
let static_root_path = page.get_static_root_path();
6869
let krate_with_trailing_slash = ensure_trailing_slash(&layout.krate).to_string();
69-
let style_files = style_files
70+
let mut themes: Vec<String> = style_files
7071
.iter()
71-
.filter_map(|t| t.path.file_stem().map(|stem| (stem, t.disabled)))
72-
.filter_map(|t| t.0.to_str().map(|path| (path, t.1)))
73-
.map(|t| {
74-
format!(
75-
r#"<link rel="stylesheet" type="text/css" href="{}.css" {} {}>"#,
76-
Escape(&format!("{}{}{}", static_root_path, t.0, page.resource_suffix)),
77-
if t.1 { "disabled" } else { "" },
78-
if t.0 == "light" { "id=\"themeStyle\"" } else { "" }
79-
)
80-
})
81-
.collect::<String>();
72+
.map(StylePath::basename)
73+
.collect::<Result<_, Error>>()
74+
.unwrap_or_default();
75+
themes.sort();
76+
let rustdoc_version = rustc_interface::util::version_str().unwrap_or("unknown version");
8277
let content = Buffer::html().to_display(t); // Note: This must happen before making the sidebar.
8378
let sidebar = Buffer::html().to_display(sidebar);
8479
let teractx = tera::Context::from_serialize(PageLayout {
8580
static_root_path,
8681
page,
8782
layout,
88-
style_files,
83+
themes,
8984
sidebar,
9085
content,
9186
krate_with_trailing_slash,
87+
rustdoc_version,
9288
})
9389
.unwrap();
9490
templates.render("page.html", &teractx).unwrap()

Diff for: src/librustdoc/html/render/context.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,9 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
504504
// by the browser as the theme stylesheet. The theme system (hackily) works by
505505
// changing the href to this stylesheet. All other themes are disabled to
506506
// prevent rule conflicts
507-
scx.style_files.push(StylePath { path: PathBuf::from("light.css"), disabled: false });
508-
scx.style_files.push(StylePath { path: PathBuf::from("dark.css"), disabled: true });
509-
scx.style_files.push(StylePath { path: PathBuf::from("ayu.css"), disabled: true });
507+
scx.style_files.push(StylePath { path: PathBuf::from("light.css") });
508+
scx.style_files.push(StylePath { path: PathBuf::from("dark.css") });
509+
scx.style_files.push(StylePath { path: PathBuf::from("ayu.css") });
510510

511511
let dst = output;
512512
scx.ensure_dir(&dst)?;
@@ -596,9 +596,13 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
596596
page.description = "Settings of Rustdoc";
597597
page.root_path = "./";
598598

599-
let mut style_files = self.shared.style_files.clone();
600599
let sidebar = "<h2 class=\"location\">Settings</h2><div class=\"sidebar-elems\"></div>";
601-
style_files.push(StylePath { path: PathBuf::from("settings.css"), disabled: false });
600+
let theme_names: Vec<String> = self
601+
.shared
602+
.style_files
603+
.iter()
604+
.map(StylePath::basename)
605+
.collect::<Result<_, Error>>()?;
602606
let v = layout::render(
603607
&self.shared.templates,
604608
&self.shared.layout,
@@ -607,9 +611,9 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
607611
settings(
608612
self.shared.static_root_path.as_deref().unwrap_or("./"),
609613
&self.shared.resource_suffix,
610-
&self.shared.style_files,
614+
theme_names,
611615
)?,
612-
&style_files,
616+
&self.shared.style_files,
613617
);
614618
self.shared.fs.write(settings_file, v)?;
615619
if let Some(ref redirections) = self.shared.redirections {

Diff for: src/librustdoc/html/render/mod.rs

+15-23
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ use serde::ser::SerializeSeq;
6464
use serde::{Serialize, Serializer};
6565

6666
use crate::clean::{self, ItemId, RenderedLink, SelfTy};
67-
use crate::docfs::PathError;
6867
use crate::error::Error;
6968
use crate::formats::cache::Cache;
7069
use crate::formats::item_type::ItemType;
@@ -173,8 +172,12 @@ impl Serialize for TypeWithKind {
173172
crate struct StylePath {
174173
/// The path to the theme
175174
crate path: PathBuf,
176-
/// What the `disabled` attribute should be set to in the HTML tag
177-
crate disabled: bool,
175+
}
176+
177+
impl StylePath {
178+
pub fn basename(&self) -> Result<String, Error> {
179+
Ok(try_none!(try_none!(self.path.file_stem(), &self.path).to_str(), &self.path).to_string())
180+
}
178181
}
179182

180183
fn write_srclink(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer) {
@@ -353,7 +356,7 @@ enum Setting {
353356
js_data_name: &'static str,
354357
description: &'static str,
355358
default_value: &'static str,
356-
options: Vec<(String, String)>,
359+
options: Vec<String>,
357360
},
358361
}
359362

@@ -393,10 +396,9 @@ impl Setting {
393396
options
394397
.iter()
395398
.map(|opt| format!(
396-
"<option value=\"{}\" {}>{}</option>",
397-
opt.0,
398-
if opt.0 == default_value { "selected" } else { "" },
399-
opt.1,
399+
"<option value=\"{name}\" {}>{name}</option>",
400+
if opt == default_value { "selected" } else { "" },
401+
name = opt,
400402
))
401403
.collect::<String>(),
402404
root_path,
@@ -421,18 +423,7 @@ impl<T: Into<Setting>> From<(&'static str, Vec<T>)> for Setting {
421423
}
422424
}
423425

424-
fn settings(root_path: &str, suffix: &str, themes: &[StylePath]) -> Result<String, Error> {
425-
let theme_names: Vec<(String, String)> = themes
426-
.iter()
427-
.map(|entry| {
428-
let theme =
429-
try_none!(try_none!(entry.path.file_stem(), &entry.path).to_str(), &entry.path)
430-
.to_string();
431-
432-
Ok((theme.clone(), theme))
433-
})
434-
.collect::<Result<_, Error>>()?;
435-
426+
fn settings(root_path: &str, suffix: &str, theme_names: Vec<String>) -> Result<String, Error> {
436427
// (id, explanation, default value)
437428
let settings: &[Setting] = &[
438429
(
@@ -469,10 +460,11 @@ fn settings(root_path: &str, suffix: &str, themes: &[StylePath]) -> Result<Strin
469460
<span class=\"in-band\">Rustdoc settings</span>\
470461
</h1>\
471462
<div class=\"settings\">{}</div>\
472-
<script src=\"{}settings{}.js\"></script>",
463+
<link rel=\"stylesheet\" href=\"{root_path}settings{suffix}.css\">\
464+
<script src=\"{root_path}settings{suffix}.js\"></script>",
473465
settings.iter().map(|s| s.display(root_path, suffix)).collect::<String>(),
474-
root_path,
475-
suffix
466+
root_path = root_path,
467+
suffix = suffix
476468
))
477469
}
478470

0 commit comments

Comments
 (0)