mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
Auto merge of #96322 - matthiaskrgr:rollup-9xejxrf, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - #96272 (Update `validate_uninhabited_zsts.rs` test after MIR building changes) - #96273 (Make `E0117` error clear) - #96315 (Make the lifetime accurate which is used in the region constraints part) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
f4ec0e7cff
@ -190,7 +190,7 @@ impl<'s, 'tcx, D: ConstraintGraphDirecton> RegionGraph<'s, 'tcx, D> {
|
||||
|
||||
/// Given a region `R`, iterate over all regions `R1` such that
|
||||
/// there exists a constraint `R: R1`.
|
||||
crate fn outgoing_regions(&self, region_sup: RegionVid) -> Successors<'_, 'tcx, D> {
|
||||
crate fn outgoing_regions(&self, region_sup: RegionVid) -> Successors<'s, 'tcx, D> {
|
||||
Successors {
|
||||
edges: self.constraint_graph.outgoing_edges(region_sup, self.set, self.static_region),
|
||||
}
|
||||
@ -225,10 +225,7 @@ impl<'s, 'tcx, D: ConstraintGraphDirecton> graph::WithSuccessors for RegionGraph
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s, 'graph, 'tcx, D: ConstraintGraphDirecton> graph::GraphSuccessors<'graph>
|
||||
for RegionGraph<'s, 'tcx, D>
|
||||
{
|
||||
impl<'s, 'tcx, D: ConstraintGraphDirecton> graph::GraphSuccessors<'_> for RegionGraph<'s, 'tcx, D> {
|
||||
type Item = RegionVid;
|
||||
// FIXME - why can't this be `'graph, 'tcx`
|
||||
type Iter = Successors<'graph, 'graph, D>;
|
||||
type Iter = Successors<'s, 'tcx, D>;
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ fn orphan_check_impl(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua
|
||||
tcx,
|
||||
sp,
|
||||
tr.path.span,
|
||||
trait_ref.self_ty(),
|
||||
impl_.self_ty.span,
|
||||
&impl_.generics,
|
||||
err,
|
||||
@ -201,18 +202,23 @@ fn emit_orphan_check_error<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
sp: Span,
|
||||
trait_span: Span,
|
||||
self_ty: Ty<'tcx>,
|
||||
self_ty_span: Span,
|
||||
generics: &hir::Generics<'tcx>,
|
||||
err: traits::OrphanCheckErr<'tcx>,
|
||||
) -> Result<!, ErrorGuaranteed> {
|
||||
Err(match err {
|
||||
traits::OrphanCheckErr::NonLocalInputType(tys) => {
|
||||
let msg = match self_ty.kind() {
|
||||
ty::Adt(..) => "can be implemented for types defined outside of the crate",
|
||||
_ if self_ty.is_primitive() => "can be implemented for primitive types",
|
||||
_ => "can be implemented for arbitrary types",
|
||||
};
|
||||
let mut err = struct_span_err!(
|
||||
tcx.sess,
|
||||
sp,
|
||||
E0117,
|
||||
"only traits defined in the current crate can be implemented for \
|
||||
arbitrary types"
|
||||
"only traits defined in the current crate {msg}"
|
||||
);
|
||||
err.span_label(sp, "impl doesn't use only types from inside the current crate");
|
||||
for (ty, is_target_ty) in &tys {
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/coherence-cow.rs:18:1
|
||||
|
|
||||
LL | impl<T> Remote for Pair<T,Cover<T>> { }
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/coherence-cow.rs:22:1
|
||||
|
|
||||
LL | impl<T> Remote for Pair<Cover<T>,T> { }
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/coherence-cow.rs:26:1
|
||||
|
|
||||
LL | impl<T,U> Remote for Pair<Cover<T>,U> { }
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for primitive types
|
||||
--> $DIR/coherence-impls-copy.rs:5:1
|
||||
|
|
||||
LL | impl Copy for i32 {}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for primitive types
|
||||
--> $DIR/coherence-orphan.rs:10:1
|
||||
|
|
||||
LL | impl TheTrait<usize> for isize { }
|
||||
@ -10,7 +10,7 @@ LL | impl TheTrait<usize> for isize { }
|
||||
|
|
||||
= note: define and implement a trait or new type instead
|
||||
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/coherence-orphan.rs:17:1
|
||||
|
|
||||
LL | impl !Send for Vec<isize> { }
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/coherence-overlapping-pairs.rs:8:1
|
||||
|
|
||||
LL | impl<T> Remote for lib::Pair<T,Foo> { }
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for primitive types
|
||||
--> $DIR/coherence-pair-covered-uncovered-1.rs:12:1
|
||||
|
|
||||
LL | impl<T, U> Remote1<Pair<T, Local<U>>> for i32 { }
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/coherence-pair-covered-uncovered.rs:8:1
|
||||
|
|
||||
LL | impl<T,U> Remote for Pair<T,Local<U>> { }
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/coherence-vec-local-2.rs:11:1
|
||||
|
|
||||
LL | impl<T> Remote for Vec<Local<T>> { }
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/coherence-vec-local.rs:11:1
|
||||
|
|
||||
LL | impl Remote for Vec<Local> { }
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/coherence_local_err_struct.rs:14:1
|
||||
|
|
||||
LL | impl lib::MyCopy for lib::MyStruct<MyType> { }
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for primitive types
|
||||
--> $DIR/impl-foreign-for-foreign.rs:10:1
|
||||
|
|
||||
LL | impl Remote for i32 {
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for primitive types
|
||||
--> $DIR/impl-foreign-for-foreign[foreign].rs:10:1
|
||||
|
|
||||
LL | impl Remote1<Rc<i32>> for i32 {
|
||||
@ -10,7 +10,7 @@ LL | impl Remote1<Rc<i32>> for i32 {
|
||||
|
|
||||
= note: define and implement a trait or new type instead
|
||||
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for primitive types
|
||||
--> $DIR/impl-foreign-for-foreign[foreign].rs:14:1
|
||||
|
|
||||
LL | impl Remote1<Rc<Local>> for f64 {
|
||||
@ -22,7 +22,7 @@ LL | impl Remote1<Rc<Local>> for f64 {
|
||||
|
|
||||
= note: define and implement a trait or new type instead
|
||||
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for primitive types
|
||||
--> $DIR/impl-foreign-for-foreign[foreign].rs:18:1
|
||||
|
|
||||
LL | impl<T> Remote1<Rc<T>> for f32 {
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/impl-foreign-for-fundamental[foreign].rs:10:1
|
||||
|
|
||||
LL | impl Remote for Box<i32> {
|
||||
@ -10,7 +10,7 @@ LL | impl Remote for Box<i32> {
|
||||
|
|
||||
= note: define and implement a trait or new type instead
|
||||
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/impl-foreign-for-fundamental[foreign].rs:14:1
|
||||
|
|
||||
LL | impl<T> Remote for Box<Rc<T>> {
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for primitive types
|
||||
--> $DIR/impl-foreign[foreign]-for-foreign.rs:10:1
|
||||
|
|
||||
LL | impl Remote1<u32> for f64 {
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for primitive types
|
||||
--> $DIR/impl-foreign[fundemental[foreign]]-for-foreign.rs:11:1
|
||||
|
|
||||
LL | impl Remote1<Box<String>> for i32 {
|
||||
@ -11,7 +11,7 @@ LL | impl Remote1<Box<String>> for i32 {
|
||||
|
|
||||
= note: define and implement a trait or new type instead
|
||||
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for primitive types
|
||||
--> $DIR/impl-foreign[fundemental[foreign]]-for-foreign.rs:15:1
|
||||
|
|
||||
LL | impl Remote1<Box<Rc<i32>>> for f64 {
|
||||
@ -24,7 +24,7 @@ LL | impl Remote1<Box<Rc<i32>>> for f64 {
|
||||
|
|
||||
= note: define and implement a trait or new type instead
|
||||
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for primitive types
|
||||
--> $DIR/impl-foreign[fundemental[foreign]]-for-foreign.rs:19:1
|
||||
|
|
||||
LL | impl<T> Remote1<Box<Rc<T>>> for f32 {
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/impl[t]-foreign-for-foreign[t].rs:11:1
|
||||
|
|
||||
LL | impl Remote for Rc<Local> {
|
||||
@ -9,7 +9,7 @@ LL | impl Remote for Rc<Local> {
|
||||
|
|
||||
= note: define and implement a trait or new type instead
|
||||
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/impl[t]-foreign-for-foreign[t].rs:16:1
|
||||
|
|
||||
LL | impl<T> Remote for Arc<T> {
|
||||
|
@ -7,14 +7,17 @@ LL | unsafe { std::mem::transmute(()) }
|
||||
| transmuting to uninhabited type
|
||||
| inside `foo` at $DIR/validate_uninhabited_zsts.rs:4:14
|
||||
...
|
||||
LL | const FOO: [Empty; 3] = [foo(); 3];
|
||||
| ----- inside `FOO` at $DIR/validate_uninhabited_zsts.rs:13:26
|
||||
LL | const FOO: [empty::Empty; 3] = [foo(); 3];
|
||||
| ----- inside `FOO` at $DIR/validate_uninhabited_zsts.rs:20:33
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/validate_uninhabited_zsts.rs:16:35
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/validate_uninhabited_zsts.rs:23:1
|
||||
|
|
||||
LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ transmuting to uninhabited type
|
||||
LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at [0].0: encountered a value of uninhabited type empty::Void
|
||||
|
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
|
||||
= note: the raw bytes of the constant (size: 0, align: 1) {}
|
||||
|
||||
warning: the type `!` does not permit zero-initialization
|
||||
--> $DIR/validate_uninhabited_zsts.rs:4:14
|
||||
@ -28,16 +31,20 @@ LL | unsafe { std::mem::transmute(()) }
|
||||
= note: `#[warn(invalid_value)]` on by default
|
||||
= note: the `!` type has no valid value
|
||||
|
||||
warning: the type `Empty` does not permit zero-initialization
|
||||
--> $DIR/validate_uninhabited_zsts.rs:16:35
|
||||
warning: the type `empty::Empty` does not permit zero-initialization
|
||||
--> $DIR/validate_uninhabited_zsts.rs:23:42
|
||||
|
|
||||
LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| this code causes undefined behavior when executed
|
||||
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
||||
LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| this code causes undefined behavior when executed
|
||||
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
||||
|
|
||||
= note: enums with no variants have no valid value
|
||||
note: enums with no variants have no valid value (in this struct field)
|
||||
--> $DIR/validate_uninhabited_zsts.rs:16:22
|
||||
|
|
||||
LL | pub struct Empty(Void);
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to 2 previous errors; 2 warnings emitted
|
||||
|
||||
|
@ -7,14 +7,17 @@ LL | unsafe { std::mem::transmute(()) }
|
||||
| transmuting to uninhabited type
|
||||
| inside `foo` at $DIR/validate_uninhabited_zsts.rs:4:14
|
||||
...
|
||||
LL | const FOO: [Empty; 3] = [foo(); 3];
|
||||
| ----- inside `FOO` at $DIR/validate_uninhabited_zsts.rs:13:26
|
||||
LL | const FOO: [empty::Empty; 3] = [foo(); 3];
|
||||
| ----- inside `FOO` at $DIR/validate_uninhabited_zsts.rs:20:33
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/validate_uninhabited_zsts.rs:16:35
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/validate_uninhabited_zsts.rs:23:1
|
||||
|
|
||||
LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ transmuting to uninhabited type
|
||||
LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at [0].0: encountered a value of uninhabited type empty::Void
|
||||
|
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
|
||||
= note: the raw bytes of the constant (size: 0, align: 1) {}
|
||||
|
||||
warning: the type `!` does not permit zero-initialization
|
||||
--> $DIR/validate_uninhabited_zsts.rs:4:14
|
||||
@ -28,16 +31,20 @@ LL | unsafe { std::mem::transmute(()) }
|
||||
= note: `#[warn(invalid_value)]` on by default
|
||||
= note: the `!` type has no valid value
|
||||
|
||||
warning: the type `Empty` does not permit zero-initialization
|
||||
--> $DIR/validate_uninhabited_zsts.rs:16:35
|
||||
warning: the type `empty::Empty` does not permit zero-initialization
|
||||
--> $DIR/validate_uninhabited_zsts.rs:23:42
|
||||
|
|
||||
LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| this code causes undefined behavior when executed
|
||||
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
||||
LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| this code causes undefined behavior when executed
|
||||
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
||||
|
|
||||
= note: enums with no variants have no valid value
|
||||
note: enums with no variants have no valid value (in this struct field)
|
||||
--> $DIR/validate_uninhabited_zsts.rs:16:22
|
||||
|
|
||||
LL | pub struct Empty(Void);
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to 2 previous errors; 2 warnings emitted
|
||||
|
||||
|
@ -6,16 +6,23 @@ const fn foo() -> ! {
|
||||
//~| WARN the type `!` does not permit zero-initialization [invalid_value]
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum Empty { }
|
||||
// Type defined in a submodule, so that it is not "visibly"
|
||||
// uninhabited (which would change interpreter behavior).
|
||||
pub mod empty {
|
||||
#[derive(Clone, Copy)]
|
||||
enum Void {}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Empty(Void);
|
||||
}
|
||||
|
||||
#[warn(const_err)]
|
||||
const FOO: [Empty; 3] = [foo(); 3];
|
||||
const FOO: [empty::Empty; 3] = [foo(); 3];
|
||||
|
||||
#[warn(const_err)]
|
||||
const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
|
||||
//~^ ERROR evaluation of constant value failed
|
||||
//~| WARN the type `Empty` does not permit zero-initialization
|
||||
const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
//~| WARN the type `empty::Empty` does not permit zero-initialization
|
||||
|
||||
fn main() {
|
||||
FOO;
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for primitive types
|
||||
--> $DIR/E0117.rs:1:1
|
||||
|
|
||||
LL | impl Drop for u32 {}
|
||||
|
@ -3,7 +3,7 @@
|
||||
pub struct Int(i32);
|
||||
|
||||
impl const std::ops::Add for i32 { //~ ERROR type annotations needed
|
||||
//~^ ERROR only traits defined in the current crate can be implemented for arbitrary types
|
||||
//~^ ERROR only traits defined in the current crate can be implemented for primitive types
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self {
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for primitive types
|
||||
--> $DIR/const-and-non-const-impl.rs:5:1
|
||||
|
|
||||
LL | impl const std::ops::Add for i32 {
|
||||
|
@ -26,7 +26,7 @@ error[E0321]: cross-crate traits with a default impl, like `DefaultedTrait`, can
|
||||
LL | impl DefaultedTrait for Box<C> { }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait for type in another crate
|
||||
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
|
||||
--> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:22:1
|
||||
|
|
||||
LL | impl DefaultedTrait for lib::Something<C> { }
|
||||
|
Loading…
Reference in New Issue
Block a user