Auto merge of #129076 - matthiaskrgr:rollup-rg8mi2x, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #128410 (Migrate `remap-path-prefix-dwarf` `run-make` test to rmake) - #128759 (alloc: add ToString specialization for `&&str`) - #128873 (Add windows-targets crate to std's sysroot) - #129001 (chore(lib): Enhance documentation for core::fmt::Formatter's write_fm…) - #129061 (Use `is_lang_item` more) - #129062 (Remove a no-longer-true assert) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
9859bf27fd
38 changed files with 543 additions and 261 deletions
|
@ -4,6 +4,7 @@ use rustc_hir as hir;
|
|||
use rustc_hir::def::DefKind;
|
||||
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
|
||||
use rustc_middle::ty::print::{FmtPrinter, Printer};
|
||||
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty};
|
||||
use rustc_span::def_id::DefId;
|
||||
|
@ -313,11 +314,15 @@ impl<T> Trait<T> for X {
|
|||
(ty::Dynamic(t, _, ty::DynKind::Dyn), _)
|
||||
if let Some(def_id) = t.principal_def_id() =>
|
||||
{
|
||||
let mut impl_def_ids = vec![];
|
||||
let mut has_matching_impl = false;
|
||||
tcx.for_each_relevant_impl(def_id, values.found, |did| {
|
||||
impl_def_ids.push(did)
|
||||
if DeepRejectCtxt::new(tcx, TreatParams::ForLookup)
|
||||
.types_may_unify(values.found, tcx.type_of(did).skip_binder())
|
||||
{
|
||||
has_matching_impl = true;
|
||||
}
|
||||
});
|
||||
if let [_] = &impl_def_ids[..] {
|
||||
if has_matching_impl {
|
||||
let trait_name = tcx.item_name(def_id);
|
||||
diag.help(format!(
|
||||
"`{}` implements `{trait_name}` so you could box the found value \
|
||||
|
@ -330,11 +335,15 @@ impl<T> Trait<T> for X {
|
|||
(_, ty::Dynamic(t, _, ty::DynKind::Dyn))
|
||||
if let Some(def_id) = t.principal_def_id() =>
|
||||
{
|
||||
let mut impl_def_ids = vec![];
|
||||
let mut has_matching_impl = false;
|
||||
tcx.for_each_relevant_impl(def_id, values.expected, |did| {
|
||||
impl_def_ids.push(did)
|
||||
if DeepRejectCtxt::new(tcx, TreatParams::ForLookup)
|
||||
.types_may_unify(values.expected, tcx.type_of(did).skip_binder())
|
||||
{
|
||||
has_matching_impl = true;
|
||||
}
|
||||
});
|
||||
if let [_] = &impl_def_ids[..] {
|
||||
if has_matching_impl {
|
||||
let trait_name = tcx.item_name(def_id);
|
||||
diag.help(format!(
|
||||
"`{}` implements `{trait_name}` so you could change the expected \
|
||||
|
@ -346,11 +355,15 @@ impl<T> Trait<T> for X {
|
|||
(ty::Dynamic(t, _, ty::DynKind::DynStar), _)
|
||||
if let Some(def_id) = t.principal_def_id() =>
|
||||
{
|
||||
let mut impl_def_ids = vec![];
|
||||
let mut has_matching_impl = false;
|
||||
tcx.for_each_relevant_impl(def_id, values.found, |did| {
|
||||
impl_def_ids.push(did)
|
||||
if DeepRejectCtxt::new(tcx, TreatParams::ForLookup)
|
||||
.types_may_unify(values.found, tcx.type_of(did).skip_binder())
|
||||
{
|
||||
has_matching_impl = true;
|
||||
}
|
||||
});
|
||||
if let [_] = &impl_def_ids[..] {
|
||||
if has_matching_impl {
|
||||
let trait_name = tcx.item_name(def_id);
|
||||
diag.help(format!(
|
||||
"`{}` implements `{trait_name}`, `#[feature(dyn_star)]` is likely \
|
||||
|
|
|
@ -230,8 +230,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
post_message,
|
||||
);
|
||||
|
||||
let (err_msg, safe_transmute_explanation) = if Some(main_trait_ref.def_id())
|
||||
== self.tcx.lang_items().transmute_trait()
|
||||
let (err_msg, safe_transmute_explanation) = if self.tcx.is_lang_item(main_trait_ref.def_id(), LangItem::TransmuteTrait)
|
||||
{
|
||||
// Recompute the safe transmute reason and use that for the error reporting
|
||||
match self.get_safe_transmute_error_and_reason(
|
||||
|
|
|
@ -2831,7 +2831,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
// Do not suggest relaxing if there is an explicit `Sized` obligation.
|
||||
&& !bounds.iter()
|
||||
.filter_map(|bound| bound.trait_ref())
|
||||
.any(|tr| tr.trait_def_id() == tcx.lang_items().sized_trait())
|
||||
.any(|tr| tr.trait_def_id().is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Sized)))
|
||||
{
|
||||
let (span, separator) = if let [.., last] = bounds {
|
||||
(last.span().shrink_to_hi(), " +")
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use rustc_hir::LangItem;
|
||||
use rustc_infer::traits::Obligation;
|
||||
pub use rustc_middle::traits::query::type_op::ProvePredicate;
|
||||
use rustc_middle::traits::query::NoSolution;
|
||||
|
@ -20,8 +21,7 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
|
|||
// such cases.
|
||||
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_ref)) =
|
||||
key.value.predicate.kind().skip_binder()
|
||||
&& let Some(sized_def_id) = tcx.lang_items().sized_trait()
|
||||
&& trait_ref.def_id() == sized_def_id
|
||||
&& tcx.is_lang_item(trait_ref.def_id(), LangItem::Sized)
|
||||
&& trait_ref.self_ty().is_trivially_sized(tcx)
|
||||
{
|
||||
return Some(());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue