Skip to content

Rollup of 5 pull requests #104017

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 15 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 10 additions & 10 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
item_segment.args(),
item_segment.infer_args,
None,
None,
ty::BoundConstness::NotConst,
);
if let Some(b) = item_segment.args().bindings.first() {
Self::prohibit_assoc_ty_binding(self.tcx(), b.span);
Expand Down Expand Up @@ -324,7 +324,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
generic_args: &'a hir::GenericArgs<'_>,
infer_args: bool,
self_ty: Option<Ty<'tcx>>,
constness: Option<ty::BoundConstness>,
constness: ty::BoundConstness,
) -> (SubstsRef<'tcx>, GenericArgCountResult) {
// If the type is parameterized by this region, then replace this
// region with the current anon region binding (in other words,
Expand Down Expand Up @@ -538,7 +538,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&mut substs_ctx,
);

if let Some(ty::BoundConstness::ConstIfConst) = constness
if let ty::BoundConstness::ConstIfConst = constness
&& generics.has_self && !tcx.has_attr(def_id, sym::const_trait)
{
tcx.sess.emit_err(crate::errors::ConstBoundForNonConstTrait { span } );
Expand Down Expand Up @@ -611,7 +611,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
item_segment.args(),
item_segment.infer_args,
None,
None,
ty::BoundConstness::NotConst,
);

if let Some(b) = item_segment.args().bindings.first() {
Expand Down Expand Up @@ -641,7 +641,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self_ty,
trait_ref.path.segments.last().unwrap(),
true,
Some(constness),
constness,
)
}

Expand All @@ -668,7 +668,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
args,
infer_args,
Some(self_ty),
Some(constness),
constness,
);

let tcx = self.tcx();
Expand Down Expand Up @@ -798,7 +798,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self_ty: Ty<'tcx>,
trait_segment: &hir::PathSegment<'_>,
is_impl: bool,
constness: Option<ty::BoundConstness>,
constness: ty::BoundConstness,
) -> ty::TraitRef<'tcx> {
let (substs, _) = self.create_substs_for_ast_trait_ref(
span,
Expand All @@ -822,7 +822,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self_ty: Ty<'tcx>,
trait_segment: &'a hir::PathSegment<'a>,
is_impl: bool,
constness: Option<ty::BoundConstness>,
constness: ty::BoundConstness,
) -> (SubstsRef<'tcx>, GenericArgCountResult) {
self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, is_impl);

Expand Down Expand Up @@ -2129,7 +2129,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self_ty,
trait_segment,
false,
Some(constness),
constness,
);

let item_substs = self.create_substs_for_associated_item(
Expand Down Expand Up @@ -2700,7 +2700,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&GenericArgs::none(),
true,
None,
None,
ty::BoundConstness::NotConst,
);
EarlyBinder(self.normalize_ty(span, tcx.at(span).type_of(def_id)))
.subst(tcx, substs)
Expand Down
15 changes: 13 additions & 2 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,12 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
}

self.suggest_bare_struct_literal(&mut err);
self.suggest_pattern_match_with_let(&mut err, source, span);

if self.suggest_pattern_match_with_let(&mut err, source, span) {
// Fallback label.
err.span_label(base_error.span, &base_error.fallback_label);
return (err, Vec::new());
}

self.suggest_self_or_self_ref(&mut err, path, span);
self.detect_assoct_type_constraint_meant_as_path(&mut err, &base_error);
Expand All @@ -341,7 +346,11 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
if !self.type_ascription_suggestion(&mut err, base_error.span) {
let mut fallback =
self.suggest_trait_and_bounds(&mut err, source, res, span, &base_error);

// if we have suggested using pattern matching, then don't add needless suggestions
// for typos.
fallback |= self.suggest_typo(&mut err, source, path, span, &base_error);

if fallback {
// Fallback label.
err.span_label(base_error.span, &base_error.fallback_label);
Expand Down Expand Up @@ -937,7 +946,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
err: &mut Diagnostic,
source: PathSource<'_>,
span: Span,
) {
) -> bool {
if let PathSource::Expr(_) = source &&
let Some(Expr {
span: expr_span,
Expand All @@ -954,8 +963,10 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
"let ",
Applicability::MaybeIncorrect,
);
return true;
}
}
false
}

fn get_single_associated_item(
Expand Down
18 changes: 18 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,24 @@ impl<'a> Builder<'a> {

false
}

pub(crate) fn maybe_open_in_browser<S: Step>(&self, path: impl AsRef<Path>) {
if self.was_invoked_explicitly::<S>(Kind::Doc) {
self.open_in_browser(path);
}
}

pub(crate) fn open_in_browser(&self, path: impl AsRef<Path>) {
if self.config.dry_run || !self.config.cmd.open() {
return;
}

let path = path.as_ref();
self.info(&format!("Opening doc {}", path.display()));
if let Err(err) = opener::open(path) {
self.info(&format!("{}\n", err));
}
}
}

#[cfg(test)]
Expand Down
35 changes: 10 additions & 25 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,6 @@ book!(
StyleGuide, "src/doc/style-guide", "style-guide";
);

fn open(builder: &Builder<'_>, path: impl AsRef<Path>) {
if builder.config.dry_run || !builder.config.cmd.open() {
return;
}

let path = path.as_ref();
builder.info(&format!("Opening doc {}", path.display()));
if let Err(err) = opener::open(path) {
builder.info(&format!("{}\n", err));
}
}

// "library/std" -> ["library", "std"]
//
// Used for deciding whether a particular step is one requested by the user on
Expand Down Expand Up @@ -240,11 +228,9 @@ impl Step for TheBook {
invoke_rustdoc(builder, compiler, &shared_assets, target, path);
}

if builder.was_invoked_explicitly::<Self>(Kind::Doc) {
let out = builder.doc_out(target);
let index = out.join("book").join("index.html");
open(builder, &index);
}
let out = builder.doc_out(target);
let index = out.join("book").join("index.html");
builder.maybe_open_in_browser::<Self>(index);
}
}

Expand Down Expand Up @@ -386,7 +372,7 @@ impl Step for Standalone {
// with no particular explicit doc requested (e.g. library/core).
if builder.paths.is_empty() || builder.was_invoked_explicitly::<Self>(Kind::Doc) {
let index = out.join("index.html");
open(builder, &index);
builder.open_in_browser(&index);
}
}
}
Expand Down Expand Up @@ -507,7 +493,7 @@ impl Step for Std {
for requested_crate in requested_crates {
if STD_PUBLIC_CRATES.iter().any(|k| *k == requested_crate.as_str()) {
let index = out.join(requested_crate).join("index.html");
open(builder, &index);
builder.open_in_browser(index);
}
}
}
Expand Down Expand Up @@ -759,7 +745,7 @@ impl Step for Rustc {
// Let's open the first crate documentation page:
if let Some(krate) = to_open {
let index = out.join(krate).join("index.html");
open(builder, &index);
builder.open_in_browser(index);
}
}
}
Expand Down Expand Up @@ -1019,10 +1005,9 @@ impl Step for RustcBook {
name: INTERNER.intern_str("rustc"),
src: INTERNER.intern_path(out_base),
});
if builder.was_invoked_explicitly::<Self>(Kind::Doc) {
let out = builder.doc_out(self.target);
let index = out.join("rustc").join("index.html");
open(builder, &index);
}

let out = builder.doc_out(self.target);
let index = out.join("rustc").join("index.html");
builder.maybe_open_in_browser::<Self>(index);
}
}
13 changes: 6 additions & 7 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ pub(crate) struct RenderOptions {
pub(crate) default_settings: FxHashMap<String, String>,
/// If present, suffix added to CSS/JavaScript files when referencing them in generated pages.
pub(crate) resource_suffix: String,
/// Whether to run the static CSS/JavaScript through a minifier when outputting them. `true` by
/// default.
pub(crate) enable_minification: bool,
/// Whether to create an index page in the root of the output directory. If this is true but
/// `enable_index_page` is None, generate a static listing of crates instead.
pub(crate) enable_index_page: bool,
Expand Down Expand Up @@ -416,7 +413,9 @@ impl Options {

let to_check = matches.opt_strs("check-theme");
if !to_check.is_empty() {
let paths = match theme::load_css_paths(static_files::themes::LIGHT) {
let paths = match theme::load_css_paths(
std::str::from_utf8(static_files::STATIC_FILES.theme_light_css.bytes).unwrap(),
) {
Ok(p) => p,
Err(e) => {
diag.struct_err(&e.to_string()).emit();
Expand Down Expand Up @@ -557,7 +556,9 @@ impl Options {

let mut themes = Vec::new();
if matches.opt_present("theme") {
let paths = match theme::load_css_paths(static_files::themes::LIGHT) {
let paths = match theme::load_css_paths(
std::str::from_utf8(static_files::STATIC_FILES.theme_light_css.bytes).unwrap(),
) {
Ok(p) => p,
Err(e) => {
diag.struct_err(&e.to_string()).emit();
Expand Down Expand Up @@ -675,7 +676,6 @@ impl Options {
ModuleSorting::Alphabetical
};
let resource_suffix = matches.opt_str("resource-suffix").unwrap_or_default();
let enable_minification = !matches.opt_present("disable-minification");
let markdown_no_toc = matches.opt_present("markdown-no-toc");
let markdown_css = matches.opt_strs("markdown-css");
let markdown_playground_url = matches.opt_str("markdown-playground-url");
Expand Down Expand Up @@ -768,7 +768,6 @@ impl Options {
extern_html_root_takes_precedence,
default_settings,
resource_suffix,
enable_minification,
enable_index_page,
index_page,
static_root_path,
Expand Down
23 changes: 14 additions & 9 deletions src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use std::path::PathBuf;

use rustc_data_structures::fx::FxHashMap;

use crate::error::Error;
use crate::externalfiles::ExternalHtml;
use crate::html::format::{Buffer, Print};
use crate::html::render::{ensure_trailing_slash, StylePath};

use askama::Template;

use super::static_files::{StaticFiles, STATIC_FILES};

#[derive(Clone)]
pub(crate) struct Layout {
pub(crate) logo: String,
Expand All @@ -34,17 +35,23 @@ pub(crate) struct Page<'a> {
}

impl<'a> Page<'a> {
pub(crate) fn get_static_root_path(&self) -> &str {
self.static_root_path.unwrap_or(self.root_path)
pub(crate) fn get_static_root_path(&self) -> String {
match self.static_root_path {
Some(s) => s.to_string(),
None => format!("{}static.files/", self.root_path),
}
}
}

#[derive(Template)]
#[template(path = "page.html")]
struct PageLayout<'a> {
static_root_path: &'a str,
static_root_path: String,
page: &'a Page<'a>,
layout: &'a Layout,

files: &'static StaticFiles,

themes: Vec<String>,
sidebar: String,
content: String,
Expand All @@ -61,19 +68,17 @@ pub(crate) fn render<T: Print, S: Print>(
) -> String {
let static_root_path = page.get_static_root_path();
let krate_with_trailing_slash = ensure_trailing_slash(&layout.krate).to_string();
let mut themes: Vec<String> = style_files
.iter()
.map(StylePath::basename)
.collect::<Result<_, Error>>()
.unwrap_or_default();
let mut themes: Vec<String> = style_files.iter().map(|s| s.basename().unwrap()).collect();
themes.sort();

let rustdoc_version = rustc_interface::util::version_str().unwrap_or("unknown version");
let content = Buffer::html().to_display(t); // Note: This must happen before making the sidebar.
let sidebar = Buffer::html().to_display(sidebar);
PageLayout {
static_root_path,
page,
layout,
files: &STATIC_FILES,
themes,
sidebar,
content,
Expand Down
Loading