Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions compiler/rustc_attr_ir/src/attribute_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,11 @@ const _: () = ();
/// positional and listed parameters are not accepted.
/// The following parameter names are valid:
/// - `Self` and all generic parameters of the trait.
/// - `This`: the name of the trait the attribute is on, without generics.
/// - `This:path`: the full path of the trait the attribute is on, with unresolved generics.
/// - `This:resolved`: the full path of the trait the attribute is on, with resolved generics.
/// - `this`: the name of the trait the attribute is on, without generics.
/// - `this:path`: the full path of the trait the attribute is on, with unresolved generics.
/// - `this:resolved`: the full path of the trait the attribute is on, with resolved generics.
/// Additionally, this will "sugar" the `Fn(...)` traits.
/// - `ItemContext`: the kind of `hir::Node` we're in, things like `"an async block"`,
/// - `item_context`: the kind of `hir::Node` we're in, things like `"an async block"`,
/// `"a function"`, `"an async function"`, etc.
///
#[doc = include_example!("rustc_on_unimplemented_format")]
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_attr_ir/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,22 +237,22 @@ pub enum FormatArg {
},
// `{Self}`
SelfUpper,
/// `{This}` and `{This:name}`.
/// `{this}` and `{this:name}`.
This,
/// The sugared form: `{This:sugared}`.
/// The sugared form: `{this:resolved}`.
ThisResolved,
/// The full path: `{This:path}`.
/// The full path: `{this:path}`.
ThisPath,
/// what we're in, like a function, method, closure etc.
/// What we're in, like a function, method, closure etc. Used via `{item_context}`.
ItemContext,
/// What the user typed, if it doesn't match anything we can use.
AsIs(Symbol),
/// {Found} in diagnostic::on_type_error
/// {found} in diagnostic::on_type_error
Found,
/// {Expected} in diagnostic::on_type_error
/// {expected} in diagnostic::on_type_error
Expected,
/// {Unresolved} in diagnostic::on_unknown
/// {unresolved} in diagnostic::on_unknown
Unresolved,
/// What the user typed, if it doesn't match anything we can use.
AsIs(Symbol),
}

/// Represents the `on` filter in `#[rustc_on_unimplemented]`.
Expand Down
24 changes: 12 additions & 12 deletions compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ impl Mode {
"only `Self` and generics of the implementation are allowed as a format argument"
}
Self::DiagnosticOnMove => {
"only `This`, `Self` and generics of the type are allowed as a format argument"
"only `this`, `Self` and generics of the type are allowed as a format argument"
}
Self::DiagnosticOnUnknown => {
"only `This` is allowed as a format argument, referring to the failed import"
"only `this` is allowed as a format argument, referring to the failed import"
}
Self::DiagnosticOnUnmatchedArgs => {
"only `This` is allowed as a format argument, referring to the macro's name"
"only `this` is allowed as a format argument, referring to the macro's name"
}
Self::DiagnosticOnTypeError => {
"only `note` is allowed as option for `diagnostic::on_type_error`"
Expand Down Expand Up @@ -515,10 +515,10 @@ fn parse_arg(
let ret = match arg.position {
// Something like "hello {name}"
Position::ArgumentNamed(name) => match (mode, Symbol::intern(name)) {
(Mode::RustcOnUnimplemented, sym::ItemContext) => FormatArg::ItemContext,
(Mode::RustcOnUnimplemented, sym::item_context) => FormatArg::ItemContext,

// `{This:ty}`
(Mode::RustcOnUnimplemented, sym::This) => match arg.format.ty {
// `{this:ty}`
(Mode::RustcOnUnimplemented, sym::this) => match arg.format.ty {
"resolved" => {
check_format = false;
FormatArg::ThisResolved
Expand All @@ -530,11 +530,11 @@ fn parse_arg(
_ => FormatArg::This,
},

(Mode::DiagnosticOnTypeError, sym::Found) => FormatArg::Found,
(Mode::DiagnosticOnTypeError, sym::Expected) => FormatArg::Expected,
(Mode::DiagnosticOnUnknown, sym::Unresolved) => FormatArg::Unresolved,
(Mode::DiagnosticOnTypeError, sym::found) => FormatArg::Found,
(Mode::DiagnosticOnTypeError, sym::expected) => FormatArg::Expected,
(Mode::DiagnosticOnUnknown, sym::unresolved) => FormatArg::Unresolved,

// Some diagnostic attributes can use `{This}` to refer to the annotated item.
// Some diagnostic attributes can use `{this}` to refer to the annotated item.
// For those that don't, we continue and maybe use it as a generic parameter.
//
// FIXME(mejrs) `DiagnosticOnUnimplemented` is intentionally not here;
Expand All @@ -544,13 +544,13 @@ fn parse_arg(
| Mode::DiagnosticOnMove
| Mode::DiagnosticOnUnmatchedArgs
| Mode::DiagnosticOnTypeError,
sym::This,
sym::this,
) => FormatArg::This,

// `{Self}`; the self type.
// - For trait declaration attributes that's the type that does not implement it.
// - for trait impl attributes, the implemented for type.
// - For ADT attributes, that's the type (which will be identical to `{This}`)
// - For ADT attributes, that's the type (which will be identical to `{this}`)
// - For everything else it doesn't make sense.
(
Mode::RustcOnUnimplemented
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
});

let is_allowed = argument_name == sym::Expected || argument_name == sym::Found;
let is_allowed = argument_name == sym::expected || argument_name == sym::found;
if !(has_generic | is_allowed) {
self.tcx.emit_node_span_lint(
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ pub(crate) struct GlobOrListDelegationUnusedTargetExpr {

#[derive(Diagnostic)]
#[diag("unknown parameter `{$name}`")]
#[help(r#"expect either a generic argument name, {"`{This}`"}, {"`{Expected}`"} or {"`{Found}`"} as format argument"#)]
#[help(r#"expect either a generic argument name, {"`{this}`"}, {"`{expected}`"} or {"`{found}`"} as format argument"#)]
pub(crate) struct OnTypeErrorMalformedFormatLiterals {
pub name: Symbol,
}
Expand Down
24 changes: 17 additions & 7 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ symbols! {
Equal,
Err,
ExitCode,
Expected,
ExternC,
ExternRust,
Float,
Expand All @@ -233,7 +232,6 @@ symbols! {
FnPtrToPtr,
Formatter,
Forward,
Found,
From,
FromIterator,
FromResidual,
Expand All @@ -257,7 +255,6 @@ symbols! {
IoBufReader,
IrTyKind,
Item,
ItemContext,
Iterator,
IteratorItem,
IteratorMap,
Expand Down Expand Up @@ -361,7 +358,6 @@ symbols! {
Type,
TypeVisitable,
Union,
Unresolved,
Unsafe,
UnsafeFnPointer,
Unsize,
Expand Down Expand Up @@ -1051,6 +1047,7 @@ symbols! {
format_macro,
format_placeholder,
format_unsafe_arg,
found,
fp,
fpregs,
framework,
Expand Down Expand Up @@ -1205,6 +1202,7 @@ symbols! {
issue_5723_bootstrap,
issue_tracker_base_url,
item,
item_context,
item_like_imports,
iter,
iter_mut,
Expand Down Expand Up @@ -2175,6 +2173,7 @@ symbols! {
test_removed_feature,
test_runner,
test_unstable_lint,
this,
thread,
thread_local,
threadptr,
Expand Down Expand Up @@ -2323,6 +2322,7 @@ symbols! {
unreachable_code,
unreachable_display,
unreachable_macro,
unresolved,
unrestricted_attribute_tokens,
unsafe_attributes,
unsafe_binders,
Expand Down Expand Up @@ -3008,9 +3008,19 @@ pub mod kw {
///
/// Given that `sym` is imported, use them like `sym::symbol_name`.
/// For example `sym::rustfmt` or `sym::u8`.
#[diagnostic::on_unknown(
label = "`{Unresolved}` is not a pre-interned symbol",
note = "consider adding `{Unresolved}` to the `symbols!` invocation in compiler/rustc_span/src/symbol.rs"
#[cfg_attr(
bootstrap,
diagnostic::on_unknown(
label = "`{Unresolved}` is not a pre-interned symbol",
note = "consider adding `{Unresolved}` to the `symbols!` invocation in compiler/rustc_span/src/symbol.rs"
)
)]
#[cfg_attr(
not(bootstrap),
diagnostic::on_unknown(
label = "`{unresolved}` is not a pre-interned symbol",
note = "consider adding `{unresolved}` to the `symbols!` invocation in compiler/rustc_span/src/symbol.rs"
)
)]
pub mod sym {
use super::Symbol;
Expand Down
10 changes: 5 additions & 5 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,14 +1038,14 @@ impl Display for Arguments<'_> {
#[rustc_on_unimplemented(
on(
all(crate_local, not(Self = "{union}")),
note = "add `#[derive(Debug)]` to `{Self}` or manually `impl {This} for {Self}`"
note = "add `#[derive(Debug)]` to `{Self}` or manually `impl {this} for {Self}`"
),
on(all(crate_local, Self = "{union}"), note = "manually `impl {This} for {Self}`"),
on(all(crate_local, Self = "{union}"), note = "manually `impl {this} for {Self}`"),
on(
from_desugaring = "FormatLiteral",
label = "`{Self}` cannot be formatted using `{{:?}}` because it doesn't implement `{This}`"
label = "`{Self}` cannot be formatted using `{{:?}}` because it doesn't implement `{this}`"
),
message = "`{Self}` doesn't implement `{This}`"
message = "`{Self}` doesn't implement `{this}`"
)]
#[doc(alias = "{:?}")]
#[rustc_diagnostic_item = "Debug"]
Expand Down Expand Up @@ -1179,7 +1179,7 @@ pub use macros::Debug;
note = "in format strings you may be able to use `{{:?}}` (or `{{:#?}}` for pretty-print) instead",
label = "`{Self}` cannot be formatted with the default formatter",
),
message = "`{Self}` doesn't implement `{This}`"
message = "`{Self}` doesn't implement `{this}`"
)]
#[doc(alias = "{}")]
#[rustc_diagnostic_item = "Display"]
Expand Down
12 changes: 6 additions & 6 deletions library/core/src/ops/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ use crate::ptr::NonNull;
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
),
message = "expected `{This:resolved}` signature, found `{Self}`",
label = "expected `{This:resolved}` signature, found `{Self}`"
message = "expected `{this:resolved}` signature, found `{Self}`",
label = "expected `{this:resolved}` signature, found `{Self}`"
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use = "closures are lazy and do nothing unless called"]
Expand Down Expand Up @@ -154,8 +154,8 @@ pub const trait Fn<Args: Tuple>: [const] FnMut<Args> {
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
),
message = "expected `{This:resolved}` signature, found `{Self}`",
label = "expected `{This:resolved}` signature, found `{Self}`"
message = "expected `{this:resolved}` signature, found `{Self}`",
label = "expected `{this:resolved}` signature, found `{Self}`"
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use = "closures are lazy and do nothing unless called"]
Expand Down Expand Up @@ -233,8 +233,8 @@ pub const trait FnMut<Args: Tuple>: FnOnce<Args> {
// SAFETY: tidy is not smart enough to tell that the below unsafe block is a string
label = "call the function in a closure: `|| unsafe {{ /* code */ }}`"
),
message = "expected `{This:resolved}` signature, found `{Self}`",
label = "expected `{This:resolved}` signature, found `{Self}`"
message = "expected `{this:resolved}` signature, found `{Self}`",
label = "expected `{this:resolved}` signature, found `{Self}`"
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use = "closures are lazy and do nothing unless called"]
Expand Down
22 changes: 11 additions & 11 deletions library/core/src/ops/try_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ use crate::ops::ControlFlow;
on(
all(from_desugaring = "TryBlock"),
message = "a `try` block must return `Result` or `Option` \
(or another type that implements `{This}`)",
(or another type that implements `{this}`)",
label = "could not wrap the final value of the block as `{Self}` doesn't implement `Try`",
),
on(
all(from_desugaring = "QuestionMark"),
message = "the `?` operator can only be applied to values that implement `{This}`",
message = "the `?` operator can only be applied to values that implement `{this}`",
label = "the `?` operator cannot be applied to type `{Self}`"
)
)]
Expand Down Expand Up @@ -232,7 +232,7 @@ pub const trait Try: [const] FromResidual {
R = "core::option::Option<!>",
),
message = "the `?` operator can only be used on `Result`s, not `Option`s, \
in {ItemContext} that returns `Result`",
in {item_context} that returns `Result`",
label = "use `.ok_or(...)?` to provide an error compatible with `{Self}`",
parent_label = "this function returns a `Result`"
),
Expand All @@ -245,7 +245,7 @@ pub const trait Try: [const] FromResidual {
// `From` in `?`, so this is not shown for result-in-result errors,
// and thus it can be phrased more strongly than `ControlFlow`'s.
message = "the `?` operator can only be used on `Result`s \
in {ItemContext} that returns `Result`",
in {item_context} that returns `Result`",
label = "this `?` produces `{R}`, which is incompatible with `{Self}`",
parent_label = "this function returns a `Result`"
),
Expand All @@ -256,7 +256,7 @@ pub const trait Try: [const] FromResidual {
R = "core::result::Result<T, E>",
),
message = "the `?` operator can only be used on `Option`s, not `Result`s, \
in {ItemContext} that returns `Option`",
in {item_context} that returns `Option`",
label = "use `.ok()?` if you want to discard the `{R}` error information",
parent_label = "this function returns an `Option`"
),
Expand All @@ -268,7 +268,7 @@ pub const trait Try: [const] FromResidual {
// `Option`-in-`Option` always works, as there's only one possible
// residual, so this can also be phrased strongly.
message = "the `?` operator can only be used on `Option`s \
in {ItemContext} that returns `Option`",
in {item_context} that returns `Option`",
label = "this `?` produces `{R}`, which is incompatible with `{Self}`",
parent_label = "this function returns an `Option`"
),
Expand All @@ -278,7 +278,7 @@ pub const trait Try: [const] FromResidual {
Self = "core::ops::control_flow::ControlFlow<B, C>",
R = "core::ops::control_flow::ControlFlow<B, C>",
),
message = "the `?` operator in {ItemContext} that returns `ControlFlow<B, _>` \
message = "the `?` operator in {item_context} that returns `ControlFlow<B, _>` \
can only be used on other `ControlFlow<B, _>`s (with the same Break type)",
label = "this `?` produces `{R}`, which is incompatible with `{Self}`",
parent_label = "this function returns a `ControlFlow`",
Expand All @@ -291,16 +291,16 @@ pub const trait Try: [const] FromResidual {
// `R` is not a `ControlFlow`, as that case was matched previously
),
message = "the `?` operator can only be used on `ControlFlow`s \
in {ItemContext} that returns `ControlFlow`",
in {item_context} that returns `ControlFlow`",
label = "this `?` produces `{R}`, which is incompatible with `{Self}`",
parent_label = "this function returns a `ControlFlow`",
),
on(
all(from_desugaring = "QuestionMark"),
message = "the `?` operator can only be used in {ItemContext} \
message = "the `?` operator can only be used in {item_context} \
that returns `Result` or `Option` \
(or another type that implements `{This}`)",
label = "cannot use the `?` operator in {ItemContext} that returns `{Self}`",
(or another type that implements `{this}`)",
label = "cannot use the `?` operator in {item_context} that returns `{Self}`",
parent_label = "this function should return `Result` or `Option` to accept `?`"
),
)]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2676,7 +2676,7 @@ pub fn id() -> u32 {
#[rustc_on_unimplemented(on(
cause = "MainFunctionType",
message = "`main` has invalid return type `{Self}`",
label = "`main` can only return types that implement `{This}`"
label = "`main` can only return types that implement `{this}`"
))]
pub trait Termination {
/// Is called to get the representation of the value as status code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ annotated declaration is involved in a name resolution error.
Format parameters with the given named parameter will be replaced with the following text:

- `{Unresolved}` — The `SimplePathSegment` of the import path that could not be resolved.
- `{This}` — The name of the annotated item. On `use` statements this is identical to `{Unresolved}`.
- `{this}` — The name of the annotated item. On `use` statements this is identical to `{unresolved}`.

The original error message will not be suppressed but is emitted as a note instead.

Expand Down Expand Up @@ -46,7 +46,7 @@ For more information about this error, try `rustc --explain E0432`.
#![feature(diagnostic_on_unknown)]

#[diagnostic::on_unknown(
message = "module `{This}` is empty, there is no `{Unresolved}` here",
message = "module `{this}` is empty, there is no `{unresolved}` here",
label = "can't import something from an empty module"
)]
mod empty {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ errors still use their existing diagnostics.
#![feature(diagnostic_on_unmatched_args)]

#[diagnostic::on_unmatched_args(
message = "invalid arguments to {This} macro invocation",
message = "invalid arguments to {this} macro invocation",
label = "expected a type and value here",
note = "this macro expects a type and a value, like `pair!(u8, 0)`",
note = "see <link/to/docs>",
Expand Down
Loading
Loading