Skip to content

Commit

Permalink
Add more targetting filters for arrays to rustc_on_unimplemented
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 10, 2018
1 parent 0e07c42 commit cd7c818
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
fn on_unimplemented_note(
&self,
trait_ref: ty::PolyTraitRef<'tcx>,
obligation: &PredicateObligation<'tcx>) ->
OnUnimplementedNote
{
let def_id = self.impl_similar_to(trait_ref, obligation)
obligation: &PredicateObligation<'tcx>,
) -> OnUnimplementedNote {
let def_id = self.impl_similar_to(trait_ref, obligation)
.unwrap_or(trait_ref.def_id());
let trait_ref = *trait_ref.skip_binder();

Expand Down Expand Up @@ -410,6 +409,37 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
flags.push(("crate_local".to_owned(), None));
}

// Allow targetting all integers using `{integral}`, even if the exact type was resolved
if self_ty.is_integral() {
flags.push(("_Self".to_owned(), Some("{integral}".to_owned())));
}

if let ty::Array(aty, len) = self_ty.sty {
flags.push(("_Self".to_owned(), Some("[]".to_owned())));
flags.push(("_Self".to_owned(), Some(format!("[{}]", aty))));
if let Some(def) = aty.ty_adt_def() {
// We also want to be able to select the array's type's original
// signature with no type arguments resolved
flags.push((
"_Self".to_owned(),
Some(format!("[{}]", self.tcx.type_of(def.did).to_string())),
));
if let Some(len) = len.val.try_to_scalar().and_then(|scalar| {
scalar.to_u64().ok()
}) {
flags.push((
"_Self".to_owned(),
Some(format!("[{}; {}]", self.tcx.type_of(def.did).to_string(), len)),
));
} else {
flags.push((
"_Self".to_owned(),
Some(format!("[{}; _]", self.tcx.type_of(def.did).to_string())),
));
}
}
}

if let Ok(Some(command)) = OnUnimplementedDirective::of_item(
self.tcx, trait_ref.def_id, def_id
) {
Expand Down

0 comments on commit cd7c818

Please sign in to comment.