Skip to content

Commit

Permalink
Rollup merge of #96269 - davidtwco:diagnostic-translation-minor-chang…
Browse files Browse the repository at this point in the history
…es, r=oli-obk

errors: minor translation-related changes

- For one error in typeck, specifying "suggestion" as the attribute for the only suggestion is unnecessary, it's the default of the derive.
- The documentation comment for the `SessionDiagnostic` derive is out-of-date, it should have been updated in #95512.

r? `@oli-obk`
  • Loading branch information
Dylan-DPC authored Apr 21, 2022
2 parents d8fcf53 + f79d5e9 commit 35ef5c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions compiler/rustc_macros/src/session_diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,41 @@ use std::collections::{BTreeSet, HashMap};
/// # extern crate rust_middle;
/// # use rustc_middle::ty::Ty;
/// #[derive(SessionDiagnostic)]
/// #[error(code = "E0505", slug = "move-out-of-borrow-error")]
/// #[error(code = "E0505", slug = "borrowck-move-out-of-borrow")]
/// pub struct MoveOutOfBorrowError<'tcx> {
/// pub name: Ident,
/// pub ty: Ty<'tcx>,
/// #[primary_span]
/// #[label = "cannot move out of borrow"]
/// #[label]
/// pub span: Span,
/// #[label = "`{ty}` first borrowed here"]
/// pub other_span: Span,
/// #[suggestion(message = "consider cloning here", code = "{name}.clone()")]
/// pub opt_sugg: Option<(Span, Applicability)>
/// #[label = "first-borrow-label"]
/// pub first_borrow_span: Span,
/// #[suggestion(code = "{name}.clone()")]
/// pub clone_sugg: Option<(Span, Applicability)>
/// }
/// ```
///
/// ```fluent
/// move-out-of-borrow = cannot move out of {$name} because it is borrowed
/// .label = cannot move out of borrow
/// .first-borrow-label = `{$ty}` first borrowed here
/// .suggestion = consider cloning here
/// ```
///
/// Then, later, to emit the error:
///
/// ```ignore (pseudo-rust)
/// sess.emit_err(MoveOutOfBorrowError {
/// expected,
/// actual,
/// span,
/// other_span,
/// opt_sugg: Some(suggestion, Applicability::MachineApplicable),
/// first_borrow_span,
/// clone_sugg: Some(suggestion, Applicability::MachineApplicable),
/// });
/// ```
///
/// See rustc dev guide for more examples on using the `#[derive(SessionDiagnostic)]`:
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/sessiondiagnostic.html>
pub fn session_diagnostic_derive(s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
// Names for the diagnostic we build and the session we build it from.
let diag = format_ident!("diag");
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub struct TypeofReservedKeywordUsed<'tcx> {
#[primary_span]
#[label]
pub span: Span,
#[suggestion_verbose(message = "suggestion", code = "{ty}")]
#[suggestion_verbose(code = "{ty}")]
pub opt_sugg: Option<(Span, Applicability)>,
}

Expand Down

0 comments on commit 35ef5c6

Please sign in to comment.