private static bool IsLegalPattern(ISyntaxFacts syntaxFacts, SyntaxNode pattern, bool designatorsLegal)
        {
            // It is illegal to create a pattern that has a designator under a not-pattern or or-pattern
            if (syntaxFacts.IsBinaryPattern(pattern))
            {
                syntaxFacts.GetPartsOfBinaryPattern(pattern, out var left, out _, out var right);
                designatorsLegal = designatorsLegal && !syntaxFacts.IsOrPattern(pattern);
                return(IsLegalPattern(syntaxFacts, left, designatorsLegal) &&
                       IsLegalPattern(syntaxFacts, right, designatorsLegal));
            }

            if (syntaxFacts.IsNotPattern(pattern))
            {
                // it's fine to have `not string s` (or `not (string s)`) as long as we're currently in a location where
                // designators are legal themselves.
                syntaxFacts.GetPartsOfUnaryPattern(pattern, out _, out var subPattern);
                if (syntaxFacts.IsParenthesizedPattern(subPattern))
                {
                    subPattern = syntaxFacts.GetPatternOfParenthesizedPattern(subPattern);
                }

                if (syntaxFacts.IsDeclarationPattern(subPattern))
                {
                    return(designatorsLegal);
                }

                return(IsLegalPattern(syntaxFacts, subPattern, designatorsLegal: false));
            }

            if (syntaxFacts.IsParenthesizedPattern(pattern))
            {
                syntaxFacts.GetPartsOfParenthesizedPattern(pattern, out _, out var subPattern, out _);
                return(IsLegalPattern(syntaxFacts, subPattern, designatorsLegal));
            }

            if (syntaxFacts.IsDeclarationPattern(pattern))
            {
                syntaxFacts.GetPartsOfDeclarationPattern(pattern, out _, out var designator);
                return(designator == null || designatorsLegal);
            }

            if (syntaxFacts.IsRecursivePattern(pattern))
            {
                syntaxFacts.GetPartsOfRecursivePattern(pattern, out _, out _, out _, out var designator);
                return(designator == null || designatorsLegal);
            }

            if (syntaxFacts.IsVarPattern(pattern))
            {
                return(designatorsLegal);
            }

            return(true);
        }