Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest to remove prefix b in cfg attribute lint string #54929

Merged
merged 7 commits into from
Oct 27, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use if let here?

LitKind::ByteStr(_) => true,
_ => false,
}
}

/// Returns true if this is a numeric literal.
pub fn is_numeric(&self) -> bool {
match *self {
Expand Down
202 changes: 147 additions & 55 deletions src/libsyntax/attr/builtin.rs

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/libsyntax/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Symbol> {
match self.node {
MetaItemKind::NameValue(ref v) => {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 5 additions & 5 deletions src/libsyntax_ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ struct S7;
#[cfg(a = 10)] //~ ERROR literal in `cfg` predicate value must be a string
struct S8;

macro_rules! generate_s9 {
#[cfg(a = b"hi")]
csmoe marked this conversation as resolved.
Show resolved Hide resolved
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"));
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,28 @@ error[E0537]: invalid predicate `a`
LL | #[cfg(a())] //~ ERROR invalid predicate `a`
| ^^^

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:22:11
|
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")]
csmoe marked this conversation as resolved.
Show resolved Hide resolved
| ^^^^^ 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

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`.
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0565-1.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/error-codes/E0565-2.rs
Original file line number Diff line number Diff line change
@@ -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 <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.

// repr currently doesn't support literals
#[deprecated(since = b"1.29", note = "hi")] //~ ERROR E0565
struct A { }

fn main() { }
9 changes: 9 additions & 0 deletions src/test/ui/error-codes/E0565-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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
| ^^^^^^^ help: consider removing the prefix: `"1.29"`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0565`.
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0565.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down