Skip to content

Commit

Permalink
parser: show a helpful note on unexpected inner comment
Browse files Browse the repository at this point in the history
Fixes: #30318.
  • Loading branch information
birkenfeld committed May 3, 2016
1 parent 3157691 commit 72560e1
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 72560e1

Please sign in to comment.