pub(super) fn check_trailing_angle_brackets(
        &mut self,
        segment: &PathSegment,
        end: &[&TokenKind],
    ) -> bool {
        // This function is intended to be invoked after parsing a path segment where there are two
        // cases:
        //
        // 1. A specific token is expected after the path segment.
        //    eg. `x.foo(`, `x.foo::<u32>(` (parenthesis - method call),
        //        `Foo::`, or `Foo::<Bar>::` (mod sep - continued path).
        // 2. No specific token is expected after the path segment.
        //    eg. `x.foo` (field access)
        //
        // This function is called after parsing `.foo` and before parsing the token `end` (if
        // present). This includes any angle bracket arguments, such as `.foo::<u32>` or
        // `Foo::<Bar>`.

        // We only care about trailing angle brackets if we previously parsed angle bracket
        // arguments. This helps stop us incorrectly suggesting that extra angle brackets be
        // removed in this case:
        //
        // `x.foo >> (3)` (where `x.foo` is a `u32` for example)
        //
        // This case is particularly tricky as we won't notice it just looking at the tokens -
        // it will appear the same (in terms of upcoming tokens) as below (since the `::<u32>` will
        // have already been parsed):
        //
        // `x.foo::<u32>>>(3)`
        let parsed_angle_bracket_args =
            segment.args.as_ref().map(|args| args.is_angle_bracketed()).unwrap_or(false);

        debug!(
            "check_trailing_angle_brackets: parsed_angle_bracket_args={:?}",
            parsed_angle_bracket_args,
        );
        if !parsed_angle_bracket_args {
            return false;
        }

        // Keep the span at the start so we can highlight the sequence of `>` characters to be
        // removed.
        let lo = self.token.span;

        // We need to look-ahead to see if we have `>` characters without moving the cursor forward
        // (since we might have the field access case and the characters we're eating are
        // actual operators and not trailing characters - ie `x.foo >> 3`).
        let mut position = 0;

        // We can encounter `>` or `>>` tokens in any order, so we need to keep track of how
        // many of each (so we can correctly pluralize our error messages) and continue to
        // advance.
        let mut number_of_shr = 0;
        let mut number_of_gt = 0;
        while self.look_ahead(position, |t| {
            trace!("check_trailing_angle_brackets: t={:?}", t);
            if *t == token::BinOp(token::BinOpToken::Shr) {
                number_of_shr += 1;
                true
            } else if *t == token::Gt {
                number_of_gt += 1;
                true
            } else {
                false
            }
        }) {
            position += 1;
        }

        // If we didn't find any trailing `>` characters, then we have nothing to error about.
        debug!(
            "check_trailing_angle_brackets: number_of_gt={:?} number_of_shr={:?}",
            number_of_gt, number_of_shr,
        );
        if number_of_gt < 1 && number_of_shr < 1 {
            return false;
        }

        // Finally, double check that we have our end token as otherwise this is the
        // second case.
        if self.look_ahead(position, |t| {
            trace!("check_trailing_angle_brackets: t={:?}", t);
            end.contains(&&t.kind)
        }) {
            // Eat from where we started until the end token so that parsing can continue
            // as if we didn't have those extra angle brackets.
            self.eat_to_tokens(end);
            let span = lo.until(self.token.span);

            let total_num_of_gt = number_of_gt + number_of_shr * 2;
            self.struct_span_err(
                span,
                &format!("unmatched angle bracket{}", pluralize!(total_num_of_gt)),
            )
            .span_suggestion(
                span,
                &format!("remove extra angle bracket{}", pluralize!(total_num_of_gt)),
                String::new(),
                Applicability::MachineApplicable,
            )
            .emit();
            return true;
        }
        false
    }
/// This function checks if there are trailing angle brackets and produces
/// a diagnostic to suggest removing them.
///
/// ```ignore (diagnostic)
/// let _ = vec![1, 2, 3].into_iter().collect::<Vec<usize>>>>();
///                                                        ^^ help: remove extra angle brackets
/// ```
///
/// If `true` is returned, then trailing brackets were recovered, tokens were consumed
/// up until one of the tokens in 'end' was encountered, and an error was emitted.
This function checks if there are trailing angle brackets and produces
a diagnostic to suggest removing them.



If `true` is returned, then trailing brackets were recovered, tokens were consumed
up until one of the tokens in 'end' was encountered, and an error was emitted.
This function checks if there are trailing angle brackets and produces a diagnostic to suggest removing them . If ` true ` is returned then trailing brackets were recovered tokens were consumed up until one of the tokens in ' end ' was encountered and an error was emitted .
pub(super) fn check_trailing_angle_brackets(
        &mut self,
        segment: &PathSegment,
        end: &[&TokenKind],
    ) -> bool {
        // This function is intended to be invoked after parsing a path segment where there are two
        // cases:
        //
        // 1. A specific token is expected after the path segment.
        //    eg. `x.foo(`, `x.foo::<u32>(` (parenthesis - method call),
        //        `Foo::`, or `Foo::<Bar>::` (mod sep - continued path).
        // 2. No specific token is expected after the path segment.
        //    eg. `x.foo` (field access)
        //
        // This function is called after parsing `.foo` and before parsing the token `end` (if
        // present). This includes any angle bracket arguments, such as `.foo::<u32>` or
        // `Foo::<Bar>`.
        // We only care about trailing angle brackets if we previously parsed angle bracket
        // arguments. This helps stop us incorrectly suggesting that extra angle brackets be
        // removed in this case:
        //
        // `x.foo >> (3)` (where `x.foo` is a `u32` for example)
        //
        // This case is particularly tricky as we won't notice it just looking at the tokens -
        // it will appear the same (in terms of upcoming tokens) as below (since the `::<u32>` will
        // have already been parsed):
        //
        // `x.foo::<u32>>>(3)`
        let parsed_angle_bracket_args =
            segment.args.as_ref().map(|args| args.is_angle_bracketed()).unwrap_or(false);
        debug!(
            "check_trailing_angle_brackets: parsed_angle_bracket_args={:?}",
            parsed_angle_bracket_args,
        );
        if !parsed_angle_bracket_args {
            return false;
        }
        // Keep the span at the start so we can highlight the sequence of `>` characters to be
        // removed.
        let lo = self.token.span;
        // We need to look-ahead to see if we have `>` characters without moving the cursor forward
        // (since we might have the field access case and the characters we're eating are
        // actual operators and not trailing characters - ie `x.foo >> 3`).
        let mut position = 0;
        // We can encounter `>` or `>>` tokens in any order, so we need to keep track of how
        // many of each (so we can correctly pluralize our error messages) and continue to
        // advance.
        let mut number_of_shr = 0;
        let mut number_of_gt = 0;
        while self.look_ahead(position, |t| {
            trace!("check_trailing_angle_brackets: t={:?}", t);
            if *t == token::BinOp(token::BinOpToken::Shr) {
                number_of_shr += 1;
                true
            } else if *t == token::Gt {
                number_of_gt += 1;
                true
            } else {
                false
            }
        }) {
            position += 1;
        }
        // If we didn't find any trailing `>` characters, then we have nothing to error about.
        debug!(
            "check_trailing_angle_brackets: number_of_gt={:?} number_of_shr={:?}",
            number_of_gt, number_of_shr,
        );
        if number_of_gt < 1 && number_of_shr < 1 {
            return false;
        }
        // Finally, double check that we have our end token as otherwise this is the
        // second case.
        if self.look_ahead(position, |t| {
            trace!("check_trailing_angle_brackets: t={:?}", t);
            end.contains(&&t.kind)
        }) {
            // Eat from where we started until the end token so that parsing can continue
            // as if we didn't have those extra angle brackets.
            self.eat_to_tokens(end);
            let span = lo.until(self.token.span);
            let total_num_of_gt = number_of_gt + number_of_shr * 2;
            self.struct_span_err(
                span,
                &format!("unmatched angle bracket{}", pluralize!(total_num_of_gt)),
            )
            .span_suggestion(
                span,
                &format!("remove extra angle bracket{}", pluralize!(total_num_of_gt)),
                String::new(),
                Applicability::MachineApplicable,
            )
            .emit();
            return true;
        }
        false
    }
pub ( super ) fn check_trailing_angle_brackets ( & mut self , segment : & PathSegment , end : & [ & TokenKind ] , ) -> bool { // This function is intended to be invoked after parsing a path segment where there are two // cases: // // 1. A specific token is expected after the path segment. //    eg. `x.foo(`, `x.foo::<u32>(` (parenthesis - method call), //        `Foo::`, or `Foo::<Bar>::` (mod sep - continued path). // 2. No specific token is expected after the path segment. //    eg. `x.foo` (field access) // // This function is called after parsing `.foo` and before parsing the token `end` (if // present). This includes any angle bracket arguments, such as `.foo::<u32>` or // `Foo::<Bar>`. // We only care about trailing angle brackets if we previously parsed angle bracket // arguments. This helps stop us incorrectly suggesting that extra angle brackets be // removed in this case: // // `x.foo >> (3)` (where `x.foo` is a `u32` for example) // // This case is particularly tricky as we won't notice it just looking at the tokens - // it will appear the same (in terms of upcoming tokens) as below (since the `::<u32>` will // have already been parsed): // // `x.foo::<u32>>>(3)` let parsed_angle_bracket_args = segment . args . as_ref ( ) . map ( | args | args . is_angle_bracketed ( ) ) . unwrap_or ( false ) ; debug ! ( " " parsed_angle_bracket_args ) ; if ! parsed_angle_bracket_args { return false ; } // Keep the span at the start so we can highlight the sequence of `>` characters to be // removed. let lo = self . token . span ; // We need to look-ahead to see if we have `>` characters without moving the cursor forward // (since we might have the field access case and the characters we're eating are // actual operators and not trailing characters - ie `x.foo >> 3`). let mut position = 0 ; // We can encounter `>` or `>>` tokens in any order, so we need to keep track of how // many of each (so we can correctly pluralize our error messages) and continue to // advance. let mut number_of_shr = 0 ; let mut number_of_gt = 0 ; while self . look_ahead ( position , | t | { trace ! ( " " t ) ; if * t == token :: BinOp ( token :: BinOpToken :: Shr ) { number_of_shr += 1 ; true } else if * t == token :: Gt { number_of_gt += 1 ; true } else { false } } ) { position += 1 ; } // If we didn't find any trailing `>` characters, then we have nothing to error about. debug ! ( " " number_of_gt number_of_shr ) ; if number_of_gt < 1 && number_of_shr < 1 { return false ; } // Finally, double check that we have our end token as otherwise this is the // second case. if self . look_ahead ( position , | t | { trace ! ( " " t ) ; end . contains ( & & t . kind ) } ) { // Eat from where we started until the end token so that parsing can continue // as if we didn't have those extra angle brackets. self . eat_to_tokens ( end ) ; let span = lo . until ( self . token . span ) ; let total_num_of_gt = number_of_gt + number_of_shr * 2 ; self . struct_span_err ( span , & format ! ( " " pluralize ( total_num_of_gt ) ) , ) . span_suggestion ( span , & format ! ( " " pluralize ( total_num_of_gt ) ) , String :: new ( ) , Applicability :: MachineApplicable , ) . emit ( ) ; return true ; } false }
This function checks if there are trailing angle brackets and produces
a diagnostic to suggest removing them.
This function checks if there are trailing angle brackets and produces a diagnostic to suggest removing them .
&mut self
segment
&PathSegment
end
&[&TokenKind]
&mut self
segment
&PathSegment
end
&[&TokenKind]