Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #136836

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1ba2153
Enable sanitizers on MSVC CI jobs
tmiasko Jan 27, 2025
aa884da
Delay bug when method confirmation cannot upcast object pick of self
compiler-errors Feb 4, 2025
bb4c9d2
Improved named region errors
compiler-errors Feb 4, 2025
fab6d8a
Prevent generic pattern types from being used in libstd
oli-obk Feb 5, 2025
de405dc
introduce CoercePointeeWellformed for coherence checks at typeck stage
dingxiangfei2009 Jan 26, 2025
c067324
rename the trait to validity and place a feature gate afront
dingxiangfei2009 Jan 28, 2025
b943505
move repr(transparent) checks to coherence
dingxiangfei2009 Jan 28, 2025
1848343
block coerce_pointee_validated for stabilization
dingxiangfei2009 Feb 9, 2025
aea5595
fix the error code document
dingxiangfei2009 Feb 9, 2025
3f50076
compiler: gate `extern "{abi}"` in ast_lowering
workingjubilee Nov 4, 2024
90c50f0
compiler: start using rustc_ast_lowering in rustc_passes
workingjubilee Feb 5, 2025
ca19347
tests: error strings for ABI stability now match
workingjubilee Feb 5, 2025
54ff6e0
compiler: remove rustc_target::spec::abi reexports
workingjubilee Feb 5, 2025
cd9d39e
compiler: remove `abi`-specific `extern "{abi}"` suggestions
workingjubilee Feb 7, 2025
1dc575c
assign marcoieni and jdno to infra-ci PRs
marcoieni Feb 10, 2025
17026e2
Reword doc comment on `CoercePointeeValidated`
compiler-errors Feb 10, 2025
387099b
Update books
rustbot Feb 10, 2025
ebdf4b0
Rollup merge of #136107 - dingxiangfei2009:coerce-pointee-wellformed,…
matthiaskrgr Feb 10, 2025
d669098
Rollup merge of #136155 - tmiasko:msvc-enable-sanitizers, r=Mark-Simu…
matthiaskrgr Feb 10, 2025
08e56c1
Rollup merge of #136524 - compiler-errors:bad-pick, r=BoxyUwU
matthiaskrgr Feb 10, 2025
bf47499
Rollup merge of #136559 - compiler-errors:resolve-regions-for-type-te…
matthiaskrgr Feb 10, 2025
afdb51a
Rollup merge of #136584 - oli-obk:pattern-types-generic, r=BoxyUwU
matthiaskrgr Feb 10, 2025
6f94363
Rollup merge of #136603 - workingjubilee:move-abi-versioning-into-ast…
matthiaskrgr Feb 10, 2025
654c483
Rollup merge of #136821 - marcoieni:infra-ci-review, r=jackh726
matthiaskrgr Feb 10, 2025
b9c13a3
Rollup merge of #136825 - rustbot:docs-update, r=ehuss
matthiaskrgr Feb 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3317,7 +3317,6 @@ dependencies = [
"rand 0.8.5",
"rand_xoshiro",
"rustc_data_structures",
"rustc_feature",
"rustc_index",
"rustc_macros",
"rustc_serialize",
Expand Down Expand Up @@ -3379,6 +3378,7 @@ dependencies = [
"rustc_ast_pretty",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_fluent_macro",
"rustc_hir",
"rustc_index",
Expand Down Expand Up @@ -3683,6 +3683,7 @@ version = "0.0.0"
dependencies = [
"ctrlc",
"libc",
"rustc_abi",
"rustc_ast",
"rustc_ast_lowering",
"rustc_ast_passes",
Expand Down Expand Up @@ -4337,6 +4338,7 @@ version = "0.0.0"
dependencies = [
"rustc_abi",
"rustc_ast",
"rustc_ast_lowering",
"rustc_ast_pretty",
"rustc_attr_parsing",
"rustc_data_structures",
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ bitflags = "2.4.1"
rand = { version = "0.8.4", default-features = false, optional = true }
rand_xoshiro = { version = "0.6.0", optional = true }
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
rustc_feature = { path = "../rustc_feature", optional = true }
rustc_index = { path = "../rustc_index", default-features = false }
rustc_macros = { path = "../rustc_macros", optional = true }
rustc_serialize = { path = "../rustc_serialize", optional = true }
Expand All @@ -24,7 +23,6 @@ default = ["nightly", "randomize"]
# without depending on rustc_data_structures, rustc_macros and rustc_serialize
nightly = [
"dep:rustc_data_structures",
"dep:rustc_feature",
"dep:rustc_macros",
"dep:rustc_serialize",
"dep:rustc_span",
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_abi/src/callconv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[cfg(feature = "nightly")]
use crate::{BackendRepr, FieldsShape, TyAbiInterface, TyAndLayout};
use crate::{Primitive, Size, Variants};
use crate::{BackendRepr, FieldsShape, Primitive, Size, TyAbiInterface, TyAndLayout, Variants};

mod reg;

Expand Down
130 changes: 9 additions & 121 deletions compiler/rustc_abi/src/extern_abi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fmt;

use rustc_macros::{Decodable, Encodable, HashStable_Generic};
use rustc_span::{Span, Symbol, sym};

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -95,14 +94,14 @@ impl Abi {

#[derive(Copy, Clone)]
pub struct AbiData {
abi: Abi,
pub abi: Abi,

/// Name of this ABI as we like it called.
name: &'static str,
pub name: &'static str,
}

#[allow(non_upper_case_globals)]
const AbiDatas: &[AbiData] = &[
pub const AbiDatas: &[AbiData] = &[
AbiData { abi: Abi::Rust, name: "Rust" },
AbiData { abi: Abi::C { unwind: false }, name: "C" },
AbiData { abi: Abi::C { unwind: true }, name: "C-unwind" },
Expand Down Expand Up @@ -142,129 +141,18 @@ const AbiDatas: &[AbiData] = &[
];

#[derive(Copy, Clone, Debug)]
pub enum AbiUnsupported {
Unrecognized,
Reason { explain: &'static str },
}

pub struct AbiUnsupported {}
/// Returns the ABI with the given name (if any).
pub fn lookup(name: &str) -> Result<Abi, AbiUnsupported> {
AbiDatas.iter().find(|abi_data| name == abi_data.name).map(|&x| x.abi).ok_or_else(|| match name {
"riscv-interrupt" => AbiUnsupported::Reason {
explain: "please use one of riscv-interrupt-m or riscv-interrupt-s for machine- or supervisor-level interrupts, respectively",
},
"riscv-interrupt-u" => AbiUnsupported::Reason {
explain: "user-mode interrupt handlers have been removed from LLVM pending standardization, see: https://reviews.llvm.org/D149314",
},
"wasm" => AbiUnsupported::Reason {
explain: "non-standard wasm ABI is no longer supported",
},

_ => AbiUnsupported::Unrecognized,

})
}

pub fn all_names() -> Vec<&'static str> {
AbiDatas.iter().map(|d| d.name).collect()
}

pub fn enabled_names(features: &rustc_feature::Features, span: Span) -> Vec<&'static str> {
AbiDatas
.iter()
.map(|d| d.name)
.filter(|name| is_enabled(features, span, name).is_ok())
.collect()
.find(|abi_data| name == abi_data.name)
.map(|&x| x.abi)
.ok_or_else(|| AbiUnsupported {})
}

pub enum AbiDisabled {
Unstable { feature: Symbol, explain: &'static str },
Unrecognized,
}

pub fn is_enabled(
features: &rustc_feature::Features,
span: Span,
name: &str,
) -> Result<(), AbiDisabled> {
let s = is_stable(name);
if let Err(AbiDisabled::Unstable { feature, .. }) = s {
if features.enabled(feature) || span.allows_unstable(feature) {
return Ok(());
}
}
s
}

/// Returns whether the ABI is stable to use.
///
/// Note that there is a separate check determining whether the ABI is even supported
/// on the current target; see `fn is_abi_supported` in `rustc_target::spec`.
pub fn is_stable(name: &str) -> Result<(), AbiDisabled> {
match name {
// Stable
"Rust" | "C" | "C-unwind" | "cdecl" | "cdecl-unwind" | "stdcall" | "stdcall-unwind"
| "fastcall" | "fastcall-unwind" | "aapcs" | "aapcs-unwind" | "win64" | "win64-unwind"
| "sysv64" | "sysv64-unwind" | "system" | "system-unwind" | "efiapi" | "thiscall"
| "thiscall-unwind" => Ok(()),
"rust-intrinsic" => Err(AbiDisabled::Unstable {
feature: sym::intrinsics,
explain: "intrinsics are subject to change",
}),
"vectorcall" => Err(AbiDisabled::Unstable {
feature: sym::abi_vectorcall,
explain: "vectorcall is experimental and subject to change",
}),
"vectorcall-unwind" => Err(AbiDisabled::Unstable {
feature: sym::abi_vectorcall,
explain: "vectorcall-unwind ABI is experimental and subject to change",
}),
"rust-call" => Err(AbiDisabled::Unstable {
feature: sym::unboxed_closures,
explain: "rust-call ABI is subject to change",
}),
"rust-cold" => Err(AbiDisabled::Unstable {
feature: sym::rust_cold_cc,
explain: "rust-cold is experimental and subject to change",
}),
"ptx-kernel" => Err(AbiDisabled::Unstable {
feature: sym::abi_ptx,
explain: "PTX ABIs are experimental and subject to change",
}),
"unadjusted" => Err(AbiDisabled::Unstable {
feature: sym::abi_unadjusted,
explain: "unadjusted ABI is an implementation detail and perma-unstable",
}),
"msp430-interrupt" => Err(AbiDisabled::Unstable {
feature: sym::abi_msp430_interrupt,
explain: "msp430-interrupt ABI is experimental and subject to change",
}),
"x86-interrupt" => Err(AbiDisabled::Unstable {
feature: sym::abi_x86_interrupt,
explain: "x86-interrupt ABI is experimental and subject to change",
}),
"gpu-kernel" => Err(AbiDisabled::Unstable {
feature: sym::abi_gpu_kernel,
explain: "gpu-kernel ABI is experimental and subject to change",
}),
"avr-interrupt" | "avr-non-blocking-interrupt" => Err(AbiDisabled::Unstable {
feature: sym::abi_avr_interrupt,
explain: "avr-interrupt and avr-non-blocking-interrupt ABIs are experimental and subject to change",
}),
"riscv-interrupt-m" | "riscv-interrupt-s" => Err(AbiDisabled::Unstable {
feature: sym::abi_riscv_interrupt,
explain: "riscv-interrupt ABIs are experimental and subject to change",
}),
"C-cmse-nonsecure-call" => Err(AbiDisabled::Unstable {
feature: sym::abi_c_cmse_nonsecure_call,
explain: "C-cmse-nonsecure-call ABI is experimental and subject to change",
}),
"C-cmse-nonsecure-entry" => Err(AbiDisabled::Unstable {
feature: sym::cmse_nonsecure_entry,
explain: "C-cmse-nonsecure-entry ABI is experimental and subject to change",
}),
_ => Err(AbiDisabled::Unrecognized),
}
pub fn all_names() -> Vec<&'static str> {
AbiDatas.iter().map(|d| d.name).collect()
}

impl Abi {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_abi/src/extern_abi/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn lookup_cdecl() {
#[test]
fn lookup_baz() {
let abi = lookup("baz");
assert_matches!(abi, Err(AbiUnsupported::Unrecognized));
assert_matches!(abi, Err(AbiUnsupported {}));
}

#[test]
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ mod extern_abi;

pub use callconv::{Heterogeneous, HomogeneousAggregate, Reg, RegKind};
#[cfg(feature = "nightly")]
pub use extern_abi::{
AbiDisabled, AbiUnsupported, ExternAbi, all_names, enabled_names, is_enabled, is_stable, lookup,
};
pub use extern_abi::{AbiDatas, AbiUnsupported, ExternAbi, all_names, lookup};
#[cfg(feature = "nightly")]
pub use layout::{FIRST_VARIANT, FieldIdx, Layout, TyAbiInterface, TyAndLayout, VariantIdx};
pub use layout::{LayoutCalculator, LayoutCalculatorError};
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast_lowering/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ use std::iter;
use ast::visit::Visitor;
use hir::def::{DefKind, PartialRes, Res};
use hir::{BodyId, HirId};
use rustc_abi::ExternAbi;
use rustc_ast::*;
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def_id::DefId;
use rustc_middle::span_bug;
use rustc_middle::ty::{Asyncness, ResolverAstLowering};
use rustc_span::{Ident, Span};
use rustc_target::spec::abi;
use {rustc_ast as ast, rustc_hir as hir};

use super::{GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode};
Expand Down Expand Up @@ -398,7 +398,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
safety: hir::Safety::Safe.into(),
constness: hir::Constness::NotConst,
asyncness: hir::IsAsync::NotAsync,
abi: abi::Abi::Rust,
abi: ExternAbi::Rust,
}
}

Expand Down
17 changes: 1 addition & 16 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_errors::DiagArgFromDisplay;
use rustc_errors::codes::*;
use rustc_errors::{Diag, DiagArgFromDisplay, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Ident, Span, Symbol};

Expand Down Expand Up @@ -32,8 +32,6 @@ pub(crate) struct InvalidAbi {
pub abi: Symbol,
pub command: String,
#[subdiagnostic]
pub explain: Option<InvalidAbiReason>,
#[subdiagnostic]
pub suggestion: Option<InvalidAbiSuggestion>,
}

Expand All @@ -45,19 +43,6 @@ pub(crate) struct TupleStructWithDefault {
pub span: Span,
}

pub(crate) struct InvalidAbiReason(pub &'static str);

impl Subdiagnostic for InvalidAbiReason {
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self,
diag: &mut Diag<'_, G>,
_: &F,
) {
#[allow(rustc::untranslatable_diagnostic)]
diag.note(self.0);
}
}

#[derive(Subdiagnostic)]
#[suggestion(
ast_lowering_invalid_abi_suggestion,
Expand Down
25 changes: 13 additions & 12 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use thin_vec::ThinVec;
use tracing::instrument;

use super::errors::{
InvalidAbi, InvalidAbiReason, InvalidAbiSuggestion, MisplacedRelaxTraitBound,
TupleStructWithDefault,
InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound, TupleStructWithDefault,
};
use super::stability::{enabled_names, gate_unstable_abi};
use super::{
AstOwner, FnDeclKind, ImplTraitContext, ImplTraitPosition, LoweringContext, ParamMode,
ResolverAstLoweringExt,
Expand Down Expand Up @@ -1479,11 +1479,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

pub(super) fn lower_abi(&mut self, abi: StrLit) -> ExternAbi {
rustc_abi::lookup(abi.symbol_unescaped.as_str()).unwrap_or_else(|err| {
self.error_on_invalid_abi(abi, err);
pub(super) fn lower_abi(&mut self, abi_str: StrLit) -> ExternAbi {
let ast::StrLit { symbol_unescaped, span, .. } = abi_str;
let extern_abi = rustc_abi::lookup(symbol_unescaped.as_str()).unwrap_or_else(|_| {
self.error_on_invalid_abi(abi_str);
ExternAbi::Rust
})
});
let sess = self.tcx.sess;
let features = self.tcx.features();
gate_unstable_abi(sess, features, span, extern_abi);
extern_abi
}

pub(super) fn lower_extern(&mut self, ext: Extern) -> ExternAbi {
Expand All @@ -1494,19 +1499,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

fn error_on_invalid_abi(&self, abi: StrLit, err: rustc_abi::AbiUnsupported) {
let abi_names = rustc_abi::enabled_names(self.tcx.features(), abi.span)
fn error_on_invalid_abi(&self, abi: StrLit) {
let abi_names = enabled_names(self.tcx.features(), abi.span)
.iter()
.map(|s| Symbol::intern(s))
.collect::<Vec<_>>();
let suggested_name = find_best_match_for_name(&abi_names, abi.symbol_unescaped, None);
self.dcx().emit_err(InvalidAbi {
abi: abi.symbol_unescaped,
span: abi.span,
explain: match err {
rustc_abi::AbiUnsupported::Reason { explain } => Some(InvalidAbiReason(explain)),
_ => None,
},
suggestion: suggested_name.map(|suggested_name| InvalidAbiSuggestion {
span: abi.span,
suggestion: format!("\"{suggested_name}\""),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ mod index;
mod item;
mod pat;
mod path;
pub mod stability;

rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

Expand Down
Loading
Loading