]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #94839 - TaKO8Ki:suggest-using-double-colon-for-struct-field-type...
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>
Fri, 11 Mar 2022 19:29:47 +0000 (20:29 +0100)
committerGitHub <noreply@github.com>
Fri, 11 Mar 2022 19:29:47 +0000 (20:29 +0100)
Suggest using double colon when a struct field type include single colon

#92685

1  2 
compiler/rustc_parse/src/parser/item.rs

index 06460c7b1b31ddcc8e21ec89ff01fe4bdbfb2c00,ec89301c1e22edf17358721a99c63179ee207dcf..122fe10e80f8fb331ce3aab4cae7a15c923ec420
@@@ -14,7 -14,7 +14,7 @@@ use rustc_ast::{FnHeader, ForeignItem, 
  use rustc_ast::{MacArgs, MacCall, MacDelimiter};
  use rustc_ast_pretty::pprust;
  use rustc_errors::{struct_span_err, Applicability, PResult, StashKey};
 -use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
 +use rustc_span::edition::Edition;
  use rustc_span::lev_distance::lev_distance;
  use rustc_span::source_map::{self, Span};
  use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@@ -1534,6 -1534,16 +1534,16 @@@ impl<'a> Parser<'a> 
          let name = self.parse_field_ident(adt_ty, lo)?;
          self.expect_field_ty_separator()?;
          let ty = self.parse_ty()?;
+         if self.token.kind == token::Colon && self.look_ahead(1, |tok| tok.kind != token::Colon) {
+             self.struct_span_err(self.token.span, "found single colon in a struct field type path")
+                 .span_suggestion_verbose(
+                     self.token.span,
+                     "write a path separator here",
+                     "::".to_string(),
+                     Applicability::MaybeIncorrect,
+                 )
+                 .emit();
+         }
          if self.token.kind == token::Eq {
              self.bump();
              let const_expr = self.parse_anon_const_expr()?;
@@@ -2102,7 -2112,8 +2112,7 @@@ impl<'a> Parser<'a> 
              let diag = self.diagnostic();
              struct_span_err!(diag, span, E0670, "`async fn` is not permitted in Rust 2015")
                  .span_label(span, "to use `async fn`, switch to Rust 2018 or later")
 -                .help(&format!("set `edition = \"{}\"` in `Cargo.toml`", LATEST_STABLE_EDITION))
 -                .note("for more on editions, read https://doc.rust-lang.org/edition-guide")
 +                .help_use_latest_edition()
                  .emit();
          }
      }