fn validate_relation(
        &self,
        package_name: &PackageName,
        package_json: &PackageJson,
        relation_package_name: &PackageName,
        tags: Option<&Spanned<Vec<Spanned<String>>>>,
        allow_list: Option<&Spanned<HashSet<String>>>,
        deny_list: Option<&Spanned<HashSet<String>>>,
    ) -> Result<Option<BoundariesDiagnostic>, Error> {
        // We allow "punning" the package name as a tag, so if the allow list contains
        // the package name, then we have a tag in the allow list
        // Likewise, if the allow list is empty, then we vacuously have a tag in the
        // allow list
        let mut has_tag_in_allowlist =
            allow_list.is_none_or(|allow_list| allow_list.contains(relation_package_name.as_str()));
        let tags_span = tags.map(|tags| tags.to(())).unwrap_or_default();
        if let Some(deny_list) = deny_list {
            if deny_list.contains(relation_package_name.as_str()) {
                let (span, text) = package_json
                    .name
                    .as_ref()
                    .map(|name| name.span_and_text("turbo.json"))
                    .unwrap_or_else(|| (None, NamedSource::new("package.json", String::new())));
                let deny_list_spanned = deny_list.to(());
                let (deny_list_span, deny_list_text) =
                    deny_list_spanned.span_and_text("turbo.json");

                return Ok(Some(BoundariesDiagnostic::DeniedTag {
                    source_package_name: package_name.clone(),
                    package_name: relation_package_name.clone(),
                    tag: relation_package_name.to_string(),
                    span,
                    text,
                    secondary: [SecondaryDiagnostic::Denylist {
                        span: deny_list_span,
                        text: deny_list_text,
                    }],
                }));
            }
        }

        for tag in tags.into_iter().flatten().flatten() {
            if let Some(allow_list) = allow_list {
                if allow_list.contains(tag.as_inner()) {
                    has_tag_in_allowlist = true;
                }
            }

            if let Some(deny_list) = deny_list {
                if deny_list.contains(tag.as_inner()) {
                    let (span, text) = tag.span_and_text("turbo.json");
                    let deny_list_spanned = deny_list.to(());
                    let (deny_list_span, deny_list_text) =
                        deny_list_spanned.span_and_text("turbo.json");

                    return Ok(Some(BoundariesDiagnostic::DeniedTag {
                        source_package_name: package_name.clone(),
                        package_name: relation_package_name.clone(),
                        tag: tag.as_inner().to_string(),
                        span,
                        text,
                        secondary: [SecondaryDiagnostic::Denylist {
                            span: deny_list_span,
                            text: deny_list_text,
                        }],
                    }));
                }
            }
        }

        if !has_tag_in_allowlist {
            let (span, text) = tags_span.span_and_text("turbo.json");
            let help = span.is_none().then(|| {
                format!(
                    "`{}` doesn't any tags defined in its `turbo.json` file",
                    relation_package_name
                )
            });

            let allow_list_spanned = allow_list
                .map(|allow_list| allow_list.to(()))
                .unwrap_or_default();
            let (allow_list_span, allow_list_text) = allow_list_spanned.span_and_text("turbo.json");

            return Ok(Some(BoundariesDiagnostic::NoTagInAllowlist {
                source_package_name: package_name.clone(),
                package_name: relation_package_name.clone(),
                help,
                span,
                text,
                secondary: [SecondaryDiagnostic::Allowlist {
                    span: allow_list_span,
                    text: allow_list_text,
                }],
            }));
        }

        Ok(None)
    }
Loops through the tags of a package that is related to `package_name`
(i.e. either a dependency or a dependent) and checks if the tag is
allowed or denied by the rules in `allow_list` and `deny_list`.
crates/turborepo-lib/src/boundaries/tags.rs