Add 1 type parameter to RangeBounds<Start, End = Start> and all existing range types#151334
Add 1 type parameter to RangeBounds<Start, End = Start> and all existing range types#151334asder8215 wants to merge 4 commits intorust-lang:mainfrom
Conversation
…t> and all existing range types
|
Feel free to take over this PR @nik-rev since this was your accepted ACP. |
This comment has been minimized.
This comment has been minimized.
I haven't sent a PR in these months, it's yours! Thanks for the help! |
|
I pinpointed the issue for the clippy ci error to fn can_switch_range<'tcx>{
// ABOVE OMITTED
// Check if `expr` is used for indexing, and if the switched range type could be used
// as well.
if let ExprKind::Index(outer_expr, index, _) = parent_expr.kind
&& index.hir_id == expr.hir_id
// Build the switched range type (for example `RangeInclusive<usize>`).
&& let Some(switched_range_def_id) = match original {
RangeLimits::HalfOpen => cx.tcx.lang_items().range_inclusive_struct(),
RangeLimits::Closed => cx.tcx.lang_items().range_struct(),
}
&& let switched_range_ty = cx
.tcx
.type_of(switched_range_def_id)
.instantiate(cx.tcx, &[inner_ty.into()]) // <- ERRORS HERE
// Check that the switched range type can be used for indexing the original expression
// through the `Index` or `IndexMut` trait.
&& let ty::Ref(_, outer_ty, mutability) = cx.typeck_results().expr_ty_adjusted(outer_expr).kind()
&& let Some(index_def_id) = match mutability {
Mutability::Not => cx.tcx.lang_items().index_trait(),
Mutability::Mut => cx.tcx.lang_items().index_mut_trait(),
}
// BELOW OMITTED
}Following through the function, I can see what triggers the impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for GenericArgsRef<'tcx> {
// OMITTED ABOVE
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
// See justification for this behavior in `try_fold_with`.
match self.len() {
1 => {
let param0 = self[0].fold_with(folder);
if param0 == self[0] { self } else { folder.cx().mk_args(&[param0]) }
}
2 => {
let param0 = self[0].fold_with(folder);
let param1 = self[1].fold_with(folder); // ERRORS HERE
if param0 == self[0] && param1 == self[1] {
self
} else {
folder.cx().mk_args(&[param0, param1])
}
}
0 => self,
_ => ty::util::fold_list(self, folder, |tcx, v| tcx.mk_args(v)),
}
}
// OMITTED BELOW
}
// calls fold_ty() eventually
impl<'a, I: Interner> TypeFolder<I> for ArgFolder<'a, I> {
// OMITTED ABOVE
fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
if !t.has_param() {
return t;
}
match t.kind() {
ty::Param(p) => self.ty_for_param(p, t), // Triggers this function
_ => t.super_fold_with(self),
}
}
// OMITTED BELOW
}
impl<'a, I: Interner> ArgFolder<'a, I> {
fn ty_for_param(&self, p: I::ParamTy, source_ty: I::Ty) -> I::Ty {
// Look up the type in the args. It really should be in there.
let opt_ty = self.args.get(p.index() as usize).map(|arg| arg.kind());
let ty = match opt_ty {
Some(ty::GenericArgKind::Type(ty)) => ty,
Some(kind) => self.type_param_expected(p, source_ty, kind),
None => self.type_param_out_of_range(p, source_ty), // Produces error here
};
self.shift_vars_through_binders(ty)
}
// OMITTED BELOW
}I know that in the Also, when I run let opt = Some(None..Some(1));^This currently has inference issue because it isn't able to ascertain that the @joboet how should I approach this? Should this be an RFC or MCP? Update: On the clippy thing, I realized that I could grab the start bound and pass in the type of that as the first argument. |
|
Also, here's the stack backtrace on the clippy ci fail with debug set to true: |
…ixed clippy linting issue with can_switch_range passing one argument instead two
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
☔ The latest upstream changes (presumably #141295) made this pull request unmergeable. Please resolve the merge conflicts. |
This commit implements adding a typed parameter to
RangeBoundstrait,Rangestruct, andRangeInclusivestruct as per nik-rev's accepted ACP here: rust-lang/libs-team#653.