Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c3cf93a
Fix diagnostic issue when using FakeReads in closures
roxelo Mar 26, 2021
1ef70d8
Reduce size of statements
roxelo Mar 30, 2021
c2c76a0
fix clippy error
roxelo Mar 30, 2021
fd66899
Suggest Pin/Box/Arc for more cases
estebank Mar 30, 2021
7528cc3
Point at `impl` and type defs introducing requirements on E0277
estebank Mar 30, 2021
923c122
Always mention `Box::pin` when dealing with `!Unpin`
estebank Mar 30, 2021
8f77356
give full path of constraint in suggest_constraining_type_param
0xPoe Mar 30, 2021
ce66588
Add a regression test for issue-68830
JohnTitor Mar 31, 2021
e7821e5
Fix documentation of conversion from String to OsString
steffahn Mar 31, 2021
f5e7dbb
Add a few missing links, fix a typo
steffahn Mar 31, 2021
7509aa1
Apply suggestions from code review
steffahn Mar 31, 2021
82c6709
Clarify `--print target-list` is a rustc's option
JohnTitor Mar 31, 2021
9acf558
Update LLVM with another wasm simd fix
alexcrichton Mar 31, 2021
06b82ab
review comments
estebank Mar 31, 2021
5b381b7
Rollup merge of #83521 - sexxi-goose:quick-diagnostic-fix, r=nikomats…
Dylan-DPC Mar 31, 2021
cb59053
Rollup merge of #83673 - hi-rustin:rustin-patch-suggestion, r=estebank
Dylan-DPC Mar 31, 2021
a41cb7d
Rollup merge of #83689 - estebank:cool-bears-hot-tip, r=davidtwco
Dylan-DPC Mar 31, 2021
cff8c5f
Rollup merge of #83699 - JohnTitor:issue-68830, r=Dylan-DPC
Dylan-DPC Mar 31, 2021
3499ec6
Rollup merge of #83700 - steffahn:string_to_pathbuf_conversion_docume…
Dylan-DPC Mar 31, 2021
cbd72e4
Rollup merge of #83711 - JohnTitor:more-friendly-unknown-target-error…
Dylan-DPC Mar 31, 2021
5eb680f
Rollup merge of #83712 - alexcrichton:more-wasm-simd-llvm-updates, r=…
Dylan-DPC Mar 31, 2021
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
Prev Previous commit
Next Next commit
Suggest Pin/Box/Arc for more cases
  • Loading branch information
estebank committed Mar 30, 2021
commit fd668997de6260edb98f11efee24d1f7ee470072
105 changes: 53 additions & 52 deletions compiler/rustc_typeck/src/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,59 +987,60 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) {
let mut alt_rcvr_sugg = false;
if let SelfSource::MethodCall(rcvr) = source {
info!(?span, ?item_name, ?rcvr_ty, ?rcvr);
if let ty::Adt(..) = rcvr_ty.kind() {
// Try alternative arbitrary self types that could fulfill this call.
// FIXME: probe for all types that *could* be arbitrary self-types, not
// just this list.
for (rcvr_ty, post) in &[
(rcvr_ty, ""),
(self.tcx.mk_mut_ref(&ty::ReErased, rcvr_ty), "&mut "),
(self.tcx.mk_imm_ref(&ty::ReErased, rcvr_ty), "&"),
debug!(?span, ?item_name, ?rcvr_ty, ?rcvr);
// Try alternative arbitrary self types that could fulfill this call.
// FIXME: probe for all types that *could* be arbitrary self-types, not
// just this list.
for (rcvr_ty, post) in &[
(rcvr_ty, ""),
(self.tcx.mk_mut_ref(&ty::ReErased, rcvr_ty), "&mut "),
(self.tcx.mk_imm_ref(&ty::ReErased, rcvr_ty), "&"),
] {
for (rcvr_ty, pre) in &[
(self.tcx.mk_lang_item(rcvr_ty, LangItem::OwnedBox), "Box::new"),
(self.tcx.mk_lang_item(rcvr_ty, LangItem::Pin), "Pin::new"),
(self.tcx.mk_diagnostic_item(rcvr_ty, sym::Arc), "Arc::new"),
(self.tcx.mk_diagnostic_item(rcvr_ty, sym::Rc), "Rc::new"),
] {
for (rcvr_ty, pre) in &[
(self.tcx.mk_lang_item(rcvr_ty, LangItem::OwnedBox), "Box::new"),
(self.tcx.mk_lang_item(rcvr_ty, LangItem::Pin), "Pin::new"),
(self.tcx.mk_diagnostic_item(rcvr_ty, sym::Arc), "Arc::new"),
(self.tcx.mk_diagnostic_item(rcvr_ty, sym::Rc), "Rc::new"),
] {
if let Some(new_rcvr_t) = *rcvr_ty {
if let Ok(pick) = self.lookup_probe(
span,
item_name,
new_rcvr_t,
rcvr,
crate::check::method::probe::ProbeScope::AllTraits,
) {
debug!("try_alt_rcvr: pick candidate {:?}", pick);
// Make sure the method is defined for the *actual* receiver:
// we don't want to treat `Box<Self>` as a receiver if
// it only works because of an autoderef to `&self`
if pick.autoderefs == 0
// We don't want to suggest a container type when the missing method is
// `.clone()`, otherwise we'd suggest `Arc::new(foo).clone()`, which is
// far from what the user really wants.
&& Some(pick.item.container.id()) != self.tcx.lang_items().clone_trait()
{
err.span_label(
pick.item.ident.span,
&format!(
"the method is available for `{}` here",
new_rcvr_t
),
);
err.multipart_suggestion(
"consider wrapping the receiver expression with the \
appropriate type",
vec![
(rcvr.span.shrink_to_lo(), format!("{}({}", pre, post)),
(rcvr.span.shrink_to_hi(), ")".to_string()),
],
Applicability::MaybeIncorrect,
);
// We don't care about the other suggestions.
alt_rcvr_sugg = true;
}
if let Some(new_rcvr_t) = *rcvr_ty {
if let Ok(pick) = self.lookup_probe(
span,
item_name,
new_rcvr_t,
rcvr,
crate::check::method::probe::ProbeScope::AllTraits,
) {
debug!("try_alt_rcvr: pick candidate {:?}", pick);
let did = Some(pick.item.container.id());
// We don't want to suggest a container type when the missing
// method is `.clone()` or `.deref()` otherwise we'd suggest
// `Arc::new(foo).clone()`, which is far from what the user wants.
let skip = [
self.tcx.lang_items().clone_trait(),
self.tcx.lang_items().deref_trait(),
self.tcx.lang_items().deref_mut_trait(),
self.tcx.lang_items().drop_trait(),
]
.contains(&did);
// Make sure the method is defined for the *actual* receiver: we don't
// want to treat `Box<Self>` as a receiver if it only works because of
// an autoderef to `&self`
if pick.autoderefs == 0 && !skip {
err.span_label(
pick.item.ident.span,
&format!("the method is available for `{}` here", new_rcvr_t),
);
err.multipart_suggestion(
"consider wrapping the receiver expression with the \
appropriate type",
vec![
(rcvr.span.shrink_to_lo(), format!("{}({}", pre, post)),
(rcvr.span.shrink_to_hi(), ")".to_string()),
],
Applicability::MaybeIncorrect,
);
// We don't care about the other suggestions.
alt_rcvr_sugg = true;
}
}
}
Expand Down