Skip to content

Commit

Permalink
Auto merge of #33333 - birkenfeld:issue-30318, r=Manishearth
Browse files Browse the repository at this point in the history
parser: show a helpful note on unexpected inner comment

Fixes: #30318.
  • Loading branch information
bors committed May 7, 2016
2 parents a9cc5b0 + 72560e1 commit 0d61bb3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/libsyntax/parse/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ impl<'a> Parser<'a> {
self.span.hi
);
if attr.node.style != ast::AttrStyle::Outer {
return Err(self.fatal("expected outer comment"));
let mut err = self.fatal("expected outer doc comment");
err.note("inner doc comments like this (starting with \
`//!` or `/*!`) can only appear before items");
return Err(err);
}
attrs.push(attr);
self.bump();
Expand Down
19 changes: 19 additions & 0 deletions src/test/parse-fail/issue-30318.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only

fn foo() { }

//! Misplaced comment...
//~^ ERROR expected outer doc comment
//~| NOTE inner doc comments like this (starting with `//!` or `/*!`) can only appear before items

fn main() { }

0 comments on commit 0d61bb3

Please sign in to comment.