Skip to content

Commit 65ad935

Browse files
committed
change on_unimplented logic
1 parent 5458d8b commit 65ad935

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/librustc/traits/error_reporting.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
161161

162162
let trait_self_ty = tcx.erase_late_bound_regions(&trait_ref).self_ty();
163163

164+
if trait_self_ty.is_ty_var() {
165+
return None;
166+
}
167+
164168
self.tcx.lookup_trait_def(trait_ref.def_id())
165169
.for_each_relevant_impl(self.tcx, trait_self_ty, |def_id| {
166170
let impl_self_ty = tcx
@@ -169,17 +173,20 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
169173
.self_ty()
170174
.subst(tcx, &self.impl_substs(def_id, obligation.clone()));
171175

176+
if !tcx.has_attr(def_id, "rustc_on_unimplemented") {
177+
return;
178+
}
179+
172180
if let Ok(..) = self.can_equate(&trait_self_ty, &impl_self_ty) {
173181
ambiguous = result.is_some();
174182
result = Some(def_id);
175183
}
176184
});
177185

178-
match result {
179-
Some(def_id) if !ambiguous && tcx.has_attr(def_id, "rustc_on_unimplemented") => {
180-
result
181-
}
182-
_ => None
186+
if ambiguous {
187+
None
188+
} else {
189+
result
183190
}
184191
}
185192

src/test/compile-fail/check_on_unimplemented_on_slice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#![feature(rustc_attrs)]
1414

15+
use std::ops::Index;
16+
1517
#[rustc_error]
1618
fn main() {
1719
let x = &[1, 2, 3] as &[i32];

0 commit comments

Comments
 (0)