Skip to content

Commit 0186027

Browse files
committed
Move diagnostic.rs to rustc_ast, part 2
1 parent 601b2a2 commit 0186027

7 files changed

Lines changed: 20 additions & 33 deletions

File tree

compiler/rustc_ast/src/attr/diagnostic.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
use std::fmt;
33
use std::fmt::Debug;
44

5-
pub use rustc_ast::attr::data_structures::*;
6-
use rustc_macros::{Decodable, Encodable, PrintAttribute, StableHash};
5+
use rustc_macros::{Decodable, Encodable, StableHash};
76
use rustc_span::{DesugaringKind, Span, Symbol, kw};
87
use thin_vec::ThinVec;
98
use tracing::debug;
109

11-
use crate::attrs::PrintAttribute;
12-
13-
#[derive(Clone, Default, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
10+
#[derive(Clone, Default, Debug, StableHash, Encodable, Decodable)]
1411
pub struct Directive {
1512
pub is_rustc_attr: bool,
1613
/// This is never nested more than once, i.e. the directives in this
@@ -109,7 +106,7 @@ impl CustomDiagnostic {
109106

110107
/// Like [std::fmt::Arguments] this is a string that has been parsed into "pieces",
111108
/// either as string pieces or dynamic arguments.
112-
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
109+
#[derive(Clone, Debug, StableHash, Encodable, Decodable)]
113110
pub struct FormatString {
114111
pub input: Symbol,
115112
pub span: Span,
@@ -211,13 +208,13 @@ pub struct FormatArgs {
211208
pub generic_args: Vec<(Symbol, String)> = Vec::new(),
212209
}
213210

214-
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
211+
#[derive(Clone, Debug, StableHash, Encodable, Decodable)]
215212
pub enum Piece {
216213
Lit(Symbol),
217214
Arg(FormatArg),
218215
}
219216

220-
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
217+
#[derive(Clone, Debug, StableHash, Encodable, Decodable)]
221218
pub enum FormatArg {
222219
// A generic parameter, like `{T}` if we're on the `From<T>` trait.
223220
GenericParam {
@@ -237,7 +234,7 @@ pub enum FormatArg {
237234
}
238235

239236
/// Represents the `on` filter in `#[rustc_on_unimplemented]`.
240-
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
237+
#[derive(Clone, Debug, StableHash, Encodable, Decodable)]
241238
pub struct Filter {
242239
pub span: Span,
243240
pub pred: Predicate,
@@ -262,7 +259,7 @@ impl Filter {
262259
///
263260
/// It is similar to the predicate in the `cfg` attribute,
264261
/// and may contain nested predicates.
265-
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
262+
#[derive(Clone, Debug, StableHash, Encodable, Decodable)]
266263
pub enum Predicate {
267264
/// A condition like `on(crate_local)`.
268265
Flag(Flag),
@@ -300,7 +297,7 @@ impl Predicate {
300297
}
301298

302299
/// Represents a `MetaWord` in an `on`-filter.
303-
#[derive(Clone, Copy, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
300+
#[derive(Clone, Copy, Debug, StableHash, Encodable, Decodable)]
304301
pub enum Flag {
305302
/// Whether the code causing the trait bound to not be fulfilled
306303
/// is part of the user's crate.
@@ -315,7 +312,7 @@ pub enum Flag {
315312
/// A `MetaNameValueStr` in an `on`-filter.
316313
///
317314
/// For example, `#[rustc_on_unimplemented(on(name = "value", message = "hello"))]`.
318-
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
315+
#[derive(Clone, Debug, StableHash, Encodable, Decodable)]
319316
pub struct NameValue {
320317
pub name: Name,
321318
/// Something like `"&str"` or `"alloc::string::String"`,
@@ -334,7 +331,7 @@ impl NameValue {
334331
}
335332

336333
/// The valid names of the `on` filter.
337-
#[derive(Clone, Copy, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
334+
#[derive(Clone, Copy, Debug, StableHash, Encodable, Decodable)]
338335
pub enum Name {
339336
Cause,
340337
FromDesugaring,
@@ -354,7 +351,7 @@ pub enum FlagOrNv<'p> {
354351
/// If it is a simple literal like this then `pieces` will be `[LitOrArg::Lit("value")]`.
355352
/// The `Arg` variant is used when it contains formatting like
356353
/// `#[rustc_on_unimplemented(on(Self = "&[{A}]", message = "hello"))]`.
357-
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
354+
#[derive(Clone, Debug, StableHash, Encodable, Decodable)]
358355
pub struct FilterFormatString {
359356
pub pieces: ThinVec<LitOrArg>,
360357
}
@@ -386,7 +383,7 @@ impl FilterFormatString {
386383
}
387384
}
388385

389-
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
386+
#[derive(Clone, Debug, StableHash, Encodable, Decodable)]
390387
pub enum LitOrArg {
391388
Lit(Symbol),
392389
Arg(Symbol),

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Functions dealing with attributes and meta items.
22
33
pub mod data_structures;
4+
pub mod diagnostic;
45
pub mod version;
56

67
use std::fmt::Debug;

compiler/rustc_ast/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// tidy-alphabetical-start
88
#![doc(test(attr(deny(warnings), allow(internal_features))))]
99
#![feature(associated_type_defaults)]
10+
#![feature(default_field_values)]
1011
#![feature(deref_patterns)]
1112
#![feature(iter_order_by)]
1213
#![feature(macro_metavar_expr)]

compiler/rustc_hir/src/attrs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
pub use data_structures::*;
88
pub use encode_cross_crate::EncodeCrossCrate;
99
pub use pretty_printing::PrintAttribute;
10+
pub use rustc_ast::attr::diagnostic;
1011

1112
mod data_structures;
12-
pub mod diagnostic;
1313
mod encode_cross_crate;
1414
mod pretty_printing;
1515

compiler/rustc_hir/src/attrs/pretty_printing.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
1717
use rustc_target::spec::SanitizerSet;
1818
use thin_vec::ThinVec;
1919

20+
use crate::attrs::diagnostic::Directive;
2021
use crate::limit::Limit;
2122

2223
/// This trait is used to print attributes in `rustc_hir_pretty`.
@@ -209,4 +210,5 @@ print_debug!(
209210
CfgEntry,
210211
DiffActivity,
211212
DiffMode,
213+
Directive,
212214
);

tests/ui/unpretty/diagnostic-attr.stdout

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,13 @@ use ::std::prelude::rust_2015::*;
66
//@ check-pass
77
//@ edition: 2015
88

9-
#[attr = OnUnimplemented {directive: Directive {is_rustc_attr: false,
10-
filters: [],
11-
message: FormatString {input: "My Message for `ImportantTrait<{A}>` implemented for `{Self}`",
12-
pieces: [Lit("My Message for `ImportantTrait<"),
13-
Arg(GenericParam {generic_param: "A"}), Lit(">` implemented for `"),
14-
Arg(SelfUpper), Lit("`")]}, label: FormatString {input: "My Label",
15-
pieces: [Lit("My Label")]}, notes: [FormatString {input: "Note 1",
16-
pieces: [Lit("Note 1")]}, FormatString {input: "Note 2",
17-
pieces: [Lit("Note 2")]}]}}]
9+
#[attr = OnUnimplemented {directive: Directive { is_rustc_attr: false, filters: [], message: Some(($DIR/diagnostic-attr.rs:7:5: 7:78 (#0), FormatString { input: "My Message for `ImportantTrait<{A}>` implemented for `{Self}`", span: $DIR/diagnostic-attr.rs:7:15: 7:78 (#0), pieces: [Lit("My Message for `ImportantTrait<"), Arg(GenericParam { generic_param: "A", span: $DIR/diagnostic-attr.rs:7:48: 7:49 (#0) }), Lit(">` implemented for `"), Arg(SelfUpper), Lit("`")] })), label: Some(($DIR/diagnostic-attr.rs:8:5: 8:23 (#0), FormatString { input: "My Label", span: $DIR/diagnostic-attr.rs:8:13: 8:23 (#0), pieces: [Lit("My Label")] })), notes: [FormatString { input: "Note 1", span: $DIR/diagnostic-attr.rs:9:12: 9:20 (#0), pieces: [Lit("Note 1")] }, FormatString { input: "Note 2", span: $DIR/diagnostic-attr.rs:10:12: 10:20 (#0), pieces: [Lit("Note 2")] }], parent_label: None }}]
1810
trait ImportantTrait<A> { }
1911

2012
#[attr = DoNotRecommend]
2113
impl <T> ImportantTrait<T> for T where T: Clone { }
2214

2315
struct X;
2416

25-
#[attr = OnConst {directive: Directive {is_rustc_attr: false, filters: [],
26-
message: FormatString {input: "My Message for `ImportantTrait<u8>` implemented for `{Self}`",
27-
pieces: [Lit("My Message for `ImportantTrait<u8>` implemented for `"),
28-
Arg(SelfUpper), Lit("`")]}, label: FormatString {input: "My Label",
29-
pieces: [Lit("My Label")]}, notes: [FormatString {input: "Note 1",
30-
pieces: [Lit("Note 1")]}, FormatString {input: "Note 2",
31-
pieces: [Lit("Note 2")]}]}}]
17+
#[attr = OnConst {directive: Directive { is_rustc_attr: false, filters: [], message: Some(($DIR/diagnostic-attr.rs:20:5: 20:77 (#0), FormatString { input: "My Message for `ImportantTrait<u8>` implemented for `{Self}`", span: $DIR/diagnostic-attr.rs:20:15: 20:77 (#0), pieces: [Lit("My Message for `ImportantTrait<u8>` implemented for `"), Arg(SelfUpper), Lit("`")] })), label: Some(($DIR/diagnostic-attr.rs:21:5: 21:23 (#0), FormatString { input: "My Label", span: $DIR/diagnostic-attr.rs:21:13: 21:23 (#0), pieces: [Lit("My Label")] })), notes: [FormatString { input: "Note 1", span: $DIR/diagnostic-attr.rs:22:12: 22:20 (#0), pieces: [Lit("Note 1")] }, FormatString { input: "Note 2", span: $DIR/diagnostic-attr.rs:23:12: 23:20 (#0), pieces: [Lit("Note 2")] }], parent_label: None }}]
3218
impl ImportantTrait<u8> for X { }

triagebot.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ cc = ["@rust-lang/wg-const-eval"]
14571457
[mentions."compiler/rustc_attr_parsing/src/attributes/diagnostic"]
14581458
message = "Some changes occurred to diagnostic attributes."
14591459
cc = ["@mejrs"]
1460-
[mentions."compiler/rustc_hir/src/attrs/diagnostic.rs"]
1460+
[mentions."compiler/rustc_ast/src/attr/diagnostic.rs"]
14611461
message = "Some changes occurred to diagnostic attributes."
14621462
cc = ["@mejrs"]
14631463

0 commit comments

Comments
 (0)