From 2ed2d1a7e6a04896b6b0e30f2b07d0cd5f55afde Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Tue, 9 Oct 2018 17:53:59 +0800 Subject: [PATCH 1/7] suggest to remove prefix `b` in lint string --- src/libsyntax/ast.rs | 8 +++ src/libsyntax/attr/builtin.rs | 129 ++++++++++++++++++++++------------ 2 files changed, 92 insertions(+), 45 deletions(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 9ed628e2ed337..24b016c3d98b1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1326,6 +1326,14 @@ impl LitKind { } } + /// Returns true if this literal is byte literal string false otherwise. + pub fn is_bytestr(&self) -> bool { + match self { + LitKind::ByteStr(_) => true, + _ => false, + } + } + /// Returns true if this is a numeric literal. pub fn is_numeric(&self) -> bool { match *self { diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 1cc2e62a9c600..c39fcf9a09136 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -27,7 +27,7 @@ enum AttrError { UnsupportedLiteral } -fn handle_errors(diag: &Handler, span: Span, error: AttrError) { +fn handle_errors(diag: &Handler, span: Span, error: AttrError, is_bytestr: bool) { match error { AttrError::MultipleItem(item) => span_err!(diag, span, E0538, "multiple '{}' items", item), @@ -44,7 +44,25 @@ fn handle_errors(diag: &Handler, span: Span, error: AttrError) { AttrError::MissingFeature => span_err!(diag, span, E0546, "missing 'feature'"), AttrError::MultipleStabilityLevels => span_err!(diag, span, E0544, "multiple stability levels"), - AttrError::UnsupportedLiteral => span_err!(diag, span, E0565, "unsupported literal"), + AttrError::UnsupportedLiteral => { + let mut err = struct_span_err!( + diag, + span, + E0565, + "unsupported literal", + ); + if is_bytestr { + if let Ok(lint_str) = sess.source_map.span_to_snippet(span) { + err.span_suggestion_with_applicability( + span, + "consider removing the prefix", + format!("{}", lint_str[1..]), + Applicability::MaybeIncorrect, + ); + } + } + err.emit(); + } } } @@ -202,7 +220,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, let meta = meta.as_ref().unwrap(); let get = |meta: &MetaItem, item: &mut Option| { if item.is_some() { - handle_errors(diagnostic, meta.span, AttrError::MultipleItem(meta.name())); + handle_errors(diagnostic, meta.span, AttrError::MultipleItem(meta.name()), false); return false } if let Some(v) = meta.value_str() { @@ -231,12 +249,14 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, handle_errors( diagnostic, mi.span, - AttrError::UnknownMetaItem(mi.name(), expected)); + AttrError::UnknownMetaItem(mi.name(), expected), + false + ); continue 'outer } } } else { - handle_errors(diagnostic, meta.span, AttrError::UnsupportedLiteral); + handle_errors(diagnostic, meta.span, AttrError::UnsupportedLiteral, false); continue 'outer } } @@ -261,7 +281,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, }) } (None, _) => { - handle_errors(diagnostic, attr.span(), AttrError::MissingSince); + handle_errors(diagnostic, attr.span(), AttrError::MissingSince, false); continue } _ => { @@ -287,7 +307,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, } "unstable" => { if stab.is_some() { - handle_errors(diagnostic, attr.span(), AttrError::MultipleStabilityLevels); + handle_errors(diagnostic, attr.span(), AttrError::MultipleStabilityLevels, false); break } @@ -308,12 +328,13 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, mi.name(), &["feature", "reason", "issue"] ), + false, ); continue 'outer } } } else { - handle_errors(diagnostic, meta.span, AttrError::UnsupportedLiteral); + handle_errors(diagnostic, meta.span, AttrError::UnsupportedLiteral, false); continue 'outer } } @@ -340,7 +361,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, }) } (None, _, _) => { - handle_errors(diagnostic, attr.span(), AttrError::MissingFeature); + handle_errors(diagnostic, attr.span(), AttrError::MissingFeature, false); continue } _ => { @@ -351,29 +372,37 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, } "stable" => { if stab.is_some() { - handle_errors(diagnostic, attr.span(), AttrError::MultipleStabilityLevels); + handle_errors(diagnostic, attr.span(), AttrError::MultipleStabilityLevels, false); break } let mut feature = None; let mut since = None; for meta in metas { - if let NestedMetaItemKind::MetaItem(ref mi) = meta.node { - match &*mi.name().as_str() { - "feature" => if !get(mi, &mut feature) { continue 'outer }, - "since" => if !get(mi, &mut since) { continue 'outer }, - _ => { - handle_errors( - diagnostic, - meta.span, - AttrError::UnknownMetaItem(mi.name(), &["since", "note"]), - ); - continue 'outer + match &meta.node { + NestedMetaItemKind::MetaItem(mi) => { + match &*mi.name().as_str() { + "feature" => if !get(mi, &mut feature) { continue 'outer }, + "since" => if !get(mi, &mut since) { continue 'outer }, + _ => { + handle_errors( + diagnostic, + meta.span, + AttrError::UnknownMetaItem(mi.name(), &["since", "note"]), + false, + ); + continue 'outer + } } + NestedMetaItemKind::Literal(lit) => { + handle_errors( + diagnostic, + meta.span, + AttrError::UnsupportedLiteral, + lit.node.is_bytestr() + ); + continue 'outer } - } else { - handle_errors(diagnostic, meta.span, AttrError::UnsupportedLiteral); - continue 'outer } } @@ -390,11 +419,11 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, }) } (None, _) => { - handle_errors(diagnostic, attr.span(), AttrError::MissingFeature); + handle_errors(diagnostic, attr.span(), AttrError::MissingFeature, false); continue } _ => { - handle_errors(diagnostic, attr.span(), AttrError::MissingSince); + handle_errors(diagnostic, attr.span(), AttrError::MissingSince, false); continue } } @@ -461,8 +490,13 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat MetaItemKind::List(..) => { error(cfg.span, "unexpected parentheses after `cfg` predicate key") } - MetaItemKind::NameValue(lit) if !lit.node.is_str() => { - error(lit.span, "literal in `cfg` predicate value must be a string") + MetaItemKind::NameValue(lit) => if !lit.node.is_str() { + handle_errors( + &sess.span_diagnostic, + lit.span, AttrError::UnsupportedLiteral, + lit.node.is_bytestr(), + ); + true } MetaItemKind::NameValue(..) | MetaItemKind::Word => { sess.config.contains(&(cfg.name(), cfg.value_str())) @@ -481,7 +515,7 @@ pub fn eval_condition(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F) ast::MetaItemKind::List(ref mis) => { for mi in mis.iter() { if !mi.is_meta_item() { - handle_errors(&sess.span_diagnostic, mi.span, AttrError::UnsupportedLiteral); + handle_errors(&sess.span_diagnostic, mi.span, AttrError::UnsupportedLiteral, false); return false; } } @@ -551,7 +585,7 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler, depr = if let Some(metas) = attr.meta_item_list() { let get = |meta: &MetaItem, item: &mut Option| { if item.is_some() { - handle_errors(diagnostic, meta.span, AttrError::MultipleItem(meta.name())); + handle_errors(diagnostic, meta.span, AttrError::MultipleItem(meta.name()), false); return false } if let Some(v) = meta.value_str() { @@ -566,22 +600,27 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler, let mut since = None; let mut note = None; for meta in metas { - if let NestedMetaItemKind::MetaItem(ref mi) = meta.node { - match &*mi.name().as_str() { - "since" => if !get(mi, &mut since) { continue 'outer }, - "note" => if !get(mi, &mut note) { continue 'outer }, - _ => { - handle_errors( - diagnostic, - meta.span, - AttrError::UnknownMetaItem(mi.name(), &["since", "note"]), - ); - continue 'outer + match &meta.node { + NestedMetaItemKind::MetaItem(mi) => { + match &*mi.name().as_str() { + "since" => if !get(mi, &mut since) { continue 'outer }, + "note" => if !get(mi, &mut note) { continue 'outer }, + _ => { + handle_errors( + diagnostic, + meta.span, + AttrError::UnknownMetaItem(mi.name(), &["since", "note"]), + false, + ); + continue 'outer + } } } - } else { - handle_errors(diagnostic, meta.span, AttrError::UnsupportedLiteral); - continue 'outer + NestedMetaItemKind::Literal(lit) => { + let is_bytestr = lit.node.is_bytestr(); + handle_errors(diagnostic, meta.span, AttrError::UnsupportedLiteral, is_bytestr); + continue 'outer + } } } @@ -638,7 +677,7 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec mark_used(attr); for item in items { if !item.is_meta_item() { - handle_errors(diagnostic, item.span, AttrError::UnsupportedLiteral); + handle_errors(diagnostic, item.span, AttrError::UnsupportedLiteral, false); continue } From 30c669819342dc09d6bd29dc72d0ff85381b71d2 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Tue, 9 Oct 2018 19:49:18 +0800 Subject: [PATCH 2/7] handle errors based on parse_sess --- src/librustc/middle/stability.rs | 6 +- src/librustc/ty/mod.rs | 2 +- src/librustc_lint/nonstandard_style.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- src/libsyntax/attr/builtin.rs | 67 ++++++++++++----------- src/libsyntax/ext/tt/macro_rules.rs | 2 +- src/libsyntax_ext/deriving/generic/mod.rs | 10 ++-- 7 files changed, 48 insertions(+), 43 deletions(-) diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 9dd13dd2272b0..d496272ae3477 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -134,11 +134,11 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { if self.tcx.features().staged_api { // This crate explicitly wants staged API. debug!("annotate(id = {:?}, attrs = {:?})", id, attrs); - if let Some(..) = attr::find_deprecation(self.tcx.sess.diagnostic(), attrs, item_sp) { + if let Some(..) = attr::find_deprecation(&self.tcx.sess.parse_sess, attrs, item_sp) { self.tcx.sess.span_err(item_sp, "`#[deprecated]` cannot be used in staged api, \ use `#[rustc_deprecated]` instead"); } - if let Some(mut stab) = attr::find_stability(self.tcx.sess.diagnostic(), + if let Some(mut stab) = attr::find_stability(&self.tcx.sess.parse_sess, attrs, item_sp) { // Error if prohibited, or can't inherit anything from a container if kind == AnnotationKind::Prohibited || @@ -224,7 +224,7 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { } } - if let Some(depr) = attr::find_deprecation(self.tcx.sess.diagnostic(), attrs, item_sp) { + if let Some(depr) = attr::find_deprecation(&self.tcx.sess.parse_sess, attrs, item_sp) { if kind == AnnotationKind::Prohibited { self.tcx.sess.span_err(item_sp, "This deprecation annotation is useless"); } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 45a70be5842fc..e2461bbf988fc 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1927,7 +1927,7 @@ impl ReprOptions { let mut max_align = 0; let mut min_pack = 0; for attr in tcx.get_attrs(did).iter() { - for r in attr::find_repr_attrs(tcx.sess.diagnostic(), attr) { + for r in attr::find_repr_attrs(&tcx.sess.parse_sess, attr) { flags.insert(match r { attr::ReprC => ReprFlags::IS_C, attr::ReprPacked(pack) => { diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 56d204f15d935..40781b0771d89 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -121,7 +121,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCamelCaseTypes { let has_repr_c = it.attrs .iter() .any(|attr| { - attr::find_repr_attrs(cx.tcx.sess.diagnostic(), attr) + attr::find_repr_attrs(&cx.tcx.sess.parse_sess, attr) .iter() .any(|r| r == &attr::ReprC) }); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index ffa21e1fc22a5..3093a6c629f42 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1713,7 +1713,7 @@ fn check_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: DefId) let repr = tcx.adt_def(def_id).repr; if repr.packed() { for attr in tcx.get_attrs(def_id).iter() { - for r in attr::find_repr_attrs(tcx.sess.diagnostic(), attr) { + for r in attr::find_repr_attrs(&tcx.sess.parse_sess, attr) { if let attr::ReprPacked(pack) = r { if pack != repr.pack { struct_span_err!(tcx.sess, sp, E0634, diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index c39fcf9a09136..0c82b5c710705 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -27,7 +27,8 @@ enum AttrError { UnsupportedLiteral } -fn handle_errors(diag: &Handler, span: Span, error: AttrError, is_bytestr: bool) { +fn handle_errors(sess: &ParseSess, span: Span, error: AttrError, is_bytestr: bool) { + let diag = &sess.span_diagnostic; match error { AttrError::MultipleItem(item) => span_err!(diag, span, E0538, "multiple '{}' items", item), @@ -52,11 +53,11 @@ fn handle_errors(diag: &Handler, span: Span, error: AttrError, is_bytestr: bool) "unsupported literal", ); if is_bytestr { - if let Ok(lint_str) = sess.source_map.span_to_snippet(span) { + if let Ok(lint_str) = sess.source_map().span_to_snippet(span) { err.span_suggestion_with_applicability( span, "consider removing the prefix", - format!("{}", lint_str[1..]), + format!("{}", &lint_str[1..]), Applicability::MaybeIncorrect, ); } @@ -179,12 +180,12 @@ pub fn contains_feature_attr(attrs: &[Attribute], feature_name: &str) -> bool { } /// Find the first stability attribute. `None` if none exists. -pub fn find_stability(diagnostic: &Handler, attrs: &[Attribute], +pub fn find_stability(sess: &ParseSess, attrs: &[Attribute], item_sp: Span) -> Option { - find_stability_generic(diagnostic, attrs.iter(), item_sp) + find_stability_generic(sess, attrs.iter(), item_sp) } -fn find_stability_generic<'a, I>(diagnostic: &Handler, +fn find_stability_generic<'a, I>(sess: &ParseSess, attrs_iter: I, item_sp: Span) -> Option @@ -196,6 +197,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, let mut rustc_depr: Option = None; let mut rustc_const_unstable: Option = None; let mut promotable = false; + let diagnostic = &sess.span_diagnostic; 'outer: for attr in attrs_iter { if ![ @@ -220,7 +222,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, let meta = meta.as_ref().unwrap(); let get = |meta: &MetaItem, item: &mut Option| { if item.is_some() { - handle_errors(diagnostic, meta.span, AttrError::MultipleItem(meta.name()), false); + handle_errors(sess, meta.span, AttrError::MultipleItem(meta.name()), false); return false } if let Some(v) = meta.value_str() { @@ -247,16 +249,16 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, _ => { let expected = &[ $( stringify!($name) ),+ ]; handle_errors( - diagnostic, + sess, mi.span, AttrError::UnknownMetaItem(mi.name(), expected), - false + false, ); continue 'outer } } } else { - handle_errors(diagnostic, meta.span, AttrError::UnsupportedLiteral, false); + handle_errors(sess, meta.span, AttrError::UnsupportedLiteral, false); continue 'outer } } @@ -281,7 +283,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, }) } (None, _) => { - handle_errors(diagnostic, attr.span(), AttrError::MissingSince, false); + handle_errors(sess, attr.span(), AttrError::MissingSince, false); continue } _ => { @@ -307,7 +309,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, } "unstable" => { if stab.is_some() { - handle_errors(diagnostic, attr.span(), AttrError::MultipleStabilityLevels, false); + handle_errors(sess, attr.span(), AttrError::MultipleStabilityLevels, false); break } @@ -322,7 +324,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, "issue" => if !get(mi, &mut issue) { continue 'outer }, _ => { handle_errors( - diagnostic, + sess, meta.span, AttrError::UnknownMetaItem( mi.name(), @@ -334,7 +336,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, } } } else { - handle_errors(diagnostic, meta.span, AttrError::UnsupportedLiteral, false); + handle_errors(sess, meta.span, AttrError::UnsupportedLiteral, false); continue 'outer } } @@ -361,7 +363,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, }) } (None, _, _) => { - handle_errors(diagnostic, attr.span(), AttrError::MissingFeature, false); + handle_errors(sess, attr.span(), AttrError::MissingFeature, false); continue } _ => { @@ -372,7 +374,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, } "stable" => { if stab.is_some() { - handle_errors(diagnostic, attr.span(), AttrError::MultipleStabilityLevels, false); + handle_errors(sess, attr.span(), AttrError::MultipleStabilityLevels, false); break } @@ -386,7 +388,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, "since" => if !get(mi, &mut since) { continue 'outer }, _ => { handle_errors( - diagnostic, + sess, meta.span, AttrError::UnknownMetaItem(mi.name(), &["since", "note"]), false, @@ -394,9 +396,10 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, continue 'outer } } + }, NestedMetaItemKind::Literal(lit) => { handle_errors( - diagnostic, + sess, meta.span, AttrError::UnsupportedLiteral, lit.node.is_bytestr() @@ -419,11 +422,11 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler, }) } (None, _) => { - handle_errors(diagnostic, attr.span(), AttrError::MissingFeature, false); + handle_errors(sess, attr.span(), AttrError::MissingFeature, false); continue } _ => { - handle_errors(diagnostic, attr.span(), AttrError::MissingSince, false); + handle_errors(sess, attr.span(), AttrError::MissingSince, false); continue } } @@ -490,9 +493,9 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat MetaItemKind::List(..) => { error(cfg.span, "unexpected parentheses after `cfg` predicate key") } - MetaItemKind::NameValue(lit) => if !lit.node.is_str() { + MetaItemKind::NameValue(lit) if !lit.node.is_str() => { handle_errors( - &sess.span_diagnostic, + sess, lit.span, AttrError::UnsupportedLiteral, lit.node.is_bytestr(), ); @@ -515,7 +518,7 @@ pub fn eval_condition(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F) ast::MetaItemKind::List(ref mis) => { for mi in mis.iter() { if !mi.is_meta_item() { - handle_errors(&sess.span_diagnostic, mi.span, AttrError::UnsupportedLiteral, false); + handle_errors(sess, mi.span, AttrError::UnsupportedLiteral, false); return false; } } @@ -557,18 +560,19 @@ pub struct Deprecation { } /// Find the deprecation attribute. `None` if none exists. -pub fn find_deprecation(diagnostic: &Handler, attrs: &[Attribute], +pub fn find_deprecation(sess: &ParseSess, attrs: &[Attribute], item_sp: Span) -> Option { - find_deprecation_generic(diagnostic, attrs.iter(), item_sp) + find_deprecation_generic(sess, attrs.iter(), item_sp) } -fn find_deprecation_generic<'a, I>(diagnostic: &Handler, +fn find_deprecation_generic<'a, I>(sess: &ParseSess, attrs_iter: I, item_sp: Span) -> Option where I: Iterator { let mut depr: Option = None; + let diagnostic = &sess.span_diagnostic; 'outer: for attr in attrs_iter { if attr.path != "deprecated" { @@ -585,7 +589,7 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler, depr = if let Some(metas) = attr.meta_item_list() { let get = |meta: &MetaItem, item: &mut Option| { if item.is_some() { - handle_errors(diagnostic, meta.span, AttrError::MultipleItem(meta.name()), false); + handle_errors(sess, meta.span, AttrError::MultipleItem(meta.name()), false); return false } if let Some(v) = meta.value_str() { @@ -607,7 +611,7 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler, "note" => if !get(mi, &mut note) { continue 'outer }, _ => { handle_errors( - diagnostic, + sess, meta.span, AttrError::UnknownMetaItem(mi.name(), &["since", "note"]), false, @@ -618,7 +622,7 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler, } NestedMetaItemKind::Literal(lit) => { let is_bytestr = lit.node.is_bytestr(); - handle_errors(diagnostic, meta.span, AttrError::UnsupportedLiteral, is_bytestr); + handle_errors(sess, meta.span, AttrError::UnsupportedLiteral, is_bytestr); continue 'outer } } @@ -668,16 +672,17 @@ impl IntType { /// the same discriminant size that the corresponding C enum would or C /// structure layout, `packed` to remove padding, and `transparent` to elegate representation /// concerns to the only non-ZST field. -pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec { +pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec { use self::ReprAttr::*; let mut acc = Vec::new(); + let diagnostic = &sess.span_diagnostic; if attr.path == "repr" { if let Some(items) = attr.meta_item_list() { mark_used(attr); for item in items { if !item.is_meta_item() { - handle_errors(diagnostic, item.span, AttrError::UnsupportedLiteral, false); + handle_errors(sess, item.span, AttrError::UnsupportedLiteral, false); continue } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 87ade278c685a..3dec93ecf7c94 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -340,7 +340,7 @@ pub fn compile(sess: &ParseSess, features: &Features, def: &ast::Item, edition: } } - let unstable_feature = attr::find_stability(&sess.span_diagnostic, + let unstable_feature = attr::find_stability(&sess, &def.attrs, def.span).and_then(|stability| { if let attr::StabilityLevel::Unstable { issue, .. } = stability.level { Some((stability.feature, issue)) diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 28a2c11ceb104..002ecce58e652 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -202,8 +202,8 @@ use syntax::source_map::{self, respan}; use syntax::util::move_map::MoveMap; use syntax::ptr::P; use syntax::symbol::{Symbol, keywords}; +use syntax::parse::ParseSess; use syntax_pos::{DUMMY_SP, Span}; -use errors::Handler; use self::ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty}; @@ -412,7 +412,7 @@ impl<'a> TraitDef<'a> { match *item { Annotatable::Item(ref item) => { let is_packed = item.attrs.iter().any(|attr| { - for r in attr::find_repr_attrs(&cx.parse_sess.span_diagnostic, attr) { + for r in attr::find_repr_attrs(&cx.parse_sess, attr) { if let attr::ReprPacked(_) = r { return true; } @@ -811,10 +811,10 @@ impl<'a> TraitDef<'a> { } } -fn find_repr_type_name(diagnostic: &Handler, type_attrs: &[ast::Attribute]) -> &'static str { +fn find_repr_type_name(sess: &ParseSess, type_attrs: &[ast::Attribute]) -> &'static str { let mut repr_type_name = "isize"; for a in type_attrs { - for r in &attr::find_repr_attrs(diagnostic, a) { + for r in &attr::find_repr_attrs(sess, a) { repr_type_name = match *r { attr::ReprPacked(_) | attr::ReprSimd | attr::ReprAlign(_) | attr::ReprTransparent => continue, @@ -1390,7 +1390,7 @@ impl<'a> MethodDef<'a> { // discriminant_test = __self0_vi == __self1_vi && __self0_vi == __self2_vi && ... let mut discriminant_test = cx.expr_bool(sp, true); - let target_type_name = find_repr_type_name(&cx.parse_sess.span_diagnostic, type_attrs); + let target_type_name = find_repr_type_name(&cx.parse_sess, type_attrs); let mut first_ident = None; for (&ident, self_arg) in vi_idents.iter().zip(&self_args) { From d3b018ccdba328389ca90cff8795e5f6b97e5c13 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Tue, 9 Oct 2018 22:54:47 +0800 Subject: [PATCH 3/7] suggest to trim prefix in nested meta items --- src/libsyntax/attr/builtin.rs | 21 ++++++++++++++++++--- src/libsyntax/attr/mod.rs | 9 +++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 0c82b5c710705..8f9f91979a42f 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -596,7 +596,17 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess, *item = Some(v); true } else { - span_err!(diagnostic, meta.span, E0551, "incorrect meta item"); + if let Some(lit) = meta.name_value_literal() { + handle_errors( + sess, + lit.span, + AttrError::UnsupportedLiteral, + lit.node.is_bytestr(), + ); + } else { + span_err!(diagnostic, meta.span, E0551, "incorrect meta item"); + } + false } }; @@ -622,7 +632,7 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess, } NestedMetaItemKind::Literal(lit) => { let is_bytestr = lit.node.is_bytestr(); - handle_errors(sess, meta.span, AttrError::UnsupportedLiteral, is_bytestr); + handle_errors(sess, lit.span, AttrError::UnsupportedLiteral, is_bytestr); continue 'outer } } @@ -682,7 +692,12 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec { mark_used(attr); for item in items { if !item.is_meta_item() { - handle_errors(sess, item.span, AttrError::UnsupportedLiteral, false); + let (span, is_bytestr) = if let Some(lit) = item.literal() { + (lit.span, lit.node.is_bytestr()) + } else { + (item.span, false) + }; + handle_errors(sess, span, AttrError::UnsupportedLiteral, is_bytestr); continue } diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index a980f3ab51584..5404420988c35 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -219,6 +219,15 @@ impl MetaItem { name_from_path(&self.ident) } + // #[attribute(name = "value")] + // ^^^^^^^^^^^^^^ + pub fn name_value_literal(&self) -> Option<&Lit> { + match &self.node { + MetaItemKind::NameValue(v) => Some(v), + _ => None, + } + } + pub fn value_str(&self) -> Option { match self.node { MetaItemKind::NameValue(ref v) => { From fb7c76bad551255b174958ccbfe7b7cda7f53897 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Tue, 9 Oct 2018 22:55:07 +0800 Subject: [PATCH 4/7] update meta item checking test --- src/libsyntax/attr/builtin.rs | 4 +++- .../cfg-attr-syntax-validation.rs | 11 +++++++---- .../cfg-attr-syntax-validation.stderr | 7 ++++--- src/test/ui/error-codes/E0565-2.rs | 15 +++++++++++++++ src/test/ui/error-codes/E0565-2.stderr | 9 +++++++++ 5 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 src/test/ui/error-codes/E0565-2.rs create mode 100644 src/test/ui/error-codes/E0565-2.stderr diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 8f9f91979a42f..86aebe6a2ab51 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -390,7 +390,9 @@ fn find_stability_generic<'a, I>(sess: &ParseSess, handle_errors( sess, meta.span, - AttrError::UnknownMetaItem(mi.name(), &["since", "note"]), + AttrError::UnknownMetaItem( + mi.name(), &["since", "note"], + ), false, ); continue 'outer diff --git a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.rs b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.rs index 06a22eff25c21..8a9740f830922 100644 --- a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.rs +++ b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.rs @@ -19,14 +19,17 @@ struct S6; #[cfg(a())] //~ ERROR invalid predicate `a` struct S7; -#[cfg(a = 10)] //~ ERROR literal in `cfg` predicate value must be a string +#[cfg(a = 10)] //~ ERROR unsupported literal struct S8; -macro_rules! generate_s9 { +#[deprecated(since = b"1.30", note = "hi")] //~ ERROR E0565 +struct S9; + +macro_rules! generate_s10 { ($expr: expr) => { #[cfg(feature = $expr)] //~ ERROR `cfg` is not a well-formed meta-item - struct S9; + struct S10; } } -generate_s9!(concat!("nonexistent")); +generate_s10!(concat!("nonexistent")); diff --git a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr index 7773fdb8cf984..0b8f2c864eb04 100644 --- a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr +++ b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr @@ -40,10 +40,10 @@ error[E0537]: invalid predicate `a` LL | #[cfg(a())] //~ ERROR invalid predicate `a` | ^^^ -error: literal in `cfg` predicate value must be a string +error[E0565]: unsupported literal --> $DIR/cfg-attr-syntax-validation.rs:22:11 | -LL | #[cfg(a = 10)] //~ ERROR literal in `cfg` predicate value must be a string +LL | #[cfg(a = 10)] //~ ERROR unsupported literal | ^^ error: `cfg` is not a well-formed meta-item @@ -57,4 +57,5 @@ LL | generate_s9!(concat!("nonexistent")); error: aborting due to 9 previous errors -For more information about this error, try `rustc --explain E0537`. +Some errors occurred: E0537, E0565. +For more information about an error, try `rustc --explain E0537`. diff --git a/src/test/ui/error-codes/E0565-2.rs b/src/test/ui/error-codes/E0565-2.rs new file mode 100644 index 0000000000000..eb13e43275111 --- /dev/null +++ b/src/test/ui/error-codes/E0565-2.rs @@ -0,0 +1,15 @@ +// Copyright 2018 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// repr currently doesn't support literals +#[deprecated(since = b"1.29", note = "hi")] //~ ERROR E0565 +struct A { } + +fn main() { } diff --git a/src/test/ui/error-codes/E0565-2.stderr b/src/test/ui/error-codes/E0565-2.stderr new file mode 100644 index 0000000000000..46125b71420a1 --- /dev/null +++ b/src/test/ui/error-codes/E0565-2.stderr @@ -0,0 +1,9 @@ +error[E0565]: unsupported literal + --> $DIR/E0565-2.rs:12:22 + | +LL | #[deprecated(since = b"1.29", note = "hi")] //~ ERROR E0565 + | ^^^^^^^ help: consider removing the prefix: `"1.29"` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0565`. From a76690f6a4292a9ca67e9b0efc70c2a82fb9f187 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Sat, 20 Oct 2018 11:11:01 +0800 Subject: [PATCH 5/7] optimize unsupported literal diag message --- src/libsyntax/attr/builtin.rs | 109 +++++++++++------- .../cfg-attr-syntax-validation.rs | 4 +- .../cfg-attr-syntax-validation.stderr | 18 ++- src/test/ui/error-codes/E0565-1.stderr | 2 +- src/test/ui/error-codes/E0565-2.stderr | 2 +- src/test/ui/error-codes/E0565.stderr | 2 +- 6 files changed, 87 insertions(+), 50 deletions(-) diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 86aebe6a2ab51..1bbc1accc07d6 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -24,10 +24,10 @@ enum AttrError { MissingSince, MissingFeature, MultipleStabilityLevels, - UnsupportedLiteral + UnsupportedLiteral(&'static str, /* is_bytestr */ bool), } -fn handle_errors(sess: &ParseSess, span: Span, error: AttrError, is_bytestr: bool) { +fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) { let diag = &sess.span_diagnostic; match error { AttrError::MultipleItem(item) => span_err!(diag, span, E0538, @@ -45,13 +45,11 @@ fn handle_errors(sess: &ParseSess, span: Span, error: AttrError, is_bytestr: boo AttrError::MissingFeature => span_err!(diag, span, E0546, "missing 'feature'"), AttrError::MultipleStabilityLevels => span_err!(diag, span, E0544, "multiple stability levels"), - AttrError::UnsupportedLiteral => { - let mut err = struct_span_err!( - diag, - span, - E0565, - "unsupported literal", - ); + AttrError::UnsupportedLiteral( + msg, + is_bytestr, + ) => { + let mut err = struct_span_err!(diag, span, E0565, "{}", msg); if is_bytestr { if let Ok(lint_str) = sess.source_map().span_to_snippet(span) { err.span_suggestion_with_applicability( @@ -222,7 +220,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess, let meta = meta.as_ref().unwrap(); let get = |meta: &MetaItem, item: &mut Option| { if item.is_some() { - handle_errors(sess, meta.span, AttrError::MultipleItem(meta.name()), false); + handle_errors(sess, meta.span, AttrError::MultipleItem(meta.name())); return false } if let Some(v) = meta.value_str() { @@ -252,13 +250,19 @@ fn find_stability_generic<'a, I>(sess: &ParseSess, sess, mi.span, AttrError::UnknownMetaItem(mi.name(), expected), - false, ); continue 'outer } } } else { - handle_errors(sess, meta.span, AttrError::UnsupportedLiteral, false); + handle_errors( + sess, + meta.span, + AttrError::UnsupportedLiteral( + "unsupported literal", + false, + ), + ); continue 'outer } } @@ -283,7 +287,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess, }) } (None, _) => { - handle_errors(sess, attr.span(), AttrError::MissingSince, false); + handle_errors(sess, attr.span(), AttrError::MissingSince); continue } _ => { @@ -309,7 +313,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess, } "unstable" => { if stab.is_some() { - handle_errors(sess, attr.span(), AttrError::MultipleStabilityLevels, false); + handle_errors(sess, attr.span(), AttrError::MultipleStabilityLevels); break } @@ -330,13 +334,19 @@ fn find_stability_generic<'a, I>(sess: &ParseSess, mi.name(), &["feature", "reason", "issue"] ), - false, ); continue 'outer } } } else { - handle_errors(sess, meta.span, AttrError::UnsupportedLiteral, false); + handle_errors( + sess, + meta.span, + AttrError::UnsupportedLiteral( + "unsupported literal", + false, + ), + ); continue 'outer } } @@ -363,7 +373,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess, }) } (None, _, _) => { - handle_errors(sess, attr.span(), AttrError::MissingFeature, false); + handle_errors(sess, attr.span(), AttrError::MissingFeature); continue } _ => { @@ -374,7 +384,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess, } "stable" => { if stab.is_some() { - handle_errors(sess, attr.span(), AttrError::MultipleStabilityLevels, false); + handle_errors(sess, attr.span(), AttrError::MultipleStabilityLevels); break } @@ -393,7 +403,6 @@ fn find_stability_generic<'a, I>(sess: &ParseSess, AttrError::UnknownMetaItem( mi.name(), &["since", "note"], ), - false, ); continue 'outer } @@ -402,9 +411,11 @@ fn find_stability_generic<'a, I>(sess: &ParseSess, NestedMetaItemKind::Literal(lit) => { handle_errors( sess, - meta.span, - AttrError::UnsupportedLiteral, - lit.node.is_bytestr() + lit.span, + AttrError::UnsupportedLiteral( + "unsupported literal", + false, + ), ); continue 'outer } @@ -424,11 +435,11 @@ fn find_stability_generic<'a, I>(sess: &ParseSess, }) } (None, _) => { - handle_errors(sess, attr.span(), AttrError::MissingFeature, false); + handle_errors(sess, attr.span(), AttrError::MissingFeature); continue } _ => { - handle_errors(sess, attr.span(), AttrError::MissingSince, false); + handle_errors(sess, attr.span(), AttrError::MissingSince); continue } } @@ -498,8 +509,11 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat MetaItemKind::NameValue(lit) if !lit.node.is_str() => { handle_errors( sess, - lit.span, AttrError::UnsupportedLiteral, - lit.node.is_bytestr(), + lit.span, + AttrError::UnsupportedLiteral( + "literal in `cfg` predicate value must be a string", + lit.node.is_bytestr() + ), ); true } @@ -520,7 +534,14 @@ pub fn eval_condition(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F) ast::MetaItemKind::List(ref mis) => { for mi in mis.iter() { if !mi.is_meta_item() { - handle_errors(sess, mi.span, AttrError::UnsupportedLiteral, false); + handle_errors( + sess, + mi.span, + AttrError::UnsupportedLiteral( + "unsupported literal", + false + ), + ); return false; } } @@ -591,7 +612,7 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess, depr = if let Some(metas) = attr.meta_item_list() { let get = |meta: &MetaItem, item: &mut Option| { if item.is_some() { - handle_errors(sess, meta.span, AttrError::MultipleItem(meta.name()), false); + handle_errors(sess, meta.span, AttrError::MultipleItem(meta.name())); return false } if let Some(v) = meta.value_str() { @@ -602,8 +623,11 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess, handle_errors( sess, lit.span, - AttrError::UnsupportedLiteral, - lit.node.is_bytestr(), + AttrError::UnsupportedLiteral( + "literal in `deprecated` \ + value must be a string", + lit.node.is_bytestr() + ), ); } else { span_err!(diagnostic, meta.span, E0551, "incorrect meta item"); @@ -626,15 +650,20 @@ fn find_deprecation_generic<'a, I>(sess: &ParseSess, sess, meta.span, AttrError::UnknownMetaItem(mi.name(), &["since", "note"]), - false, ); continue 'outer } } } NestedMetaItemKind::Literal(lit) => { - let is_bytestr = lit.node.is_bytestr(); - handle_errors(sess, lit.span, AttrError::UnsupportedLiteral, is_bytestr); + handle_errors( + sess, + lit.span, + AttrError::UnsupportedLiteral( + "item in `deprecated` must be a key/value pair", + false, + ), + ); continue 'outer } } @@ -694,12 +723,14 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec { mark_used(attr); for item in items { if !item.is_meta_item() { - let (span, is_bytestr) = if let Some(lit) = item.literal() { - (lit.span, lit.node.is_bytestr()) - } else { - (item.span, false) - }; - handle_errors(sess, span, AttrError::UnsupportedLiteral, is_bytestr); + handle_errors( + sess, + item.span, + AttrError::UnsupportedLiteral( + "meta item in `repr` must be an identifier", + false, + ), + ); continue } diff --git a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.rs b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.rs index 8a9740f830922..539c0777d66bc 100644 --- a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.rs +++ b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.rs @@ -19,10 +19,10 @@ struct S6; #[cfg(a())] //~ ERROR invalid predicate `a` struct S7; -#[cfg(a = 10)] //~ ERROR unsupported literal +#[cfg(a = 10)] //~ ERROR literal in `cfg` predicate value must be a string struct S8; -#[deprecated(since = b"1.30", note = "hi")] //~ ERROR E0565 +#[cfg(a = b"hi")] struct S9; macro_rules! generate_s10 { diff --git a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr index 0b8f2c864eb04..84a5728c6ce0f 100644 --- a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr +++ b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr @@ -40,22 +40,28 @@ error[E0537]: invalid predicate `a` LL | #[cfg(a())] //~ ERROR invalid predicate `a` | ^^^ -error[E0565]: unsupported literal +error[E0565]: literal in `cfg` predicate value must be a string --> $DIR/cfg-attr-syntax-validation.rs:22:11 | -LL | #[cfg(a = 10)] //~ ERROR unsupported literal +LL | #[cfg(a = 10)] //~ ERROR literal in `cfg` predicate value must be a string | ^^ +error[E0565]: literal in `cfg` predicate value must be a string + --> $DIR/cfg-attr-syntax-validation.rs:25:11 + | +LL | #[cfg(a = b"hi")] + | ^^^^^ help: consider removing the prefix: `"hi"` + error: `cfg` is not a well-formed meta-item - --> $DIR/cfg-attr-syntax-validation.rs:27:9 + --> $DIR/cfg-attr-syntax-validation.rs:30:9 | LL | #[cfg(feature = $expr)] //~ ERROR `cfg` is not a well-formed meta-item | ^^^^^^^^^^^^^^^^^^^^^^^ help: expected syntax is: `#[cfg(/* predicate */)]` ... -LL | generate_s9!(concat!("nonexistent")); - | ------------------------------------- in this macro invocation +LL | generate_s10!(concat!("nonexistent")); + | -------------------------------------- in this macro invocation -error: aborting due to 9 previous errors +error: aborting due to 10 previous errors Some errors occurred: E0537, E0565. For more information about an error, try `rustc --explain E0537`. diff --git a/src/test/ui/error-codes/E0565-1.stderr b/src/test/ui/error-codes/E0565-1.stderr index 2a9bf92e9dd48..a2e099acd3c6a 100644 --- a/src/test/ui/error-codes/E0565-1.stderr +++ b/src/test/ui/error-codes/E0565-1.stderr @@ -1,4 +1,4 @@ -error[E0565]: unsupported literal +error[E0565]: item in `deprecated` must be a key/value pair --> $DIR/E0565-1.rs:12:14 | LL | #[deprecated("since")] //~ ERROR E0565 diff --git a/src/test/ui/error-codes/E0565-2.stderr b/src/test/ui/error-codes/E0565-2.stderr index 46125b71420a1..68093e4e2f077 100644 --- a/src/test/ui/error-codes/E0565-2.stderr +++ b/src/test/ui/error-codes/E0565-2.stderr @@ -1,4 +1,4 @@ -error[E0565]: unsupported literal +error[E0565]: literal in `deprecated` value must be a string --> $DIR/E0565-2.rs:12:22 | LL | #[deprecated(since = b"1.29", note = "hi")] //~ ERROR E0565 diff --git a/src/test/ui/error-codes/E0565.stderr b/src/test/ui/error-codes/E0565.stderr index abea4290f0a68..04edff8ec6962 100644 --- a/src/test/ui/error-codes/E0565.stderr +++ b/src/test/ui/error-codes/E0565.stderr @@ -1,4 +1,4 @@ -error[E0565]: unsupported literal +error[E0565]: meta item in `repr` must be an identifier --> $DIR/E0565.rs:12:8 | LL | #[repr("C")] //~ ERROR E0565 From 82b86e53e0a02631cbd98c83c7bc4d9ba3ca3225 Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Tue, 23 Oct 2018 09:03:11 +0800 Subject: [PATCH 6/7] add expected error comment Co-Authored-By: csmoe --- .../ui/conditional-compilation/cfg-attr-syntax-validation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.rs b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.rs index 539c0777d66bc..83e162e08712f 100644 --- a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.rs +++ b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.rs @@ -22,7 +22,7 @@ struct S7; #[cfg(a = 10)] //~ ERROR literal in `cfg` predicate value must be a string struct S8; -#[cfg(a = b"hi")] +#[cfg(a = b"hi")] //~ ERROR literal in `cfg` predicate value must be a string struct S9; macro_rules! generate_s10 { From 81a609bd4c7a8244e1cedaf9d34824b241deadbb Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Tue, 23 Oct 2018 09:03:35 +0800 Subject: [PATCH 7/7] add expected error comment Co-Authored-By: csmoe --- .../conditional-compilation/cfg-attr-syntax-validation.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr index 84a5728c6ce0f..da06a81751cdb 100644 --- a/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr +++ b/src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr @@ -49,7 +49,7 @@ LL | #[cfg(a = 10)] //~ ERROR literal in `cfg` predicate value must be a string error[E0565]: literal in `cfg` predicate value must be a string --> $DIR/cfg-attr-syntax-validation.rs:25:11 | -LL | #[cfg(a = b"hi")] +LL | #[cfg(a = b"hi")] //~ ERROR literal in `cfg` predicate value must be a string | ^^^^^ help: consider removing the prefix: `"hi"` error: `cfg` is not a well-formed meta-item