Skip to content

Commit

Permalink
comment return sites
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed May 20, 2020
1 parent 5a5017e commit ea47fdf
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/librustc_trait_selection/traits/structural_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,19 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
}
ty::Foreign(_) => {
self.found = Some(NonStructuralMatchTy::Foreign);
return true; // Stop visiting
return true; // Stop visiting.
}
ty::Opaque(..) => {
self.found = Some(NonStructuralMatchTy::Opaque);
return true;
return true; // Stop visiting.
}
ty::Projection(..) => {
self.found = Some(NonStructuralMatchTy::Projection);
return true;
return true; // Stop visiting.
}
ty::Generator(..) | ty::GeneratorWitness(..) => {
self.found = Some(NonStructuralMatchTy::Generator);
return true;
return true; // Stop visiting.
}
ty::RawPtr(..) => {
// structural-match ignores substructure of
Expand All @@ -179,31 +179,36 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
// structural equality on `T` does not recur into the raw
// pointer. Therefore, one can still use `C` in a pattern.

// (But still tell caller to continue search.)
// (But still tell the caller to continue search.)
return false;
}
ty::FnDef(..) | ty::FnPtr(..) => {
// Types of formals and return in `fn(_) -> _` are also irrelevant;
// so we do not recur into them via `super_visit_with`
//
// (But still tell caller to continue search.)
// (But still tell the caller to continue search.)
return false;
}
ty::Array(_, n)
if { n.try_eval_usize(self.tcx(), ty::ParamEnv::reveal_all()) == Some(0) } =>
{
// rust-lang/rust#62336: ignore type of contents
// for empty array.
//
// (But still tell the caller to continue search.)
return false;
}
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str | ty::Never => {
// These primitive types are always structural match.
//
// `Never` is kind of special here, but as it is not inhabitable, this should be fine.
//
// (But still tell the caller to continue search.)
return false;
}

ty::Array(..) | ty::Slice(_) | ty::Ref(..) | ty::Tuple(..) => {
// First check all contained types and then tell the caller to continue searching.
ty.super_visit_with(self);
return false;
}
Expand All @@ -214,13 +219,15 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
self.tcx().sess.delay_span_bug(self.span, "ty::Error in structural-match check");
// We still want to check other types after encountering an error,
// as this may still emit relevant errors.
//
// So we continue searching here.
return false;
}
};

if !self.seen.insert(adt_def.did) {
debug!("Search already seen adt_def: {:?}", adt_def);
// let caller continue its search
// Let caller continue its search.
return false;
}

Expand Down

0 comments on commit ea47fdf

Please sign in to comment.