Skip to content

Commit 371100b

Browse files
committed
Auto merge of #104017 - matthiaskrgr:rollup-k8i0j9m, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #101702 (rustdoc: add hash to filename of toolchain files) - #103920 (Move browser opening logic in `Builder`) - #103927 (Do not make typo suggestions when suggesting pattern matching) - #103972 (Remove an option and choose a behaviour-preserving default instead.) - #103988 (Fix search result bottom border color) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6b8d9dd + e51e4a4 commit 371100b

File tree

28 files changed

+372
-553
lines changed

28 files changed

+372
-553
lines changed

Diff for: compiler/rustc_hir_analysis/src/astconv/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
274274
item_segment.args(),
275275
item_segment.infer_args,
276276
None,
277-
None,
277+
ty::BoundConstness::NotConst,
278278
);
279279
if let Some(b) = item_segment.args().bindings.first() {
280280
Self::prohibit_assoc_ty_binding(self.tcx(), b.span);
@@ -324,7 +324,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
324324
generic_args: &'a hir::GenericArgs<'_>,
325325
infer_args: bool,
326326
self_ty: Option<Ty<'tcx>>,
327-
constness: Option<ty::BoundConstness>,
327+
constness: ty::BoundConstness,
328328
) -> (SubstsRef<'tcx>, GenericArgCountResult) {
329329
// If the type is parameterized by this region, then replace this
330330
// region with the current anon region binding (in other words,
@@ -538,7 +538,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
538538
&mut substs_ctx,
539539
);
540540

541-
if let Some(ty::BoundConstness::ConstIfConst) = constness
541+
if let ty::BoundConstness::ConstIfConst = constness
542542
&& generics.has_self && !tcx.has_attr(def_id, sym::const_trait)
543543
{
544544
tcx.sess.emit_err(crate::errors::ConstBoundForNonConstTrait { span } );
@@ -611,7 +611,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
611611
item_segment.args(),
612612
item_segment.infer_args,
613613
None,
614-
None,
614+
ty::BoundConstness::NotConst,
615615
);
616616

617617
if let Some(b) = item_segment.args().bindings.first() {
@@ -641,7 +641,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
641641
self_ty,
642642
trait_ref.path.segments.last().unwrap(),
643643
true,
644-
Some(constness),
644+
constness,
645645
)
646646
}
647647

@@ -668,7 +668,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
668668
args,
669669
infer_args,
670670
Some(self_ty),
671-
Some(constness),
671+
constness,
672672
);
673673

674674
let tcx = self.tcx();
@@ -798,7 +798,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
798798
self_ty: Ty<'tcx>,
799799
trait_segment: &hir::PathSegment<'_>,
800800
is_impl: bool,
801-
constness: Option<ty::BoundConstness>,
801+
constness: ty::BoundConstness,
802802
) -> ty::TraitRef<'tcx> {
803803
let (substs, _) = self.create_substs_for_ast_trait_ref(
804804
span,
@@ -822,7 +822,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
822822
self_ty: Ty<'tcx>,
823823
trait_segment: &'a hir::PathSegment<'a>,
824824
is_impl: bool,
825-
constness: Option<ty::BoundConstness>,
825+
constness: ty::BoundConstness,
826826
) -> (SubstsRef<'tcx>, GenericArgCountResult) {
827827
self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, is_impl);
828828

@@ -2129,7 +2129,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21292129
self_ty,
21302130
trait_segment,
21312131
false,
2132-
Some(constness),
2132+
constness,
21332133
);
21342134

21352135
let item_substs = self.create_substs_for_associated_item(
@@ -2700,7 +2700,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27002700
&GenericArgs::none(),
27012701
true,
27022702
None,
2703-
None,
2703+
ty::BoundConstness::NotConst,
27042704
);
27052705
EarlyBinder(self.normalize_ty(span, tcx.at(span).type_of(def_id)))
27062706
.subst(tcx, substs)

Diff for: compiler/rustc_resolve/src/late/diagnostics.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,12 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
322322
}
323323

324324
self.suggest_bare_struct_literal(&mut err);
325-
self.suggest_pattern_match_with_let(&mut err, source, span);
325+
326+
if self.suggest_pattern_match_with_let(&mut err, source, span) {
327+
// Fallback label.
328+
err.span_label(base_error.span, &base_error.fallback_label);
329+
return (err, Vec::new());
330+
}
326331

327332
self.suggest_self_or_self_ref(&mut err, path, span);
328333
self.detect_assoct_type_constraint_meant_as_path(&mut err, &base_error);
@@ -341,7 +346,11 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
341346
if !self.type_ascription_suggestion(&mut err, base_error.span) {
342347
let mut fallback =
343348
self.suggest_trait_and_bounds(&mut err, source, res, span, &base_error);
349+
350+
// if we have suggested using pattern matching, then don't add needless suggestions
351+
// for typos.
344352
fallback |= self.suggest_typo(&mut err, source, path, span, &base_error);
353+
345354
if fallback {
346355
// Fallback label.
347356
err.span_label(base_error.span, &base_error.fallback_label);
@@ -937,7 +946,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
937946
err: &mut Diagnostic,
938947
source: PathSource<'_>,
939948
span: Span,
940-
) {
949+
) -> bool {
941950
if let PathSource::Expr(_) = source &&
942951
let Some(Expr {
943952
span: expr_span,
@@ -954,8 +963,10 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
954963
"let ",
955964
Applicability::MaybeIncorrect,
956965
);
966+
return true;
957967
}
958968
}
969+
false
959970
}
960971

961972
fn get_single_associated_item(

Diff for: src/bootstrap/builder.rs

+18
Original file line numberDiff line numberDiff line change
@@ -2207,6 +2207,24 @@ impl<'a> Builder<'a> {
22072207

22082208
false
22092209
}
2210+
2211+
pub(crate) fn maybe_open_in_browser<S: Step>(&self, path: impl AsRef<Path>) {
2212+
if self.was_invoked_explicitly::<S>(Kind::Doc) {
2213+
self.open_in_browser(path);
2214+
}
2215+
}
2216+
2217+
pub(crate) fn open_in_browser(&self, path: impl AsRef<Path>) {
2218+
if self.config.dry_run || !self.config.cmd.open() {
2219+
return;
2220+
}
2221+
2222+
let path = path.as_ref();
2223+
self.info(&format!("Opening doc {}", path.display()));
2224+
if let Err(err) = opener::open(path) {
2225+
self.info(&format!("{}\n", err));
2226+
}
2227+
}
22102228
}
22112229

22122230
#[cfg(test)]

Diff for: src/bootstrap/doc.rs

+10-25
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,6 @@ book!(
8585
StyleGuide, "src/doc/style-guide", "style-guide";
8686
);
8787

88-
fn open(builder: &Builder<'_>, path: impl AsRef<Path>) {
89-
if builder.config.dry_run || !builder.config.cmd.open() {
90-
return;
91-
}
92-
93-
let path = path.as_ref();
94-
builder.info(&format!("Opening doc {}", path.display()));
95-
if let Err(err) = opener::open(path) {
96-
builder.info(&format!("{}\n", err));
97-
}
98-
}
99-
10088
// "library/std" -> ["library", "std"]
10189
//
10290
// Used for deciding whether a particular step is one requested by the user on
@@ -240,11 +228,9 @@ impl Step for TheBook {
240228
invoke_rustdoc(builder, compiler, &shared_assets, target, path);
241229
}
242230

243-
if builder.was_invoked_explicitly::<Self>(Kind::Doc) {
244-
let out = builder.doc_out(target);
245-
let index = out.join("book").join("index.html");
246-
open(builder, &index);
247-
}
231+
let out = builder.doc_out(target);
232+
let index = out.join("book").join("index.html");
233+
builder.maybe_open_in_browser::<Self>(index);
248234
}
249235
}
250236

@@ -386,7 +372,7 @@ impl Step for Standalone {
386372
// with no particular explicit doc requested (e.g. library/core).
387373
if builder.paths.is_empty() || builder.was_invoked_explicitly::<Self>(Kind::Doc) {
388374
let index = out.join("index.html");
389-
open(builder, &index);
375+
builder.open_in_browser(&index);
390376
}
391377
}
392378
}
@@ -507,7 +493,7 @@ impl Step for Std {
507493
for requested_crate in requested_crates {
508494
if STD_PUBLIC_CRATES.iter().any(|k| *k == requested_crate.as_str()) {
509495
let index = out.join(requested_crate).join("index.html");
510-
open(builder, &index);
496+
builder.open_in_browser(index);
511497
}
512498
}
513499
}
@@ -759,7 +745,7 @@ impl Step for Rustc {
759745
// Let's open the first crate documentation page:
760746
if let Some(krate) = to_open {
761747
let index = out.join(krate).join("index.html");
762-
open(builder, &index);
748+
builder.open_in_browser(index);
763749
}
764750
}
765751
}
@@ -1019,10 +1005,9 @@ impl Step for RustcBook {
10191005
name: INTERNER.intern_str("rustc"),
10201006
src: INTERNER.intern_path(out_base),
10211007
});
1022-
if builder.was_invoked_explicitly::<Self>(Kind::Doc) {
1023-
let out = builder.doc_out(self.target);
1024-
let index = out.join("rustc").join("index.html");
1025-
open(builder, &index);
1026-
}
1008+
1009+
let out = builder.doc_out(self.target);
1010+
let index = out.join("rustc").join("index.html");
1011+
builder.maybe_open_in_browser::<Self>(index);
10271012
}
10281013
}

Diff for: src/librustdoc/config.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,6 @@ pub(crate) struct RenderOptions {
239239
pub(crate) default_settings: FxHashMap<String, String>,
240240
/// If present, suffix added to CSS/JavaScript files when referencing them in generated pages.
241241
pub(crate) resource_suffix: String,
242-
/// Whether to run the static CSS/JavaScript through a minifier when outputting them. `true` by
243-
/// default.
244-
pub(crate) enable_minification: bool,
245242
/// Whether to create an index page in the root of the output directory. If this is true but
246243
/// `enable_index_page` is None, generate a static listing of crates instead.
247244
pub(crate) enable_index_page: bool,
@@ -416,7 +413,9 @@ impl Options {
416413

417414
let to_check = matches.opt_strs("check-theme");
418415
if !to_check.is_empty() {
419-
let paths = match theme::load_css_paths(static_files::themes::LIGHT) {
416+
let paths = match theme::load_css_paths(
417+
std::str::from_utf8(static_files::STATIC_FILES.theme_light_css.bytes).unwrap(),
418+
) {
420419
Ok(p) => p,
421420
Err(e) => {
422421
diag.struct_err(&e.to_string()).emit();
@@ -557,7 +556,9 @@ impl Options {
557556

558557
let mut themes = Vec::new();
559558
if matches.opt_present("theme") {
560-
let paths = match theme::load_css_paths(static_files::themes::LIGHT) {
559+
let paths = match theme::load_css_paths(
560+
std::str::from_utf8(static_files::STATIC_FILES.theme_light_css.bytes).unwrap(),
561+
) {
561562
Ok(p) => p,
562563
Err(e) => {
563564
diag.struct_err(&e.to_string()).emit();
@@ -675,7 +676,6 @@ impl Options {
675676
ModuleSorting::Alphabetical
676677
};
677678
let resource_suffix = matches.opt_str("resource-suffix").unwrap_or_default();
678-
let enable_minification = !matches.opt_present("disable-minification");
679679
let markdown_no_toc = matches.opt_present("markdown-no-toc");
680680
let markdown_css = matches.opt_strs("markdown-css");
681681
let markdown_playground_url = matches.opt_str("markdown-playground-url");
@@ -768,7 +768,6 @@ impl Options {
768768
extern_html_root_takes_precedence,
769769
default_settings,
770770
resource_suffix,
771-
enable_minification,
772771
enable_index_page,
773772
index_page,
774773
static_root_path,

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

+14-9
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ use std::path::PathBuf;
22

33
use rustc_data_structures::fx::FxHashMap;
44

5-
use crate::error::Error;
65
use crate::externalfiles::ExternalHtml;
76
use crate::html::format::{Buffer, Print};
87
use crate::html::render::{ensure_trailing_slash, StylePath};
98

109
use askama::Template;
1110

11+
use super::static_files::{StaticFiles, STATIC_FILES};
12+
1213
#[derive(Clone)]
1314
pub(crate) struct Layout {
1415
pub(crate) logo: String,
@@ -34,17 +35,23 @@ pub(crate) struct Page<'a> {
3435
}
3536

3637
impl<'a> Page<'a> {
37-
pub(crate) fn get_static_root_path(&self) -> &str {
38-
self.static_root_path.unwrap_or(self.root_path)
38+
pub(crate) fn get_static_root_path(&self) -> String {
39+
match self.static_root_path {
40+
Some(s) => s.to_string(),
41+
None => format!("{}static.files/", self.root_path),
42+
}
3943
}
4044
}
4145

4246
#[derive(Template)]
4347
#[template(path = "page.html")]
4448
struct PageLayout<'a> {
45-
static_root_path: &'a str,
49+
static_root_path: String,
4650
page: &'a Page<'a>,
4751
layout: &'a Layout,
52+
53+
files: &'static StaticFiles,
54+
4855
themes: Vec<String>,
4956
sidebar: String,
5057
content: String,
@@ -61,19 +68,17 @@ pub(crate) fn render<T: Print, S: Print>(
6168
) -> String {
6269
let static_root_path = page.get_static_root_path();
6370
let krate_with_trailing_slash = ensure_trailing_slash(&layout.krate).to_string();
64-
let mut themes: Vec<String> = style_files
65-
.iter()
66-
.map(StylePath::basename)
67-
.collect::<Result<_, Error>>()
68-
.unwrap_or_default();
71+
let mut themes: Vec<String> = style_files.iter().map(|s| s.basename().unwrap()).collect();
6972
themes.sort();
73+
7074
let rustdoc_version = rustc_interface::util::version_str().unwrap_or("unknown version");
7175
let content = Buffer::html().to_display(t); // Note: This must happen before making the sidebar.
7276
let sidebar = Buffer::html().to_display(sidebar);
7377
PageLayout {
7478
static_root_path,
7579
page,
7680
layout,
81+
files: &STATIC_FILES,
7782
themes,
7883
sidebar,
7984
content,

0 commit comments

Comments
 (0)