Skip to content

Commit

Permalink
Derive both Diagnostic and LintDiagnostic on some tys
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Oct 24, 2024
1 parent 0f0d42d commit aee03c5
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 57 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,10 @@ fn lint_uncovered_ty_params<'tcx>(
Some(local_type) => tcx.emit_node_lint(
UNCOVERED_PARAM_IN_PROJECTION,
hir_id,
errors::TyParamFirstLocalLint { span, note: (), param: name, local_type },
errors::TyParamFirstLocal { span, note: (), param: name, local_type },
),
None => {
tcx.emit_node_lint(UNCOVERED_PARAM_IN_PROJECTION, hir_id, errors::TyParamSomeLint {
tcx.emit_node_lint(UNCOVERED_PARAM_IN_PROJECTION, hir_id, errors::TyParamSome {
span,
note: (),
param: name,
Expand Down
31 changes: 2 additions & 29 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,9 +1382,7 @@ pub(crate) struct CrossCrateTraitsDefined {
pub traits: String,
}

// FIXME(fmease): Deduplicate:

#[derive(Diagnostic)]
#[derive(Diagnostic, LintDiagnostic)]
#[diag(hir_analysis_ty_param_first_local, code = E0210)]
#[note]
pub(crate) struct TyParamFirstLocal<'tcx> {
Expand All @@ -1397,20 +1395,7 @@ pub(crate) struct TyParamFirstLocal<'tcx> {
pub local_type: Ty<'tcx>,
}

#[derive(LintDiagnostic)]
#[diag(hir_analysis_ty_param_first_local, code = E0210)]
#[note]
pub(crate) struct TyParamFirstLocalLint<'tcx> {
#[primary_span]
#[label]
pub span: Span,
#[note(hir_analysis_case_note)]
pub note: (),
pub param: Symbol,
pub local_type: Ty<'tcx>,
}

#[derive(Diagnostic)]
#[derive(Diagnostic, LintDiagnostic)]
#[diag(hir_analysis_ty_param_some, code = E0210)]
#[note]
pub(crate) struct TyParamSome {
Expand All @@ -1422,18 +1407,6 @@ pub(crate) struct TyParamSome {
pub param: Symbol,
}

#[derive(LintDiagnostic)]
#[diag(hir_analysis_ty_param_some, code = E0210)]
#[note]
pub(crate) struct TyParamSomeLint {
#[primary_span]
#[label]
pub span: Span,
#[note(hir_analysis_only_note)]
pub note: (),
pub param: Symbol,
}

#[derive(Diagnostic)]
pub(crate) enum OnlyCurrentTraits {
#[diag(hir_analysis_only_current_traits_outside, code = E0117)]
Expand Down
13 changes: 1 addition & 12 deletions compiler/rustc_hir_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ pub(crate) enum SuggestBoxingForReturnImplTrait {
},
}

#[derive(Diagnostic)]
#[derive(Diagnostic, LintDiagnostic)]
#[diag(hir_typeck_self_ctor_from_outer_item, code = E0401)]
pub(crate) struct SelfCtorFromOuterItem {
#[primary_span]
Expand All @@ -708,17 +708,6 @@ pub(crate) struct SelfCtorFromOuterItem {
pub sugg: Option<ReplaceWithName>,
}

#[derive(LintDiagnostic)]
#[diag(hir_typeck_self_ctor_from_outer_item)]
pub(crate) struct SelfCtorFromOuterItemLint {
#[primary_span]
pub span: Span,
#[label]
pub impl_span: Span,
#[subdiagnostic]
pub sugg: Option<ReplaceWithName>,
}

#[derive(Subdiagnostic)]
#[suggestion(hir_typeck_suggestion, code = "{name}", applicability = "machine-applicable")]
pub(crate) struct ReplaceWithName {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx.emit_node_lint(
SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
hir_id,
errors::SelfCtorFromOuterItemLint {
errors::SelfCtorFromOuterItem {
span: path_span,
impl_span: tcx.def_span(impl_def_id),
sugg,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1838,8 +1838,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
});
}
if is_explicit_rust && (int_reprs > 0 || is_c || is_simd) {
let hint_spans = hint_spans.clone().collect();
self.dcx().emit_err(errors::ReprConflicting { hint_spans });
self.dcx().emit_err(errors::ReprConflicting { spans: hint_spans.clone().collect() });
}
// Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
if (int_reprs > 1)
Expand All @@ -1850,7 +1849,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
if let ItemLike::Item(item) = item { is_c_like_enum(item) } else { false }
}))
{
self.tcx.emit_node_lint(CONFLICTING_REPR_HINTS, hir_id, errors::ReprConflictingLint {
self.tcx.emit_node_lint(CONFLICTING_REPR_HINTS, hir_id, errors::ReprConflicting {
spans: hint_spans.collect(),
});
}
Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,16 +621,9 @@ pub(crate) struct ReprIdent {
pub span: Span,
}

#[derive(Diagnostic)]
#[derive(Diagnostic, LintDiagnostic)]
#[diag(passes_repr_conflicting, code = E0566)]
pub(crate) struct ReprConflicting {
#[primary_span]
pub hint_spans: Vec<Span>,
}

#[derive(LintDiagnostic)]
#[diag(passes_repr_conflicting, code = E0566)]
pub(crate) struct ReprConflictingLint {
#[primary_span]
pub spans: Vec<Span>,
}
Expand Down
5 changes: 3 additions & 2 deletions tests/ui/self/self-ctor-nongeneric.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning: can't reference `Self` constructor from outer item
warning[E0401]: can't reference `Self` constructor from outer item
--> $DIR/self-ctor-nongeneric.rs:8:23
|
LL | impl S0 {
Expand All @@ -11,7 +11,7 @@ LL | const C: S0 = Self(0);
= note: for more information, see issue #124186 <https://github.com/rust-lang/rust/issues/124186>
= note: `#[warn(self_constructor_from_outer_item)]` on by default

warning: can't reference `Self` constructor from outer item
warning[E0401]: can't reference `Self` constructor from outer item
--> $DIR/self-ctor-nongeneric.rs:12:13
|
LL | impl S0 {
Expand All @@ -25,3 +25,4 @@ LL | Self(0)

warning: 2 warnings emitted

For more information about this error, try `rustc --explain E0401`.

0 comments on commit aee03c5

Please sign in to comment.