check extern "custom" function pointers#159780
Conversation
b71966b to
a8807aa
Compare
| && match &ret_ty.kind { | ||
| TyKind::Never => false, | ||
| TyKind::Never if abi != ExternAbi::Custom => false, | ||
| TyKind::Tup(tup) if tup.is_empty() => false, | ||
| _ => true, | ||
| } |
There was a problem hiding this comment.
@WaffleLapkin As requested, ! is now no longer allowed as a return type to extern "custom". Reading this code now, I think the ability to return ! just accidentally fell out of the logic here, and it was less of a deliberate inclusion.
We can always allow it again later, if a compelling reason comes up.
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| &self, | ||
| abi: ExternAbi, | ||
| ctxt: FnCtxt, | ||
| opt_ident: Option<&Ident>, |
There was a problem hiding this comment.
Could you document what the ident means/is used for?
There was a problem hiding this comment.
Maybe function_name: ... + "function_name is none iff this is called for a function pointer type"?
| self.header.ext.span().unwrap_or(self.safety_span().shrink_to_hi()) | ||
| } | ||
|
|
||
| pub fn as_borrowed<'a>(&'a self) -> BorrowedFnSig<'a> { |
There was a problem hiding this comment.
nit:
| pub fn as_borrowed<'a>(&'a self) -> BorrowedFnSig<'a> { | |
| pub fn as_borrowed(&self) -> BorrowedFnSig<'_> { |
|
|
||
| pub fn as_borrowed_fn_sig<'a>(&'a self) -> BorrowedFnSig<'a> { | ||
| BorrowedFnSig { header: self.header(), decl: &self.decl, span: self.decl_span } | ||
| } |
There was a problem hiding this comment.
nit; this (and some other unexpected changes) is in the "update tests now that we check the ABI of function pointer types" commit, seems like something got messed up during a rebase or something...
There was a problem hiding this comment.
the changes were intentional, I've updated the commit name
| && match &ret_ty.kind { | ||
| TyKind::Never => false, | ||
| TyKind::Never if abi != ExternAbi::Custom => false, | ||
| TyKind::Tup(tup) if tup.is_empty() => false, | ||
| _ => true, | ||
| } |
There was a problem hiding this comment.
Maybe this could be a bit more readable?
| && match &ret_ty.kind { | |
| TyKind::Never => false, | |
| TyKind::Never if abi != ExternAbi::Custom => false, | |
| TyKind::Tup(tup) if tup.is_empty() => false, | |
| _ => true, | |
| } | |
| let allowed_return = |ty| match &ret_ty.kind { | |
| TyKind::Never if abi != ExternAbi::Custom => true, | |
| TyKind::Tup(tup) if tup.is_empty() => true, | |
| _ => false, | |
| }; | |
| if let FnRetTy::Ty(ref ret_ty) = sig.decl.output | |
| && !allowed_return(ret_ty) |
| // An `extern "custom"` function must be unsafe. | ||
| self.reject_safe_fn(abi, ctxt, sig); | ||
| self.reject_safe_fn(abi, ctxt, sig, opt_ident.is_none()); |
There was a problem hiding this comment.
I think instead of special casing function pointers inside of reject_safe_fn, just not call it for them
There was a problem hiding this comment.
For extern "custom" an error message should be generated on a missing unsafe also: extern "custom" must always be unsafe.
|
Reminder, once the PR becomes ready for a review, use |
Are any of these stable? i.e. is this technically a breaking change we should worry about? |
and update the tests as needed.
5d6144e to
d0dde60
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot ready |
…ptrs, r=WaffleLapkin check `extern "custom"` function pointers tracking issue: rust-lang#140829 related RFC: rust-lang/rfcs#3980 Best reviewed commit-by-commit. This PR makes 3 changes - extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`. - remove the ability for `extern "custom"` to return `!` - improve the suggestion when `safe` is used in a function pointer type
…ptrs, r=WaffleLapkin check `extern "custom"` function pointers tracking issue: rust-lang#140829 related RFC: rust-lang/rfcs#3980 Best reviewed commit-by-commit. This PR makes 3 changes - extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`. - remove the ability for `extern "custom"` to return `!` - improve the suggestion when `safe` is used in a function pointer type
Rollup of 17 pull requests Successful merges: - #158168 (Added implementation on `set_permissions_nofollow` for all primary platforms) - #138618 (Support using const pointers in asm `const` operand) - #157962 (Function item should not be used as const arg) - #158404 (trait_solver: normalize next-gen region constraints) - #158709 (rustdoc: warn on improperly interleaved HTML/MD) - #159720 (document #[global_allocator] constraints) - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled) - #159740 (reuse regular exported_non_generic_symbols logic in Miri) - #159780 (check `extern "custom"` function pointers) - #159786 (rustdoc-js: ignore editor temp files in test folder discovery) - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new) - #155388 (stepping into where-clauses during normalization may be productive) - #155914 (when bailing on ambiguity, don't force other results to ambig) - #159411 ([rustdoc] Correctly handle output options with --show-coverage) - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`) - #159809 (Avoid `#[target_features]`) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate)
…ptrs, r=WaffleLapkin check `extern "custom"` function pointers tracking issue: rust-lang#140829 related RFC: rust-lang/rfcs#3980 Best reviewed commit-by-commit. This PR makes 3 changes - extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`. - remove the ability for `extern "custom"` to return `!` - improve the suggestion when `safe` is used in a function pointer type
Rollup of 16 pull requests Successful merges: - #138618 (Support using const pointers in asm `const` operand) - #157962 (Function item should not be used as const arg) - #158404 (trait_solver: normalize next-gen region constraints) - #158709 (rustdoc: warn on improperly interleaved HTML/MD) - #159720 (document #[global_allocator] constraints) - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled) - #159740 (reuse regular exported_non_generic_symbols logic in Miri) - #159780 (check `extern "custom"` function pointers) - #159786 (rustdoc-js: ignore editor temp files in test folder discovery) - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new) - #155388 (stepping into where-clauses during normalization may be productive) - #155914 (when bailing on ambiguity, don't force other results to ambig) - #159411 ([rustdoc] Correctly handle output options with --show-coverage) - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`) - #159809 (Avoid `#[target_features]`) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate)
…ptrs, r=WaffleLapkin check `extern "custom"` function pointers tracking issue: rust-lang#140829 related RFC: rust-lang/rfcs#3980 Best reviewed commit-by-commit. This PR makes 3 changes - extend the ABI checks we already performed on function definitions and trait and foreign declarations to function pointer types. This touches the various `interupt` ABIs and `extern "custom"`. - remove the ability for `extern "custom"` to return `!` - improve the suggestion when `safe` is used in a function pointer type
tracking issue: #140829
related RFC: rust-lang/rfcs#3980
Best reviewed commit-by-commit.
This PR makes 3 changes
interuptABIs andextern "custom".extern "custom"to return!safeis used in a function pointer type