Skip to content

Commit

Permalink
Try to render shorthand differently
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 14, 2025
1 parent 2069650 commit c6d9ec6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {

if self_ty.is_fn() {
let fn_sig = self_ty.fn_sig(self.tcx);
let shortname = match fn_sig.safety() {
hir::Safety::Safe => "fn",
hir::Safety::Unsafe => "unsafe fn",
let shortname = if let ty::FnDef(def_id, _) = self_ty.kind()
&& self.tcx.codegen_fn_attrs(def_id).safe_target_features
{
"#[target_feature] fn"
} else {
match fn_sig.safety() {
hir::Safety::Safe => "fn",
hir::Safety::Unsafe => "unsafe fn",
}
};
flags.push((sym::_Self, Some(shortname.to_owned())));
}
Expand Down
9 changes: 3 additions & 6 deletions tests/ui/rfcs/rfc-2396-target_feature-11/fn-traits.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ error[E0277]: expected a `Fn()` closure, found `#[target_features] fn() {foo}`
--> $DIR/fn-traits.rs:24:10
|
LL | call(foo);
| ---- ^^^ call the function in a closure: `|| unsafe { /* code */ }`
| ---- ^^^ expected an `Fn()` closure, found `#[target_features] fn() {foo}`
| |
| required by a bound introduced by this call
|
= help: the trait `Fn()` is not implemented for fn item `#[target_features] fn() {foo}`
= note: unsafe function cannot be called generically without an unsafe block
= note: wrap the `#[target_features] fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
= note: `#[target_feature]` functions do not implement the `Fn` traits
note: required by a bound in `call`
Expand All @@ -20,12 +19,11 @@ error[E0277]: expected a `FnMut()` closure, found `#[target_features] fn() {foo}
--> $DIR/fn-traits.rs:25:14
|
LL | call_mut(foo);
| -------- ^^^ call the function in a closure: `|| unsafe { /* code */ }`
| -------- ^^^ expected an `FnMut()` closure, found `#[target_features] fn() {foo}`
| |
| required by a bound introduced by this call
|
= help: the trait `FnMut()` is not implemented for fn item `#[target_features] fn() {foo}`
= note: unsafe function cannot be called generically without an unsafe block
= note: wrap the `#[target_features] fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
= note: `#[target_feature]` functions do not implement the `Fn` traits
note: required by a bound in `call_mut`
Expand All @@ -38,12 +36,11 @@ error[E0277]: expected a `FnOnce()` closure, found `#[target_features] fn() {foo
--> $DIR/fn-traits.rs:26:15
|
LL | call_once(foo);
| --------- ^^^ call the function in a closure: `|| unsafe { /* code */ }`
| --------- ^^^ expected an `FnOnce()` closure, found `#[target_features] fn() {foo}`
| |
| required by a bound introduced by this call
|
= help: the trait `FnOnce()` is not implemented for fn item `#[target_features] fn() {foo}`
= note: unsafe function cannot be called generically without an unsafe block
= note: wrap the `#[target_features] fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
= note: `#[target_feature]` functions do not implement the `Fn` traits
note: required by a bound in `call_once`
Expand Down

0 comments on commit c6d9ec6

Please sign in to comment.