Skip to content

Commit e14cb3b

Browse files
committed
Try to render shorthand differently
1 parent aa3ce37 commit e14cb3b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
205205

206206
if self_ty.is_fn() {
207207
let fn_sig = self_ty.fn_sig(self.tcx);
208-
let shortname = match fn_sig.safety() {
209-
hir::Safety::Safe => "fn",
210-
hir::Safety::Unsafe => "unsafe fn",
208+
let shortname = if let ty::FnDef(def_id, _) = self_ty.kind()
209+
&& self.tcx.codegen_fn_attrs(def_id).safe_target_features
210+
{
211+
"#[target_feature] fn"
212+
} else {
213+
match fn_sig.safety() {
214+
hir::Safety::Safe => "fn",
215+
hir::Safety::Unsafe => "unsafe fn",
216+
}
211217
};
212218
flags.push((sym::_Self, Some(shortname.to_owned())));
213219
}

tests/ui/rfcs/rfc-2396-target_feature-11/fn-traits.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ error[E0277]: expected a `Fn()` closure, found `#[target_features] fn() {foo}`
22
--> $DIR/fn-traits.rs:24:10
33
|
44
LL | call(foo);
5-
| ---- ^^^ call the function in a closure: `|| unsafe { /* code */ }`
5+
| ---- ^^^ expected an `Fn()` closure, found `#[target_features] fn() {foo}`
66
| |
77
| required by a bound introduced by this call
88
|
99
= help: the trait `Fn()` is not implemented for fn item `#[target_features] fn() {foo}`
10-
= note: unsafe function cannot be called generically without an unsafe block
1110
= note: wrap the `#[target_features] fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
1211
= note: `#[target_feature]` functions do not implement the `Fn` traits
1312
note: required by a bound in `call`
@@ -20,12 +19,11 @@ error[E0277]: expected a `FnMut()` closure, found `#[target_features] fn() {foo}
2019
--> $DIR/fn-traits.rs:25:14
2120
|
2221
LL | call_mut(foo);
23-
| -------- ^^^ call the function in a closure: `|| unsafe { /* code */ }`
22+
| -------- ^^^ expected an `FnMut()` closure, found `#[target_features] fn() {foo}`
2423
| |
2524
| required by a bound introduced by this call
2625
|
2726
= help: the trait `FnMut()` is not implemented for fn item `#[target_features] fn() {foo}`
28-
= note: unsafe function cannot be called generically without an unsafe block
2927
= note: wrap the `#[target_features] fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
3028
= note: `#[target_feature]` functions do not implement the `Fn` traits
3129
note: required by a bound in `call_mut`
@@ -38,12 +36,11 @@ error[E0277]: expected a `FnOnce()` closure, found `#[target_features] fn() {foo
3836
--> $DIR/fn-traits.rs:26:15
3937
|
4038
LL | call_once(foo);
41-
| --------- ^^^ call the function in a closure: `|| unsafe { /* code */ }`
39+
| --------- ^^^ expected an `FnOnce()` closure, found `#[target_features] fn() {foo}`
4240
| |
4341
| required by a bound introduced by this call
4442
|
4543
= help: the trait `FnOnce()` is not implemented for fn item `#[target_features] fn() {foo}`
46-
= note: unsafe function cannot be called generically without an unsafe block
4744
= note: wrap the `#[target_features] fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
4845
= note: `#[target_feature]` functions do not implement the `Fn` traits
4946
note: required by a bound in `call_once`

0 commit comments

Comments
 (0)