Skip to content

Commit

Permalink
Split hir_typeck_never_type_fallback_flowing_into_unsafe into 5 slugs
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed May 2, 2024
1 parent 9b79c8c commit ea4473d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
18 changes: 9 additions & 9 deletions compiler/rustc_hir_typeck/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ hir_typeck_lossy_provenance_ptr2int =
hir_typeck_missing_parentheses_in_range = can't call method `{$method_name}` on type `{$ty_str}`
hir_typeck_never_type_fallback_flowing_into_unsafe =
never type fallback affects this {$reason ->
[call] call to an `unsafe` function
[union_field] union access
[deref] raw pointer dereference
[path] `unsafe` function
[method] call to an `unsafe` method
*[other] THIS SHOULD NOT BE REACHABLE
}
hir_typeck_never_type_fallback_flowing_into_unsafe_call = never type fallback affects this call to an `unsafe` function
.help = specify the type explicitly
hir_typeck_never_type_fallback_flowing_into_unsafe_deref = never type fallback affects this raw pointer dereference
.help = specify the type explicitly
hir_typeck_never_type_fallback_flowing_into_unsafe_method = never type fallback affects this call to an `unsafe` method
.help = specify the type explicitly
hir_typeck_never_type_fallback_flowing_into_unsafe_path = never type fallback affects this `unsafe` function
.help = specify the type explicitly
hir_typeck_never_type_fallback_flowing_into_unsafe_union_field = never type fallback affects this union access
.help = specify the type explicitly
hir_typeck_no_associated_item = no {$item_kind} named `{$item_name}` found for {$ty_prefix} `{$ty_str}`{$trait_missing_method ->
Expand Down
22 changes: 17 additions & 5 deletions compiler/rustc_hir_typeck/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Errors emitted by `rustc_hir_typeck`.
use std::borrow::Cow;

use crate::{fallback::UnsafeUseReason, fluent_generated as fluent};
use crate::fluent_generated as fluent;
use rustc_errors::{
codes::*, Applicability, Diag, DiagArgValue, EmissionGuarantee, IntoDiagArg, MultiSpan,
SubdiagMessageOp, Subdiagnostic,
Expand Down Expand Up @@ -165,10 +165,22 @@ pub struct MissingParenthesesInRange {
}

#[derive(LintDiagnostic)]
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe)]
#[help]
pub struct NeverTypeFallbackFlowingIntoUnsafe {
pub reason: UnsafeUseReason,
pub enum NeverTypeFallbackFlowingIntoUnsafe {
#[help]
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_call)]
Call,
#[help]
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_method)]
Method,
#[help]
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_path)]
Path,
#[help]
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_union_field)]
UnionField,
#[help]
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_deref)]
Deref,
}

#[derive(Subdiagnostic)]
Expand Down
34 changes: 18 additions & 16 deletions compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::{borrow::Cow, cell::OnceCell};
use std::cell::OnceCell;

use crate::{errors, FnCtxt, TypeckRootCtxt};
use rustc_data_structures::{
graph::{self, iterate::DepthFirstSearch, vec_graph::VecGraph},
unord::{UnordBag, UnordMap, UnordSet},
};
use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_hir as hir;
use rustc_hir::intravisit::Visitor;
use rustc_hir::HirId;
Expand Down Expand Up @@ -380,7 +379,23 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
lint::builtin::NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
hir_id,
span,
errors::NeverTypeFallbackFlowingIntoUnsafe { reason },
match reason {
UnsafeUseReason::Call => {
errors::NeverTypeFallbackFlowingIntoUnsafe::Call
}
UnsafeUseReason::Method => {
errors::NeverTypeFallbackFlowingIntoUnsafe::Method
}
UnsafeUseReason::Path => {
errors::NeverTypeFallbackFlowingIntoUnsafe::Path
}
UnsafeUseReason::UnionField => {
errors::NeverTypeFallbackFlowingIntoUnsafe::UnionField
}
UnsafeUseReason::Deref => {
errors::NeverTypeFallbackFlowingIntoUnsafe::Deref
}
},
);
}

Expand Down Expand Up @@ -503,19 +518,6 @@ pub(crate) enum UnsafeUseReason {
Deref,
}

impl IntoDiagArg for UnsafeUseReason {
fn into_diag_arg(self) -> DiagArgValue {
let s = match self {
UnsafeUseReason::Call => "call",
UnsafeUseReason::Method => "method",
UnsafeUseReason::Path => "path",
UnsafeUseReason::UnionField => "union_field",
UnsafeUseReason::Deref => "deref",
};
DiagArgValue::Str(Cow::Borrowed(s))
}
}

/// Finds all type variables which are passed to an `unsafe` operation.
///
/// For example, for this function `f`:
Expand Down

0 comments on commit ea4473d

Please sign in to comment.