Skip to content

Commit addacb5

Browse files
committed
Auto merge of #100963 - matthiaskrgr:rollup-pjr0lb3, r=matthiaskrgr
Rollup of 15 pull requests Successful merges: - #99993 (linker: Update some outdated comments) - #100220 (Properly forward `ByRefSized::fold` to the inner iterator) - #100826 (sugg: take into count the debug formatting) - #100855 (Extra documentation for new formatting feature) - #100888 (Coherence negative impls implied bounds) - #100901 (Make some methods private) - #100906 (Suggest alternatives when trying to mutate a `HashMap`/`BTreeMap` via indexing) - #100912 (Diagnose missing includes in run-make tests) - #100919 (Use par_body_owners for liveness) - #100922 (Rewrite error index generator to greatly reduce the size of the pages) - #100926 (Update README.md) - #100930 (Use `--userns=keep-id` when "docker" is really podman) - #100938 (rustdoc: remove unused CSS rule) - #100940 (Do not suggest adding a bound to a opaque type) - #100945 (Add a missing test case for impl generic mismatch) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ebfc7aa + fb88e25 commit addacb5

File tree

321 files changed

+774
-691
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

321 files changed

+774
-691
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ by running it with the `--help` flag or reading the [rustc dev guide][rustcguide
8383
If you plan to use `x.py install` to create an installation, it is recommended
8484
that you set the `prefix` value in the `[install]` section to a directory.
8585

86-
Create install directory if you are not installing in default directory.
86+
Create an install directory if you are not installing in the default directory.
8787

8888
4. Build and install:
8989

@@ -153,7 +153,7 @@ build.
153153
#### MSVC
154154
155155
MSVC builds of Rust additionally require an installation of Visual Studio 2017
156-
(or later) so `rustc` can use its linker. The simplest way is to get the
156+
(or later) so `rustc` can use its linker. The simplest way is to get
157157
[Visual Studio], check the “C++ build tools” and “Windows 10 SDK” workload.
158158
159159
[Visual Studio]: https://visualstudio.microsoft.com/downloads/

Diff for: compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,17 @@ impl<'tcx> BorrowExplanation<'tcx> {
273273
_ => {}
274274
}
275275
}
276-
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(
276+
277+
fn add_lifetime_bound_suggestion_to_diagnostic(
277278
&self,
278279
err: &mut Diagnostic,
279280
category: &ConstraintCategory<'tcx>,
280281
span: Span,
281282
region_name: &RegionName,
282283
) {
284+
if !span.is_desugaring(DesugaringKind::OpaqueTy) {
285+
return;
286+
}
283287
if let ConstraintCategory::OpaqueType = category {
284288
let suggestable_name =
285289
if region_name.was_named() { region_name.name } else { kw::UnderscoreLifetime };

Diff for: compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed};
12
use rustc_hir as hir;
23
use rustc_hir::Node;
34
use rustc_middle::hir::map::Map;
@@ -12,12 +13,11 @@ use rustc_middle::{
1213
};
1314
use rustc_span::source_map::DesugaringKind;
1415
use rustc_span::symbol::{kw, Symbol};
15-
use rustc_span::{BytePos, Span};
16+
use rustc_span::{sym, BytePos, Span};
1617

1718
use crate::diagnostics::BorrowedContentSource;
1819
use crate::MirBorrowckCtxt;
1920
use rustc_const_eval::util::collect_writes::FindAssignments;
20-
use rustc_errors::{Applicability, Diagnostic};
2121

2222
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
2323
pub(crate) enum AccessKind {
@@ -614,6 +614,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
614614
"trait `IndexMut` is required to modify indexed content, \
615615
but it is not implemented for `{ty}`",
616616
));
617+
self.suggest_map_index_mut_alternatives(ty, &mut err);
617618
}
618619
_ => (),
619620
}
@@ -627,6 +628,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
627628
self.buffer_error(err);
628629
}
629630

631+
fn suggest_map_index_mut_alternatives(
632+
&self,
633+
ty: Ty<'_>,
634+
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
635+
) {
636+
let Some(adt) = ty.ty_adt_def() else { return };
637+
let did = adt.did();
638+
if self.infcx.tcx.is_diagnostic_item(sym::HashMap, did)
639+
|| self.infcx.tcx.is_diagnostic_item(sym::BTreeMap, did)
640+
{
641+
err.help(format!("to modify a `{ty}`, use `.get_mut()`, `.insert()` or the entry API"));
642+
}
643+
}
644+
630645
/// User cannot make signature of a trait mutable without changing the
631646
/// trait. So we find if this error belongs to a trait and if so we move
632647
/// suggestion to the trait or disable it if it is out of scope of this crate

Diff for: compiler/rustc_codegen_ssa/src/back/link.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,6 @@ fn linker_with_args<'a>(
19581958
// Upstream rust libraries are not supposed to depend on our local native
19591959
// libraries as that would violate the structure of the DAG, in that
19601960
// scenario they are required to link to them as well in a shared fashion.
1961-
// (The current implementation still doesn't prevent it though, see the FIXME below.)
19621961
//
19631962
// Note that upstream rust libraries may contain native dependencies as
19641963
// well, but they also can't depend on what we just started to add to the
@@ -1979,15 +1978,16 @@ fn linker_with_args<'a>(
19791978
// and move this option back to the top.
19801979
cmd.add_as_needed();
19811980

1982-
// FIXME: Move this below to other native libraries
1983-
// (or alternatively link all native libraries after their respective crates).
1984-
// This change is somewhat breaking in practice due to local static libraries being linked
1985-
// as whole-archive (#85144), so removing whole-archive may be a pre-requisite.
1981+
// Local native libraries of all kinds.
1982+
//
1983+
// If `-Zlink-native-libraries=false` is set, then the assumption is that an
1984+
// external build system already has the native dependencies defined, and it
1985+
// will provide them to the linker itself.
19861986
if sess.opts.unstable_opts.link_native_libraries {
19871987
add_local_native_libraries(cmd, sess, codegen_results);
19881988
}
19891989

1990-
// Upstream rust libraries and their non-bundled static libraries
1990+
// Upstream rust libraries and their (possibly bundled) static native libraries.
19911991
add_upstream_rust_crates(
19921992
cmd,
19931993
sess,
@@ -1997,11 +1997,11 @@ fn linker_with_args<'a>(
19971997
tmpdir,
19981998
);
19991999

2000-
// Upstream dynamic native libraries linked with `#[link]` attributes at and `-l`
2001-
// command line options.
2002-
// If -Zlink-native-libraries=false is set, then the assumption is that an
2003-
// external build system already has the native dependencies defined, and it
2004-
// will provide them to the linker itself.
2000+
// Dynamic native libraries from upstream crates.
2001+
//
2002+
// FIXME: Merge this to `add_upstream_rust_crates` so that all native libraries are linked
2003+
// together with their respective upstream crates, and in their originally specified order.
2004+
// This may be slightly breaking due to our use of `--as-needed` and needs a crater run.
20052005
if sess.opts.unstable_opts.link_native_libraries {
20062006
add_upstream_native_libraries(cmd, sess, codegen_results);
20072007
}
@@ -2415,7 +2415,7 @@ fn add_upstream_rust_crates<'a>(
24152415
// or is an rlib already included via some other dylib crate, the symbols from
24162416
// native libs will have already been included in that dylib.
24172417
//
2418-
// If -Zlink-native-libraries=false is set, then the assumption is that an
2418+
// If `-Zlink-native-libraries=false` is set, then the assumption is that an
24192419
// external build system already has the native dependencies defined, and it
24202420
// will provide them to the linker itself.
24212421
if sess.opts.unstable_opts.link_native_libraries {

Diff for: compiler/rustc_codegen_ssa/src/back/metadata.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ pub enum MetadataPosition {
187187
Last,
188188
}
189189

190-
// For rlibs we "pack" rustc metadata into a dummy object file. When rustc
191-
// creates a dylib crate type it will pass `--whole-archive` (or the
192-
// platform equivalent) to include all object files from an rlib into the
193-
// final dylib itself. This causes linkers to iterate and try to include all
194-
// files located in an archive, so if metadata is stored in an archive then
195-
// it needs to be of a form that the linker will be able to process.
190+
// For rlibs we "pack" rustc metadata into a dummy object file.
191+
//
192+
// Historically it was needed because rustc linked rlibs as whole-archive in some cases.
193+
// In that case linkers try to include all files located in an archive, so if metadata is stored
194+
// in an archive then it needs to be of a form that the linker is able to process.
195+
// Now it's not clear whether metadata still needs to be wrapped into an object file or not.
196196
//
197197
// Note, though, that we don't actually want this metadata to show up in any
198198
// final output of the compiler. Instead this is purely for rustc's own

Diff for: compiler/rustc_interface/src/passes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -911,13 +911,13 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
911911
});
912912
},
913913
{
914-
sess.time("liveness_and_intrinsic_checking", || {
915-
tcx.hir().par_for_each_module(|module| {
914+
sess.time("liveness_checking", || {
915+
tcx.hir().par_body_owners(|def_id| {
916916
// this must run before MIR dump, because
917917
// "not all control paths return a value" is reported here.
918918
//
919919
// maybe move the check to a MIR pass?
920-
tcx.ensure().check_mod_liveness(module);
920+
tcx.ensure().check_liveness(def_id.to_def_id());
921921
});
922922
});
923923
}

Diff for: compiler/rustc_lint/src/context.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,14 @@ pub trait LintContext: Sized {
865865

866866
if let Some(positional_arg_to_replace) = position_sp_to_replace {
867867
let name = if is_formatting_arg { named_arg_name + "$" } else { named_arg_name };
868-
868+
let span_to_replace = if let Ok(positional_arg_content) =
869+
self.sess().source_map().span_to_snippet(positional_arg_to_replace) && positional_arg_content.starts_with(":") {
870+
positional_arg_to_replace.shrink_to_lo()
871+
} else {
872+
positional_arg_to_replace
873+
};
869874
db.span_suggestion_verbose(
870-
positional_arg_to_replace,
875+
span_to_replace,
871876
"use the named argument by name to avoid ambiguity",
872877
name,
873878
Applicability::MaybeIncorrect,

Diff for: compiler/rustc_middle/src/query/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,8 @@ rustc_queries! {
818818
desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
819819
}
820820

821-
query check_mod_liveness(key: LocalDefId) -> () {
822-
desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) }
821+
query check_liveness(key: DefId) {
822+
desc { |tcx| "checking liveness of variables in {}", tcx.def_path_str(key) }
823823
}
824824

825825
/// Return the live symbols in the crate for dead code check.

Diff for: compiler/rustc_passes/src/liveness.rs

+46-55
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,10 @@ use rustc_data_structures::fx::FxIndexMap;
8989
use rustc_errors::Applicability;
9090
use rustc_hir as hir;
9191
use rustc_hir::def::*;
92-
use rustc_hir::def_id::LocalDefId;
92+
use rustc_hir::def_id::{DefId, LocalDefId};
9393
use rustc_hir::intravisit::{self, Visitor};
9494
use rustc_hir::{Expr, HirId, HirIdMap, HirIdSet};
9595
use rustc_index::vec::IndexVec;
96-
use rustc_middle::hir::nested_filter;
9796
use rustc_middle::ty::query::Providers;
9897
use rustc_middle::ty::{self, DefIdTree, RootVariableMinCaptureList, Ty, TyCtxt};
9998
use rustc_session::lint;
@@ -139,12 +138,54 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String {
139138
}
140139
}
141140

142-
fn check_mod_liveness(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
143-
tcx.hir().visit_item_likes_in_module(module_def_id, &mut IrMaps::new(tcx));
141+
fn check_liveness(tcx: TyCtxt<'_>, def_id: DefId) {
142+
let local_def_id = match def_id.as_local() {
143+
None => return,
144+
Some(def_id) => def_id,
145+
};
146+
147+
// Don't run unused pass for #[derive()]
148+
let parent = tcx.local_parent(local_def_id);
149+
if let DefKind::Impl = tcx.def_kind(parent)
150+
&& tcx.has_attr(parent.to_def_id(), sym::automatically_derived)
151+
{
152+
return;
153+
}
154+
155+
// Don't run unused pass for #[naked]
156+
if tcx.has_attr(def_id, sym::naked) {
157+
return;
158+
}
159+
160+
let mut maps = IrMaps::new(tcx);
161+
let body_id = tcx.hir().body_owned_by(local_def_id);
162+
let hir_id = tcx.hir().body_owner(body_id);
163+
let body = tcx.hir().body(body_id);
164+
165+
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
166+
for &var_hir_id in upvars.keys() {
167+
let var_name = tcx.hir().name(var_hir_id);
168+
maps.add_variable(Upvar(var_hir_id, var_name));
169+
}
170+
}
171+
172+
// gather up the various local variables, significant expressions,
173+
// and so forth:
174+
maps.visit_body(body);
175+
176+
// compute liveness
177+
let mut lsets = Liveness::new(&mut maps, local_def_id);
178+
let entry_ln = lsets.compute(&body, hir_id);
179+
lsets.log_liveness(entry_ln, body_id.hir_id);
180+
181+
// check for various error conditions
182+
lsets.visit_body(body);
183+
lsets.warn_about_unused_upvars(entry_ln);
184+
lsets.warn_about_unused_args(body, entry_ln);
144185
}
145186

146187
pub fn provide(providers: &mut Providers) {
147-
*providers = Providers { check_mod_liveness, ..*providers };
188+
*providers = Providers { check_liveness, ..*providers };
148189
}
149190

150191
// ______________________________________________________________________
@@ -316,56 +357,6 @@ impl<'tcx> IrMaps<'tcx> {
316357
}
317358

318359
impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
319-
type NestedFilter = nested_filter::OnlyBodies;
320-
321-
fn nested_visit_map(&mut self) -> Self::Map {
322-
self.tcx.hir()
323-
}
324-
325-
fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
326-
debug!("visit_body {:?}", body.id());
327-
328-
// swap in a new set of IR maps for this body
329-
let mut maps = IrMaps::new(self.tcx);
330-
let hir_id = maps.tcx.hir().body_owner(body.id());
331-
let local_def_id = maps.tcx.hir().local_def_id(hir_id);
332-
let def_id = local_def_id.to_def_id();
333-
334-
// Don't run unused pass for #[derive()]
335-
let parent = self.tcx.local_parent(local_def_id);
336-
if let DefKind::Impl = self.tcx.def_kind(parent)
337-
&& self.tcx.has_attr(parent.to_def_id(), sym::automatically_derived)
338-
{
339-
return;
340-
}
341-
342-
// Don't run unused pass for #[naked]
343-
if self.tcx.has_attr(def_id, sym::naked) {
344-
return;
345-
}
346-
347-
if let Some(upvars) = maps.tcx.upvars_mentioned(def_id) {
348-
for &var_hir_id in upvars.keys() {
349-
let var_name = maps.tcx.hir().name(var_hir_id);
350-
maps.add_variable(Upvar(var_hir_id, var_name));
351-
}
352-
}
353-
354-
// gather up the various local variables, significant expressions,
355-
// and so forth:
356-
intravisit::walk_body(&mut maps, body);
357-
358-
// compute liveness
359-
let mut lsets = Liveness::new(&mut maps, local_def_id);
360-
let entry_ln = lsets.compute(&body, hir_id);
361-
lsets.log_liveness(entry_ln, body.id().hir_id);
362-
363-
// check for various error conditions
364-
lsets.visit_body(body);
365-
lsets.warn_about_unused_upvars(entry_ln);
366-
lsets.warn_about_unused_args(body, entry_ln);
367-
}
368-
369360
fn visit_local(&mut self, local: &'tcx hir::Local<'tcx>) {
370361
self.add_from_pat(&local.pat);
371362
if local.els.is_some() {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
21802180
err.emit()
21812181
}
21822182

2183-
pub(crate) fn add_missing_lifetime_specifiers_label(
2183+
fn add_missing_lifetime_specifiers_label(
21842184
&mut self,
21852185
err: &mut Diagnostic,
21862186
lifetime_refs: Vec<MissingLifetime>,

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

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![feature(let_else)]
2121
#![feature(if_let_guard)]
2222
#![feature(never_type)]
23+
#![feature(type_alias_impl_trait)]
2324
#![recursion_limit = "512"] // For rustdoc
2425

2526
#[macro_use]

0 commit comments

Comments
 (0)