Skip to content

[beta] backports #144087

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

Open
wants to merge 4 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions compiler/rustc_abi/src/extern_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ pub enum ExternAbi {
/// Stronger than just `#[cold]` because `fn` pointers might be incompatible.
RustCold,

/// An always-invalid ABI that's used to test "this ABI is not supported by this platform"
/// in a platform-agnostic way.
RustInvalid,

/// Unstable impl detail that directly uses Rust types to describe the ABI to LLVM.
/// Even normally-compatible Rust types can become ABI-incompatible with this ABI!
Unadjusted,
Expand Down Expand Up @@ -157,6 +161,7 @@ abi_impls! {
RiscvInterruptS =><= "riscv-interrupt-s",
RustCall =><= "rust-call",
RustCold =><= "rust-cold",
RustInvalid =><= "rust-invalid",
Stdcall { unwind: false } =><= "stdcall",
Stdcall { unwind: true } =><= "stdcall-unwind",
System { unwind: false } =><= "system",
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_ast_lowering/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> {
ExternAbi::RustCold => {
Err(UnstableAbi { abi, feature: sym::rust_cold_cc, explain: GateReason::Experimental })
}
ExternAbi::RustInvalid => {
Err(UnstableAbi { abi, feature: sym::rustc_attrs, explain: GateReason::ImplDetail })
}
ExternAbi::GpuKernel => Err(UnstableAbi {
abi,
feature: sym::abi_gpu_kernel,
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(crate) fn check_call_abi(&self, abi: ExternAbi, span: Span) {
let canon_abi = match AbiMap::from_target(&self.sess().target).canonize_abi(abi, false) {
AbiMapping::Direct(canon_abi) | AbiMapping::Deprecated(canon_abi) => canon_abi,
AbiMapping::Invalid => return,
AbiMapping::Invalid => {
// This should be reported elsewhere, but we want to taint this body
// so that we don't try to evaluate calls to ABIs that are invalid.
let guar = self.dcx().span_delayed_bug(
span,
format!("invalid abi for platform should have reported an error: {abi}"),
);
self.set_tainted_by_errors(guar);
return;
}
};

let valid = match canon_abi {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,8 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: ExternAbi)
| CCmseNonSecureCall
| CCmseNonSecureEntry
| Custom
| Unadjusted => false,
| Unadjusted
| RustInvalid => false,
Rust | RustCall | RustCold => tcx.sess.panic_strategy() == PanicStrategy::Unwind,
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_smir/src/rustc_internal/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ impl RustcInternal for Abi {
Abi::RustCall => rustc_abi::ExternAbi::RustCall,
Abi::Unadjusted => rustc_abi::ExternAbi::Unadjusted,
Abi::RustCold => rustc_abi::ExternAbi::RustCold,
Abi::RustInvalid => rustc_abi::ExternAbi::RustInvalid,
Abi::RiscvInterruptM => rustc_abi::ExternAbi::RiscvInterruptM,
Abi::RiscvInterruptS => rustc_abi::ExternAbi::RiscvInterruptS,
Abi::Custom => rustc_abi::ExternAbi::Custom,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_smir/src/rustc_smir/convert/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ impl<'tcx> Stable<'tcx> for rustc_abi::ExternAbi {
ExternAbi::RustCall => Abi::RustCall,
ExternAbi::Unadjusted => Abi::Unadjusted,
ExternAbi::RustCold => Abi::RustCold,
ExternAbi::RustInvalid => Abi::RustInvalid,
ExternAbi::RiscvInterruptM => Abi::RiscvInterruptM,
ExternAbi::RiscvInterruptS => Abi::RiscvInterruptS,
ExternAbi::Custom => Abi::Custom,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_smir/src/stable_mir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,7 @@ pub enum Abi {
RustCold,
RiscvInterruptM,
RiscvInterruptS,
RustInvalid,
Custom,
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_target/src/spec/abi_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ impl AbiMap {
| ExternAbi::Msp430Interrupt
| ExternAbi::RiscvInterruptM
| ExternAbi::RiscvInterruptS
| ExternAbi::X86Interrupt,
| ExternAbi::X86Interrupt
| ExternAbi::RustInvalid,
_,
) => return AbiMapping::Invalid,
};
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_trait_selection/src/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ pub fn sizedness_fast_path<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
_ => return false,
};

// FIXME(sized_hierarchy): this temporarily reverts the `sized_hierarchy` feature
// while a proper fix for `tests/ui/sized-hierarchy/incomplete-inference-issue-143992.rs`
// is pending a proper fix
if !tcx.features().sized_hierarchy() && matches!(sizedness, SizedTraitKind::MetaSized) {
return true;
}

if trait_ref.self_ty().has_trivial_sizedness(tcx, sizedness) {
debug!("fast path -- trivial sizedness");
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2746,7 +2746,8 @@ fn add_without_unwanted_attributes<'hir>(
attrs.push((Cow::Owned(attr), import_parent));
}
}
hir::Attribute::Parsed(..) if is_inline => {
// FIXME: make sure to exclude `#[cfg_trace]` here when it is ported to the new parsers
hir::Attribute::Parsed(..) => {
attrs.push((Cow::Owned(attr), import_parent));
}
_ => {}
Expand Down
13 changes: 13 additions & 0 deletions tests/rustdoc/attributes-re-export.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Tests that attributes are correctly copied onto a re-exported item.
//@ edition:2021
#![crate_name = "re_export"]

//@ has 're_export/fn.thingy2.html' '//pre[@class="rust item-decl"]' '#[no_mangle]'
pub use thingymod::thingy as thingy2;

mod thingymod {
#[no_mangle]
pub fn thingy() {

}
}
14 changes: 14 additions & 0 deletions tests/ui/abi/invalid-call-abi-ctfe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Fix for #142969 where an invalid ABI in a signature still had its call ABI computed
// because CTFE tried to evaluate it, despite previous errors during AST-to-HIR lowering.

#![feature(rustc_attrs)]

const extern "rust-invalid" fn foo() {
//~^ ERROR `"rust-invalid"` is not a supported ABI for the current target
panic!()
}

const _: () = foo();


fn main() {}
9 changes: 9 additions & 0 deletions tests/ui/abi/invalid-call-abi-ctfe.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0570]: `"rust-invalid"` is not a supported ABI for the current target
--> $DIR/invalid-call-abi-ctfe.rs:6:1
|
LL | const extern "rust-invalid" fn foo() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0570`.
12 changes: 12 additions & 0 deletions tests/ui/abi/invalid-call-abi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Tests the `"rustc-invalid"` ABI, which is never canonizable.

#![feature(rustc_attrs)]

const extern "rust-invalid" fn foo() {
//~^ ERROR `"rust-invalid"` is not a supported ABI for the current target
panic!()
}

fn main() {
foo();
}
9 changes: 9 additions & 0 deletions tests/ui/abi/invalid-call-abi.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0570]: `"rust-invalid"` is not a supported ABI for the current target
--> $DIR/invalid-call-abi.rs:5:1
|
LL | const extern "rust-invalid" fn foo() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0570`.
4 changes: 2 additions & 2 deletions tests/ui/consts/const-size_of_val-align_of_val-extern-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ extern "C" {
}

const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) };
//~^ ERROR the size for values of type `Opaque` cannot be known
//~^ ERROR `extern type` does not have known layout
const _ALIGN: usize = unsafe { align_of_val(&4 as *const i32 as *const Opaque) };
//~^ ERROR the size for values of type `Opaque` cannot be known
//~^ ERROR `extern type` does not have known layout

fn main() {}
26 changes: 7 additions & 19 deletions tests/ui/consts/const-size_of_val-align_of_val-extern-type.stderr
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
error[E0277]: the size for values of type `Opaque` cannot be known
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:10:43
error[E0080]: `extern type` does not have known layout
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:10:31
|
LL | const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) };
| ----------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a known size
| |
| required by a bound introduced by this call
|
= help: the trait `MetaSized` is not implemented for `Opaque`
note: required by a bound in `std::intrinsics::size_of_val`
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_SIZE` failed here

error[E0277]: the size for values of type `Opaque` cannot be known
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:12:45
error[E0080]: `extern type` does not have known layout
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:12:32
|
LL | const _ALIGN: usize = unsafe { align_of_val(&4 as *const i32 as *const Opaque) };
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a known size
| |
| required by a bound introduced by this call
|
= help: the trait `MetaSized` is not implemented for `Opaque`
note: required by a bound in `std::intrinsics::align_of_val`
--> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_ALIGN` failed here

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
For more information about this error, try `rustc --explain E0080`.
4 changes: 1 addition & 3 deletions tests/ui/extern/extern-types-size_of_val.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ check-fail
//@ check-pass
#![feature(extern_types)]

use std::mem::{align_of_val, size_of_val};
Expand All @@ -11,7 +11,5 @@ fn main() {
let x: &A = unsafe { &*(1usize as *const A) };

size_of_val(x);
//~^ ERROR the size for values of type `A` cannot be known
align_of_val(x);
//~^ ERROR the size for values of type `A` cannot be known
}
39 changes: 0 additions & 39 deletions tests/ui/extern/extern-types-size_of_val.stderr

This file was deleted.

2 changes: 0 additions & 2 deletions tests/ui/extern/extern-types-unsized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ fn main() {

assert_sized::<Bar<A>>();
//~^ ERROR the size for values of type
//~| ERROR the size for values of type

assert_sized::<Bar<Bar<A>>>();
//~^ ERROR the size for values of type
//~| ERROR the size for values of type
}
30 changes: 2 additions & 28 deletions tests/ui/extern/extern-types-unsized.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,8 @@ help: consider relaxing the implicit `Sized` restriction
LL | fn assert_sized<T: ?Sized>() {}
| ++++++++

error[E0277]: the size for values of type `A` cannot be known
--> $DIR/extern-types-unsized.rs:28:20
|
LL | assert_sized::<Bar<A>>();
| ^^^^^^ doesn't have a known size
|
= help: the trait `MetaSized` is not implemented for `A`
note: required by a bound in `Bar`
--> $DIR/extern-types-unsized.rs:14:12
|
LL | struct Bar<T: ?Sized> {
| ^ required by this bound in `Bar`

error[E0277]: the size for values of type `A` cannot be known at compilation time
--> $DIR/extern-types-unsized.rs:32:20
--> $DIR/extern-types-unsized.rs:31:20
|
LL | assert_sized::<Bar<Bar<A>>>();
| ^^^^^^^^^^^ doesn't have a size known at compile-time
Expand All @@ -94,19 +81,6 @@ help: consider relaxing the implicit `Sized` restriction
LL | fn assert_sized<T: ?Sized>() {}
| ++++++++

error[E0277]: the size for values of type `A` cannot be known
--> $DIR/extern-types-unsized.rs:32:20
|
LL | assert_sized::<Bar<Bar<A>>>();
| ^^^^^^^^^^^ doesn't have a known size
|
= help: the trait `MetaSized` is not implemented for `A`
note: required by a bound in `Bar`
--> $DIR/extern-types-unsized.rs:14:12
|
LL | struct Bar<T: ?Sized> {
| ^ required by this bound in `Bar`

error: aborting due to 6 previous errors
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.
4 changes: 0 additions & 4 deletions tests/ui/extern/unsized-extern-derefmove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ extern "C" {
}

unsafe fn make_device() -> Box<Device> {
//~^ ERROR the size for values of type `Device` cannot be known
Box::from_raw(0 as *mut _)
//~^ ERROR the size for values of type `Device` cannot be known
//~| ERROR the size for values of type `Device` cannot be known
}

fn main() {
let d: Device = unsafe { *make_device() };
//~^ ERROR the size for values of type `Device` cannot be known
//~| ERROR the size for values of type `Device` cannot be known
}
Loading
Loading