Skip to content

Commit 19bb4ed

Browse files
Fix coercion ICE
1 parent c87aa8e commit 19bb4ed

File tree

3 files changed

+24
-40
lines changed

3 files changed

+24
-40
lines changed

src/librustc_typeck/check/method/mod.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -382,25 +382,4 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
382382
.map(|&did| self.tcx.impl_or_trait_item(did))
383383
.find(|m| m.name() == item_name)
384384
}
385-
386-
pub fn matches_return_type(&self, method: &ty::ImplOrTraitItem<'tcx>,
387-
expected: ty::Ty<'tcx>) -> bool {
388-
match *method {
389-
ty::ImplOrTraitItem::MethodTraitItem(ref x) => {
390-
self.can_sub_types(x.fty.sig.skip_binder().output, expected).is_ok()
391-
}
392-
_ => false,
393-
}
394-
}
395-
396-
pub fn impl_or_return_item(&self,
397-
def_id: DefId,
398-
return_type: ty::Ty<'tcx>)
399-
-> Option<ty::ImplOrTraitItem<'tcx>> {
400-
self.tcx
401-
.impl_or_trait_items(def_id)
402-
.iter()
403-
.map(|&did| self.tcx.impl_or_trait_item(did))
404-
.find(|m| self.matches_return_type(m, return_type))
405-
}
406385
}

src/librustc_typeck/check/method/probe.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use hir::def::Def;
1919
use rustc::ty::subst::{Subst, Substs};
2020
use rustc::traits;
2121
use rustc::ty::{self, Ty, ToPolyTraitRef, TraitRef, TypeFoldable};
22-
use rustc::infer::{InferOk, TypeOrigin};
22+
use rustc::infer::{self, InferOk, TypeOrigin};
2323
use rustc::util::nodemap::FnvHashSet;
2424
use syntax::ast;
2525
use syntax_pos::{Span, DUMMY_SP};
@@ -636,35 +636,35 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
636636
Ok(())
637637
}
638638

639+
pub fn matches_return_type(&self, method: &ty::ImplOrTraitItem<'tcx>,
640+
expected: ty::Ty<'tcx>) -> bool {
641+
match *method {
642+
ty::ImplOrTraitItem::MethodTraitItem(ref x) => {
643+
self.probe(|_| {
644+
let output = self.replace_late_bound_regions_with_fresh_var(
645+
self.span, infer::FnCall, &x.fty.sig.output());
646+
self.can_sub_types(output.0, expected).is_ok()
647+
})
648+
}
649+
_ => false,
650+
}
651+
}
652+
639653
fn assemble_extension_candidates_for_trait(&mut self,
640654
trait_def_id: DefId)
641655
-> Result<(), MethodError<'tcx>> {
642656
debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})",
643657
trait_def_id);
644658

645-
// Check whether `trait_def_id` defines a method with suitable name:
646-
let trait_items = self.tcx.trait_items(trait_def_id);
647-
let maybe_item = match self.looking_for {
648-
LookingFor::MethodName(item_name) => {
649-
trait_items.iter()
650-
.find(|item| item.name() == item_name)
651-
}
652-
LookingFor::ReturnType(item_ty) => {
653-
trait_items.iter()
654-
.find(|item| {
655-
self.fcx.matches_return_type(item, &item_ty)
656-
})
657-
}
658-
};
659-
let item = match maybe_item {
659+
let item = match self.impl_or_trait_item(trait_def_id) {
660660
Some(i) => i,
661661
None => {
662662
return Ok(());
663663
}
664664
};
665665

666666
// Check whether `trait_def_id` defines a method with suitable name:
667-
if !self.has_applicable_self(item) {
667+
if !self.has_applicable_self(&item) {
668668
debug!("method has inapplicable self");
669669
self.record_static_candidate(TraitSource(trait_def_id));
670670
return Ok(());
@@ -1369,7 +1369,11 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
13691369
self.fcx.impl_or_trait_item(def_id, name)
13701370
}
13711371
LookingFor::ReturnType(return_ty) => {
1372-
self.fcx.impl_or_return_item(def_id, return_ty)
1372+
self.tcx
1373+
.impl_or_trait_items(def_id)
1374+
.iter()
1375+
.map(|&did| self.tcx.impl_or_trait_item(did))
1376+
.find(|m| self.matches_return_type(m, return_ty))
13731377
}
13741378
}
13751379
}

src/libsyntax/feature_gate.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,8 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeGat
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)