Auto merge of #96134 - Dylan-DPC:rollup-ejug3yq, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #95346 (Stablize `const_extern_fn` for "Rust" and "C") - #95933 (htmldocck: Compare HTML tree instead of plain text html) - #96105 (Make the debug output for `TargetSelection` less verbose) - #96112 (Strict provenance lint diagnostics improvements) - #96119 (update Miri) - #96124 (to_digit tweak) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
2c28b0eaf9
12 changed files with 187 additions and 102 deletions
|
@ -58,9 +58,22 @@ struct PostExpansionVisitor<'a> {
|
|||
}
|
||||
|
||||
impl<'a> PostExpansionVisitor<'a> {
|
||||
fn check_abi(&self, abi: ast::StrLit) {
|
||||
fn check_abi(&self, abi: ast::StrLit, constness: ast::Const) {
|
||||
let ast::StrLit { symbol_unescaped, span, .. } = abi;
|
||||
|
||||
if let ast::Const::Yes(_) = constness {
|
||||
match symbol_unescaped.as_str() {
|
||||
// Stable
|
||||
"Rust" | "C" => {}
|
||||
abi => gate_feature_post!(
|
||||
&self,
|
||||
const_extern_fn,
|
||||
span,
|
||||
&format!("`{}` as a `const fn` ABI is unstable", abi)
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
match symbol_unescaped.as_str() {
|
||||
// Stable
|
||||
"Rust" | "C" | "cdecl" | "stdcall" | "fastcall" | "aapcs" | "win64" | "sysv64"
|
||||
|
@ -261,9 +274,9 @@ impl<'a> PostExpansionVisitor<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_extern(&self, ext: ast::Extern) {
|
||||
fn check_extern(&self, ext: ast::Extern, constness: ast::Const) {
|
||||
if let ast::Extern::Explicit(abi) = ext {
|
||||
self.check_abi(abi);
|
||||
self.check_abi(abi, constness);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -437,7 +450,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
match i.kind {
|
||||
ast::ItemKind::ForeignMod(ref foreign_module) => {
|
||||
if let Some(abi) = foreign_module.abi {
|
||||
self.check_abi(abi);
|
||||
self.check_abi(abi, ast::Const::No);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -560,7 +573,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
fn visit_ty(&mut self, ty: &'a ast::Ty) {
|
||||
match ty.kind {
|
||||
ast::TyKind::BareFn(ref bare_fn_ty) => {
|
||||
self.check_extern(bare_fn_ty.ext);
|
||||
// Function pointers cannot be `const`
|
||||
self.check_extern(bare_fn_ty.ext, ast::Const::No);
|
||||
}
|
||||
ast::TyKind::Never => {
|
||||
gate_feature_post!(&self, never_type, ty.span, "the `!` type is experimental");
|
||||
|
@ -660,18 +674,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
fn visit_fn(&mut self, fn_kind: FnKind<'a>, span: Span, _: NodeId) {
|
||||
if let Some(header) = fn_kind.header() {
|
||||
// Stability of const fn methods are covered in `visit_assoc_item` below.
|
||||
self.check_extern(header.ext);
|
||||
|
||||
if let (ast::Const::Yes(_), ast::Extern::Implicit)
|
||||
| (ast::Const::Yes(_), ast::Extern::Explicit(_)) = (header.constness, header.ext)
|
||||
{
|
||||
gate_feature_post!(
|
||||
&self,
|
||||
const_extern_fn,
|
||||
span,
|
||||
"`const extern fn` definitions are unstable"
|
||||
);
|
||||
}
|
||||
self.check_extern(header.ext, header.constness);
|
||||
}
|
||||
|
||||
if fn_kind.ctxt() != Some(FnCtxt::Foreign) && fn_kind.decl().c_variadic() {
|
||||
|
|
|
@ -523,6 +523,9 @@ impl<'a> Parser<'a> {
|
|||
let decl = self.parse_fn_decl(|_| false, AllowPlus::No, recover_return_sign)?;
|
||||
let whole_span = lo.to(self.prev_token.span);
|
||||
if let ast::Const::Yes(span) = constness {
|
||||
// If we ever start to allow `const fn()`, then update
|
||||
// feature gating for `#![feature(const_extern_fn)]` to
|
||||
// cover it.
|
||||
self.error_fn_ptr_bad_qualifier(whole_span, span, "const");
|
||||
}
|
||||
if let ast::Async::Yes { span, .. } = asyncness {
|
||||
|
|
|
@ -993,20 +993,33 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
|||
));
|
||||
|
||||
let msg = "use `.addr()` to obtain the address of a pointer";
|
||||
if let Ok(snippet) = fcx.tcx.sess.source_map().span_to_snippet(self.expr_span) {
|
||||
let scalar_cast = match t_c {
|
||||
ty::cast::IntTy::U(ty::UintTy::Usize) => String::new(),
|
||||
_ => format!(" as {}", self.cast_ty),
|
||||
};
|
||||
err.span_suggestion(
|
||||
self.span,
|
||||
msg,
|
||||
format!("({snippet}).addr(){scalar_cast}"),
|
||||
Applicability::MaybeIncorrect
|
||||
);
|
||||
|
||||
let expr_prec = self.expr.precedence().order();
|
||||
let needs_parens = expr_prec < rustc_ast::util::parser::PREC_POSTFIX;
|
||||
|
||||
let scalar_cast = match t_c {
|
||||
ty::cast::IntTy::U(ty::UintTy::Usize) => String::new(),
|
||||
_ => format!(" as {}", self.cast_ty),
|
||||
};
|
||||
|
||||
let cast_span = self.expr_span.shrink_to_hi().to(self.cast_span);
|
||||
|
||||
if needs_parens {
|
||||
let suggestions = vec![
|
||||
(self.expr_span.shrink_to_lo(), String::from("(")),
|
||||
(cast_span, format!(").addr(){scalar_cast}")),
|
||||
];
|
||||
|
||||
err.multipart_suggestion(msg, suggestions, Applicability::MaybeIncorrect);
|
||||
} else {
|
||||
err.help(msg);
|
||||
err.span_suggestion(
|
||||
cast_span,
|
||||
msg,
|
||||
format!(".addr(){scalar_cast}"),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
|
||||
err.help(
|
||||
"if you can't comply with strict provenance and need to expose the pointer \
|
||||
provenance you can use `.expose_addr()` instead"
|
||||
|
@ -1028,16 +1041,12 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
|||
self.expr_ty, self.cast_ty
|
||||
));
|
||||
let msg = "use `.with_addr()` to adjust a valid pointer in the same allocation, to this address";
|
||||
if let Ok(snippet) = fcx.tcx.sess.source_map().span_to_snippet(self.expr_span) {
|
||||
err.span_suggestion(
|
||||
self.span,
|
||||
msg,
|
||||
format!("(...).with_addr({snippet})"),
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
} else {
|
||||
err.help(msg);
|
||||
}
|
||||
let suggestions = vec![
|
||||
(self.expr_span.shrink_to_lo(), String::from("(...).with_addr(")),
|
||||
(self.expr_span.shrink_to_hi().to(self.cast_span), String::from(")")),
|
||||
];
|
||||
|
||||
err.multipart_suggestion(msg, suggestions, Applicability::MaybeIncorrect);
|
||||
err.help(
|
||||
"if you can't comply with strict provenance and don't have a pointer with \
|
||||
the correct provenance you can use `std::ptr::from_exposed_addr()` instead"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue