use crate::autoderef::Autoderef;
use crate::infer::InferCtxt;
+use crate::traits::NormalizeExt;
use hir::def::CtorOf;
use hir::HirId;
use super::InferCtxtPrivExt;
use crate::infer::InferCtxtExt as _;
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
-use rustc_middle::ty::print::with_no_trimmed_paths;
+use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths};
#[derive(Debug)]
pub enum GeneratorInteriorOrUpvar {
obligated_types: &mut Vec<Ty<'tcx>>,
seen_requirements: &mut FxHashSet<DefId>,
) where
- T: fmt::Display + ToPredicate<'tcx, T>;
+ T: fmt::Display + ToPredicate<'tcx>;
/// Suggest to await before try: future? => future.await?
fn suggest_await_before_try(
obligation.param_env,
trait_pred_and_suggested_ty,
);
- let suggested_ty_would_satisfy_obligation =
- self.predicate_must_hold_modulo_regions(&new_obligation);
+ let suggested_ty_would_satisfy_obligation = self
+ .evaluate_obligation_no_overflow(&new_obligation)
+ .must_apply_modulo_regions();
if suggested_ty_would_satisfy_obligation {
let sp = self
.tcx
) -> Ty<'tcx> {
let inputs = trait_ref.skip_binder().substs.type_at(1);
let sig = match inputs.kind() {
- ty::Tuple(inputs)
- if infcx.tcx.fn_trait_kind_from_lang_item(trait_ref.def_id()).is_some() =>
- {
+ ty::Tuple(inputs) if infcx.tcx.is_fn_trait(trait_ref.def_id()) => {
infcx.tcx.mk_fn_sig(
inputs.iter(),
infcx.next_ty_var(TypeVariableOrigin {
&& let predicates = self.tcx.predicates_of(def_id).instantiate_identity(self.tcx)
&& let Some(pred) = predicates.predicates.get(*idx)
&& let ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) = pred.kind().skip_binder()
- && ty::ClosureKind::from_def_id(self.tcx, trait_pred.def_id()).is_some()
+ && self.tcx.is_fn_trait(trait_pred.def_id())
{
let expected_self =
self.tcx.anonymize_late_bound_regions(pred.kind().rebind(trait_pred.self_ty()));
.enumerate()
.find(|(other_idx, (pred, _))| match pred.kind().skip_binder() {
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred))
- if ty::ClosureKind::from_def_id(self.tcx, trait_pred.def_id())
- .is_some()
+ if self.tcx.is_fn_trait(trait_pred.def_id())
&& other_idx != idx
// Make sure that the self type matches
// (i.e. constraining this closure)
.as_local()
.and_then(|def_id| hir.maybe_body_owned_by(def_id))
.map(|body_id| hir.body(body_id));
- let is_async = self
- .tcx
- .generator_kind(generator_did)
- .map(|generator_kind| matches!(generator_kind, hir::GeneratorKind::Async(..)))
- .unwrap_or(false);
let mut visitor = AwaitsVisitor::default();
if let Some(body) = generator_body {
visitor.visit_body(body);
debug!(?interior_or_upvar_span);
if let Some(interior_or_upvar_span) = interior_or_upvar_span {
+ let is_async = self.tcx.generator_is_async(generator_did);
let typeck_results = match generator_data {
GeneratorData::Local(typeck_results) => Some(typeck_results),
GeneratorData::Foreign(_) => None,
obligated_types: &mut Vec<Ty<'tcx>>,
seen_requirements: &mut FxHashSet<DefId>,
) where
- T: fmt::Display,
+ T: fmt::Display + ToPredicate<'tcx>,
{
let tcx = self.tcx;
match *cause_code {
ObligationCauseCode::BindingObligation(item_def_id, span)
| ObligationCauseCode::ExprBindingObligation(item_def_id, span, ..) => {
let item_name = tcx.def_path_str(item_def_id);
+ let short_item_name = with_forced_trimmed_paths!(tcx.def_path_str(item_def_id));
let mut multispan = MultiSpan::from(span);
+ let sm = tcx.sess.source_map();
if let Some(ident) = tcx.opt_item_ident(item_def_id) {
- let sm = tcx.sess.source_map();
let same_line =
match (sm.lookup_line(ident.span.hi()), sm.lookup_line(span.lo())) {
(Ok(l), Ok(r)) => l.line == r.line,
_ => true,
};
- if !ident.span.is_dummy() && !ident.span.overlaps(span) && !same_line {
+ if ident.span.is_visible(sm) && !ident.span.overlaps(span) && !same_line {
multispan.push_span_label(ident.span, "required by a bound in this");
}
}
- let descr = format!("required by a bound in `{}`", item_name);
- if !span.is_dummy() {
- let msg = format!("required by this bound in `{}`", item_name);
+ let descr = format!("required by a bound in `{item_name}`");
+ if span.is_visible(sm) {
+ let msg = format!("required by this bound in `{short_item_name}`");
multispan.push_span_label(span, msg);
err.span_note(multispan, &descr);
} else {
if is_future
&& obligated_types.last().map_or(false, |ty| match ty.kind() {
ty::Generator(last_def_id, ..) => {
- matches!(
- tcx.generator_kind(last_def_id),
- Some(GeneratorKind::Async(..))
- )
+ tcx.generator_is_async(*last_def_id)
}
_ => false,
})
let sp = self.tcx.def_span(def_id);
// Special-case this to say "async block" instead of `[static generator]`.
- let kind = tcx.generator_kind(def_id).unwrap();
+ let kind = tcx.generator_kind(def_id).unwrap().descr();
err.span_note(
sp,
&format!("required because it's used within this {}", kind),
self.tcx.mk_substs_trait(trait_pred.self_ty(), []),
)
});
- let InferOk { value: projection_ty, .. } = self
- .partially_normalize_associated_types_in(
- obligation.cause.clone(),
- obligation.param_env,
- projection_ty,
- );
+ let InferOk { value: projection_ty, .. } =
+ self.at(&obligation.cause, obligation.param_env).normalize(projection_ty);
debug!(
normalized_projection_type = ?self.resolve_vars_if_possible(projection_ty)