Skip to content

Commit f5355b9

Browse files
committed
Auto merge of #124356 - fmease:fewer-magic-numbers-in-names, r=lcnr
Cleanup: Replace item names referencing GitHub issues or error codes with something more meaningful **lcnr** in #117164 (review): > […] while I know that there's precendent to name things `Issue69420`, I really dislike this as it requires looking up the issue to figure out the purpose of such a variant. Actually referring to the underlying issue, e.g. `AliasMayNormToUncovered` or whatever and then linking to the issue in a doc comment feels a lot more desirable to me. We should ideally rename all the functions and enums which currently use issue numbers. I've grepped through `compiler/` like crazy and think that I've found all instances of this pattern. However, I haven't renamed `compute_2229_migrations_*`. Should I? The first commit introduces an abhorrent and super long name for an item because naming is hard but also scary looking / unwelcoming names are good for things related to temporary-ish backcompat hacks. I'll let you discover it by yourself. Contains a bit of drive-by cleanup and a diag migration bc that was the simplest option. r? lcnr or compiler
2 parents f705de5 + 2a1d748 commit f5355b9

File tree

27 files changed

+111
-105
lines changed

27 files changed

+111
-105
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+5-6
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_data_structures/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ pub fn make_display(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl
144144
Printer { f }
145145
}
146146

147-
// See comments in compiler/rustc_middle/src/tests.rs
147+
// See comment in compiler/rustc_middle/src/tests.rs and issue #27438.
148148
#[doc(hidden)]
149-
pub fn __noop_fix_for_27438() {}
149+
pub fn __noop_fix_for_windows_dllimport_issue() {}
150150

151151
#[macro_export]
152152
macro_rules! external_bitflags_debug {

compiler/rustc_hir_analysis/messages.ftl

+6
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

+4-14
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

+10
Original file line numberDiff line numberDiff line change
@@ -1666,3 +1666,13 @@ pub struct NonConstRange {
16661666
#[primary_span]
16671667
pub span: Span,
16681668
}
1669+
1670+
#[derive(Diagnostic)]
1671+
#[diag(hir_analysis_invalid_receiver_ty, code = E0307)]
1672+
#[note]
1673+
#[help(hir_analysis_invalid_receiver_ty_help)]
1674+
pub struct InvalidReceiverTy<'tcx> {
1675+
#[primary_span]
1676+
pub span: Span,
1677+
pub receiver_ty: Ty<'tcx>,
1678+
}

compiler/rustc_hir_typeck/src/pat.rs

+10-4
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_middle/src/query/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,10 @@ rustc_queries! {
847847
separate_provide_extern
848848
}
849849

850-
query issue33140_self_ty(key: DefId) -> Option<ty::EarlyBinder<ty::Ty<'tcx>>> {
851-
desc { |tcx| "computing Self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
850+
query self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(
851+
key: DefId
852+
) -> Option<ty::EarlyBinder<ty::Ty<'tcx>>> {
853+
desc { |tcx| "computing self type wrt issue #33140 `{}`", tcx.def_path_str(key) }
852854
}
853855

854856
/// Maps a `DefId` of a type to a list of its inherent impls.

compiler/rustc_middle/src/tests.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
// FIXME(#27438): right now the unit tests of rustc_middle don't refer to any actual
2-
// functions generated in rustc_data_structures (all
3-
// references are through generic functions), but statics are
4-
// referenced from time to time. Due to this bug we won't
5-
// actually correctly link in the statics unless we also
6-
// reference a function, so be sure to reference a dummy
7-
// function.
1+
// FIXME(#27438): Right now, the unit tests of `rustc_middle` don't refer to any actual functions
2+
// generated in `rustc_data_structures` (all references are through generic functions),
3+
// but statics are referenced from time to time. Due to this Windows `dllimport` bug
4+
// we won't actually correctly link in the statics unless we also reference a function,
5+
// so be sure to reference a dummy function.
86
#[test]
97
fn noop() {
10-
rustc_data_structures::__noop_fix_for_27438();
8+
rustc_data_structures::__noop_fix_for_windows_dllimport_issue();
119
}

compiler/rustc_middle/src/ty/mod.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -1503,14 +1503,14 @@ pub enum ImplOverlapKind {
15031503
/// Whether or not the impl is permitted due to the trait being a `#[marker]` trait
15041504
marker: bool,
15051505
},
1506-
/// These impls are allowed to overlap, but that raises
1507-
/// an issue #33140 future-compatibility warning.
1506+
/// These impls are allowed to overlap, but that raises an
1507+
/// issue #33140 future-compatibility warning (tracked in #56484).
15081508
///
15091509
/// Some background: in Rust 1.0, the trait-object types `Send + Sync` (today's
15101510
/// `dyn Send + Sync`) and `Sync + Send` (now `dyn Sync + Send`) were different.
15111511
///
1512-
/// The widely-used version 0.1.0 of the crate `traitobject` had accidentally relied
1513-
/// that difference, making what reduces to the following set of impls:
1512+
/// The widely-used version 0.1.0 of the crate `traitobject` had accidentally relied on
1513+
/// that difference, doing what reduces to the following set of impls:
15141514
///
15151515
/// ```compile_fail,(E0119)
15161516
/// trait Trait {}
@@ -1535,7 +1535,7 @@ pub enum ImplOverlapKind {
15351535
/// 4. Neither of the impls can have any where-clauses.
15361536
///
15371537
/// Once `traitobject` 0.1.0 is no longer an active concern, this hack can be removed.
1538-
Issue33140,
1538+
FutureCompatOrderDepTraitObjects,
15391539
}
15401540

15411541
/// Useful source information about where a desugared associated type for an
@@ -1730,27 +1730,26 @@ impl<'tcx> TyCtxt<'tcx> {
17301730
| (ImplPolarity::Negative, ImplPolarity::Negative) => {}
17311731
};
17321732

1733-
let is_marker_overlap = {
1734-
let is_marker_impl =
1735-
|trait_ref: TraitRef<'_>| -> bool { self.trait_def(trait_ref.def_id).is_marker };
1736-
is_marker_impl(trait_ref1) && is_marker_impl(trait_ref2)
1737-
};
1733+
let is_marker_impl = |trait_ref: TraitRef<'_>| self.trait_def(trait_ref.def_id).is_marker;
1734+
let is_marker_overlap = is_marker_impl(trait_ref1) && is_marker_impl(trait_ref2);
17381735

17391736
if is_marker_overlap {
1740-
Some(ImplOverlapKind::Permitted { marker: true })
1741-
} else {
1742-
if let Some(self_ty1) = self.issue33140_self_ty(def_id1) {
1743-
if let Some(self_ty2) = self.issue33140_self_ty(def_id2) {
1744-
if self_ty1 == self_ty2 {
1745-
return Some(ImplOverlapKind::Issue33140);
1746-
} else {
1747-
debug!("found {self_ty1:?} != {self_ty2:?}");
1748-
}
1749-
}
1750-
}
1737+
return Some(ImplOverlapKind::Permitted { marker: true });
1738+
}
17511739

1752-
None
1740+
if let Some(self_ty1) =
1741+
self.self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(def_id1)
1742+
&& let Some(self_ty2) =
1743+
self.self_ty_of_trait_impl_enabling_order_dep_trait_object_hack(def_id2)
1744+
{
1745+
if self_ty1 == self_ty2 {
1746+
return Some(ImplOverlapKind::FutureCompatOrderDepTraitObjects);
1747+
} else {
1748+
debug!("found {self_ty1:?} != {self_ty2:?}");
1749+
}
17531750
}
1751+
1752+
None
17541753
}
17551754

17561755
/// Returns `ty::VariantDef` if `res` refers to a struct,

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

+5-11
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,

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
20012001
// any associated items and there are no where-clauses.
20022002
//
20032003
// We can just arbitrarily drop one of the impls.
2004-
Some(ty::ImplOverlapKind::Issue33140) => {
2004+
Some(ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects) => {
20052005
assert_eq!(other.evaluation, victim.evaluation);
20062006
DropVictim::Yes
20072007
}

compiler/rustc_trait_selection/src/traits/specialize/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ fn report_conflicting_impls<'tcx>(
453453
overlap.trait_ref.print_trait_sugared(),
454454
overlap.self_ty.map_or_else(String::new, |ty| format!(" for type `{ty}`")),
455455
match used_to_be_allowed {
456-
Some(FutureCompatOverlapErrorKind::Issue33140) => ": (E0119)",
456+
Some(FutureCompatOverlapErrorKind::OrderDepTraitObjects) => ": (E0119)",
457457
_ => "",
458458
}
459459
)
@@ -480,7 +480,7 @@ fn report_conflicting_impls<'tcx>(
480480
}
481481
Some(kind) => {
482482
let lint = match kind {
483-
FutureCompatOverlapErrorKind::Issue33140 => ORDER_DEPENDENT_TRAIT_OBJECTS,
483+
FutureCompatOverlapErrorKind::OrderDepTraitObjects => ORDER_DEPENDENT_TRAIT_OBJECTS,
484484
FutureCompatOverlapErrorKind::LeakCheck => COHERENCE_LEAK_CHECK,
485485
};
486486
tcx.node_span_lint(

compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub use rustc_middle::traits::specialization_graph::*;
1111

1212
#[derive(Copy, Clone, Debug)]
1313
pub enum FutureCompatOverlapErrorKind {
14-
Issue33140,
14+
OrderDepTraitObjects,
1515
LeakCheck,
1616
}
1717

@@ -150,10 +150,10 @@ impl<'tcx> Children {
150150
{
151151
match overlap_kind {
152152
ty::ImplOverlapKind::Permitted { marker: _ } => {}
153-
ty::ImplOverlapKind::Issue33140 => {
153+
ty::ImplOverlapKind::FutureCompatOrderDepTraitObjects => {
154154
*last_lint_mut = Some(FutureCompatOverlapError {
155155
error: create_overlap_error(overlap),
156-
kind: FutureCompatOverlapErrorKind::Issue33140,
156+
kind: FutureCompatOverlapErrorKind::OrderDepTraitObjects,
157157
});
158158
}
159159
}

0 commit comments

Comments
 (0)