Skip to content

Commit b2d0ec0

Browse files
Fix coercion ICE
1 parent 8057d48 commit b2d0ec0

File tree

3 files changed

+24
-39
lines changed

3 files changed

+24
-39
lines changed

src/librustc_typeck/check/method/mod.rs

-21
Original file line numberDiff line numberDiff line change
@@ -354,25 +354,4 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
354354
-> Option<ty::AssociatedItem> {
355355
self.tcx.associated_items(def_id).find(|item| item.name == item_name)
356356
}
357-
358-
pub fn matches_return_type(&self, method: &ty::ImplOrTraitItem<'tcx>,
359-
expected: ty::Ty<'tcx>) -> bool {
360-
match *method {
361-
ty::ImplOrTraitItem::MethodTraitItem(ref x) => {
362-
self.can_sub_types(x.fty.sig.skip_binder().output, expected).is_ok()
363-
}
364-
_ => false,
365-
}
366-
}
367-
368-
pub fn impl_or_return_item(&self,
369-
def_id: DefId,
370-
return_type: ty::Ty<'tcx>)
371-
-> Option<ty::ImplOrTraitItem<'tcx>> {
372-
self.tcx
373-
.impl_or_trait_items(def_id)
374-
.iter()
375-
.map(|&did| self.tcx.impl_or_trait_item(did))
376-
.find(|m| self.matches_return_type(m, return_type))
377-
}
378357
}

src/librustc_typeck/check/method/probe.rs

+22-17
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ use rustc::ty::subst::{Subst, Substs};
2121
use rustc::traits::{self, ObligationCause};
2222
use rustc::ty::{self, Ty, ToPolyTraitRef, TraitRef, TypeFoldable};
2323
use rustc::infer::type_variable::TypeVariableOrigin;
24-
use rustc::util::nodemap::FxHashSet;
24+
use rustc::util::nodemap::{FnvHashSet, FxHashSet};
25+
use rustc::infer::{self, InferOk, TypeOrigin};
2526
use syntax::ast;
2627
use syntax_pos::Span;
2728
use rustc::hir;
@@ -626,27 +627,27 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
626627
Ok(())
627628
}
628629

630+
pub fn matches_return_type(&self, method: &ty::ImplOrTraitItem<'tcx>,
631+
expected: ty::Ty<'tcx>) -> bool {
632+
match *method {
633+
ty::ImplOrTraitItem::MethodTraitItem(ref x) => {
634+
self.probe(|_| {
635+
let output = self.replace_late_bound_regions_with_fresh_var(
636+
self.span, infer::FnCall, &x.fty.sig.output());
637+
self.can_sub_types(output.0, expected).is_ok()
638+
})
639+
}
640+
_ => false,
641+
}
642+
}
643+
629644
fn assemble_extension_candidates_for_trait(&mut self,
630645
trait_def_id: DefId)
631646
-> Result<(), MethodError<'tcx>> {
632647
debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})",
633648
trait_def_id);
634649

635-
// Check whether `trait_def_id` defines a method with suitable name:
636-
let trait_items = self.tcx.associated_items(trait_def_id);
637-
let maybe_item = match self.looking_for {
638-
LookingFor::MethodName(item_name) => {
639-
trait_items.iter()
640-
.find(|item| item.name == item_name)
641-
}
642-
LookingFor::ReturnType(item_ty) => {
643-
trait_items.iter()
644-
.find(|item| {
645-
self.fcx.matches_return_type(item, &item_ty)
646-
})
647-
}
648-
};
649-
let item = match maybe_item {
650+
let item = match self.impl_or_trait_item(trait_def_id) {
650651
Some(i) => i,
651652
None => {
652653
return Ok(());
@@ -1351,7 +1352,11 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
13511352
self.fcx.impl_or_trait_item(def_id, name)
13521353
}
13531354
LookingFor::ReturnType(return_ty) => {
1354-
self.fcx.impl_or_return_item(def_id, return_ty)
1355+
self.tcx
1356+
.impl_or_trait_items(def_id)
1357+
.iter()
1358+
.map(|&did| self.tcx.impl_or_trait_item(did))
1359+
.find(|m| self.matches_return_type(m, return_ty))
13551360
}
13561361
}
13571362
}

src/libsyntax/feature_gate.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,8 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
652652
"internal implementation detail",
653653
cfg_fn!(rustc_attrs))),
654654

655-
("safe_suggestion", Whitelisted, Gated("safe_suggestion",
655+
("safe_suggestion", Whitelisted, Gated(Stability::Unstable,
656+
"safe_suggestion",
656657
"the `#[safe_suggestion]` attribute \
657658
is an experimental feature",
658659
cfg_fn!(safe_suggestion))),

0 commit comments

Comments
 (0)