Skip to content

Commit c884ecf

Browse files
committed
Auto merge of #166182 - JonathanBrouwer:rollup-yfOUPW4, r=JonathanBrouwer
Rollup of 6 pull requests Successful merges: - #165943 (Tweak "missing method on type available here" diagnostic) - #165321 (Add examples to Allocator methods) - #165851 (fix ICE when confirming invalid dyn method receivers) - #166146 (Remove `#[allow(missing_docs)]` where possible) - #166165 (Fix spurious parallel frontend test failure + Fix link) - #166172 (Remove dead size assertion)
2 parents b0b6006 + 72def63 commit c884ecf

53 files changed

Lines changed: 689 additions & 205 deletions

File tree

Some content is hidden

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

‎compiler/rustc_hir_typeck/src/method/confirm.rs‎

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -333,27 +333,32 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
333333
return ty::GenericArgs::extend_with_error(self.tcx, trait_def_id, &[]);
334334
}
335335

336-
self.extract_existential_trait_ref(self_ty, |this, object_ty, principal| {
337-
// The object data has no entry for the Self
338-
// Type. For the purposes of this method call, we
339-
// instantiate the object type itself. This
340-
// wouldn't be a sound instantiation in all cases,
341-
// since each instance of the object type is a
342-
// different existential and hence could match
343-
// distinct types (e.g., if `Self` appeared as an
344-
// argument type), but those cases have already
345-
// been ruled out when we deemed the trait to be
346-
// "dyn-compatible".
347-
let original_poly_trait_ref = principal.with_self_ty(this.tcx, object_ty);
348-
let upcast_poly_trait_ref = this.upcast(original_poly_trait_ref, trait_def_id);
349-
let upcast_trait_ref =
350-
this.instantiate_binder_with_fresh_vars(upcast_poly_trait_ref);
351-
debug!(
352-
"original_poly_trait_ref={:?} upcast_trait_ref={:?} target_trait={:?}",
353-
original_poly_trait_ref, upcast_trait_ref, trait_def_id
354-
);
355-
upcast_trait_ref.args
356-
})
336+
self.extract_existential_trait_ref(
337+
self_ty,
338+
trait_def_id,
339+
|this, object_ty, principal| {
340+
// The object data has no entry for the Self
341+
// Type. For the purposes of this method call, we
342+
// instantiate the object type itself. This
343+
// wouldn't be a sound instantiation in all cases,
344+
// since each instance of the object type is a
345+
// different existential and hence could match
346+
// distinct types (e.g., if `Self` appeared as an
347+
// argument type), but those cases have already
348+
// been ruled out when we deemed the trait to be
349+
// "dyn-compatible".
350+
let original_poly_trait_ref = principal.with_self_ty(this.tcx, object_ty);
351+
let upcast_poly_trait_ref =
352+
this.upcast(original_poly_trait_ref, trait_def_id);
353+
let upcast_trait_ref =
354+
this.instantiate_binder_with_fresh_vars(upcast_poly_trait_ref);
355+
debug!(
356+
"original_poly_trait_ref={:?} upcast_trait_ref={:?} target_trait={:?}",
357+
original_poly_trait_ref, upcast_trait_ref, trait_def_id
358+
);
359+
upcast_trait_ref.args
360+
},
361+
)
357362
}
358363

359364
probe::TraitPick { .. } => {
@@ -375,9 +380,18 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
375380
}
376381
}
377382

378-
fn extract_existential_trait_ref<R, F>(&mut self, self_ty: Ty<'tcx>, mut closure: F) -> R
383+
fn extract_existential_trait_ref<F>(
384+
&mut self,
385+
self_ty: Ty<'tcx>,
386+
trait_def_id: DefId,
387+
mut closure: F,
388+
) -> GenericArgs<'tcx>
379389
where
380-
F: FnMut(&mut ConfirmContext<'a, 'tcx>, Ty<'tcx>, ty::PolyExistentialTraitRef<'tcx>) -> R,
390+
F: FnMut(
391+
&mut ConfirmContext<'a, 'tcx>,
392+
Ty<'tcx>,
393+
ty::PolyExistentialTraitRef<'tcx>,
394+
) -> GenericArgs<'tcx>,
381395
{
382396
// If we specified that this is an object method, then the
383397
// self-type ought to be something that can be dereferenced to
@@ -407,11 +421,11 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
407421
_ => None,
408422
})
409423
.unwrap_or_else(|| {
410-
span_bug!(
424+
self.dcx().span_delayed_bug(
411425
self.span,
412-
"self-type `{}` for ObjectPick never dereferenced to an object",
413-
self_ty
414-
)
426+
format!("self-type `{self_ty}` for ObjectPick never dereferenced to an object"),
427+
);
428+
ty::GenericArgs::extend_with_error(self.tcx, trait_def_id, &[])
415429
})
416430
}
417431

‎compiler/rustc_hir_typeck/src/method/probe.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,7 @@ impl<'tcx> Pick<'tcx> {
19131913
// the code from `report_method_error()`.
19141914
lint.help(format!(
19151915
"call with fully qualified syntax `{}(...)` to keep using the current \
1916-
method",
1916+
method",
19171917
tcx.def_path_str(this.item.def_id),
19181918
));
19191919
}

0 commit comments

Comments
 (0)