Currently, we check if the returned type equals to `tcx.ty_error()` not to emit erroneous types, but this has a pitfall; for example, `Option<[type error]> != tcx.ty_error()` holds.
For high-level intro to how type checking works in rustc, see the type checking chapter of the rustc dev guide.