Skip to content

Commit 7a6af27

Browse files
committed
Auto merge of #105760 - matthiaskrgr:rollup-r8beo9w, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #105481 (Start improving monomorphization items stats) - #105674 (Point at method chains on `E0271` errors) - #105679 (Suggest constraining type parameter with `Clone`) - #105694 (Don't create dummy if val has escaping bounds var) - #105727 (Tweak output for bare `dyn Trait` in arguments) - #105739 (Migrate Jump to def links background to CSS variable) - #105743 (`SimplifiedType` cleanups) - #105758 (Move `TypeckResults` to separate module) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ec56537 + 2e03ff1 commit 7a6af27

File tree

64 files changed

+1345
-996
lines changed

Some content is hidden

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

64 files changed

+1345
-996
lines changed

compiler/rustc_error_messages/locales/en-US/monomorphize.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ monomorphize_large_assignments =
2121
moving {$size} bytes
2222
.label = value moved from here
2323
.note = The current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
24+
25+
monomorphize_couldnt_dump_mono_stats =
26+
unexpected error occurred while dumping monomorphization stats: {$error}

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use rustc_hir_analysis::astconv::AstConv;
1313
use rustc_infer::infer;
1414
use rustc_infer::traits::{self, StatementAsExpression};
1515
use rustc_middle::lint::in_external_macro;
16-
use rustc_middle::ty::{self, Binder, DefIdTree, IsSuggestable, Ty};
16+
use rustc_middle::ty::{
17+
self, suggest_constraining_type_params, Binder, DefIdTree, IsSuggestable, ToPredicate, Ty,
18+
};
1719
use rustc_session::errors::ExprParenthesesNeeded;
1820
use rustc_span::symbol::sym;
1921
use rustc_span::Span;
@@ -1276,15 +1278,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12761278
&& !results.expr_adjustments(callee_expr).iter().any(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(..)))
12771279
// Check that we're in fact trying to clone into the expected type
12781280
&& self.can_coerce(*pointee_ty, expected_ty)
1281+
&& let trait_ref = ty::Binder::dummy(self.tcx.mk_trait_ref(clone_trait_did, [expected_ty]))
12791282
// And the expected type doesn't implement `Clone`
12801283
&& !self.predicate_must_hold_considering_regions(&traits::Obligation::new(
12811284
self.tcx,
12821285
traits::ObligationCause::dummy(),
12831286
self.param_env,
1284-
ty::Binder::dummy(self.tcx.mk_trait_ref(
1285-
clone_trait_did,
1286-
[expected_ty],
1287-
)),
1287+
trait_ref,
12881288
))
12891289
{
12901290
diag.span_note(
@@ -1293,6 +1293,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12931293
"`{expected_ty}` does not implement `Clone`, so `{found_ty}` was cloned instead"
12941294
),
12951295
);
1296+
let owner = self.tcx.hir().enclosing_body_owner(expr.hir_id);
1297+
if let ty::Param(param) = expected_ty.kind()
1298+
&& let Some(generics) = self.tcx.hir().get_generics(owner)
1299+
{
1300+
suggest_constraining_type_params(
1301+
self.tcx,
1302+
generics,
1303+
diag,
1304+
vec![(param.name.as_str(), "Clone", Some(clone_trait_did))].into_iter(),
1305+
);
1306+
} else {
1307+
self.suggest_derive(diag, &[(trait_ref.to_predicate(self.tcx), None, None)]);
1308+
}
12961309
}
12971310
}
12981311

compiler/rustc_hir_typeck/src/method/suggest.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin
2525
use rustc_middle::traits::util::supertraits;
2626
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
2727
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
28-
use rustc_middle::ty::print::with_crate_prefix;
28+
use rustc_middle::ty::print::{with_crate_prefix, with_forced_trimmed_paths};
2929
use rustc_middle::ty::{self, DefIdTree, GenericArgKind, Ty, TyCtxt, TypeVisitable};
3030
use rustc_middle::ty::{IsSuggestable, ToPolyTraitRef};
3131
use rustc_span::symbol::{kw, sym, Ident};
@@ -270,7 +270,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
270270
let tcx = self.tcx;
271271

272272
let rcvr_ty = self.resolve_vars_if_possible(rcvr_ty);
273-
let ty_str = self.ty_to_string(rcvr_ty);
273+
let ty_str = with_forced_trimmed_paths!(self.ty_to_string(rcvr_ty));
274274
let is_method = mode == Mode::MethodCall;
275275
let item_kind = if is_method {
276276
"method"
@@ -563,7 +563,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
563563
let term = pred.skip_binder().term;
564564

565565
let obligation = format!("{} = {}", projection_ty, term);
566-
let quiet = format!("{} = {}", quiet_projection_ty, term);
566+
let quiet = with_forced_trimmed_paths!(format!(
567+
"{} = {}",
568+
quiet_projection_ty, term
569+
));
567570

568571
bound_span_label(projection_ty.self_ty(), &obligation, &quiet);
569572
Some((obligation, projection_ty.self_ty()))
@@ -573,7 +576,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
573576
let self_ty = p.self_ty();
574577
let path = p.print_only_trait_path();
575578
let obligation = format!("{}: {}", self_ty, path);
576-
let quiet = format!("_: {}", path);
579+
let quiet = with_forced_trimmed_paths!(format!("_: {}", path));
577580
bound_span_label(self_ty, &obligation, &quiet);
578581
Some((obligation, self_ty))
579582
}
@@ -796,7 +799,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
796799
(None, None)
797800
};
798801
let primary_message = primary_message.unwrap_or_else(|| format!(
799-
"the {item_kind} `{item_name}` exists for {actual_prefix} `{ty_str}`, but its trait bounds were not satisfied"
802+
"the {item_kind} `{item_name}` exists for {actual_prefix} `{ty_str}`, \
803+
but its trait bounds were not satisfied"
800804
));
801805
err.set_primary_message(&primary_message);
802806
if let Some(label) = label {
@@ -1848,7 +1852,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18481852
self.suggest_derive(err, &preds);
18491853
}
18501854

1851-
fn suggest_derive(
1855+
pub fn suggest_derive(
18521856
&self,
18531857
err: &mut Diagnostic,
18541858
unsatisfied_predicates: &[(

compiler/rustc_middle/src/mir/mono.rs

+9
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ impl<'tcx> MonoItem<'tcx> {
200200
MonoItem::GlobalAsm(..) => LOCAL_CRATE,
201201
}
202202
}
203+
204+
/// Returns the item's `DefId`
205+
pub fn def_id(&self) -> DefId {
206+
match *self {
207+
MonoItem::Fn(Instance { def, .. }) => def.def_id(),
208+
MonoItem::Static(def_id) => def_id,
209+
MonoItem::GlobalAsm(item_id) => item_id.owner_id.to_def_id(),
210+
}
211+
}
203212
}
204213

205214
impl<'tcx> fmt::Display for MonoItem<'tcx> {

0 commit comments

Comments
 (0)