Skip to content

Commit b562617

Browse files
committed
Split hir_typeck_never_type_fallback_flowing_into_unsafe into 5 slugs
1 parent 0df43db commit b562617

File tree

3 files changed

+44
-30
lines changed

3 files changed

+44
-30
lines changed

compiler/rustc_hir_typeck/messages.ftl

+9-9
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ hir_typeck_lossy_provenance_ptr2int =
9999
100100
hir_typeck_missing_parentheses_in_range = can't call method `{$method_name}` on type `{$ty_str}`
101101
102-
hir_typeck_never_type_fallback_flowing_into_unsafe =
103-
never type fallback affects this {$reason ->
104-
[call] call to an `unsafe` function
105-
[union_field] union access
106-
[deref] raw pointer dereference
107-
[path] `unsafe` function
108-
[method] call to an `unsafe` method
109-
*[other] THIS SHOULD NOT BE REACHABLE
110-
}
102+
hir_typeck_never_type_fallback_flowing_into_unsafe_call = never type fallback affects this call to an `unsafe` function
103+
.help = specify the type explicitly
104+
hir_typeck_never_type_fallback_flowing_into_unsafe_deref = never type fallback affects this raw pointer dereference
105+
.help = specify the type explicitly
106+
hir_typeck_never_type_fallback_flowing_into_unsafe_method = never type fallback affects this call to an `unsafe` method
107+
.help = specify the type explicitly
108+
hir_typeck_never_type_fallback_flowing_into_unsafe_path = never type fallback affects this `unsafe` function
109+
.help = specify the type explicitly
110+
hir_typeck_never_type_fallback_flowing_into_unsafe_union_field = never type fallback affects this union access
111111
.help = specify the type explicitly
112112
113113
hir_typeck_no_associated_item = no {$item_kind} named `{$item_name}` found for {$ty_prefix} `{$ty_str}`{$trait_missing_method ->

compiler/rustc_hir_typeck/src/errors.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Errors emitted by `rustc_hir_typeck`.
22
use std::borrow::Cow;
33

4-
use crate::{fallback::UnsafeUseReason, fluent_generated as fluent};
4+
use crate::fluent_generated as fluent;
55
use rustc_errors::{
66
codes::*, Applicability, Diag, DiagArgValue, EmissionGuarantee, IntoDiagArg, MultiSpan,
77
SubdiagMessageOp, Subdiagnostic,
@@ -165,10 +165,22 @@ pub struct MissingParenthesesInRange {
165165
}
166166

167167
#[derive(LintDiagnostic)]
168-
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe)]
169-
#[help]
170-
pub struct NeverTypeFallbackFlowingIntoUnsafe {
171-
pub reason: UnsafeUseReason,
168+
pub enum NeverTypeFallbackFlowingIntoUnsafe {
169+
#[help]
170+
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_call)]
171+
Call,
172+
#[help]
173+
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_method)]
174+
Method,
175+
#[help]
176+
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_path)]
177+
Path,
178+
#[help]
179+
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_union_field)]
180+
UnionField,
181+
#[help]
182+
#[diag(hir_typeck_never_type_fallback_flowing_into_unsafe_deref)]
183+
Deref,
172184
}
173185

174186
#[derive(Subdiagnostic)]

compiler/rustc_hir_typeck/src/fallback.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use std::{borrow::Cow, cell::OnceCell};
1+
use std::cell::OnceCell;
22

33
use crate::{errors, FnCtxt, TypeckRootCtxt};
44
use rustc_data_structures::{
55
graph::{self, iterate::DepthFirstSearch, vec_graph::VecGraph},
66
unord::{UnordBag, UnordMap, UnordSet},
77
};
8-
use rustc_errors::{DiagArgValue, IntoDiagArg};
98
use rustc_hir as hir;
109
use rustc_hir::intravisit::Visitor;
1110
use rustc_hir::HirId;
@@ -380,7 +379,23 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
380379
lint::builtin::NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
381380
hir_id,
382381
span,
383-
errors::NeverTypeFallbackFlowingIntoUnsafe { reason },
382+
match reason {
383+
UnsafeUseReason::Call => {
384+
errors::NeverTypeFallbackFlowingIntoUnsafe::Call
385+
}
386+
UnsafeUseReason::Method => {
387+
errors::NeverTypeFallbackFlowingIntoUnsafe::Method
388+
}
389+
UnsafeUseReason::Path => {
390+
errors::NeverTypeFallbackFlowingIntoUnsafe::Path
391+
}
392+
UnsafeUseReason::UnionField => {
393+
errors::NeverTypeFallbackFlowingIntoUnsafe::UnionField
394+
}
395+
UnsafeUseReason::Deref => {
396+
errors::NeverTypeFallbackFlowingIntoUnsafe::Deref
397+
}
398+
},
384399
);
385400
}
386401

@@ -503,19 +518,6 @@ pub(crate) enum UnsafeUseReason {
503518
Deref,
504519
}
505520

506-
impl IntoDiagArg for UnsafeUseReason {
507-
fn into_diag_arg(self) -> DiagArgValue {
508-
let s = match self {
509-
UnsafeUseReason::Call => "call",
510-
UnsafeUseReason::Method => "method",
511-
UnsafeUseReason::Path => "path",
512-
UnsafeUseReason::UnionField => "union_field",
513-
UnsafeUseReason::Deref => "deref",
514-
};
515-
DiagArgValue::Str(Cow::Borrowed(s))
516-
}
517-
}
518-
519521
/// Finds all type variables which are passed to an `unsafe` operation.
520522
///
521523
/// For example, for this function `f`:

0 commit comments

Comments
 (0)