Skip to content

Commit

Permalink
Rollup merge of rust-lang#57565 - petrochenkov:turbowarn, r=Centril
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cuviper authored Mar 28, 2019
2 parents 74a69f2 + 4b38294 commit c818c1a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/libsyntax/ext/tt/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
31 changes: 10 additions & 21 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,7 @@ impl<'a> Parser<'a> {
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)
Expand Down Expand Up @@ -2294,7 +2294,7 @@ impl<'a> Parser<'a> {
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) }))
}
Expand All @@ -2310,11 +2310,6 @@ impl<'a> Parser<'a> {
/// `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()) {
Expand All @@ -2329,7 +2324,7 @@ impl<'a> Parser<'a> {
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) })
}
Expand Down Expand Up @@ -2357,11 +2352,10 @@ impl<'a> Parser<'a> {

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),
Expand Down Expand Up @@ -2389,8 +2383,7 @@ impl<'a> Parser<'a> {
}
}

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 {
Expand All @@ -2407,13 +2400,6 @@ impl<'a> Parser<'a> {
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.
Expand All @@ -2422,6 +2408,9 @@ impl<'a> Parser<'a> {
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) =
Expand Down Expand Up @@ -3043,7 +3032,7 @@ impl<'a> Parser<'a> {

// 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 {
Expand Down
12 changes: 6 additions & 6 deletions src/test/run-pass/packed/packed-struct-generic-size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
36 changes: 0 additions & 36 deletions src/test/run-pass/packed/packed-struct-generic-size.stderr

This file was deleted.

6 changes: 3 additions & 3 deletions src/test/ui/issues/issue-36116.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>);
}


Expand Down
12 changes: 0 additions & 12 deletions src/test/ui/issues/issue-36116.stderr

This file was deleted.

0 comments on commit c818c1a

Please sign in to comment.