Skip to content

Commit ab17068

Browse files
committed
Consider negative polarity on trait selection
1 parent 8b0bfb0 commit ab17068

File tree

1 file changed

+23
-25
lines changed
  • compiler/rustc_trait_selection/src/traits/select

1 file changed

+23
-25
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

+23-25
Original file line numberDiff line numberDiff line change
@@ -1127,34 +1127,32 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11271127
}
11281128
// Treat negative impls as unimplemented, and reservation impls as ambiguity.
11291129
if let ImplCandidate(def_id) = candidate {
1130-
match tcx.impl_polarity(def_id) {
1131-
ty::ImplPolarity::Negative if !self.allow_negative_impls => {
1132-
return Err(Unimplemented);
1133-
}
1134-
ty::ImplPolarity::Reservation => {
1135-
if let Some(intercrate_ambiguity_clauses) =
1136-
&mut self.intercrate_ambiguity_causes
1137-
{
1138-
let attrs = tcx.get_attrs(def_id);
1139-
let attr = tcx.sess.find_by_name(&attrs, sym::rustc_reservation_impl);
1140-
let value = attr.and_then(|a| a.value_str());
1141-
if let Some(value) = value {
1142-
debug!(
1143-
"filter_impls: \
1130+
if let ty::ImplPolarity::Reservation = tcx.impl_polarity(def_id) {
1131+
if let Some(intercrate_ambiguity_clauses) = &mut self.intercrate_ambiguity_causes {
1132+
let attrs = tcx.get_attrs(def_id);
1133+
let attr = tcx.sess.find_by_name(&attrs, sym::rustc_reservation_impl);
1134+
let value = attr.and_then(|a| a.value_str());
1135+
if let Some(value) = value {
1136+
debug!(
1137+
"filter_impls: \
11441138
reservation impl ambiguity on {:?}",
1145-
def_id
1146-
);
1147-
intercrate_ambiguity_clauses.push(
1148-
IntercrateAmbiguityCause::ReservationImpl {
1149-
message: value.to_string(),
1150-
},
1151-
);
1152-
}
1139+
def_id
1140+
);
1141+
intercrate_ambiguity_clauses.push(
1142+
IntercrateAmbiguityCause::ReservationImpl {
1143+
message: value.to_string(),
1144+
},
1145+
);
11531146
}
1154-
return Ok(None);
11551147
}
1156-
_ => {}
1157-
};
1148+
return Ok(None);
1149+
}
1150+
1151+
if !self.allow_negative_impls {
1152+
if obligation.predicate.skip_binder().polarity != tcx.impl_polarity(def_id) {
1153+
return Err(Unimplemented);
1154+
}
1155+
}
11581156
}
11591157
Ok(Some(candidate))
11601158
}

0 commit comments

Comments
 (0)