Skip to content

Commit

Permalink
Some code review suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
adetaylor committed Aug 30, 2024
1 parent e77eb04 commit 8e20b66
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1652,11 +1652,10 @@ fn check_fn_or_method<'tcx>(
}

/// The `arbitrary_self_types_pointers` feature implies `arbitrary_self_types`.
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq)]
enum ArbitrarySelfTypesLevel {
None, // neither arbitrary_self_types nor arbitrary_self_types_pointers
ArbitrarySelfTypes, // just arbitrary_self_types
ArbitrarySelfTypesPointers, // both arbitrary_self_types and arbitrary_self_types_pointers
Basic, // just arbitrary_self_types
WithPointers, // both arbitrary_self_types and arbitrary_self_types_pointers
}

#[instrument(level = "debug", skip(wfcx))]
Expand Down Expand Up @@ -1692,26 +1691,25 @@ fn check_method_receiver<'tcx>(
}

let arbitrary_self_types_level = if tcx.features().arbitrary_self_types_pointers {
ArbitrarySelfTypesLevel::ArbitrarySelfTypesPointers
Some(ArbitrarySelfTypesLevel::WithPointers)
} else if tcx.features().arbitrary_self_types {
ArbitrarySelfTypesLevel::ArbitrarySelfTypes
Some(ArbitrarySelfTypesLevel::Basic)
} else {
ArbitrarySelfTypesLevel::None
None
};

if !receiver_is_valid(wfcx, span, receiver_ty, self_ty, arbitrary_self_types_level) {
return Err(match arbitrary_self_types_level {
// Wherever possible, emit a message advising folks that the features
// `arbitrary_self_types` or `arbitrary_self_types_pointers` might
// have helped.
ArbitrarySelfTypesLevel::None
if receiver_is_valid(
wfcx,
span,
receiver_ty,
self_ty,
ArbitrarySelfTypesLevel::ArbitrarySelfTypes,
) =>
None if receiver_is_valid(
wfcx,
span,
receiver_ty,
self_ty,
Some(ArbitrarySelfTypesLevel::Basic),
) =>
{
// Report error; would have worked with `arbitrary_self_types`.
feature_err(
Expand All @@ -1726,13 +1724,13 @@ fn check_method_receiver<'tcx>(
.with_help(fluent::hir_analysis_invalid_receiver_ty_help)
.emit()
}
ArbitrarySelfTypesLevel::ArbitrarySelfTypes | ArbitrarySelfTypesLevel::None
None | Some(ArbitrarySelfTypesLevel::Basic)
if receiver_is_valid(
wfcx,
span,
receiver_ty,
self_ty,
ArbitrarySelfTypesLevel::ArbitrarySelfTypesPointers,
Some(ArbitrarySelfTypesLevel::WithPointers),
) =>
{
// Report error; would have worked with `arbitrary_self_types_pointers`.
Expand Down Expand Up @@ -1772,7 +1770,7 @@ fn receiver_is_valid<'tcx>(
span: Span,
receiver_ty: Ty<'tcx>,
self_ty: Ty<'tcx>,
arbitrary_self_types_enabled: ArbitrarySelfTypesLevel,
arbitrary_self_types_enabled: Option<ArbitrarySelfTypesLevel>,
) -> bool {
let infcx = wfcx.infcx;
let tcx = wfcx.tcx();
Expand All @@ -1791,7 +1789,7 @@ fn receiver_is_valid<'tcx>(
let mut autoderef = Autoderef::new(infcx, wfcx.param_env, wfcx.body_def_id, span, receiver_ty);

// The `arbitrary_self_types_pointers` feature allows raw pointer receivers like `self: *const Self`.
if matches!(arbitrary_self_types_enabled, ArbitrarySelfTypesLevel::ArbitrarySelfTypesPointers) {
if arbitrary_self_types_enabled == Some(ArbitrarySelfTypesLevel::WithPointers) {
autoderef = autoderef.include_raw_pointers();
}

Expand All @@ -1817,7 +1815,7 @@ fn receiver_is_valid<'tcx>(

// Without `feature(arbitrary_self_types)`, we require that each step in the
// deref chain implement `receiver`.
if matches!(arbitrary_self_types_enabled, ArbitrarySelfTypesLevel::None) {
if arbitrary_self_types_enabled.is_none() {
if !receiver_is_implemented(
wfcx,
receiver_trait_def_id,
Expand Down

0 comments on commit 8e20b66

Please sign in to comment.