]> git.lizzy.rs Git - rust.git/commitdiff
syntax: Remove warning for unnecessary path disambiguators
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 13 Jan 2019 01:52:59 +0000 (04:52 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 23 Mar 2019 14:20:11 +0000 (17:20 +0300)
src/libsyntax/ext/tt/macro_parser.rs
src/libsyntax/parse/parser.rs
src/test/run-pass/packed/packed-struct-generic-size.rs
src/test/run-pass/packed/packed-struct-generic-size.stderr [deleted file]
src/test/ui/issues/issue-36116.rs
src/test/ui/issues/issue-36116.stderr [deleted file]

index 1a419e7fadaa0228e884595b824cc5e32f328ad7..ab5823eaca52af4f3d7443392ffd51636a3888ed 100644 (file)
@@ -929,7 +929,7 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
             p.fatal(&format!("expected ident, found {}", &token_str)).emit();
             FatalError.raise()
         }
-        "path" => token::NtPath(panictry!(p.parse_path_common(PathStyle::Type, false))),
+        "path" => token::NtPath(panictry!(p.parse_path(PathStyle::Type))),
         "meta" => token::NtMeta(panictry!(p.parse_meta_item())),
         "vis" => token::NtVis(panictry!(p.parse_visibility(true))),
         "lifetime" => if p.check_lifetime() {
index 6ff06aa4b31d39c00530764e3a5586fd6b5ef3f7..c3e1aa7ae117fb69ef92bfc95e445521fd359ac5 100644 (file)
@@ -1903,7 +1903,7 @@ fn maybe_recover_from_bad_qpath_stage_2<T: RecoverQPath>(&mut self, ty_span: Spa
         self.expect(&token::ModSep)?;
 
         let mut path = ast::Path { segments: Vec::new(), span: syntax_pos::DUMMY_SP };
-        self.parse_path_segments(&mut path.segments, T::PATH_STYLE, true)?;
+        self.parse_path_segments(&mut path.segments, T::PATH_STYLE)?;
         path.span = ty_span.to(self.prev_span);
 
         let ty_str = self.sess.source_map().span_to_snippet(ty_span)
@@ -2294,7 +2294,7 @@ fn parse_qpath(&mut self, style: PathStyle) -> PResult<'a, (QSelf, ast::Path)> {
         self.expect(&token::ModSep)?;
 
         let qself = QSelf { ty, path_span, position: path.segments.len() };
-        self.parse_path_segments(&mut path.segments, style, true)?;
+        self.parse_path_segments(&mut path.segments, style)?;
 
         Ok((qself, ast::Path { segments: path.segments, span: lo.to(self.prev_span) }))
     }
@@ -2310,11 +2310,6 @@ fn parse_qpath(&mut self, style: PathStyle) -> PResult<'a, (QSelf, ast::Path)> {
     /// `Fn(Args)` (without disambiguator)
     /// `Fn::(Args)` (with disambiguator)
     pub fn parse_path(&mut self, style: PathStyle) -> PResult<'a, ast::Path> {
-        self.parse_path_common(style, true)
-    }
-
-    crate fn parse_path_common(&mut self, style: PathStyle, enable_warning: bool)
-                             -> PResult<'a, ast::Path> {
         maybe_whole!(self, NtPath, |path| {
             if style == PathStyle::Mod &&
                path.segments.iter().any(|segment| segment.args.is_some()) {
@@ -2329,7 +2324,7 @@ pub fn parse_path(&mut self, style: PathStyle) -> PResult<'a, ast::Path> {
         if self.eat(&token::ModSep) {
             segments.push(PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt)));
         }
-        self.parse_path_segments(&mut segments, style, enable_warning)?;
+        self.parse_path_segments(&mut segments, style)?;
 
         Ok(ast::Path { segments, span: lo.to(self.prev_span) })
     }
@@ -2357,11 +2352,10 @@ pub fn parse_path_allowing_meta(&mut self, style: PathStyle) -> PResult<'a, ast:
 
     fn parse_path_segments(&mut self,
                            segments: &mut Vec<PathSegment>,
-                           style: PathStyle,
-                           enable_warning: bool)
+                           style: PathStyle)
                            -> PResult<'a, ()> {
         loop {
-            let segment = self.parse_path_segment(style, enable_warning)?;
+            let segment = self.parse_path_segment(style)?;
             if style == PathStyle::Expr {
                 // In order to check for trailing angle brackets, we must have finished
                 // recursing (`parse_path_segment` can indirectly call this function),
@@ -2389,8 +2383,7 @@ fn parse_path_segments(&mut self,
         }
     }
 
-    fn parse_path_segment(&mut self, style: PathStyle, enable_warning: bool)
-                          -> PResult<'a, PathSegment> {
+    fn parse_path_segment(&mut self, style: PathStyle) -> PResult<'a, PathSegment> {
         let ident = self.parse_path_segment_ident()?;
 
         let is_args_start = |token: &token::Token| match *token {
@@ -2407,13 +2400,6 @@ fn parse_path_segment(&mut self, style: PathStyle, enable_warning: bool)
         Ok(if style == PathStyle::Type && check_args_start(self) ||
               style != PathStyle::Mod && self.check(&token::ModSep)
                                       && self.look_ahead(1, |t| is_args_start(t)) {
-            // Generic arguments are found - `<`, `(`, `::<` or `::(`.
-            if self.eat(&token::ModSep) && style == PathStyle::Type && enable_warning {
-                self.diagnostic().struct_span_warn(self.prev_span, "unnecessary path disambiguator")
-                                 .span_label(self.prev_span, "try removing `::`").emit();
-            }
-            let lo = self.span;
-
             // We use `style == PathStyle::Expr` to check if this is in a recursion or not. If
             // it isn't, then we reset the unmatched angle bracket count as we're about to start
             // parsing a new path.
@@ -2422,6 +2408,9 @@ fn parse_path_segment(&mut self, style: PathStyle, enable_warning: bool)
                 self.max_angle_bracket_count = 0;
             }
 
+            // Generic arguments are found - `<`, `(`, `::<` or `::(`.
+            self.eat(&token::ModSep);
+            let lo = self.span;
             let args = if self.eat_lt() {
                 // `<'a, T, A = U>`
                 let (args, bindings) =
@@ -3043,7 +3032,7 @@ fn parse_dot_or_call_expr_with(&mut self,
 
     // Assuming we have just parsed `.`, continue parsing into an expression.
     fn parse_dot_suffix(&mut self, self_arg: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> {
-        let segment = self.parse_path_segment(PathStyle::Expr, true)?;
+        let segment = self.parse_path_segment(PathStyle::Expr)?;
         self.check_trailing_angle_brackets(&segment, token::OpenDelim(token::Paren));
 
         Ok(match self.token {
index 08d4674d2a88a19feb81d9fc46e8c96de839269f..7c93e46c30c23ff2fede4848337627b051629191 100644 (file)
@@ -33,12 +33,12 @@ macro_rules! check {
 }
 
 pub fn main() {
-    check!(P1::<u8, u8>, 1, 3);
-    check!(P1::<u64, u16>, 1, 11);
+    check!(P1<u8, u8>, 1, 3);
+    check!(P1<u64, u16>, 1, 11);
 
-    check!(P2::<u8, u8>, 1, 3);
-    check!(P2::<u64, u16>, 2, 12);
+    check!(P2<u8, u8>, 1, 3);
+    check!(P2<u64, u16>, 2, 12);
 
-    check!(P4C::<u8, u8>, 1, 3);
-    check!(P4C::<u16, u64>, 4, 12);
+    check!(P4C<u8, u8>, 1, 3);
+    check!(P4C<u16, u64>, 4, 12);
 }
diff --git a/src/test/run-pass/packed/packed-struct-generic-size.stderr b/src/test/run-pass/packed/packed-struct-generic-size.stderr
deleted file mode 100644 (file)
index 1af476c..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-warning: unnecessary path disambiguator
-  --> $DIR/packed-struct-generic-size.rs:36:14
-   |
-LL |     check!(P1::<u8, u8>, 1, 3);
-   |              ^^ try removing `::`
-
-warning: unnecessary path disambiguator
-  --> $DIR/packed-struct-generic-size.rs:37:14
-   |
-LL |     check!(P1::<u64, u16>, 1, 11);
-   |              ^^ try removing `::`
-
-warning: unnecessary path disambiguator
-  --> $DIR/packed-struct-generic-size.rs:39:14
-   |
-LL |     check!(P2::<u8, u8>, 1, 3);
-   |              ^^ try removing `::`
-
-warning: unnecessary path disambiguator
-  --> $DIR/packed-struct-generic-size.rs:40:14
-   |
-LL |     check!(P2::<u64, u16>, 2, 12);
-   |              ^^ try removing `::`
-
-warning: unnecessary path disambiguator
-  --> $DIR/packed-struct-generic-size.rs:42:15
-   |
-LL |     check!(P4C::<u8, u8>, 1, 3);
-   |               ^^ try removing `::`
-
-warning: unnecessary path disambiguator
-  --> $DIR/packed-struct-generic-size.rs:43:15
-   |
-LL |     check!(P4C::<u16, u64>, 4, 12);
-   |               ^^ try removing `::`
-
index f4fe96cf75b558a68356be3bc6ae89f4a29c1b86..b4bfba4d6e5d7c2a4742c66394cc9afbb4fe82aa 100644 (file)
@@ -17,10 +17,10 @@ struct Foo<T> {
 struct S<T>(T);
 
 fn f() {
-    let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>); //~ WARN unnecessary path disambiguator
-    let g: Foo::<i32> = Foo { _a: 42 }; //~ WARN unnecessary path disambiguator
+    let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
+    let g: Foo::<i32> = Foo { _a: 42 };
 
-    m!(S::<u8>); // OK, no warning
+    m!(S::<u8>);
 }
 
 
diff --git a/src/test/ui/issues/issue-36116.stderr b/src/test/ui/issues/issue-36116.stderr
deleted file mode 100644 (file)
index 5236db2..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-warning: unnecessary path disambiguator
-  --> $DIR/issue-36116.rs:20:50
-   |
-LL |     let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
-   |                                                  ^^ try removing `::`
-
-warning: unnecessary path disambiguator
-  --> $DIR/issue-36116.rs:21:15
-   |
-LL |     let g: Foo::<i32> = Foo { _a: 42 };
-   |               ^^ try removing `::`
-