1
Fork 0

Split hir_typeck_never_type_fallback_flowing_into_unsafe into 5 slugs

This commit is contained in:
Waffle Lapkin 2024-05-02 03:29:18 +02:00
parent 0df43db50c
commit b5626172d1
3 changed files with 44 additions and 30 deletions

View file

@ -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 ->

View file

@ -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,
@ -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)]

View file

@ -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;
@ -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
}
},
);
}
@ -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`: