Skip to content

Commit 1a4ac00

Browse files
authored
Rollup merge of rust-lang#57565 - petrochenkov:turbowarn, r=Centril
syntax: Remove warning for unnecessary path disambiguators `rustfmt` is now stable and it removes unnecessary turbofishes, so removing the warning as discussed in rust-lang#43540 (where it was introduced). One hardcoded warning less. Closes rust-lang#58055 r? @nikomatsakis
2 parents d7dfa2e + 4b38294 commit 1a4ac00

File tree

6 files changed

+20
-79
lines changed

6 files changed

+20
-79
lines changed

src/libsyntax/ext/tt/macro_parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
929929
p.fatal(&format!("expected ident, found {}", &token_str)).emit();
930930
FatalError.raise()
931931
}
932-
"path" => token::NtPath(panictry!(p.parse_path_common(PathStyle::Type, false))),
932+
"path" => token::NtPath(panictry!(p.parse_path(PathStyle::Type))),
933933
"meta" => token::NtMeta(panictry!(p.parse_meta_item())),
934934
"vis" => token::NtVis(panictry!(p.parse_visibility(true))),
935935
"lifetime" => if p.check_lifetime() {

src/libsyntax/parse/parser.rs

+10-21
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ impl<'a> Parser<'a> {
19031903
self.expect(&token::ModSep)?;
19041904

19051905
let mut path = ast::Path { segments: Vec::new(), span: syntax_pos::DUMMY_SP };
1906-
self.parse_path_segments(&mut path.segments, T::PATH_STYLE, true)?;
1906+
self.parse_path_segments(&mut path.segments, T::PATH_STYLE)?;
19071907
path.span = ty_span.to(self.prev_span);
19081908

19091909
let ty_str = self.sess.source_map().span_to_snippet(ty_span)
@@ -2294,7 +2294,7 @@ impl<'a> Parser<'a> {
22942294
self.expect(&token::ModSep)?;
22952295

22962296
let qself = QSelf { ty, path_span, position: path.segments.len() };
2297-
self.parse_path_segments(&mut path.segments, style, true)?;
2297+
self.parse_path_segments(&mut path.segments, style)?;
22982298

22992299
Ok((qself, ast::Path { segments: path.segments, span: lo.to(self.prev_span) }))
23002300
}
@@ -2310,11 +2310,6 @@ impl<'a> Parser<'a> {
23102310
/// `Fn(Args)` (without disambiguator)
23112311
/// `Fn::(Args)` (with disambiguator)
23122312
pub fn parse_path(&mut self, style: PathStyle) -> PResult<'a, ast::Path> {
2313-
self.parse_path_common(style, true)
2314-
}
2315-
2316-
crate fn parse_path_common(&mut self, style: PathStyle, enable_warning: bool)
2317-
-> PResult<'a, ast::Path> {
23182313
maybe_whole!(self, NtPath, |path| {
23192314
if style == PathStyle::Mod &&
23202315
path.segments.iter().any(|segment| segment.args.is_some()) {
@@ -2329,7 +2324,7 @@ impl<'a> Parser<'a> {
23292324
if self.eat(&token::ModSep) {
23302325
segments.push(PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt)));
23312326
}
2332-
self.parse_path_segments(&mut segments, style, enable_warning)?;
2327+
self.parse_path_segments(&mut segments, style)?;
23332328

23342329
Ok(ast::Path { segments, span: lo.to(self.prev_span) })
23352330
}
@@ -2357,11 +2352,10 @@ impl<'a> Parser<'a> {
23572352

23582353
fn parse_path_segments(&mut self,
23592354
segments: &mut Vec<PathSegment>,
2360-
style: PathStyle,
2361-
enable_warning: bool)
2355+
style: PathStyle)
23622356
-> PResult<'a, ()> {
23632357
loop {
2364-
let segment = self.parse_path_segment(style, enable_warning)?;
2358+
let segment = self.parse_path_segment(style)?;
23652359
if style == PathStyle::Expr {
23662360
// In order to check for trailing angle brackets, we must have finished
23672361
// recursing (`parse_path_segment` can indirectly call this function),
@@ -2389,8 +2383,7 @@ impl<'a> Parser<'a> {
23892383
}
23902384
}
23912385

2392-
fn parse_path_segment(&mut self, style: PathStyle, enable_warning: bool)
2393-
-> PResult<'a, PathSegment> {
2386+
fn parse_path_segment(&mut self, style: PathStyle) -> PResult<'a, PathSegment> {
23942387
let ident = self.parse_path_segment_ident()?;
23952388

23962389
let is_args_start = |token: &token::Token| match *token {
@@ -2407,13 +2400,6 @@ impl<'a> Parser<'a> {
24072400
Ok(if style == PathStyle::Type && check_args_start(self) ||
24082401
style != PathStyle::Mod && self.check(&token::ModSep)
24092402
&& self.look_ahead(1, |t| is_args_start(t)) {
2410-
// Generic arguments are found - `<`, `(`, `::<` or `::(`.
2411-
if self.eat(&token::ModSep) && style == PathStyle::Type && enable_warning {
2412-
self.diagnostic().struct_span_warn(self.prev_span, "unnecessary path disambiguator")
2413-
.span_label(self.prev_span, "try removing `::`").emit();
2414-
}
2415-
let lo = self.span;
2416-
24172403
// We use `style == PathStyle::Expr` to check if this is in a recursion or not. If
24182404
// it isn't, then we reset the unmatched angle bracket count as we're about to start
24192405
// parsing a new path.
@@ -2422,6 +2408,9 @@ impl<'a> Parser<'a> {
24222408
self.max_angle_bracket_count = 0;
24232409
}
24242410

2411+
// Generic arguments are found - `<`, `(`, `::<` or `::(`.
2412+
self.eat(&token::ModSep);
2413+
let lo = self.span;
24252414
let args = if self.eat_lt() {
24262415
// `<'a, T, A = U>`
24272416
let (args, bindings) =
@@ -3043,7 +3032,7 @@ impl<'a> Parser<'a> {
30433032

30443033
// Assuming we have just parsed `.`, continue parsing into an expression.
30453034
fn parse_dot_suffix(&mut self, self_arg: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> {
3046-
let segment = self.parse_path_segment(PathStyle::Expr, true)?;
3035+
let segment = self.parse_path_segment(PathStyle::Expr)?;
30473036
self.check_trailing_angle_brackets(&segment, token::OpenDelim(token::Paren));
30483037

30493038
Ok(match self.token {

src/test/run-pass/packed/packed-struct-generic-size.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ macro_rules! check {
3333
}
3434

3535
pub fn main() {
36-
check!(P1::<u8, u8>, 1, 3);
37-
check!(P1::<u64, u16>, 1, 11);
36+
check!(P1<u8, u8>, 1, 3);
37+
check!(P1<u64, u16>, 1, 11);
3838

39-
check!(P2::<u8, u8>, 1, 3);
40-
check!(P2::<u64, u16>, 2, 12);
39+
check!(P2<u8, u8>, 1, 3);
40+
check!(P2<u64, u16>, 2, 12);
4141

42-
check!(P4C::<u8, u8>, 1, 3);
43-
check!(P4C::<u16, u64>, 4, 12);
42+
check!(P4C<u8, u8>, 1, 3);
43+
check!(P4C<u16, u64>, 4, 12);
4444
}

src/test/run-pass/packed/packed-struct-generic-size.stderr

-36
This file was deleted.

src/test/ui/issues/issue-36116.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ struct Foo<T> {
1717
struct S<T>(T);
1818

1919
fn f() {
20-
let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>); //~ WARN unnecessary path disambiguator
21-
let g: Foo::<i32> = Foo { _a: 42 }; //~ WARN unnecessary path disambiguator
20+
let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
21+
let g: Foo::<i32> = Foo { _a: 42 };
2222

23-
m!(S::<u8>); // OK, no warning
23+
m!(S::<u8>);
2424
}
2525

2626

src/test/ui/issues/issue-36116.stderr

-12
This file was deleted.

0 commit comments

Comments
 (0)