Skip to content

Commit f74bb35

Browse files
authored
Rollup merge of #108983 - LeSeulArtichaut:108646-target-feature-default-impl, r=cjgillot
Forbid `#[target_feature]` on safe default implementations Fixes #108646.
2 parents 42ca383 + ad2bcb5 commit f74bb35

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

compiler/rustc_codegen_ssa/src/target_features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ fn asm_target_features(tcx: TyCtxt<'_>, did: DefId) -> &FxIndexSet<Symbol> {
442442
pub fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_span: Span) {
443443
if let DefKind::AssocFn = tcx.def_kind(id) {
444444
let parent_id = tcx.local_parent(id);
445-
if let DefKind::Impl { of_trait: true } = tcx.def_kind(parent_id) {
445+
if let DefKind::Trait | DefKind::Impl { of_trait: true } = tcx.def_kind(parent_id) {
446446
tcx.sess
447447
.struct_span_err(
448448
attr_span,

tests/ui/rfcs/rfc-2396-target_feature-11/trait-impl.rs

+6
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ impl Foo for Bar {
1818
unsafe fn unsf_foo(&self) {}
1919
}
2020

21+
trait Qux {
22+
#[target_feature(enable = "sse2")]
23+
//~^ ERROR cannot be applied to safe trait method
24+
fn foo(&self) {}
25+
}
26+
2127
fn main() {}

tests/ui/rfcs/rfc-2396-target_feature-11/trait-impl.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
error: `#[target_feature(..)]` cannot be applied to safe trait method
2+
--> $DIR/trait-impl.rs:22:5
3+
|
4+
LL | #[target_feature(enable = "sse2")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot be applied to safe trait method
6+
LL |
7+
LL | fn foo(&self) {}
8+
| ------------- not an `unsafe` function
9+
110
error: `#[target_feature(..)]` cannot be applied to safe trait method
211
--> $DIR/trait-impl.rs:13:5
312
|
@@ -7,5 +16,5 @@ LL |
716
LL | fn foo(&self) {}
817
| ------------- not an `unsafe` function
918

10-
error: aborting due to previous error
19+
error: aborting due to 2 previous errors
1120

0 commit comments

Comments
 (0)