Skip to content
Permalink
Browse files

Rename `infer_types` to `infer_args`

  • Loading branch information...
varkor committed Jun 7, 2019
1 parent 8b36867 commit f1867c549754403ac305be8f22a9e93642b3e288
@@ -2168,7 +2168,7 @@ impl<'a> LoweringContext<'a> {
itctx: ImplTraitContext<'_>,
explicit_owner: Option<NodeId>,
) -> hir::PathSegment {
let (mut generic_args, infer_types) = if let Some(ref generic_args) = segment.args {
let (mut generic_args, infer_args) = if let Some(ref generic_args) = segment.args {
let msg = "parenthesized type parameters may only be used with a `Fn` trait";
match **generic_args {
GenericArgs::AngleBracketed(ref data) => {
@@ -2305,7 +2305,7 @@ impl<'a> LoweringContext<'a> {
Some(id),
Some(self.lower_res(res)),
generic_args,
infer_types,
infer_args,
)
}

@@ -348,7 +348,7 @@ pub struct PathSegment {
/// This only applies to expression and pattern paths, and
/// out of those only the segments with no type parameters
/// to begin with, e.g., `Vec::new` is `<Vec<..>>::new::<..>`.
pub infer_types: bool,
pub infer_args: bool,
}

impl PathSegment {
@@ -358,7 +358,7 @@ impl PathSegment {
ident,
hir_id: None,
res: None,
infer_types: true,
infer_args: true,
args: None,
}
}
@@ -368,13 +368,13 @@ impl PathSegment {
hir_id: Option<HirId>,
res: Option<Res>,
args: GenericArgs,
infer_types: bool,
infer_args: bool,
) -> Self {
PathSegment {
ident,
hir_id,
res,
infer_types,
infer_args,
args: if args.is_empty() {
None
} else {
@@ -1196,7 +1196,7 @@ impl<'a> State<'a> {

segment.with_generic_args(|generic_args| {
if !generic_args.args.is_empty() || !generic_args.bindings.is_empty() {
return self.print_generic_args(&generic_args, segment.infer_types, true);
return self.print_generic_args(&generic_args, segment.infer_args, true);
}
Ok(())
})?;
@@ -1561,7 +1561,7 @@ impl<'a> State<'a> {
if segment.ident.name != kw::PathRoot {
self.print_ident(segment.ident)?;
segment.with_generic_args(|generic_args| {
self.print_generic_args(generic_args, segment.infer_types,
self.print_generic_args(generic_args, segment.infer_args,
colons_before_params)
})?;
}
@@ -1574,7 +1574,7 @@ impl<'a> State<'a> {
if segment.ident.name != kw::PathRoot {
self.print_ident(segment.ident)?;
segment.with_generic_args(|generic_args| {
self.print_generic_args(generic_args, segment.infer_types, false)
self.print_generic_args(generic_args, segment.infer_args, false)
})?;
}
Ok(())
@@ -1602,7 +1602,7 @@ impl<'a> State<'a> {
self.print_ident(segment.ident)?;
segment.with_generic_args(|generic_args| {
self.print_generic_args(generic_args,
segment.infer_types,
segment.infer_args,
colons_before_params)
})?;
}
@@ -1614,7 +1614,7 @@ impl<'a> State<'a> {
self.print_ident(item_segment.ident)?;
item_segment.with_generic_args(|generic_args| {
self.print_generic_args(generic_args,
item_segment.infer_types,
item_segment.infer_args,
colons_before_params)
})
}
@@ -1626,7 +1626,7 @@ impl<'a> State<'a> {
self.print_ident(item_segment.ident)?;
item_segment.with_generic_args(|generic_args| {
self.print_generic_args(generic_args,
item_segment.infer_types,
item_segment.infer_args,
colons_before_params)
})
}
@@ -1635,7 +1635,7 @@ impl<'a> State<'a> {

fn print_generic_args(&mut self,
generic_args: &hir::GenericArgs,
infer_types: bool,
infer_args: bool,
colons_before_params: bool)
-> io::Result<()> {
if generic_args.parenthesized {
@@ -1681,7 +1681,7 @@ impl<'a> State<'a> {

// FIXME(eddyb): this would leak into error messages (e.g.,
// "non-exhaustive patterns: `Some::<..>(_)` not covered").
if infer_types && false {
if infer_args && false {
start_or_comma(self)?;
self.s.word("..")?;
}
@@ -191,7 +191,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
span,
def_id,
generic_args,
item_segment.infer_types,
item_segment.infer_args,
None,
)
});
@@ -208,7 +208,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
seg: &hir::PathSegment,
generics: &ty::Generics,
) -> bool {
let explicit = !seg.infer_types;
let explicit = !seg.infer_args;
let impl_trait = generics.params.iter().any(|param| match param.kind {
ty::GenericParamDefKind::Type {
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), ..
@@ -259,7 +259,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
GenericArgPosition::Value
},
def.parent.is_none() && def.has_self, // `has_self`
seg.infer_types || suppress_mismatch, // `infer_types`
seg.infer_args || suppress_mismatch, // `infer_args`
).0
}

@@ -272,7 +272,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
args: &hir::GenericArgs,
position: GenericArgPosition,
has_self: bool,
infer_types: bool,
infer_args: bool,
) -> (bool, Option<Vec<Span>>) {
// At this stage we are guaranteed that the generic arguments are in the correct order, e.g.
// that lifetimes will proceed types. So it suffices to check the number of each generic
@@ -414,7 +414,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
);
}
// Note that type errors are currently be emitted *after* const errors.
if !infer_types
if !infer_args
|| arg_counts.types > param_counts.types - defaults.types - has_self as usize {
check_kind_count(
"type",
@@ -511,7 +511,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
}

// Check whether this segment takes generic arguments and the user has provided any.
let (generic_args, infer_types) = args_for_def_id(def_id);
let (generic_args, infer_args) = args_for_def_id(def_id);

let mut args = generic_args.iter().flat_map(|generic_args| generic_args.args.iter())
.peekable();
@@ -535,7 +535,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
| (GenericArg::Const(_), GenericParamDefKind::Lifetime) => {
// We expected a lifetime argument, but got a type or const
// argument. That means we're inferring the lifetimes.
substs.push(inferred_kind(None, param, infer_types));
substs.push(inferred_kind(None, param, infer_args));
params.next();
}
(_, _) => {
@@ -556,7 +556,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
(None, Some(&param)) => {
// If there are fewer arguments than parameters, it means
// we're inferring the remaining arguments.
substs.push(inferred_kind(Some(&substs), param, infer_types));
substs.push(inferred_kind(Some(&substs), param, infer_args));
args.next();
params.next();
}
@@ -592,7 +592,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
span: Span,
def_id: DefId,
generic_args: &'a hir::GenericArgs,
infer_types: bool,
infer_args: bool,
self_ty: Option<Ty<'tcx>>)
-> (SubstsRef<'tcx>, Vec<ConvertedBinding<'tcx>>, Option<Vec<Span>>)
{
@@ -617,7 +617,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
&generic_args,
GenericArgPosition::Type,
has_self,
infer_types,
infer_args,
);

let is_object = self_ty.map_or(false, |ty| {
@@ -644,7 +644,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
self_ty.is_some(),
self_ty,
// Provide the generic args, and whether types should be inferred.
|_| (Some(generic_args), infer_types),
|_| (Some(generic_args), infer_args),
// Provide substitutions for parameters for which (valid) arguments have been provided.
|param, arg| {
match (&param.kind, arg) {
@@ -661,11 +661,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
}
},
// Provide substitutions for parameters for which arguments are inferred.
|substs, param, infer_types| {
|substs, param, infer_args| {
match param.kind {
GenericParamDefKind::Lifetime => tcx.lifetimes.re_static.into(),
GenericParamDefKind::Type { has_default, .. } => {
if !infer_types && has_default {
if !infer_args && has_default {
// No type parameter provided, but a default exists.

// If we are converting an object type, then the
@@ -693,7 +693,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
.subst_spanned(tcx, substs.unwrap(), Some(span))
).into()
}
} else if infer_types {
} else if infer_args {
// No type parameters were provided, we can infer all.
if !default_needs_object_self(param) {
self.ty_infer_for_def(param, span).into()
@@ -880,7 +880,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
self.create_substs_for_ast_path(span,
trait_def_id,
generic_args,
trait_segment.infer_types,
trait_segment.infer_args,
Some(self_ty))
})
}
@@ -5419,10 +5419,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if !infer_args_for_err.contains(&index) {
// Check whether the user has provided generic arguments.
if let Some(ref data) = segments[index].args {
return (Some(data), segments[index].infer_types);
return (Some(data), segments[index].infer_args);
}
}
return (None, segments[index].infer_types);
return (None, segments[index].infer_args);
}

(None, true)
@@ -5443,13 +5443,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
},
// Provide substitutions for parameters for which arguments are inferred.
|substs, param, infer_types| {
|substs, param, infer_args| {
match param.kind {
GenericParamDefKind::Lifetime => {
self.re_infer(span, Some(param)).unwrap().into()
}
GenericParamDefKind::Type { has_default, .. } => {
if !infer_types && has_default {
if !infer_args && has_default {
// If we have a default, then we it doesn't matter that we're not
// inferring the type arguments: we provide the default where any
// is missing.

0 comments on commit f1867c5

Please sign in to comment.
You can’t perform that action at this time.