Skip to content

Commit 2b3f260

Browse files
committed
Auto merge of rust-lang#107928 - matthiaskrgr:rollup-qnn380r, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#107657 (Add only modified subcommand for compiletest) - rust-lang#107864 (rustdoc: clean up `write!` calls with less stuttering) - rust-lang#107873 (Emit JSON output for the building of bootstrap itself) - rust-lang#107895 (remove redundant clones) - rust-lang#107897 (Reexported macros docs) - rust-lang#107909 (rustdoc: remove redundant `if s.is_empty()` from `find_testable_code`) - rust-lang#107912 (rustdoc: Don't resolve link to field on different variant) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8dabf5d + c8614a7 commit 2b3f260

File tree

21 files changed

+242
-62
lines changed

21 files changed

+242
-62
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@ dependencies = [
895895
name = "compiletest"
896896
version = "0.0.0"
897897
dependencies = [
898+
"build_helper",
898899
"colored",
899900
"diff",
900901
"getopts",

compiler/rustc_codegen_ssa/src/back/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
203203
}
204204
}
205205

206-
self.src_archives.push((archive_path.to_owned(), archive_map));
206+
self.src_archives.push((archive_path, archive_map));
207207
Ok(())
208208
}
209209

compiler/rustc_log/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> {
9292
let fmt_layer = tracing_subscriber::fmt::layer()
9393
.with_writer(io::stderr)
9494
.without_time()
95-
.event_format(BacktraceFormatter { backtrace_target: str.to_string() });
95+
.event_format(BacktraceFormatter { backtrace_target: str });
9696
let subscriber = subscriber.with(fmt_layer);
9797
tracing::subscriber::set_global_default(subscriber).unwrap();
9898
}

compiler/rustc_parse_format/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,7 @@ impl<'a> Parser<'a> {
847847
0,
848848
ParseError {
849849
description: "expected format parameter to occur after `:`".to_owned(),
850-
note: Some(
851-
format!("`?` comes after `:`, try `{}:{}` instead", word, "?").to_owned(),
852-
),
850+
note: Some(format!("`?` comes after `:`, try `{}:{}` instead", word, "?")),
853851
label: "expected `?` to occur after `:`".to_owned(),
854852
span: pos.to(pos),
855853
secondary_label: None,

src/bootstrap/bootstrap.py

+4
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,8 @@ def build_bootstrap(self, color, verbose_count):
784784
if self.get_toml("metrics", "build"):
785785
args.append("--features")
786786
args.append("build-metrics")
787+
if self.json_output:
788+
args.append("--message-format=json")
787789
if color == "always":
788790
args.append("--color=always")
789791
elif color == "never":
@@ -841,6 +843,7 @@ def parse_args():
841843
parser.add_argument('--build')
842844
parser.add_argument('--color', choices=['always', 'never', 'auto'])
843845
parser.add_argument('--clean', action='store_true')
846+
parser.add_argument('--json-output', action='store_true')
844847
parser.add_argument('-v', '--verbose', action='count', default=0)
845848

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

856860
# Read from `--config`, then `RUST_BOOTSTRAP_CONFIG`, then `./config.toml`,
857861
# then `config.toml` in the root directory.

src/bootstrap/builder/tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ mod dist {
557557
rustfix_coverage: false,
558558
pass: None,
559559
run: None,
560+
only_modified: false,
560561
};
561562

562563
let build = Build::new(config);
@@ -627,6 +628,7 @@ mod dist {
627628
rustfix_coverage: false,
628629
pass: None,
629630
run: None,
631+
only_modified: false,
630632
};
631633
// Make sure rustfmt binary not being found isn't an error.
632634
config.channel = "beta".to_string();

src/bootstrap/flags.rs

+10
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ pub enum Subcommand {
124124
fail_fast: bool,
125125
doc_tests: DocTests,
126126
rustfix_coverage: bool,
127+
only_modified: bool,
127128
},
128129
Bench {
129130
paths: Vec<PathBuf>,
@@ -301,6 +302,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
301302
opts.optflag("", "doc", "only run doc tests");
302303
opts.optflag("", "bless", "update all stderr/stdout files of failing ui tests");
303304
opts.optflag("", "force-rerun", "rerun tests even if the inputs are unchanged");
305+
opts.optflag("", "only-modified", "only run tests that result has been changed");
304306
opts.optopt(
305307
"",
306308
"compare-mode",
@@ -598,6 +600,7 @@ Arguments:
598600
rustc_args: matches.opt_strs("rustc-args"),
599601
fail_fast: !matches.opt_present("no-fail-fast"),
600602
rustfix_coverage: matches.opt_present("rustfix-coverage"),
603+
only_modified: matches.opt_present("only-modified"),
601604
doc_tests: if matches.opt_present("doc") {
602605
DocTests::Only
603606
} else if matches.opt_present("no-doc") {
@@ -777,6 +780,13 @@ impl Subcommand {
777780
}
778781
}
779782

783+
pub fn only_modified(&self) -> bool {
784+
match *self {
785+
Subcommand::Test { only_modified, .. } => only_modified,
786+
_ => false,
787+
}
788+
}
789+
780790
pub fn force_rerun(&self) -> bool {
781791
match *self {
782792
Subcommand::Test { force_rerun, .. } => force_rerun,

src/bootstrap/format.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Runs rustfmt on the repository.
22
33
use crate::builder::Builder;
4-
use crate::util::{output, output_result, program_out_of_date, t};
5-
use build_helper::git::updated_master_branch;
4+
use crate::util::{output, program_out_of_date, t};
5+
use build_helper::git::get_git_modified_files;
66
use ignore::WalkBuilder;
77
use std::collections::VecDeque;
88
use std::path::{Path, PathBuf};
@@ -80,23 +80,11 @@ fn update_rustfmt_version(build: &Builder<'_>) {
8080
///
8181
/// Returns `None` if all files should be formatted.
8282
fn get_modified_rs_files(build: &Builder<'_>) -> Result<Option<Vec<String>>, String> {
83-
let Ok(updated_master) = updated_master_branch(Some(&build.config.src)) else { return Ok(None); };
84-
8583
if !verify_rustfmt_version(build) {
8684
return Ok(None);
8785
}
8886

89-
let merge_base =
90-
output_result(build.config.git().arg("merge-base").arg(&updated_master).arg("HEAD"))?;
91-
Ok(Some(
92-
output_result(
93-
build.config.git().arg("diff-index").arg("--name-only").arg(merge_base.trim()),
94-
)?
95-
.lines()
96-
.map(|s| s.trim().to_owned())
97-
.filter(|f| Path::new(f).extension().map_or(false, |ext| ext == "rs"))
98-
.collect(),
99-
))
87+
get_git_modified_files(Some(&build.config.src), &vec!["rs"])
10088
}
10189

10290
#[derive(serde::Deserialize)]

src/bootstrap/test.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,10 @@ note: if you're sure you want to do this, please open an issue as to why. In the
15101510
if builder.config.rust_optimize_tests {
15111511
cmd.arg("--optimize-tests");
15121512
}
1513+
if builder.config.cmd.only_modified() {
1514+
cmd.arg("--only-modified");
1515+
}
1516+
15131517
let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
15141518
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
15151519
flags.extend(builder.config.cmd.rustc_args().iter().map(|s| s.to_string()));

src/librustdoc/clean/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2209,10 +2209,12 @@ fn clean_maybe_renamed_item<'tcx>(
22092209
};
22102210

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

src/librustdoc/html/markdown.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,7 @@ pub(crate) fn find_testable_code<T: doctest::Tester>(
740740
}
741741
Event::Text(ref s) if register_header.is_some() => {
742742
let level = register_header.unwrap();
743-
if s.is_empty() {
744-
tests.register_header("", level);
745-
} else {
746-
tests.register_header(s, level);
747-
}
743+
tests.register_header(s, level);
748744
register_header = None;
749745
}
750746
_ => {}

src/librustdoc/html/render/print_item.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -1081,10 +1081,10 @@ fn item_typedef(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clea
10811081
fn write_content(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Typedef) {
10821082
wrap_item(w, |w| {
10831083
render_attributes_in_pre(w, it, "");
1084-
write!(w, "{}", visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx));
10851084
write!(
10861085
w,
1087-
"type {}{}{where_clause} = {type_};",
1086+
"{}type {}{}{where_clause} = {type_};",
1087+
visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx),
10881088
it.name.unwrap(),
10891089
t.generics.print(cx),
10901090
where_clause = print_where_clause(&t.generics, cx, 0, Ending::Newline),
@@ -1138,13 +1138,11 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
11381138
<a href=\"#{id}\" class=\"anchor field\">§</a>\
11391139
<code>{name}: {ty}</code>\
11401140
</span>",
1141-
id = id,
1142-
name = name,
11431141
shortty = ItemType::StructField,
11441142
ty = ty.print(cx),
11451143
);
11461144
if let Some(stability_class) = field.stability_class(cx.tcx()) {
1147-
write!(w, "<span class=\"stab {stab}\"></span>", stab = stability_class);
1145+
write!(w, "<span class=\"stab {stability_class}\"></span>");
11481146
}
11491147
document(w, cx, field, Some(it), HeadingOffset::H3);
11501148
}
@@ -1242,7 +1240,6 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
12421240
w,
12431241
"<section id=\"{id}\" class=\"variant\">\
12441242
<a href=\"#{id}\" class=\"anchor\">§</a>",
1245-
id = id,
12461243
);
12471244
render_stability_since_raw_with_extra(
12481245
w,
@@ -1280,8 +1277,11 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
12801277
if let Some((heading, fields)) = heading_and_fields {
12811278
let variant_id =
12821279
cx.derive_id(format!("{}.{}.fields", ItemType::Variant, variant.name.unwrap()));
1283-
write!(w, "<div class=\"sub-variant\" id=\"{id}\">", id = variant_id);
1284-
write!(w, "<h4>{heading}</h4>", heading = heading);
1280+
write!(
1281+
w,
1282+
"<div class=\"sub-variant\" id=\"{variant_id}\">\
1283+
<h4>{heading}</h4>",
1284+
);
12851285
document_non_exhaustive(w, variant);
12861286
for field in fields {
12871287
match *field.kind {
@@ -1299,7 +1299,6 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
12991299
<a href=\"#{id}\" class=\"anchor field\">§</a>\
13001300
<code>{f}: {t}</code>\
13011301
</span>",
1302-
id = id,
13031302
f = field.name.unwrap(),
13041303
t = ty.print(cx)
13051304
);
@@ -1450,11 +1449,9 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
14501449
w,
14511450
"<span id=\"{id}\" class=\"{item_type} small-section-header\">\
14521451
<a href=\"#{id}\" class=\"anchor field\">§</a>\
1453-
<code>{name}: {ty}</code>\
1452+
<code>{field_name}: {ty}</code>\
14541453
</span>",
14551454
item_type = ItemType::StructField,
1456-
id = id,
1457-
name = field_name,
14581455
ty = ty.print(cx)
14591456
);
14601457
document(w, cx, field, Some(it), HeadingOffset::H3);
@@ -1840,8 +1837,8 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
18401837
if layout.abi.is_unsized() {
18411838
write!(w, "(unsized)");
18421839
} else {
1843-
let bytes = layout.size.bytes() - tag_size;
1844-
write!(w, "{size} byte{pl}", size = bytes, pl = if bytes == 1 { "" } else { "s" },);
1840+
let size = layout.size.bytes() - tag_size;
1841+
write!(w, "{size} byte{pl}", pl = if size == 1 { "" } else { "s" },);
18451842
}
18461843
}
18471844

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

18971894
for (index, layout) in variants.iter_enumerated() {
18981895
let name = adt.variant(index).name;
1899-
write!(w, "<li><code>{name}</code>: ", name = name);
1896+
write!(w, "<li><code>{name}</code>: ");
19001897
write_size_of_layout(w, layout, tag_size);
19011898
writeln!(w, "</li>");
19021899
}

src/librustdoc/passes/collect_intra_doc_links.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
297297
match ty_res {
298298
Res::Def(DefKind::Enum, did) => match tcx.type_of(did).kind() {
299299
ty::Adt(def, _) if def.is_enum() => {
300-
if let Some(field) = def.all_fields().find(|f| f.name == variant_field_name) {
300+
if let Some(variant) = def.variants().iter().find(|v| v.name == variant_name)
301+
&& let Some(field) = variant.fields.iter().find(|f| f.name == variant_field_name) {
301302
Ok((ty_res, field.did))
302303
} else {
303304
Err(UnresolvedPath {
@@ -1716,15 +1717,35 @@ fn resolution_failure(
17161717

17171718
// Otherwise, it must be an associated item or variant
17181719
let res = partial_res.expect("None case was handled by `last_found_module`");
1719-
let kind = match res {
1720-
Res::Def(kind, _) => Some(kind),
1720+
let kind_did = match res {
1721+
Res::Def(kind, did) => Some((kind, did)),
17211722
Res::Primitive(_) => None,
17221723
};
1723-
let path_description = if let Some(kind) = kind {
1724+
let is_struct_variant = |did| {
1725+
if let ty::Adt(def, _) = tcx.type_of(did).kind()
1726+
&& def.is_enum()
1727+
&& let Some(variant) = def.variants().iter().find(|v| v.name == res.name(tcx)) {
1728+
// ctor is `None` if variant is a struct
1729+
variant.ctor.is_none()
1730+
} else {
1731+
false
1732+
}
1733+
};
1734+
let path_description = if let Some((kind, did)) = kind_did {
17241735
match kind {
17251736
Mod | ForeignMod => "inner item",
17261737
Struct => "field or associated item",
17271738
Enum | Union => "variant or associated item",
1739+
Variant if is_struct_variant(did) => {
1740+
let variant = res.name(tcx);
1741+
let note = format!("variant `{variant}` has no such field");
1742+
if let Some(span) = sp {
1743+
diag.span_label(span, &note);
1744+
} else {
1745+
diag.note(&note);
1746+
}
1747+
return;
1748+
}
17281749
Variant
17291750
| Field
17301751
| Closure

src/librustdoc/visit_ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
378378
let nonexported = !tcx.has_attr(def_id, sym::macro_export);
379379

380380
if is_macro_2_0 || nonexported || self.inlining {
381-
self.add_to_current_mod(item, renamed, None);
381+
self.add_to_current_mod(item, renamed, import_id);
382382
}
383383
}
384384
hir::ItemKind::Mod(ref m) => {

0 commit comments

Comments
 (0)