Skip to content

Commit fa45602

Browse files
committed
Auto merge of #54929 - csmoe:cfg_lint, r=petrochenkov
Suggest to remove prefix `b` in cfg attribute lint string Closes #54926 r? @estebank
2 parents 3e6f30e + 81a609b commit fa45602

File tree

15 files changed

+221
-78
lines changed

15 files changed

+221
-78
lines changed

src/librustc/middle/stability.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
134134
if self.tcx.features().staged_api {
135135
// This crate explicitly wants staged API.
136136
debug!("annotate(id = {:?}, attrs = {:?})", id, attrs);
137-
if let Some(..) = attr::find_deprecation(self.tcx.sess.diagnostic(), attrs, item_sp) {
137+
if let Some(..) = attr::find_deprecation(&self.tcx.sess.parse_sess, attrs, item_sp) {
138138
self.tcx.sess.span_err(item_sp, "`#[deprecated]` cannot be used in staged api, \
139139
use `#[rustc_deprecated]` instead");
140140
}
141-
if let Some(mut stab) = attr::find_stability(self.tcx.sess.diagnostic(),
141+
if let Some(mut stab) = attr::find_stability(&self.tcx.sess.parse_sess,
142142
attrs, item_sp) {
143143
// Error if prohibited, or can't inherit anything from a container
144144
if kind == AnnotationKind::Prohibited ||
@@ -224,7 +224,7 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
224224
}
225225
}
226226

227-
if let Some(depr) = attr::find_deprecation(self.tcx.sess.diagnostic(), attrs, item_sp) {
227+
if let Some(depr) = attr::find_deprecation(&self.tcx.sess.parse_sess, attrs, item_sp) {
228228
if kind == AnnotationKind::Prohibited {
229229
self.tcx.sess.span_err(item_sp, "This deprecation annotation is useless");
230230
}

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ impl ReprOptions {
19281928
let mut max_align = 0;
19291929
let mut min_pack = 0;
19301930
for attr in tcx.get_attrs(did).iter() {
1931-
for r in attr::find_repr_attrs(tcx.sess.diagnostic(), attr) {
1931+
for r in attr::find_repr_attrs(&tcx.sess.parse_sess, attr) {
19321932
flags.insert(match r {
19331933
attr::ReprC => ReprFlags::IS_C,
19341934
attr::ReprPacked(pack) => {

src/librustc_lint/nonstandard_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCamelCaseTypes {
121121
let has_repr_c = it.attrs
122122
.iter()
123123
.any(|attr| {
124-
attr::find_repr_attrs(cx.tcx.sess.diagnostic(), attr)
124+
attr::find_repr_attrs(&cx.tcx.sess.parse_sess, attr)
125125
.iter()
126126
.any(|r| r == &attr::ReprC)
127127
});

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ fn check_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: DefId)
17131713
let repr = tcx.adt_def(def_id).repr;
17141714
if repr.packed() {
17151715
for attr in tcx.get_attrs(def_id).iter() {
1716-
for r in attr::find_repr_attrs(tcx.sess.diagnostic(), attr) {
1716+
for r in attr::find_repr_attrs(&tcx.sess.parse_sess, attr) {
17171717
if let attr::ReprPacked(pack) = r {
17181718
if pack != repr.pack {
17191719
struct_span_err!(tcx.sess, sp, E0634,

src/libsyntax/ast.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,14 @@ impl LitKind {
13281328
}
13291329
}
13301330

1331+
/// Returns true if this literal is byte literal string false otherwise.
1332+
pub fn is_bytestr(&self) -> bool {
1333+
match self {
1334+
LitKind::ByteStr(_) => true,
1335+
_ => false,
1336+
}
1337+
}
1338+
13311339
/// Returns true if this is a numeric literal.
13321340
pub fn is_numeric(&self) -> bool {
13331341
match *self {

src/libsyntax/attr/builtin.rs

+147-55
Large diffs are not rendered by default.

src/libsyntax/attr/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ impl MetaItem {
219219
name_from_path(&self.ident)
220220
}
221221

222+
// #[attribute(name = "value")]
223+
// ^^^^^^^^^^^^^^
224+
pub fn name_value_literal(&self) -> Option<&Lit> {
225+
match &self.node {
226+
MetaItemKind::NameValue(v) => Some(v),
227+
_ => None,
228+
}
229+
}
230+
222231
pub fn value_str(&self) -> Option<Symbol> {
223232
match self.node {
224233
MetaItemKind::NameValue(ref v) => {

src/libsyntax/ext/tt/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ pub fn compile(sess: &ParseSess, features: &Features, def: &ast::Item, edition:
355355
}
356356
}
357357

358-
let unstable_feature = attr::find_stability(&sess.span_diagnostic,
358+
let unstable_feature = attr::find_stability(&sess,
359359
&def.attrs, def.span).and_then(|stability| {
360360
if let attr::StabilityLevel::Unstable { issue, .. } = stability.level {
361361
Some((stability.feature, issue))

src/libsyntax_ext/deriving/generic/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ use syntax::source_map::{self, respan};
202202
use syntax::util::move_map::MoveMap;
203203
use syntax::ptr::P;
204204
use syntax::symbol::{Symbol, keywords};
205+
use syntax::parse::ParseSess;
205206
use syntax_pos::{DUMMY_SP, Span};
206-
use errors::Handler;
207207

208208
use self::ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty};
209209

@@ -412,7 +412,7 @@ impl<'a> TraitDef<'a> {
412412
match *item {
413413
Annotatable::Item(ref item) => {
414414
let is_packed = item.attrs.iter().any(|attr| {
415-
for r in attr::find_repr_attrs(&cx.parse_sess.span_diagnostic, attr) {
415+
for r in attr::find_repr_attrs(&cx.parse_sess, attr) {
416416
if let attr::ReprPacked(_) = r {
417417
return true;
418418
}
@@ -811,10 +811,10 @@ impl<'a> TraitDef<'a> {
811811
}
812812
}
813813

814-
fn find_repr_type_name(diagnostic: &Handler, type_attrs: &[ast::Attribute]) -> &'static str {
814+
fn find_repr_type_name(sess: &ParseSess, type_attrs: &[ast::Attribute]) -> &'static str {
815815
let mut repr_type_name = "isize";
816816
for a in type_attrs {
817-
for r in &attr::find_repr_attrs(diagnostic, a) {
817+
for r in &attr::find_repr_attrs(sess, a) {
818818
repr_type_name = match *r {
819819
attr::ReprPacked(_) | attr::ReprSimd | attr::ReprAlign(_) | attr::ReprTransparent =>
820820
continue,
@@ -1390,7 +1390,7 @@ impl<'a> MethodDef<'a> {
13901390
// discriminant_test = __self0_vi == __self1_vi && __self0_vi == __self2_vi && ...
13911391
let mut discriminant_test = cx.expr_bool(sp, true);
13921392

1393-
let target_type_name = find_repr_type_name(&cx.parse_sess.span_diagnostic, type_attrs);
1393+
let target_type_name = find_repr_type_name(&cx.parse_sess, type_attrs);
13941394

13951395
let mut first_ident = None;
13961396
for (&ident, self_arg) in vi_idents.iter().zip(&self_args) {

src/test/ui/conditional-compilation/cfg-attr-syntax-validation.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ struct S7;
2222
#[cfg(a = 10)] //~ ERROR literal in `cfg` predicate value must be a string
2323
struct S8;
2424

25-
macro_rules! generate_s9 {
25+
#[cfg(a = b"hi")] //~ ERROR literal in `cfg` predicate value must be a string
26+
struct S9;
27+
28+
macro_rules! generate_s10 {
2629
($expr: expr) => {
2730
#[cfg(feature = $expr)] //~ ERROR `cfg` is not a well-formed meta-item
28-
struct S9;
31+
struct S10;
2932
}
3033
}
3134

32-
generate_s9!(concat!("nonexistent"));
35+
generate_s10!(concat!("nonexistent"));

src/test/ui/conditional-compilation/cfg-attr-syntax-validation.stderr

+13-6
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,28 @@ error[E0537]: invalid predicate `a`
4040
LL | #[cfg(a())] //~ ERROR invalid predicate `a`
4141
| ^^^
4242

43-
error: literal in `cfg` predicate value must be a string
43+
error[E0565]: literal in `cfg` predicate value must be a string
4444
--> $DIR/cfg-attr-syntax-validation.rs:22:11
4545
|
4646
LL | #[cfg(a = 10)] //~ ERROR literal in `cfg` predicate value must be a string
4747
| ^^
4848

49+
error[E0565]: literal in `cfg` predicate value must be a string
50+
--> $DIR/cfg-attr-syntax-validation.rs:25:11
51+
|
52+
LL | #[cfg(a = b"hi")] //~ ERROR literal in `cfg` predicate value must be a string
53+
| ^^^^^ help: consider removing the prefix: `"hi"`
54+
4955
error: `cfg` is not a well-formed meta-item
50-
--> $DIR/cfg-attr-syntax-validation.rs:27:9
56+
--> $DIR/cfg-attr-syntax-validation.rs:30:9
5157
|
5258
LL | #[cfg(feature = $expr)] //~ ERROR `cfg` is not a well-formed meta-item
5359
| ^^^^^^^^^^^^^^^^^^^^^^^ help: expected syntax is: `#[cfg(/* predicate */)]`
5460
...
55-
LL | generate_s9!(concat!("nonexistent"));
56-
| ------------------------------------- in this macro invocation
61+
LL | generate_s10!(concat!("nonexistent"));
62+
| -------------------------------------- in this macro invocation
5763

58-
error: aborting due to 9 previous errors
64+
error: aborting due to 10 previous errors
5965

60-
For more information about this error, try `rustc --explain E0537`.
66+
Some errors occurred: E0537, E0565.
67+
For more information about an error, try `rustc --explain E0537`.

src/test/ui/error-codes/E0565-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0565]: unsupported literal
1+
error[E0565]: item in `deprecated` must be a key/value pair
22
--> $DIR/E0565-1.rs:12:14
33
|
44
LL | #[deprecated("since")] //~ ERROR E0565

src/test/ui/error-codes/E0565-2.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// repr currently doesn't support literals
12+
#[deprecated(since = b"1.29", note = "hi")] //~ ERROR E0565
13+
struct A { }
14+
15+
fn main() { }
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0565]: literal in `deprecated` value must be a string
2+
--> $DIR/E0565-2.rs:12:22
3+
|
4+
LL | #[deprecated(since = b"1.29", note = "hi")] //~ ERROR E0565
5+
| ^^^^^^^ help: consider removing the prefix: `"1.29"`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0565`.

src/test/ui/error-codes/E0565.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0565]: unsupported literal
1+
error[E0565]: meta item in `repr` must be an identifier
22
--> $DIR/E0565.rs:12:8
33
|
44
LL | #[repr("C")] //~ ERROR E0565

0 commit comments

Comments
 (0)