Skip to content

Commit ba666ea

Browse files
committed
WIP: add some more mess in inference
1 parent 3fbced7 commit ba666ea

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

lints/par_iter/src/lib.rs

+34-10
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ use clippy_utils::get_parent_expr;
1919
use rustc_data_structures::fx::FxHashSet;
2020
use rustc_errors::Applicability;
2121
use rustc_hir::intravisit::{walk_expr, Visitor};
22-
use rustc_hir::{self as hir};
22+
use rustc_hir::{self as hir, GenericArg};
2323
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
2424
use rustc_infer::infer::TyCtxtInferExt;
25+
use rustc_infer::traits::{Obligation, ObligationCause};
2526
use rustc_lint::{LateContext, LateLintPass, LintContext};
27+
use rustc_middle::query::Key;
28+
use rustc_middle::ty::{AliasTy, Binder, ProjectionPredicate};
2629
use rustc_span::{sym, Span};
2730
use rustc_trait_selection::traits::ObligationCtxt;
2831
use variable_check::{
@@ -179,22 +182,43 @@ fn get_methods<'tcx>(
179182

180183
let tcx = cx.tcx;
181184
let infcx = tcx.infer_ctxt().build();
182-
let origin = TypeVariableOrigin {
183-
kind: TypeVariableOriginKind::TypeInference,
184-
span,
185-
};
186-
let ty_var = infcx.next_ty_var(origin);
187-
if let Some(param_env) =
188-
// FIXME: what is assoc_ty
189-
if let Some(projection) =
190-
make_normalized_projection(tcx, param_env, trait_def_id, sym::Item, vec![])
185+
186+
if let Some(ty_def_id) = original_ty.ty_def_id()
187+
&& let param_env = tcx.param_env(ty_def_id)
188+
&& let Some(projection) =
189+
make_normalized_projection(tcx, param_env, trait_def_id, sym::Item, vec![])
191190
{
191+
let cause = ObligationCause::dummy();
192+
let origin = TypeVariableOrigin {
193+
kind: TypeVariableOriginKind::TypeInference,
194+
span,
195+
};
196+
let projection_ty = infcx.next_ty_var(origin);
197+
198+
let projection = ProjectionPredicate {
199+
projection_ty: AliasTy::new(tcx, trait_def_id, vec![]),
200+
term: tcx.mk_ty_var(tcx.next_ty_var_id()), // Or the specific type you expect the projection to equal.
201+
};
202+
203+
let norm_ty = infcx.next_ty_var(TypeVariableOrigin {
204+
kind: TypeVariableOriginKind::TypeInference,
205+
span: cause.span,
206+
});
207+
208+
// Create a projection obligation
209+
let obligation = Obligation::new(
210+
cause.clone(),
211+
param_env,
212+
projection.to_predicate(tcx, norm_ty),
213+
);
214+
192215
let ocx = ObligationCtxt::new(&infcx);
193216

194217
// FIXME: what is obligation
195218
ocx.register_obligation(obligation);
196219
let some_errors = ocx.select_where_possible();
197220
}
221+
// FIXME: what is assoc_ty
198222

199223
res
200224
}

0 commit comments

Comments
 (0)