Skip to content

Commit 9f4d5d2

Browse files
committed
Auto merge of #101167 - matthiaskrgr:rollup-yt3jdmp, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #100898 (Do not report too many expr field candidates) - #101056 (Add the syntax of references to their documentation summary.) - #101106 (Rustdoc-Json: Retain Stripped Modules when they are imported, not when they have items) - #101131 (CTFE: exposing pointers and calling extern fn is just impossible) - #101141 (Simplify `get_trait_ref` fn used for `virtual_function_elimination`) - #101146 (Various changes to logging of borrowck-related code) - #101156 (Remove `Sync` requirement from lint pass objects) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents bc4b39c + bf42ba4 commit 9f4d5d2

Some content is hidden

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

42 files changed

+341
-202
lines changed

compiler/rustc_borrowck/src/constraints/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ impl<'tcx> fmt::Debug for OutlivesConstraint<'tcx> {
105105
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
106106
write!(
107107
formatter,
108-
"({:?}: {:?}) due to {:?} ({:?})",
109-
self.sup, self.sub, self.locations, self.variance_info
108+
"({:?}: {:?}) due to {:?} ({:?}) ({:?})",
109+
self.sup, self.sub, self.locations, self.variance_info, self.category,
110110
)
111111
}
112112
}

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -1119,20 +1119,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11191119
/// short a lifetime. (But sometimes it is more useful to report
11201120
/// it as a more direct conflict between the execution of a
11211121
/// `Drop::drop` with an aliasing borrow.)
1122+
#[instrument(level = "debug", skip(self))]
11221123
pub(crate) fn report_borrowed_value_does_not_live_long_enough(
11231124
&mut self,
11241125
location: Location,
11251126
borrow: &BorrowData<'tcx>,
11261127
place_span: (Place<'tcx>, Span),
11271128
kind: Option<WriteKind>,
11281129
) {
1129-
debug!(
1130-
"report_borrowed_value_does_not_live_long_enough(\
1131-
{:?}, {:?}, {:?}, {:?}\
1132-
)",
1133-
location, borrow, place_span, kind
1134-
);
1135-
11361130
let drop_span = place_span.1;
11371131
let root_place =
11381132
self.prefixes(borrow.borrowed_place.as_ref(), PrefixSet::All).last().unwrap();
@@ -1189,10 +1183,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11891183
let kind_place = kind.filter(|_| place_desc.is_some()).map(|k| (k, place_span.0));
11901184
let explanation = self.explain_why_borrow_contains_point(location, &borrow, kind_place);
11911185

1192-
debug!(
1193-
"report_borrowed_value_does_not_live_long_enough(place_desc: {:?}, explanation: {:?})",
1194-
place_desc, explanation
1195-
);
1186+
debug!(?place_desc, ?explanation);
1187+
11961188
let err = match (place_desc, explanation) {
11971189
// If the outlives constraint comes from inside the closure,
11981190
// for example:
@@ -1464,6 +1456,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14641456
err
14651457
}
14661458

1459+
#[instrument(level = "debug", skip(self))]
14671460
fn report_temporary_value_does_not_live_long_enough(
14681461
&mut self,
14691462
location: Location,
@@ -1473,13 +1466,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14731466
proper_span: Span,
14741467
explanation: BorrowExplanation<'tcx>,
14751468
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
1476-
debug!(
1477-
"report_temporary_value_does_not_live_long_enough(\
1478-
{:?}, {:?}, {:?}, {:?}\
1479-
)",
1480-
location, borrow, drop_span, proper_span
1481-
);
1482-
14831469
if let BorrowExplanation::MustBeValidFor { category, span, from_closure: false, .. } =
14841470
explanation
14851471
{

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+5-15
Original file line numberDiff line numberDiff line change
@@ -336,26 +336,22 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
336336
/// - second half is the place being accessed
337337
///
338338
/// [d]: https://rust-lang.github.io/rfcs/2094-nll.html#leveraging-intuition-framing-errors-in-terms-of-points
339+
#[instrument(level = "debug", skip(self))]
339340
pub(crate) fn explain_why_borrow_contains_point(
340341
&self,
341342
location: Location,
342343
borrow: &BorrowData<'tcx>,
343344
kind_place: Option<(WriteKind, Place<'tcx>)>,
344345
) -> BorrowExplanation<'tcx> {
345-
debug!(
346-
"explain_why_borrow_contains_point(location={:?}, borrow={:?}, kind_place={:?})",
347-
location, borrow, kind_place
348-
);
349-
350346
let regioncx = &self.regioncx;
351347
let body: &Body<'_> = &self.body;
352348
let tcx = self.infcx.tcx;
353349

354350
let borrow_region_vid = borrow.region;
355-
debug!("explain_why_borrow_contains_point: borrow_region_vid={:?}", borrow_region_vid);
351+
debug!(?borrow_region_vid);
356352

357353
let region_sub = self.regioncx.find_sub_region_live_at(borrow_region_vid, location);
358-
debug!("explain_why_borrow_contains_point: region_sub={:?}", region_sub);
354+
debug!(?region_sub);
359355

360356
match find_use::find(body, regioncx, tcx, region_sub, location) {
361357
Some(Cause::LiveVar(local, location)) => {
@@ -408,17 +404,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
408404
opt_place_desc,
409405
}
410406
} else {
411-
debug!(
412-
"explain_why_borrow_contains_point: \
413-
Could not generate a region name"
414-
);
407+
debug!("Could not generate a region name");
415408
BorrowExplanation::Unexplained
416409
}
417410
} else {
418-
debug!(
419-
"explain_why_borrow_contains_point: \
420-
Could not generate an error region vid"
421-
);
411+
debug!("Could not generate an error region vid");
422412
BorrowExplanation::Unexplained
423413
}
424414
}

compiler/rustc_borrowck/src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
975975
}
976976
}
977977

978+
#[instrument(level = "debug", skip(self, flow_state))]
978979
fn check_access_for_conflict(
979980
&mut self,
980981
location: Location,
@@ -983,11 +984,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
983984
rw: ReadOrWrite,
984985
flow_state: &Flows<'cx, 'tcx>,
985986
) -> bool {
986-
debug!(
987-
"check_access_for_conflict(location={:?}, place_span={:?}, sd={:?}, rw={:?})",
988-
location, place_span, sd, rw,
989-
);
990-
991987
let mut error_reported = false;
992988
let tcx = self.infcx.tcx;
993989
let body = self.body;
@@ -1451,13 +1447,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14511447

14521448
/// Checks whether a borrow of this place is invalidated when the function
14531449
/// exits
1450+
#[instrument(level = "debug", skip(self))]
14541451
fn check_for_invalidation_at_exit(
14551452
&mut self,
14561453
location: Location,
14571454
borrow: &BorrowData<'tcx>,
14581455
span: Span,
14591456
) {
1460-
debug!("check_for_invalidation_at_exit({:?})", borrow);
14611457
let place = borrow.borrowed_place;
14621458
let mut root_place = PlaceRef { local: place.local, projection: &[] };
14631459

compiler/rustc_borrowck/src/places_conflict.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub(crate) fn places_conflict<'tcx>(
4444
/// access depth. The `bias` parameter is used to determine how the unknowable (comparing runtime
4545
/// array indices, for example) should be interpreted - this depends on what the caller wants in
4646
/// order to make the conservative choice and preserve soundness.
47+
#[instrument(level = "debug", skip(tcx, body))]
4748
pub(super) fn borrow_conflicts_with_place<'tcx>(
4849
tcx: TyCtxt<'tcx>,
4950
body: &Body<'tcx>,
@@ -53,11 +54,6 @@ pub(super) fn borrow_conflicts_with_place<'tcx>(
5354
access: AccessDepth,
5455
bias: PlaceConflictBias,
5556
) -> bool {
56-
debug!(
57-
"borrow_conflicts_with_place({:?}, {:?}, {:?}, {:?})",
58-
borrow_place, access_place, access, bias,
59-
);
60-
6157
// This Local/Local case is handled by the more general code below, but
6258
// it's so common that it's a speed win to check for it first.
6359
if let Some(l1) = borrow_place.as_local() && let Some(l2) = access_place.as_local() {
@@ -140,10 +136,9 @@ fn place_components_conflict<'tcx>(
140136
for (i, (borrow_c, &access_c)) in
141137
iter::zip(borrow_place.projection, access_place.projection).enumerate()
142138
{
143-
debug!("borrow_conflicts_with_place: borrow_c = {:?}", borrow_c);
144-
let borrow_proj_base = &borrow_place.projection[..i];
139+
debug!(?borrow_c, ?access_c);
145140

146-
debug!("borrow_conflicts_with_place: access_c = {:?}", access_c);
141+
let borrow_proj_base = &borrow_place.projection[..i];
147142

148143
// Borrow and access path both have more components.
149144
//
@@ -180,7 +175,7 @@ fn place_components_conflict<'tcx>(
180175
// idea, at least for now, so just give up and
181176
// report a conflict. This is unsafe code anyway so
182177
// the user could always use raw pointers.
183-
debug!("borrow_conflicts_with_place: arbitrary -> conflict");
178+
debug!("arbitrary -> conflict");
184179
return true;
185180
}
186181
Overlap::EqualOrDisjoint => {
@@ -189,7 +184,7 @@ fn place_components_conflict<'tcx>(
189184
Overlap::Disjoint => {
190185
// We have proven the borrow disjoint - further
191186
// projections will remain disjoint.
192-
debug!("borrow_conflicts_with_place: disjoint");
187+
debug!("disjoint");
193188
return false;
194189
}
195190
}

compiler/rustc_borrowck/src/region_infer/mod.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -1167,8 +1167,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11671167
/// Therefore, this method should only be used in diagnostic code,
11681168
/// where displaying *some* named universal region is better than
11691169
/// falling back to 'static.
1170+
#[instrument(level = "debug", skip(self))]
11701171
pub(crate) fn approx_universal_upper_bound(&self, r: RegionVid) -> RegionVid {
1171-
debug!("approx_universal_upper_bound(r={:?}={})", r, self.region_value_str(r));
1172+
debug!("{}", self.region_value_str(r));
11721173

11731174
// Find the smallest universal region that contains all other
11741175
// universal regions within `region`.
@@ -1177,7 +1178,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11771178
let static_r = self.universal_regions.fr_static;
11781179
for ur in self.scc_values.universal_regions_outlived_by(r_scc) {
11791180
let new_lub = self.universal_region_relations.postdom_upper_bound(lub, ur);
1180-
debug!("approx_universal_upper_bound: ur={:?} lub={:?} new_lub={:?}", ur, lub, new_lub);
1181+
debug!(?ur, ?lub, ?new_lub);
11811182
// The upper bound of two non-static regions is static: this
11821183
// means we know nothing about the relationship between these
11831184
// two regions. Pick a 'better' one to use when constructing
@@ -1201,7 +1202,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12011202
}
12021203
}
12031204

1204-
debug!("approx_universal_upper_bound: r={:?} lub={:?}", r, lub);
1205+
debug!(?r, ?lub);
12051206

12061207
lub
12071208
}
@@ -2048,23 +2049,19 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20482049
/// creating a constraint path that forces `R` to outlive
20492050
/// `from_region`, and then finding the best choices within that
20502051
/// path to blame.
2052+
#[instrument(level = "debug", skip(self, target_test))]
20512053
pub(crate) fn best_blame_constraint(
20522054
&self,
20532055
body: &Body<'tcx>,
20542056
from_region: RegionVid,
20552057
from_region_origin: NllRegionVariableOrigin,
20562058
target_test: impl Fn(RegionVid) -> bool,
20572059
) -> BlameConstraint<'tcx> {
2058-
debug!(
2059-
"best_blame_constraint(from_region={:?}, from_region_origin={:?})",
2060-
from_region, from_region_origin
2061-
);
2062-
20632060
// Find all paths
20642061
let (path, target_region) =
20652062
self.find_constraint_paths_between_regions(from_region, target_test).unwrap();
20662063
debug!(
2067-
"best_blame_constraint: path={:#?}",
2064+
"path={:#?}",
20682065
path.iter()
20692066
.map(|c| format!(
20702067
"{:?} ({:?}: {:?})",
@@ -2116,7 +2113,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21162113
}
21172114
})
21182115
.collect();
2119-
debug!("best_blame_constraint: categorized_path={:#?}", categorized_path);
2116+
debug!("categorized_path={:#?}", categorized_path);
21202117

21212118
// To find the best span to cite, we first try to look for the
21222119
// final constraint that is interesting and where the `sup` is
@@ -2214,10 +2211,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22142211
let best_choice =
22152212
if blame_source { range.rev().find(find_region) } else { range.find(find_region) };
22162213

2217-
debug!(
2218-
"best_blame_constraint: best_choice={:?} blame_source={}",
2219-
best_choice, blame_source
2220-
);
2214+
debug!(?best_choice, ?blame_source);
22212215

22222216
if let Some(i) = best_choice {
22232217
if let Some(next) = categorized_path.get(i + 1) {
@@ -2254,7 +2248,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22542248
// appears to be the most interesting point to report to the
22552249
// user via an even more ad-hoc guess.
22562250
categorized_path.sort_by(|p0, p1| p0.category.cmp(&p1.category));
2257-
debug!("best_blame_constraint: sorted_path={:#?}", categorized_path);
2251+
debug!("sorted_path={:#?}", categorized_path);
22582252

22592253
categorized_path.remove(0)
22602254
}

compiler/rustc_borrowck/src/type_check/canonical.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2424
/// **Any `rustc_infer::infer` operations that might generate region
2525
/// constraints should occur within this method so that those
2626
/// constraints can be properly localized!**
27-
#[instrument(skip(self, category, op), level = "trace")]
27+
#[instrument(skip(self, op), level = "trace")]
2828
pub(super) fn fully_perform_op<R, Op>(
2929
&mut self,
3030
locations: Locations,

compiler/rustc_borrowck/src/type_check/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10431043
let CanonicalUserTypeAnnotation { span, ref user_ty, inferred_ty } = *user_annotation;
10441044
let inferred_ty = self.normalize(inferred_ty, Locations::All(span));
10451045
let annotation = self.instantiate_canonical_with_fresh_inference_vars(span, user_ty);
1046+
debug!(?annotation);
10461047
match annotation {
10471048
UserType::Ty(mut ty) => {
10481049
ty = self.normalize(ty, Locations::All(span));

compiler/rustc_codegen_ssa/src/meth.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::traits::*;
22

3-
use rustc_middle::ty::{self, subst::GenericArgKind, ExistentialPredicate, Ty, TyCtxt};
3+
use rustc_middle::ty::{self, subst::GenericArgKind, Ty};
44
use rustc_session::config::Lto;
55
use rustc_symbol_mangling::typeid_for_trait_ref;
66
use rustc_target::abi::call::FnAbi;
@@ -29,7 +29,7 @@ impl<'a, 'tcx> VirtualIndex {
2929
&& bx.cx().sess().lto() == Lto::Fat
3030
{
3131
let typeid =
32-
bx.typeid_metadata(typeid_for_trait_ref(bx.tcx(), get_trait_ref(bx.tcx(), ty)));
32+
bx.typeid_metadata(typeid_for_trait_ref(bx.tcx(), expect_dyn_trait_in_self(ty)));
3333
let vtable_byte_offset = self.0 * bx.data_layout().pointer_size.bytes();
3434
let type_checked_load = bx.type_checked_load(llvtable, vtable_byte_offset, typeid);
3535
let func = bx.extract_value(type_checked_load, 0);
@@ -64,17 +64,13 @@ impl<'a, 'tcx> VirtualIndex {
6464
}
6565
}
6666

67-
fn get_trait_ref<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::PolyExistentialTraitRef<'tcx> {
67+
/// This takes a valid `self` receiver type and extracts the principal trait
68+
/// ref of the type.
69+
fn expect_dyn_trait_in_self<'tcx>(ty: Ty<'tcx>) -> ty::PolyExistentialTraitRef<'tcx> {
6870
for arg in ty.peel_refs().walk() {
6971
if let GenericArgKind::Type(ty) = arg.unpack() {
70-
if let ty::Dynamic(trait_refs, _) = ty.kind() {
71-
return trait_refs[0].map_bound(|trait_ref| match trait_ref {
72-
ExistentialPredicate::Trait(tr) => tr,
73-
ExistentialPredicate::Projection(proj) => proj.trait_ref(tcx),
74-
ExistentialPredicate::AutoTrait(_) => {
75-
bug!("auto traits don't have functions")
76-
}
77-
});
72+
if let ty::Dynamic(data, _) = ty.kind() {
73+
return data.principal().expect("expected principal trait object");
7874
}
7975
}
8076
}

compiler/rustc_const_eval/src/const_eval/error.rs

-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::interpret::{
1515
/// The CTFE machine has some custom error kinds.
1616
#[derive(Clone, Debug)]
1717
pub enum ConstEvalErrKind {
18-
NeedsRfc(String),
1918
ConstAccessesStatic,
2019
ModifiedGlobal,
2120
AssertFailure(AssertKind<ConstInt>),
@@ -42,9 +41,6 @@ impl fmt::Display for ConstEvalErrKind {
4241
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4342
use self::ConstEvalErrKind::*;
4443
match *self {
45-
NeedsRfc(ref msg) => {
46-
write!(f, "\"{}\" needs an rfc before being allowed inside constants", msg)
47-
}
4844
ConstAccessesStatic => write!(f, "constant accesses static"),
4945
ModifiedGlobal => {
5046
write!(f, "modifying a static's initial value from another static's initializer")

0 commit comments

Comments
 (0)