Skip to content

Rollup of 7 pull requests #107928

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 17 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
1a98305
rustdoc: clean up `write!` calls with less stuttering
notriddle Feb 10, 2023
414eb48
add only modified for compiletest
chenyukang Feb 3, 2023
5201bb5
remove redundant clones
matthiaskrgr Feb 10, 2023
c52435a
cleanup and fix naming
chenyukang Feb 10, 2023
c003c01
Correctly handle reexports for macros
GuillaumeGomez Feb 10, 2023
ddb31de
Also get current import attributes
GuillaumeGomez Feb 10, 2023
295fd0d
Add regression test for reexported macros docs
GuillaumeGomez Feb 10, 2023
897647b
rustdoc: remove redundant `if s.is_empty()` from `find_testable_code`
notriddle Feb 10, 2023
1057e21
emit JSON output for building of bootstrap itself
zephaniahong Feb 11, 2023
ef8de38
rustdoc: Don't resolve link to field on different variant
clubby789 Feb 11, 2023
585b458
Rollup merge of #107657 - chenyukang:yukang/add-only-modified, r=albe…
matthiaskrgr Feb 11, 2023
240d5e0
Rollup merge of #107864 - notriddle:notriddle/rustdoc-write-stutter, …
matthiaskrgr Feb 11, 2023
420e756
Rollup merge of #107873 - zephaniahong:issue-107832-fix, r=albertlars…
matthiaskrgr Feb 11, 2023
4b7b569
Rollup merge of #107895 - matthiaskrgr:cl, r=compiler-errors
matthiaskrgr Feb 11, 2023
1305119
Rollup merge of #107897 - GuillaumeGomez:reexported-macros-docs, r=no…
matthiaskrgr Feb 11, 2023
f95f68e
Rollup merge of #107909 - notriddle:notriddle/register-header-empty-c…
matthiaskrgr Feb 11, 2023
c8614a7
Rollup merge of #107912 - clubby789:doc-bad-enum-field, r=camelid,Gui…
matthiaskrgr Feb 11, 2023
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ dependencies = [
name = "compiletest"
version = "0.0.0"
dependencies = [
"build_helper",
"colored",
"diff",
"getopts",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
}
}

self.src_archives.push((archive_path.to_owned(), archive_map));
self.src_archives.push((archive_path, archive_map));
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> {
let fmt_layer = tracing_subscriber::fmt::layer()
.with_writer(io::stderr)
.without_time()
.event_format(BacktraceFormatter { backtrace_target: str.to_string() });
.event_format(BacktraceFormatter { backtrace_target: str });
let subscriber = subscriber.with(fmt_layer);
tracing::subscriber::set_global_default(subscriber).unwrap();
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,7 @@ impl<'a> Parser<'a> {
0,
ParseError {
description: "expected format parameter to occur after `:`".to_owned(),
note: Some(
format!("`?` comes after `:`, try `{}:{}` instead", word, "?").to_owned(),
),
note: Some(format!("`?` comes after `:`, try `{}:{}` instead", word, "?")),
label: "expected `?` to occur after `:`".to_owned(),
span: pos.to(pos),
secondary_label: None,
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,8 @@ def build_bootstrap(self, color, verbose_count):
if self.get_toml("metrics", "build"):
args.append("--features")
args.append("build-metrics")
if self.json_output:
args.append("--message-format=json")
if color == "always":
args.append("--color=always")
elif color == "never":
Expand Down Expand Up @@ -841,6 +843,7 @@ def parse_args():
parser.add_argument('--build')
parser.add_argument('--color', choices=['always', 'never', 'auto'])
parser.add_argument('--clean', action='store_true')
parser.add_argument('--json-output', action='store_true')
parser.add_argument('-v', '--verbose', action='count', default=0)

return parser.parse_known_args(sys.argv)[0]
Expand All @@ -852,6 +855,7 @@ def bootstrap(args):
build.rust_root = os.path.abspath(os.path.join(__file__, '../../..'))
build.verbose = args.verbose != 0
build.clean = args.clean
build.json_output = args.json_output

# Read from `--config`, then `RUST_BOOTSTRAP_CONFIG`, then `./config.toml`,
# then `config.toml` in the root directory.
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ mod dist {
rustfix_coverage: false,
pass: None,
run: None,
only_modified: false,
};

let build = Build::new(config);
Expand Down Expand Up @@ -627,6 +628,7 @@ mod dist {
rustfix_coverage: false,
pass: None,
run: None,
only_modified: false,
};
// Make sure rustfmt binary not being found isn't an error.
config.channel = "beta".to_string();
Expand Down
10 changes: 10 additions & 0 deletions src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub enum Subcommand {
fail_fast: bool,
doc_tests: DocTests,
rustfix_coverage: bool,
only_modified: bool,
},
Bench {
paths: Vec<PathBuf>,
Expand Down Expand Up @@ -301,6 +302,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
opts.optflag("", "doc", "only run doc tests");
opts.optflag("", "bless", "update all stderr/stdout files of failing ui tests");
opts.optflag("", "force-rerun", "rerun tests even if the inputs are unchanged");
opts.optflag("", "only-modified", "only run tests that result has been changed");
opts.optopt(
"",
"compare-mode",
Expand Down Expand Up @@ -598,6 +600,7 @@ Arguments:
rustc_args: matches.opt_strs("rustc-args"),
fail_fast: !matches.opt_present("no-fail-fast"),
rustfix_coverage: matches.opt_present("rustfix-coverage"),
only_modified: matches.opt_present("only-modified"),
doc_tests: if matches.opt_present("doc") {
DocTests::Only
} else if matches.opt_present("no-doc") {
Expand Down Expand Up @@ -777,6 +780,13 @@ impl Subcommand {
}
}

pub fn only_modified(&self) -> bool {
match *self {
Subcommand::Test { only_modified, .. } => only_modified,
_ => false,
}
}

pub fn force_rerun(&self) -> bool {
match *self {
Subcommand::Test { force_rerun, .. } => force_rerun,
Expand Down
18 changes: 3 additions & 15 deletions src/bootstrap/format.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Runs rustfmt on the repository.

use crate::builder::Builder;
use crate::util::{output, output_result, program_out_of_date, t};
use build_helper::git::updated_master_branch;
use crate::util::{output, program_out_of_date, t};
use build_helper::git::get_git_modified_files;
use ignore::WalkBuilder;
use std::collections::VecDeque;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -80,23 +80,11 @@ fn update_rustfmt_version(build: &Builder<'_>) {
///
/// Returns `None` if all files should be formatted.
fn get_modified_rs_files(build: &Builder<'_>) -> Result<Option<Vec<String>>, String> {
let Ok(updated_master) = updated_master_branch(Some(&build.config.src)) else { return Ok(None); };

if !verify_rustfmt_version(build) {
return Ok(None);
}

let merge_base =
output_result(build.config.git().arg("merge-base").arg(&updated_master).arg("HEAD"))?;
Ok(Some(
output_result(
build.config.git().arg("diff-index").arg("--name-only").arg(merge_base.trim()),
)?
.lines()
.map(|s| s.trim().to_owned())
.filter(|f| Path::new(f).extension().map_or(false, |ext| ext == "rs"))
.collect(),
))
get_git_modified_files(Some(&build.config.src), &vec!["rs"])
}

#[derive(serde::Deserialize)]
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,10 @@ note: if you're sure you want to do this, please open an issue as to why. In the
if builder.config.rust_optimize_tests {
cmd.arg("--optimize-tests");
}
if builder.config.cmd.only_modified() {
cmd.arg("--only-modified");
}

let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
flags.extend(builder.config.cmd.rustc_args().iter().map(|s| s.to_string()));
Expand Down
8 changes: 5 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2209,10 +2209,12 @@ fn clean_maybe_renamed_item<'tcx>(
};

let mut extra_attrs = Vec::new();
if let Some(hir::Node::Item(use_node)) =
import_id.and_then(|def_id| cx.tcx.hir().find_by_def_id(def_id))
if let Some(import_id) = import_id &&
let Some(hir::Node::Item(use_node)) = cx.tcx.hir().find_by_def_id(import_id)
{
// We get all the various imports' attributes.
// First, we add the attributes from the current import.
extra_attrs.extend_from_slice(inline::load_attrs(cx, import_id.to_def_id()));
// Then we get all the various imports' attributes.
get_all_import_attributes(use_node, cx.tcx, item.owner_id.def_id, &mut extra_attrs);
}

Expand Down
6 changes: 1 addition & 5 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,7 @@ pub(crate) fn find_testable_code<T: doctest::Tester>(
}
Event::Text(ref s) if register_header.is_some() => {
let level = register_header.unwrap();
if s.is_empty() {
tests.register_header("", level);
} else {
tests.register_header(s, level);
}
tests.register_header(s, level);
register_header = None;
}
_ => {}
Expand Down
27 changes: 12 additions & 15 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,10 +1081,10 @@ fn item_typedef(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clea
fn write_content(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Typedef) {
wrap_item(w, |w| {
render_attributes_in_pre(w, it, "");
write!(w, "{}", visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx));
write!(
w,
"type {}{}{where_clause} = {type_};",
"{}type {}{}{where_clause} = {type_};",
visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx),
it.name.unwrap(),
t.generics.print(cx),
where_clause = print_where_clause(&t.generics, cx, 0, Ending::Newline),
Expand Down Expand Up @@ -1138,13 +1138,11 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
<a href=\"#{id}\" class=\"anchor field\">§</a>\
<code>{name}: {ty}</code>\
</span>",
id = id,
name = name,
shortty = ItemType::StructField,
ty = ty.print(cx),
);
if let Some(stability_class) = field.stability_class(cx.tcx()) {
write!(w, "<span class=\"stab {stab}\"></span>", stab = stability_class);
write!(w, "<span class=\"stab {stability_class}\"></span>");
}
document(w, cx, field, Some(it), HeadingOffset::H3);
}
Expand Down Expand Up @@ -1242,7 +1240,6 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
w,
"<section id=\"{id}\" class=\"variant\">\
<a href=\"#{id}\" class=\"anchor\">§</a>",
id = id,
);
render_stability_since_raw_with_extra(
w,
Expand Down Expand Up @@ -1280,8 +1277,11 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
if let Some((heading, fields)) = heading_and_fields {
let variant_id =
cx.derive_id(format!("{}.{}.fields", ItemType::Variant, variant.name.unwrap()));
write!(w, "<div class=\"sub-variant\" id=\"{id}\">", id = variant_id);
write!(w, "<h4>{heading}</h4>", heading = heading);
write!(
w,
"<div class=\"sub-variant\" id=\"{variant_id}\">\
<h4>{heading}</h4>",
);
document_non_exhaustive(w, variant);
for field in fields {
match *field.kind {
Expand All @@ -1299,7 +1299,6 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
<a href=\"#{id}\" class=\"anchor field\">§</a>\
<code>{f}: {t}</code>\
</span>",
id = id,
f = field.name.unwrap(),
t = ty.print(cx)
);
Expand Down Expand Up @@ -1450,11 +1449,9 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
w,
"<span id=\"{id}\" class=\"{item_type} small-section-header\">\
<a href=\"#{id}\" class=\"anchor field\">§</a>\
<code>{name}: {ty}</code>\
<code>{field_name}: {ty}</code>\
</span>",
item_type = ItemType::StructField,
id = id,
name = field_name,
ty = ty.print(cx)
);
document(w, cx, field, Some(it), HeadingOffset::H3);
Expand Down Expand Up @@ -1840,8 +1837,8 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
if layout.abi.is_unsized() {
write!(w, "(unsized)");
} else {
let bytes = layout.size.bytes() - tag_size;
write!(w, "{size} byte{pl}", size = bytes, pl = if bytes == 1 { "" } else { "s" },);
let size = layout.size.bytes() - tag_size;
write!(w, "{size} byte{pl}", pl = if size == 1 { "" } else { "s" },);
}
}

Expand Down Expand Up @@ -1896,7 +1893,7 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {

for (index, layout) in variants.iter_enumerated() {
let name = adt.variant(index).name;
write!(w, "<li><code>{name}</code>: ", name = name);
write!(w, "<li><code>{name}</code>: ");
write_size_of_layout(w, layout, tag_size);
writeln!(w, "</li>");
}
Expand Down
29 changes: 25 additions & 4 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
match ty_res {
Res::Def(DefKind::Enum, did) => match tcx.type_of(did).kind() {
ty::Adt(def, _) if def.is_enum() => {
if let Some(field) = def.all_fields().find(|f| f.name == variant_field_name) {
if let Some(variant) = def.variants().iter().find(|v| v.name == variant_name)
&& let Some(field) = variant.fields.iter().find(|f| f.name == variant_field_name) {
Ok((ty_res, field.did))
} else {
Err(UnresolvedPath {
Expand Down Expand Up @@ -1716,15 +1717,35 @@ fn resolution_failure(

// Otherwise, it must be an associated item or variant
let res = partial_res.expect("None case was handled by `last_found_module`");
let kind = match res {
Res::Def(kind, _) => Some(kind),
let kind_did = match res {
Res::Def(kind, did) => Some((kind, did)),
Res::Primitive(_) => None,
};
let path_description = if let Some(kind) = kind {
let is_struct_variant = |did| {
if let ty::Adt(def, _) = tcx.type_of(did).kind()
&& def.is_enum()
&& let Some(variant) = def.variants().iter().find(|v| v.name == res.name(tcx)) {
// ctor is `None` if variant is a struct
variant.ctor.is_none()
} else {
false
}
};
let path_description = if let Some((kind, did)) = kind_did {
match kind {
Mod | ForeignMod => "inner item",
Struct => "field or associated item",
Enum | Union => "variant or associated item",
Variant if is_struct_variant(did) => {
let variant = res.name(tcx);
let note = format!("variant `{variant}` has no such field");
if let Some(span) = sp {
diag.span_label(span, &note);
} else {
diag.note(&note);
}
return;
}
Variant
| Field
| Closure
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let nonexported = !tcx.has_attr(def_id, sym::macro_export);

if is_macro_2_0 || nonexported || self.inlining {
self.add_to_current_mod(item, renamed, None);
self.add_to_current_mod(item, renamed, import_id);
}
}
hir::ItemKind::Mod(ref m) => {
Expand Down
Loading