Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #105760

Merged
merged 26 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
75cf31f
skip if val has ecaping bound vars
ouz-a Dec 14, 2022
74f4da4
add helper to get DefId from MonoItem
lqd Dec 8, 2022
7611933
add `-Z dump-mono-stats`
lqd Dec 8, 2022
6379e5e
bless rustdoc test for unstable options
lqd Dec 9, 2022
b720847
wrap output in BufWriter
lqd Dec 14, 2022
124f194
Tweak output for bare `dyn Trait` in arguments
estebank Dec 15, 2022
2a5aabd
Remove `SimplifiedTypeGen::map_def`.
nnethercote Dec 15, 2022
5258b65
Merge `SimplifiedTypeGen<D>` into `SimplifiedType`.
nnethercote Dec 15, 2022
f194880
Suggest constraining type parameter with `Clone`
estebank Dec 14, 2022
e1b3401
Suggest `#[derive(Clone)]`
estebank Dec 14, 2022
8ae479a
Migrate Jump to def links background to CSS variable
GuillaumeGomez Dec 15, 2022
294944d
Point at method chains on `E0271` errors
estebank Dec 13, 2022
30ae261
Use `with_forced_trimmed_paths` more
estebank Dec 13, 2022
4d4d478
Shorten trimmed display of closures
estebank Dec 14, 2022
153419b
Small cleanup in parameterized
Nilstrieb Dec 15, 2022
651e41c
Move `TypeckResults` to seperate module
Nilstrieb Dec 15, 2022
3b938f7
Trim paths in E0599
estebank Dec 14, 2022
2492235
Consider lifetimes when comparing assoc types in method chain
estebank Dec 14, 2022
863d1f6
Rollup merge of #105481 - lqd:mono-stats, r=wesleywiser
matthiaskrgr Dec 15, 2022
622f560
Rollup merge of #105674 - estebank:iterator-chains, r=oli-obk
matthiaskrgr Dec 15, 2022
86cedb4
Rollup merge of #105679 - estebank:suggest-clone, r=compiler-errors
matthiaskrgr Dec 15, 2022
24e584b
Rollup merge of #105694 - ouz-a:issue_105689, r=estebank
matthiaskrgr Dec 15, 2022
abfad27
Rollup merge of #105727 - estebank:use-impl-trait, r=oli-obk
matthiaskrgr Dec 15, 2022
0fbaf76
Rollup merge of #105739 - GuillaumeGomez:migrate-jump-to-def-link-to-…
matthiaskrgr Dec 15, 2022
0f90ea9
Rollup merge of #105743 - nnethercote:SimplifiedType-cleanups, r=lcnr
matthiaskrgr Dec 15, 2022
2e03ff1
Rollup merge of #105758 - Nilstrieb:typeck-results-mod, r=compiler-er…
matthiaskrgr Dec 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/monomorphize.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ monomorphize_large_assignments =
moving {$size} bytes
.label = value moved from here
.note = The current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`

monomorphize_couldnt_dump_mono_stats =
unexpected error occurred while dumping monomorphization stats: {$error}
23 changes: 18 additions & 5 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use rustc_hir_analysis::astconv::AstConv;
use rustc_infer::infer;
use rustc_infer::traits::{self, StatementAsExpression};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, Binder, DefIdTree, IsSuggestable, Ty};
use rustc_middle::ty::{
self, suggest_constraining_type_params, Binder, DefIdTree, IsSuggestable, ToPredicate, Ty,
};
use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::symbol::sym;
use rustc_span::Span;
Expand Down Expand Up @@ -1276,15 +1278,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& !results.expr_adjustments(callee_expr).iter().any(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(..)))
// Check that we're in fact trying to clone into the expected type
&& self.can_coerce(*pointee_ty, expected_ty)
&& let trait_ref = ty::Binder::dummy(self.tcx.mk_trait_ref(clone_trait_did, [expected_ty]))
// And the expected type doesn't implement `Clone`
&& !self.predicate_must_hold_considering_regions(&traits::Obligation::new(
self.tcx,
traits::ObligationCause::dummy(),
self.param_env,
ty::Binder::dummy(self.tcx.mk_trait_ref(
clone_trait_did,
[expected_ty],
)),
trait_ref,
))
{
diag.span_note(
Expand All @@ -1293,6 +1293,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
"`{expected_ty}` does not implement `Clone`, so `{found_ty}` was cloned instead"
),
);
let owner = self.tcx.hir().enclosing_body_owner(expr.hir_id);
if let ty::Param(param) = expected_ty.kind()
&& let Some(generics) = self.tcx.hir().get_generics(owner)
{
suggest_constraining_type_params(
self.tcx,
generics,
diag,
vec![(param.name.as_str(), "Clone", Some(clone_trait_did))].into_iter(),
);
} else {
self.suggest_derive(diag, &[(trait_ref.to_predicate(self.tcx), None, None)]);
}
}
}

Expand Down
16 changes: 10 additions & 6 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin
use rustc_middle::traits::util::supertraits;
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
use rustc_middle::ty::print::with_crate_prefix;
use rustc_middle::ty::print::{with_crate_prefix, with_forced_trimmed_paths};
use rustc_middle::ty::{self, DefIdTree, GenericArgKind, Ty, TyCtxt, TypeVisitable};
use rustc_middle::ty::{IsSuggestable, ToPolyTraitRef};
use rustc_span::symbol::{kw, sym, Ident};
Expand Down Expand Up @@ -270,7 +270,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let tcx = self.tcx;

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

let obligation = format!("{} = {}", projection_ty, term);
let quiet = format!("{} = {}", quiet_projection_ty, term);
let quiet = with_forced_trimmed_paths!(format!(
"{} = {}",
quiet_projection_ty, term
));

bound_span_label(projection_ty.self_ty(), &obligation, &quiet);
Some((obligation, projection_ty.self_ty()))
Expand All @@ -573,7 +576,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let self_ty = p.self_ty();
let path = p.print_only_trait_path();
let obligation = format!("{}: {}", self_ty, path);
let quiet = format!("_: {}", path);
let quiet = with_forced_trimmed_paths!(format!("_: {}", path));
bound_span_label(self_ty, &obligation, &quiet);
Some((obligation, self_ty))
}
Expand Down Expand Up @@ -796,7 +799,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(None, None)
};
let primary_message = primary_message.unwrap_or_else(|| format!(
"the {item_kind} `{item_name}` exists for {actual_prefix} `{ty_str}`, but its trait bounds were not satisfied"
"the {item_kind} `{item_name}` exists for {actual_prefix} `{ty_str}`, \
but its trait bounds were not satisfied"
));
err.set_primary_message(&primary_message);
if let Some(label) = label {
Expand Down Expand Up @@ -1848,7 +1852,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.suggest_derive(err, &preds);
}

fn suggest_derive(
pub fn suggest_derive(
&self,
err: &mut Diagnostic,
unsatisfied_predicates: &[(
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ impl<'tcx> MonoItem<'tcx> {
MonoItem::GlobalAsm(..) => LOCAL_CRATE,
}
}

/// Returns the item's `DefId`
pub fn def_id(&self) -> DefId {
match *self {
MonoItem::Fn(Instance { def, .. }) => def.def_id(),
MonoItem::Static(def_id) => def_id,
MonoItem::GlobalAsm(item_id) => item_id.owner_id.to_def_id(),
}
}
}

impl<'tcx> fmt::Display for MonoItem<'tcx> {
Expand Down
Loading