Auto merge of #115910 - eduardosm:lang-fns-target-features, r=cjgillot · rust-lang/rust@aace2df (original) (raw)

`@@ -118,7 +118,7 @@ impl CheckAttrVisitor<'_> {

`

118

118

` sym::coverage => self.check_coverage(hir_id, attr, span, target),

`

119

119

` sym::non_exhaustive => self.check_non_exhaustive(hir_id, attr, span, target),

`

120

120

` sym::marker => self.check_marker(hir_id, attr, span, target),

`

121

``

`-

sym::target_feature => self.check_target_feature(hir_id, attr, span, target),

`

``

121

`+

sym::target_feature => self.check_target_feature(hir_id, attr, span, target, attrs),

`

122

122

` sym::thread_local => self.check_thread_local(attr, span, target),

`

123

123

` sym::track_caller => {

`

124

124

`self.check_track_caller(hir_id, attr.span, attrs, span, target)

`

`@@ -591,10 +591,36 @@ impl CheckAttrVisitor<'_> {

`

591

591

`attr: &Attribute,

`

592

592

`span: Span,

`

593

593

`target: Target,

`

``

594

`+

attrs: &[Attribute],

`

594

595

`) -> bool {

`

595

596

`match target {

`

596

``

`-

Target::Fn

`

597

``

`-

| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,

`

``

597

`+

Target::Fn => {

`

``

598

`` +

// #[target_feature] is not allowed in language items.

``

``

599

`+

if let Some((lang_item, _)) = hir::lang_items::extract(attrs)

`

``

600

`` +

// Calling functions with #[target_feature] is

``

``

601

`+

// not unsafe on WASM, see #84988

`

``

602

`+

&& !self.tcx.sess.target.is_like_wasm

`

``

603

`+

&& !self.tcx.sess.opts.actually_rustdoc

`

``

604

`+

{

`

``

605

`+

let hir::Node::Item(item) = self.tcx.hir().get(hir_id) else {

`

``

606

`+

unreachable!();

`

``

607

`+

};

`

``

608

`+

let hir::ItemKind::Fn(sig, _, _) = item.kind else {

`

``

609

`` +

// target is Fn

``

``

610

`+

unreachable!();

`

``

611

`+

};

`

``

612

+

``

613

`+

self.tcx.sess.emit_err(errors::LangItemWithTargetFeature {

`

``

614

`+

attr_span: attr.span,

`

``

615

`+

name: lang_item,

`

``

616

`+

sig_span: sig.span,

`

``

617

`+

});

`

``

618

`+

false

`

``

619

`+

} else {

`

``

620

`+

true

`

``

621

`+

}

`

``

622

`+

}

`

``

623

`+

Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,

`

598

624

`// FIXME: #[target_feature] was previously erroneously allowed on statements and some

`

599

625

`// crates used this, so only emit a warning.

`

600

626

`Target::Statement => {

`