Skip to content

Commit 93417fa

Browse files
committedOct 18, 2016
Add invalid doc comment help message
1 parent 16eeeac commit 93417fa

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed
 

‎src/libsyntax/config.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use attr::HasAttrs;
12-
use feature_gate::{emit_feature_err, EXPLAIN_STMT_ATTR_SYNTAX, Features, get_features, GateIssue};
12+
use feature_gate::{feature_err, EXPLAIN_STMT_ATTR_SYNTAX, Features, get_features, GateIssue};
1313
use {fold, attr};
1414
use ast;
1515
use codemap::{Spanned, respan};
@@ -157,11 +157,15 @@ impl<'a> StripUnconfigured<'a> {
157157
// flag the offending attributes
158158
for attr in attrs.iter() {
159159
if !self.features.map(|features| features.stmt_expr_attributes).unwrap_or(true) {
160-
emit_feature_err(&self.sess,
161-
"stmt_expr_attributes",
162-
attr.span,
163-
GateIssue::Language,
164-
EXPLAIN_STMT_ATTR_SYNTAX);
160+
let mut err = feature_err(&self.sess,
161+
"stmt_expr_attributes",
162+
attr.span,
163+
GateIssue::Language,
164+
EXPLAIN_STMT_ATTR_SYNTAX);
165+
if attr.node.is_sugared_doc {
166+
err.help("`///` is for documentation comments. For a plain comment, use `//`.");
167+
}
168+
err.emit();
165169
}
166170
}
167171
}

‎src/libsyntax/feature_gate.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use ast::{self, NodeId, PatKind};
3030
use attr;
3131
use codemap::{CodeMap, Spanned};
3232
use syntax_pos::Span;
33-
use errors::Handler;
33+
use errors::{DiagnosticBuilder, Handler};
3434
use visit::{self, FnKind, Visitor};
3535
use parse::ParseSess;
3636
use parse::token::InternedString;
@@ -792,6 +792,11 @@ pub enum GateIssue {
792792

793793
pub fn emit_feature_err(sess: &ParseSess, feature: &str, span: Span, issue: GateIssue,
794794
explain: &str) {
795+
feature_err(sess, feature, span, issue, explain).emit();
796+
}
797+
798+
pub fn feature_err<'a>(sess: &'a ParseSess, feature: &str, span: Span, issue: GateIssue,
799+
explain: &str) -> DiagnosticBuilder<'a> {
795800
let diag = &sess.span_diagnostic;
796801

797802
let issue = match issue {
@@ -812,7 +817,7 @@ pub fn emit_feature_err(sess: &ParseSess, feature: &str, span: Span, issue: Gate
812817
feature));
813818
}
814819

815-
err.emit();
820+
err
816821
}
817822

818823
const EXPLAIN_BOX_SYNTAX: &'static str =

0 commit comments

Comments
 (0)
Please sign in to comment.