Skip to content

Commit 867da89

Browse files
committed
Render fn defs with target_features attrs with the attribute
1 parent 0712869 commit 867da89

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,14 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
691691
if with_reduced_queries() {
692692
p!(print_def_path(def_id, args));
693693
} else {
694-
let sig = self.tcx().fn_sig(def_id).instantiate(self.tcx(), args);
694+
let mut sig = self.tcx().fn_sig(def_id).instantiate(self.tcx(), args);
695+
if self.tcx().codegen_fn_attrs(def_id).safe_target_features {
696+
p!("#[target_features] ");
697+
sig = sig.map_bound(|mut sig| {
698+
sig.safety = hir::Safety::Safe;
699+
sig
700+
});
701+
}
695702
p!(print(sig), " {{", print_value_path(def_id, args), "}}");
696703
}
697704
}

tests/ui/async-await/async-closures/fn-exception-target-features.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
error[E0277]: the trait bound `unsafe fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {target_feature}: AsyncFn()` is not satisfied
1+
error[E0277]: the trait bound `#[target_features] fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {target_feature}: AsyncFn()` is not satisfied
22
--> $DIR/fn-exception-target-features.rs:16:10
33
|
44
LL | test(target_feature);
5-
| ---- ^^^^^^^^^^^^^^ the trait `AsyncFn()` is not implemented for fn item `unsafe fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {target_feature}`
5+
| ---- ^^^^^^^^^^^^^^ unsatisfied trait bound
66
| |
77
| required by a bound introduced by this call
88
|
9+
= help: the trait `AsyncFn()` is not implemented for fn item `#[target_features] fn() -> Pin<Box<(dyn Future<Output = ()> + 'static)>> {target_feature}`
910
note: required by a bound in `test`
1011
--> $DIR/fn-exception-target-features.rs:13:17
1112
|

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ fn call_once(f: impl FnOnce()) {
2121
}
2222

2323
fn main() {
24-
call(foo); //~ ERROR expected a `Fn()` closure, found `unsafe fn() {foo}`
25-
call_mut(foo); //~ ERROR expected a `FnMut()` closure, found `unsafe fn() {foo}`
26-
call_once(foo); //~ ERROR expected a `FnOnce()` closure, found `unsafe fn() {foo}`
24+
call(foo); //~ ERROR expected a `Fn()` closure, found `#[target_features] fn() {foo}`
25+
call_mut(foo); //~ ERROR expected a `FnMut()` closure, found `#[target_features] fn() {foo}`
26+
call_once(foo); //~ ERROR expected a `FnOnce()` closure, found `#[target_features] fn() {foo}`
2727

2828
call(foo_unsafe);
2929
//~^ ERROR expected a `Fn()` closure, found `unsafe fn() {foo_unsafe}`

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
error[E0277]: expected a `Fn()` closure, found `unsafe fn() {foo}`
1+
error[E0277]: expected a `Fn()` closure, found `#[target_features] fn() {foo}`
22
--> $DIR/fn-traits.rs:24:10
33
|
44
LL | call(foo);
55
| ---- ^^^ call the function in a closure: `|| unsafe { /* code */ }`
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the trait `Fn()` is not implemented for fn item `unsafe fn() {foo}`
9+
= help: the trait `Fn()` is not implemented for fn item `#[target_features] fn() {foo}`
1010
= note: unsafe function cannot be called generically without an unsafe block
11-
= note: wrap the `unsafe fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
11+
= note: wrap the `#[target_features] fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
1212
= note: `#[target_feature]` functions do not implement the `Fn` traits
1313
note: required by a bound in `call`
1414
--> $DIR/fn-traits.rs:11:17
1515
|
1616
LL | fn call(f: impl Fn()) {
1717
| ^^^^ required by this bound in `call`
1818

19-
error[E0277]: expected a `FnMut()` closure, found `unsafe fn() {foo}`
19+
error[E0277]: expected a `FnMut()` closure, found `#[target_features] fn() {foo}`
2020
--> $DIR/fn-traits.rs:25:14
2121
|
2222
LL | call_mut(foo);
2323
| -------- ^^^ call the function in a closure: `|| unsafe { /* code */ }`
2424
| |
2525
| required by a bound introduced by this call
2626
|
27-
= help: the trait `FnMut()` is not implemented for fn item `unsafe fn() {foo}`
27+
= help: the trait `FnMut()` is not implemented for fn item `#[target_features] fn() {foo}`
2828
= note: unsafe function cannot be called generically without an unsafe block
29-
= note: wrap the `unsafe fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
29+
= note: wrap the `#[target_features] fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
3030
= note: `#[target_feature]` functions do not implement the `Fn` traits
3131
note: required by a bound in `call_mut`
3232
--> $DIR/fn-traits.rs:15:25
3333
|
3434
LL | fn call_mut(mut f: impl FnMut()) {
3535
| ^^^^^^^ required by this bound in `call_mut`
3636

37-
error[E0277]: expected a `FnOnce()` closure, found `unsafe fn() {foo}`
37+
error[E0277]: expected a `FnOnce()` closure, found `#[target_features] fn() {foo}`
3838
--> $DIR/fn-traits.rs:26:15
3939
|
4040
LL | call_once(foo);
4141
| --------- ^^^ call the function in a closure: `|| unsafe { /* code */ }`
4242
| |
4343
| required by a bound introduced by this call
4444
|
45-
= help: the trait `FnOnce()` is not implemented for fn item `unsafe fn() {foo}`
45+
= help: the trait `FnOnce()` is not implemented for fn item `#[target_features] fn() {foo}`
4646
= note: unsafe function cannot be called generically without an unsafe block
47-
= note: wrap the `unsafe fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
47+
= note: wrap the `#[target_features] fn() {foo}` in a closure with no arguments: `|| { /* code */ }`
4848
= note: `#[target_feature]` functions do not implement the `Fn` traits
4949
note: required by a bound in `call_once`
5050
--> $DIR/fn-traits.rs:19:22

0 commit comments

Comments
 (0)