Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2a1d748

Browse files
committed
Replace item names containing an error code with something more meaningful
or inline such functions if useless.
1 parent dec1d16 commit 2a1d748

19 files changed

+55
-50
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -632,20 +632,19 @@ impl<'a> AstValidator<'a> {
632632
}
633633
}
634634

635-
fn emit_e0568(&self, span: Span, ident: Span) {
636-
self.dcx().emit_err(errors::AutoTraitBounds { span, ident });
637-
}
638-
639635
fn deny_super_traits(&self, bounds: &GenericBounds, ident_span: Span) {
640636
if let [.., last] = &bounds[..] {
641637
let span = ident_span.shrink_to_hi().to(last.span());
642-
self.emit_e0568(span, ident_span);
638+
self.dcx().emit_err(errors::AutoTraitBounds { span, ident: ident_span });
643639
}
644640
}
645641

646642
fn deny_where_clause(&self, where_clause: &WhereClause, ident_span: Span) {
647643
if !where_clause.predicates.is_empty() {
648-
self.emit_e0568(where_clause.span, ident_span);
644+
// FIXME: The current diagnostic is misleading since it only talks about
645+
// super trait and lifetime bounds while we should just say “bounds”.
646+
self.dcx()
647+
.emit_err(errors::AutoTraitBounds { span: where_clause.span, ident: ident_span });
649648
}
650649
}
651650

compiler/rustc_hir_analysis/messages.ftl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ hir_analysis_inherent_ty_outside_relevant = cannot define inherent `impl` for a
201201
.help = consider moving this inherent impl into the crate defining the type if possible
202202
.span_help = alternatively add `#[rustc_allow_incoherent_impl]` to the relevant impl items
203203
204+
hir_analysis_invalid_receiver_ty = invalid `self` parameter type: `{$receiver_ty}`
205+
.note = type of `self` must be `Self` or a type that dereferences to it
206+
207+
hir_analysis_invalid_receiver_ty_help =
208+
consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
209+
204210
hir_analysis_invalid_union_field =
205211
field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
206212
.note = union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::autoderef::Autoderef;
22
use crate::collect::CollectItemTypesVisitor;
33
use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter};
44
use crate::errors;
5+
use crate::fluent_generated as fluent;
56

67
use hir::intravisit::Visitor;
78
use rustc_ast as ast;
@@ -1636,10 +1637,6 @@ fn check_fn_or_method<'tcx>(
16361637
}
16371638
}
16381639

1639-
const HELP_FOR_SELF_TYPE: &str = "consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, \
1640-
`self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one \
1641-
of the previous types except `Self`)";
1642-
16431640
#[instrument(level = "debug", skip(wfcx))]
16441641
fn check_method_receiver<'tcx>(
16451642
wfcx: &WfCheckingCtxt<'_, 'tcx>,
@@ -1675,7 +1672,7 @@ fn check_method_receiver<'tcx>(
16751672
if tcx.features().arbitrary_self_types {
16761673
if !receiver_is_valid(wfcx, span, receiver_ty, self_ty, true) {
16771674
// Report error; `arbitrary_self_types` was enabled.
1678-
return Err(e0307(tcx, span, receiver_ty));
1675+
return Err(tcx.dcx().emit_err(errors::InvalidReceiverTy { span, receiver_ty }));
16791676
}
16801677
} else {
16811678
if !receiver_is_valid(wfcx, span, receiver_ty, self_ty, false) {
@@ -1690,24 +1687,17 @@ fn check_method_receiver<'tcx>(
16901687
the `arbitrary_self_types` feature",
16911688
),
16921689
)
1693-
.with_help(HELP_FOR_SELF_TYPE)
1690+
.with_help(fluent::hir_analysis_invalid_receiver_ty_help)
16941691
.emit()
16951692
} else {
16961693
// Report error; would not have worked with `arbitrary_self_types`.
1697-
e0307(tcx, span, receiver_ty)
1694+
tcx.dcx().emit_err(errors::InvalidReceiverTy { span, receiver_ty })
16981695
});
16991696
}
17001697
}
17011698
Ok(())
17021699
}
17031700

1704-
fn e0307(tcx: TyCtxt<'_>, span: Span, receiver_ty: Ty<'_>) -> ErrorGuaranteed {
1705-
struct_span_code_err!(tcx.dcx(), span, E0307, "invalid `self` parameter type: {receiver_ty}")
1706-
.with_note("type of `self` must be `Self` or a type that dereferences to it")
1707-
.with_help(HELP_FOR_SELF_TYPE)
1708-
.emit()
1709-
}
1710-
17111701
/// Returns whether `receiver_ty` would be considered a valid receiver type for `self_ty`. If
17121702
/// `arbitrary_self_types` is enabled, `receiver_ty` must transitively deref to `self_ty`, possibly
17131703
/// through a `*const/mut T` raw pointer. If the feature is not enabled, the requirements are more

compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,3 +1641,13 @@ pub struct NonConstRange {
16411641
#[primary_span]
16421642
pub span: Span,
16431643
}
1644+
1645+
#[derive(Diagnostic)]
1646+
#[diag(hir_analysis_invalid_receiver_ty, code = E0307)]
1647+
#[note]
1648+
#[help(hir_analysis_invalid_receiver_ty_help)]
1649+
pub struct InvalidReceiverTy<'tcx> {
1650+
#[primary_span]
1651+
pub span: Span,
1652+
pub receiver_ty: Ty<'tcx>,
1653+
}

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,16 +1228,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12281228
);
12291229
}
12301230
} else {
1231-
// Pattern has wrong number of fields.
1232-
let e =
1233-
self.e0023(pat.span, res, qpath, subpats, &variant.fields.raw, expected, had_err);
1231+
let e = self.emit_err_pat_wrong_number_of_fields(
1232+
pat.span,
1233+
res,
1234+
qpath,
1235+
subpats,
1236+
&variant.fields.raw,
1237+
expected,
1238+
had_err,
1239+
);
12341240
on_error(e);
12351241
return Ty::new_error(tcx, e);
12361242
}
12371243
pat_ty
12381244
}
12391245

1240-
fn e0023(
1246+
fn emit_err_pat_wrong_number_of_fields(
12411247
&self,
12421248
pat_span: Span,
12431249
res: Res,

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ use rustc_arena::{DroplessArena, TypedArena};
1010
use rustc_ast::Mutability;
1111
use rustc_data_structures::fx::FxIndexSet;
1212
use rustc_data_structures::stack::ensure_sufficient_stack;
13-
use rustc_errors::{
14-
codes::*, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, MultiSpan,
15-
};
13+
use rustc_errors::{codes::*, struct_span_code_err, Applicability, ErrorGuaranteed, MultiSpan};
1614
use rustc_hir::def::*;
1715
use rustc_hir::def_id::LocalDefId;
1816
use rustc_hir::{self as hir, BindingMode, ByRef, HirId};
@@ -24,7 +22,6 @@ use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
2422
use rustc_session::lint::builtin::{
2523
BINDINGS_WITH_VARIANT_NAME, IRREFUTABLE_LET_PATTERNS, UNREACHABLE_PATTERNS,
2624
};
27-
use rustc_session::Session;
2825
use rustc_span::hygiene::DesugaringKind;
2926
use rustc_span::{sym, Span};
3027

@@ -64,10 +61,6 @@ pub(crate) fn check_match(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), Err
6461
visitor.error
6562
}
6663

67-
fn create_e0004(sess: &Session, sp: Span, error_message: String) -> Diag<'_> {
68-
struct_span_code_err!(sess.dcx(), sp, E0004, "{}", &error_message)
69-
}
70-
7164
#[derive(Debug, Copy, Clone, PartialEq)]
7265
enum RefutableFlag {
7366
Irrefutable,
@@ -975,10 +968,11 @@ fn report_non_exhaustive_match<'p, 'tcx>(
975968

976969
// FIXME: migration of this diagnostic will require list support
977970
let joined_patterns = joined_uncovered_patterns(cx, &witnesses);
978-
let mut err = create_e0004(
979-
cx.tcx.sess,
971+
let mut err = struct_span_code_err!(
972+
cx.tcx.dcx(),
980973
sp,
981-
format!("non-exhaustive patterns: {joined_patterns} not covered"),
974+
E0004,
975+
"non-exhaustive patterns: {joined_patterns} not covered"
982976
);
983977
err.span_label(
984978
sp,

tests/ui/async-await/inference_var_self_argument.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
trait Foo {
55
async fn foo(self: &dyn Foo) {
66
//~^ ERROR: `Foo` cannot be made into an object
7-
//~| ERROR invalid `self` parameter type: &dyn Foo
7+
//~| ERROR invalid `self` parameter type: `&dyn Foo`
88
todo!()
99
}
1010
}

tests/ui/async-await/inference_var_self_argument.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | async fn foo(self: &dyn Foo) {
1313
| ^^^ ...because method `foo` is `async`
1414
= help: consider moving `foo` to another trait
1515

16-
error[E0307]: invalid `self` parameter type: &dyn Foo
16+
error[E0307]: invalid `self` parameter type: `&dyn Foo`
1717
--> $DIR/inference_var_self_argument.rs:5:24
1818
|
1919
LL | async fn foo(self: &dyn Foo) {

tests/ui/async-await/issue-66312.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0308]: mismatched types
44
LL | if x.is_some() {
55
| ^^^^^^^^^^^ expected `bool`, found `()`
66

7-
error[E0307]: invalid `self` parameter type: T
7+
error[E0307]: invalid `self` parameter type: `T`
88
--> $DIR/issue-66312.rs:4:22
99
|
1010
LL | fn is_some(self: T);

tests/ui/feature-gates/feature-gate-dispatch-from-dyn-cell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::cell::Cell;
44

55
trait Trait{
6-
fn cell(self: Cell<&Self>); //~ ERROR invalid `self` parameter type: Cell<&Self>
6+
fn cell(self: Cell<&Self>); //~ ERROR invalid `self` parameter type: `Cell<&Self>`
77
}
88

99
fn main() {}

0 commit comments

Comments
 (0)