if "trait_bound" in bound:
for param in bound["trait_bound"]["generic_params"]:
check_generic_param(param)
- check_type(bound["trait_bound"]["trait"])
+ check_path(bound["trait_bound"]["trait"])
def check_decl(decl):
if decl["output"]:
check_type(decl["output"])
+def check_path(path):
+ args = path["args"]
+ if args:
+ if "angle_bracketed" in args:
+ for arg in args["angle_bracketed"]["args"]:
+ if "type" in arg:
+ check_type(arg["type"])
+ elif "const" in arg:
+ check_type(arg["const"]["type"])
+ for binding in args["angle_bracketed"]["bindings"]:
+ if "equality" in binding["binding"]:
+ term = binding["binding"]["equality"]
+ if "type" in term: check_type(term["type"])
+ elif "const" in term: check_type(term["const"])
+ elif "constraint" in binding["binding"]:
+ for bound in binding["binding"]["constraint"]:
+ check_generic_bound(bound)
+ elif "parenthesized" in args:
+ for input_ty in args["parenthesized"]["inputs"]:
+ check_type(input_ty)
+ if args["parenthesized"]["output"]:
+ check_type(args["parenthesized"]["output"])
+ if not valid_id(path["id"]):
+ print("Type contained an invalid ID:", path["id"])
+ sys.exit(1)
def check_type(ty):
if ty["kind"] == "resolved_path":
- for bound in ty["inner"]["param_names"]:
- check_generic_bound(bound)
- args = ty["inner"]["args"]
- if args:
- if "angle_bracketed" in args:
- for arg in args["angle_bracketed"]["args"]:
- if "type" in arg:
- check_type(arg["type"])
- elif "const" in arg:
- check_type(arg["const"]["type"])
- for binding in args["angle_bracketed"]["bindings"]:
- if "equality" in binding["binding"]:
- term = binding["binding"]["equality"]
- if "type" in term: check_type(term["type"])
- elif "const" in term: check_type(term["const"])
- elif "constraint" in binding["binding"]:
- for bound in binding["binding"]["constraint"]:
- check_generic_bound(bound)
- elif "parenthesized" in args:
- for ty in args["parenthesized"]["inputs"]:
- check_type(ty)
- if args["parenthesized"]["output"]:
- check_type(args["parenthesized"]["output"])
- if not valid_id(ty["inner"]["id"]):
- print("Type contained an invalid ID:", ty["inner"]["id"])
- sys.exit(1)
+ check_path(ty["inner"])
elif ty["kind"] == "tuple":
for ty in ty["inner"]:
check_type(ty)
check_decl(ty["inner"]["decl"])
elif ty["kind"] == "qualified_path":
check_type(ty["inner"]["self_type"])
- check_type(ty["inner"]["trait"])
+ check_path(ty["inner"]["trait"])
work_list = set([crate["root"]])
elif item["kind"] == "impl":
check_generics(item["inner"]["generics"])
if item["inner"]["trait"]:
- check_type(item["inner"]["trait"])
+ check_path(item["inner"]["trait"])
if item["inner"]["blanket_impl"]:
check_type(item["inner"]["blanket_impl"])
check_type(item["inner"]["for"])