diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-05-02 18:27:27 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-02 18:27:27 +0200 |
| commit | e96036fca2d9aac14a4329a5f355cceeefdde5cc (patch) | |
| tree | 09b3fefd52a0fa275a32bbe26d4efd1fe66c3e6f /src/librustc_middle | |
| parent | 53d3bc02ed90eba01c5dbc5b2d0c4cabb67ffb4d (diff) | |
| parent | 8d9f73a6902064e1a5508af98d77aed2ae055944 (diff) | |
Rollup merge of #69274 - LeSeulArtichaut:target-feature-11, r=hanna-kruppe
Implement RFC 2396: `#[target_feature]` 1.1 Tracking issue: #69098 r? @nikomatsakis cc @gnzlbg @joshtriplett
Diffstat (limited to 'src/librustc_middle')
| -rw-r--r-- | src/librustc_middle/ty/error.rs | 23 | ||||
| -rw-r--r-- | src/librustc_middle/ty/structural_impls.rs | 1 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/librustc_middle/ty/error.rs b/src/librustc_middle/ty/error.rs index d0bc0d5fabf..78a94b62d47 100644 --- a/src/librustc_middle/ty/error.rs +++ b/src/librustc_middle/ty/error.rs @@ -3,11 +3,13 @@ use rustc_ast::ast; use rustc_errors::{pluralize, Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_span::symbol::sym; use rustc_span::Span; use rustc_target::spec::abi; use std::borrow::Cow; use std::fmt; +use std::ops::Deref; #[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable)] pub struct ExpectedFound<T> { @@ -58,6 +60,8 @@ pub enum TypeError<'tcx> { ConstMismatch(ExpectedFound<&'tcx ty::Const<'tcx>>), IntrinsicCast, + /// Safe `#[target_feature]` functions are not assignable to safe function pointers. + TargetFeatureCast(DefId), } pub enum UnconstrainedNumeric { @@ -183,6 +187,10 @@ impl<'tcx> fmt::Display for TypeError<'tcx> { write!(f, "expected `{}`, found `{}`", values.expected, values.found) } IntrinsicCast => write!(f, "cannot coerce intrinsics to function pointers"), + TargetFeatureCast(_) => write!( + f, + "cannot coerce functions with `#[target_feature]` to safe function pointers" + ), ObjectUnsafeCoercion(_) => write!(f, "coercion to object-unsafe trait object"), } } @@ -193,7 +201,8 @@ impl<'tcx> TypeError<'tcx> { use self::TypeError::*; match self { CyclicTy(_) | UnsafetyMismatch(_) | Mismatch | AbiMismatch(_) | FixedArraySize(_) - | Sorts(_) | IntMismatch(_) | FloatMismatch(_) | VariadicMismatch(_) => false, + | Sorts(_) | IntMismatch(_) | FloatMismatch(_) | VariadicMismatch(_) + | TargetFeatureCast(_) => false, Mutability | TupleSize(_) @@ -489,6 +498,18 @@ impl Trait for X { ); } } + TargetFeatureCast(def_id) => { + let attrs = self.get_attrs(*def_id); + let target_spans = attrs + .deref() + .iter() + .filter(|attr| attr.has_name(sym::target_feature)) + .map(|attr| attr.span); + db.note( + "functions with `#[target_feature]` can only be coerced to `unsafe` function pointers" + ); + db.span_labels(target_spans, "`#[target_feature]` added here"); + } _ => {} } } diff --git a/src/librustc_middle/ty/structural_impls.rs b/src/librustc_middle/ty/structural_impls.rs index 1c0ffe12314..c8406a024ec 100644 --- a/src/librustc_middle/ty/structural_impls.rs +++ b/src/librustc_middle/ty/structural_impls.rs @@ -645,6 +645,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> { ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch), ConstMismatch(ref x) => return tcx.lift(x).map(ConstMismatch), IntrinsicCast => IntrinsicCast, + TargetFeatureCast(ref x) => TargetFeatureCast(*x), ObjectUnsafeCoercion(ref x) => return tcx.lift(x).map(ObjectUnsafeCoercion), }) } |
