Skip to content

Commit 1dea922

Browse files
committed
Auto merge of rust-lang#124015 - GuillaumeGomez:rollup-s46ksxa, r=GuillaumeGomez
Rollup of 14 pull requests Successful merges: - rust-lang#120781 (Correct usage note on OpenOptions::append()) - rust-lang#121694 (sess: stabilize `-Zrelro-level` as `-Crelro-level`) - rust-lang#122521 (doc(bootstrap): add top-level doc-comment to utils/tarball.rs) - rust-lang#123491 (Fix ICE in `eval_body_using_ecx`) - rust-lang#123574 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 6)) - rust-lang#123687 (Update ar_archive_writer to 0.2.0) - rust-lang#123721 (Various visionOS fixes) - rust-lang#123797 (Better graphviz output for SCCs and NLL constraints) - rust-lang#123990 (Make `suggest_deref_closure_return` more idiomatic/easier to understand) - rust-lang#123995 (Make `thir_tree` and `thir_flat` into hooks) - rust-lang#123998 (Opaque types have no namespace) - rust-lang#124001 (Fix docs for unstable_features lint.) - rust-lang#124006 (Move size assertions for `mir::syntax` types into the same file) - rust-lang#124011 (rustdoc: update the module-level docs of `rustdoc::clean`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4e1f5d9 + f11b21b commit 1dea922

File tree

63 files changed

+351
-221
lines changed

Some content is hidden

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

63 files changed

+351
-221
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ dependencies = [
210210

211211
[[package]]
212212
name = "ar_archive_writer"
213-
version = "0.1.5"
213+
version = "0.2.0"
214214
source = "registry+https://github.com/rust-lang/crates.io-index"
215-
checksum = "9792d37ca5173d7e7f4fe453739a0671d0557915a030a383d6b866476bbc3e71"
215+
checksum = "f0c269894b6fe5e9d7ada0cf69b5bf847ff35bc25fc271f08e1d080fce80339a"
216216
dependencies = [
217217
"object 0.32.2",
218218
]

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+64-73
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use rustc_middle::ty::{self, RegionVid, Ty};
2626
use rustc_middle::ty::{Region, TyCtxt};
2727
use rustc_span::symbol::{kw, Ident};
2828
use rustc_span::Span;
29-
use rustc_trait_selection::infer::type_variable::TypeVariableOrigin;
3029
use rustc_trait_selection::infer::InferCtxtExt;
3130
use rustc_trait_selection::traits::{Obligation, ObligationCtxt};
3231

@@ -813,7 +812,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
813812
self.add_static_impl_trait_suggestion(&mut diag, *fr, fr_name, *outlived_fr);
814813
self.suggest_adding_lifetime_params(&mut diag, *fr, *outlived_fr);
815814
self.suggest_move_on_borrowing_closure(&mut diag);
816-
self.suggest_deref_closure_value(&mut diag);
815+
self.suggest_deref_closure_return(&mut diag);
817816

818817
diag
819818
}
@@ -1048,115 +1047,107 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10481047
/// When encountering a lifetime error caused by the return type of a closure, check the
10491048
/// corresponding trait bound and see if dereferencing the closure return value would satisfy
10501049
/// them. If so, we produce a structured suggestion.
1051-
fn suggest_deref_closure_value(&self, diag: &mut Diag<'_>) {
1050+
fn suggest_deref_closure_return(&self, diag: &mut Diag<'_>) {
10521051
let tcx = self.infcx.tcx;
1053-
let map = tcx.hir();
10541052

10551053
// Get the closure return value and type.
1056-
let body_id = map.body_owned_by(self.mir_def_id());
1057-
let body = &map.body(body_id);
1058-
let value = &body.value.peel_blocks();
1059-
let hir::Node::Expr(closure_expr) = tcx.hir_node_by_def_id(self.mir_def_id()) else {
1054+
let closure_def_id = self.mir_def_id();
1055+
let hir::Node::Expr(
1056+
closure_expr @ hir::Expr {
1057+
kind: hir::ExprKind::Closure(hir::Closure { body, .. }), ..
1058+
},
1059+
) = tcx.hir_node_by_def_id(closure_def_id)
1060+
else {
10601061
return;
10611062
};
1062-
let fn_call_id = tcx.parent_hir_id(self.mir_hir_id());
1063-
let hir::Node::Expr(expr) = tcx.hir_node(fn_call_id) else { return };
1064-
let def_id = map.enclosing_body_owner(fn_call_id);
1065-
let tables = tcx.typeck(def_id);
1066-
let Some(return_value_ty) = tables.node_type_opt(value.hir_id) else { return };
1067-
let return_value_ty = self.infcx.resolve_vars_if_possible(return_value_ty);
1063+
let ty::Closure(_, args) = *tcx.type_of(closure_def_id).instantiate_identity().kind()
1064+
else {
1065+
return;
1066+
};
1067+
let args = args.as_closure();
1068+
1069+
// Make sure that the parent expression is a method call.
1070+
let parent_expr_id = tcx.parent_hir_id(self.mir_hir_id());
1071+
let hir::Node::Expr(
1072+
parent_expr @ hir::Expr {
1073+
kind: hir::ExprKind::MethodCall(_, rcvr, call_args, _), ..
1074+
},
1075+
) = tcx.hir_node(parent_expr_id)
1076+
else {
1077+
return;
1078+
};
1079+
let typeck_results = tcx.typeck(self.mir_def_id());
10681080

10691081
// We don't use `ty.peel_refs()` to get the number of `*`s needed to get the root type.
1070-
let mut ty = return_value_ty;
1082+
let liberated_sig = tcx.liberate_late_bound_regions(closure_def_id.to_def_id(), args.sig());
1083+
let mut peeled_ty = liberated_sig.output();
10711084
let mut count = 0;
1072-
while let ty::Ref(_, t, _) = ty.kind() {
1073-
ty = *t;
1085+
while let ty::Ref(_, ref_ty, _) = *peeled_ty.kind() {
1086+
peeled_ty = ref_ty;
10741087
count += 1;
10751088
}
1076-
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty) {
1089+
if !self.infcx.type_is_copy_modulo_regions(self.param_env, peeled_ty) {
10771090
return;
10781091
}
10791092

10801093
// Build a new closure where the return type is an owned value, instead of a ref.
1081-
let Some(ty::Closure(did, args)) =
1082-
tables.node_type_opt(closure_expr.hir_id).as_ref().map(|ty| ty.kind())
1083-
else {
1084-
return;
1085-
};
1086-
let sig = args.as_closure().sig();
10871094
let closure_sig_as_fn_ptr_ty = Ty::new_fn_ptr(
10881095
tcx,
1089-
sig.map_bound(|s| {
1090-
let unsafety = hir::Unsafety::Normal;
1091-
use rustc_target::spec::abi;
1092-
tcx.mk_fn_sig(
1093-
[s.inputs()[0]],
1094-
s.output().peel_refs(),
1095-
s.c_variadic,
1096-
unsafety,
1097-
abi::Abi::Rust,
1098-
)
1099-
}),
1100-
);
1101-
let parent_args = GenericArgs::identity_for_item(
1102-
tcx,
1103-
tcx.typeck_root_def_id(self.mir_def_id().to_def_id()),
1096+
ty::Binder::dummy(tcx.mk_fn_sig(
1097+
liberated_sig.inputs().iter().copied(),
1098+
peeled_ty,
1099+
liberated_sig.c_variadic,
1100+
hir::Unsafety::Normal,
1101+
rustc_target::spec::abi::Abi::Rust,
1102+
)),
11041103
);
1105-
let closure_kind = args.as_closure().kind();
1106-
let closure_kind_ty = Ty::from_closure_kind(tcx, closure_kind);
1107-
let tupled_upvars_ty = self
1108-
.infcx
1109-
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: closure_expr.span });
1110-
let closure_args = ty::ClosureArgs::new(
1104+
let closure_ty = Ty::new_closure(
11111105
tcx,
1112-
ty::ClosureArgsParts {
1113-
parent_args,
1114-
closure_kind_ty,
1115-
closure_sig_as_fn_ptr_ty,
1116-
tupled_upvars_ty,
1117-
},
1106+
closure_def_id.to_def_id(),
1107+
ty::ClosureArgs::new(
1108+
tcx,
1109+
ty::ClosureArgsParts {
1110+
parent_args: args.parent_args(),
1111+
closure_kind_ty: args.kind_ty(),
1112+
tupled_upvars_ty: args.tupled_upvars_ty(),
1113+
closure_sig_as_fn_ptr_ty,
1114+
},
1115+
)
1116+
.args,
11181117
);
1119-
let closure_ty = Ty::new_closure(tcx, *did, closure_args.args);
1120-
let closure_ty = tcx.erase_regions(closure_ty);
1121-
1122-
let hir::ExprKind::MethodCall(_, rcvr, args, _) = expr.kind else { return };
1123-
let Some(pos) = args
1124-
.iter()
1125-
.enumerate()
1126-
.find(|(_, arg)| arg.hir_id == closure_expr.hir_id)
1127-
.map(|(i, _)| i)
1118+
1119+
let Some((closure_arg_pos, _)) =
1120+
call_args.iter().enumerate().find(|(_, arg)| arg.hir_id == closure_expr.hir_id)
11281121
else {
11291122
return;
11301123
};
1131-
// The found `Self` type of the method call.
1132-
let Some(possible_rcvr_ty) = tables.node_type_opt(rcvr.hir_id) else { return };
1133-
let Some(method_def_id) = tables.type_dependent_def_id(expr.hir_id) else { return };
1134-
11351124
// Get the type for the parameter corresponding to the argument the closure with the
11361125
// lifetime error we had.
1137-
let Some(input) = tcx
1126+
let Some(method_def_id) = typeck_results.type_dependent_def_id(parent_expr.hir_id) else {
1127+
return;
1128+
};
1129+
let Some(input_arg) = tcx
11381130
.fn_sig(method_def_id)
1139-
.instantiate_identity()
1131+
.skip_binder()
11401132
.inputs()
11411133
.skip_binder()
11421134
// Methods have a `self` arg, so `pos` is actually `+ 1` to match the method call arg.
1143-
.get(pos + 1)
1135+
.get(closure_arg_pos + 1)
11441136
else {
11451137
return;
11461138
};
1147-
1148-
trace!(?input);
1149-
1150-
let ty::Param(closure_param) = input.kind() else { return };
1139+
// If this isn't a param, then we can't substitute a new closure.
1140+
let ty::Param(closure_param) = input_arg.kind() else { return };
11511141

11521142
// Get the arguments for the found method, only specifying that `Self` is the receiver type.
1143+
let Some(possible_rcvr_ty) = typeck_results.node_type_opt(rcvr.hir_id) else { return };
11531144
let args = GenericArgs::for_item(tcx, method_def_id, |param, _| {
11541145
if param.index == 0 {
11551146
possible_rcvr_ty.into()
11561147
} else if param.index == closure_param.index {
11571148
closure_ty.into()
11581149
} else {
1159-
self.infcx.var_for_def(expr.span, param)
1150+
self.infcx.var_for_def(parent_expr.span, param)
11601151
}
11611152
});
11621153

@@ -1170,7 +1161,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
11701161

11711162
if ocx.select_all_or_error().is_empty() {
11721163
diag.span_suggestion_verbose(
1173-
value.span.shrink_to_lo(),
1164+
tcx.hir().body(*body).value.peel_blocks().span.shrink_to_lo(),
11741165
"dereference the return value",
11751166
"*".repeat(count),
11761167
Applicability::MachineApplicable,

compiler/rustc_borrowck/src/region_infer/graphviz.rs

+36-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,38 @@ use std::borrow::Cow;
66
use std::io::{self, Write};
77

88
use super::*;
9+
use itertools::Itertools;
910
use rustc_graphviz as dot;
11+
use rustc_middle::ty::UniverseIndex;
12+
13+
fn render_outlives_constraint(constraint: &OutlivesConstraint<'_>) -> String {
14+
match constraint.locations {
15+
Locations::All(_) => "All(...)".to_string(),
16+
Locations::Single(loc) => format!("{loc:?}"),
17+
}
18+
}
19+
20+
fn render_universe(u: UniverseIndex) -> String {
21+
if u.is_root() {
22+
return "".to_string();
23+
}
24+
25+
format!("/{:?}", u)
26+
}
27+
28+
fn render_region_vid(rvid: RegionVid, regioncx: &RegionInferenceContext<'_>) -> String {
29+
let universe_str = render_universe(regioncx.region_definition(rvid).universe);
30+
31+
let external_name_str = if let Some(external_name) =
32+
regioncx.region_definition(rvid).external_name.and_then(|e| e.get_name())
33+
{
34+
format!(" ({external_name})")
35+
} else {
36+
"".to_string()
37+
};
38+
39+
format!("{:?}{universe_str}{external_name_str}", rvid)
40+
}
1041

1142
impl<'tcx> RegionInferenceContext<'tcx> {
1243
/// Write out the region constraint graph.
@@ -46,10 +77,10 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for RawConstraints<'a, 'tcx> {
4677
Some(dot::LabelText::LabelStr(Cow::Borrowed("box")))
4778
}
4879
fn node_label(&'this self, n: &RegionVid) -> dot::LabelText<'this> {
49-
dot::LabelText::LabelStr(format!("{n:?}").into())
80+
dot::LabelText::LabelStr(render_region_vid(*n, self.regioncx).into())
5081
}
5182
fn edge_label(&'this self, e: &OutlivesConstraint<'tcx>) -> dot::LabelText<'this> {
52-
dot::LabelText::LabelStr(format!("{:?}", e.locations).into())
83+
dot::LabelText::LabelStr(render_outlives_constraint(e).into())
5384
}
5485
}
5586

@@ -96,8 +127,9 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for SccConstraints<'a, 'tcx> {
96127
Some(dot::LabelText::LabelStr(Cow::Borrowed("box")))
97128
}
98129
fn node_label(&'this self, n: &ConstraintSccIndex) -> dot::LabelText<'this> {
99-
let nodes = &self.nodes_per_scc[*n];
100-
dot::LabelText::LabelStr(format!("{n:?} = {nodes:?}").into())
130+
let nodes_str =
131+
self.nodes_per_scc[*n].iter().map(|n| render_region_vid(*n, self.regioncx)).join(", ");
132+
dot::LabelText::LabelStr(format!("SCC({n}) = {{{nodes_str}}}", n = n.as_usize()).into())
101133
}
102134
}
103135

compiler/rustc_borrowck/src/region_infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
15621562

15631563
// Because this free region must be in the ROOT universe, we
15641564
// know it cannot contain any bound universes.
1565-
assert!(self.scc_universes[longer_fr_scc] == ty::UniverseIndex::ROOT);
1565+
assert!(self.scc_universes[longer_fr_scc].is_root());
15661566
debug_assert!(self.scc_values.placeholders_contained_in(longer_fr_scc).next().is_none());
15671567

15681568
// Only check all of the relations for the main representative of each

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
213213
let scc = self.constraint_sccs.scc(vid);
214214

215215
// Special handling of higher-ranked regions.
216-
if self.scc_universes[scc] != ty::UniverseIndex::ROOT {
216+
if !self.scc_universes[scc].is_root() {
217217
match self.scc_values.placeholders_contained_in(scc).enumerate().last() {
218218
// If the region contains a single placeholder then they're equal.
219219
Some((0, placeholder)) => {

compiler/rustc_codegen_ssa/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
ar_archive_writer = "0.1.5"
8+
ar_archive_writer = "0.2.0"
99
bitflags = "2.4.1"
1010
cc = "1.0.90"
1111
itertools = "0.12"

compiler/rustc_codegen_ssa/src/back/archive.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,7 @@ impl<'a> ArArchiveBuilder<'a> {
285285
.tempfile_in(output.parent().unwrap_or_else(|| Path::new("")))
286286
.map_err(|err| io_error_context("couldn't create a temp file", err))?;
287287

288-
write_archive_to_stream(
289-
archive_tmpfile.as_file_mut(),
290-
&entries,
291-
true,
292-
archive_kind,
293-
true,
294-
false,
295-
)?;
288+
write_archive_to_stream(archive_tmpfile.as_file_mut(), &entries, archive_kind, false)?;
296289

297290
let any_entries = !entries.is_empty();
298291
drop(entries);

compiler/rustc_codegen_ssa/src/back/link.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,7 @@ fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained:
20592059
/// Add options making relocation sections in the produced ELF files read-only
20602060
/// and suppressing lazy binding.
20612061
fn add_relro_args(cmd: &mut dyn Linker, sess: &Session) {
2062-
match sess.opts.unstable_opts.relro_level.unwrap_or(sess.target.relro_level) {
2062+
match sess.opts.cg.relro_level.unwrap_or(sess.target.relro_level) {
20632063
RelroLevel::Full => cmd.full_relro(),
20642064
RelroLevel::Partial => cmd.partial_relro(),
20652065
RelroLevel::Off => cmd.no_relro(),
@@ -3038,9 +3038,10 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, errors::AppleSdkRootErro
30383038
|| sdkroot.contains("MacOSX.platform") => {}
30393039
"watchsimulator"
30403040
if sdkroot.contains("WatchOS.platform") || sdkroot.contains("MacOSX.platform") => {}
3041-
"visionos"
3042-
if sdkroot.contains("XROS.platform") || sdkroot.contains("MacOSX.platform") => {}
3043-
"visionossimulator"
3041+
"xros"
3042+
if sdkroot.contains("XRSimulator.platform")
3043+
|| sdkroot.contains("MacOSX.platform") => {}
3044+
"xrsimulator"
30443045
if sdkroot.contains("XROS.platform") || sdkroot.contains("MacOSX.platform") => {}
30453046
// Ignore `SDKROOT` if it's not a valid path.
30463047
_ if !p.is_absolute() || p == Path::new("/") || !p.exists() => {}

compiler/rustc_hir/src/def.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ impl DefKind {
207207
| DefKind::Enum
208208
| DefKind::Variant
209209
| DefKind::Trait
210-
| DefKind::OpaqueTy
211210
| DefKind::TyAlias
212211
| DefKind::ForeignTy
213212
| DefKind::TraitAlias
@@ -234,7 +233,8 @@ impl DefKind {
234233
| DefKind::Use
235234
| DefKind::ForeignMod
236235
| DefKind::GlobalAsm
237-
| DefKind::Impl { .. } => None,
236+
| DefKind::Impl { .. }
237+
| DefKind::OpaqueTy => None,
238238
}
239239
}
240240

compiler/rustc_interface/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ fn test_codegen_options_tracking_hash() {
624624
tracked!(profile_generate, SwitchWithOptPath::Enabled(None));
625625
tracked!(profile_use, Some(PathBuf::from("abc")));
626626
tracked!(relocation_model, Some(RelocModel::Pic));
627+
tracked!(relro_level, Some(RelroLevel::Full));
627628
tracked!(soft_float, true);
628629
tracked!(split_debuginfo, Some(SplitDebuginfo::Packed));
629630
tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0));
@@ -822,7 +823,6 @@ fn test_unstable_options_tracking_hash() {
822823
tracked!(profile_sample_use, Some(PathBuf::from("abc")));
823824
tracked!(profiler_runtime, "abc".to_string());
824825
tracked!(relax_elf_relocations, Some(true));
825-
tracked!(relro_level, Some(RelroLevel::Full));
826826
tracked!(remap_cwd_prefix, Some(PathBuf::from("abc")));
827827
tracked!(sanitizer, SanitizerSet::ADDRESS);
828828
tracked!(sanitizer_cfi_canonical_jump_tables, None);

compiler/rustc_middle/src/hooks/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,10 @@ declare_hooks! {
102102
/// turn a deserialized `DefPathHash` into its current `DefId`.
103103
/// Will fetch a DefId from a DefPathHash for a foreign crate.
104104
hook def_path_hash_to_def_id_extern(hash: DefPathHash, stable_crate_id: StableCrateId) -> DefId;
105+
106+
/// Create a THIR tree for debugging.
107+
hook thir_tree(key: LocalDefId) -> String;
108+
109+
/// Create a list-like THIR representation for debugging.
110+
hook thir_flat(key: LocalDefId) -> String;
105111
}

0 commit comments

Comments
 (0)