Skip to content

Commit

Permalink
finishing touches, move fixed ICEs to ui tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed Jun 28, 2024
1 parent 0a23306 commit 8b2fac9
Show file tree
Hide file tree
Showing 19 changed files with 182 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ where

let mut first_non_maybe = None;
let mut non_maybe_count = 0;
for ty in types {
for ty in types.iter() {
if !matches!(ty::EffectKind::try_from_ty(cx, ty), Some(ty::EffectKind::Maybe)) {
first_non_maybe.get_or_insert(ty);
non_maybe_count += 1;
Expand All @@ -902,7 +902,7 @@ where
_ => {
let mut min = ty::EffectKind::Maybe;

for ty in types {
for ty in types.iter() {
let Some(kind) = ty::EffectKind::try_from_ty(cx, ty) else {
return Err(NoSolution);
};
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_next_trait_solver/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ where

let cx = ecx.cx();
let maybe_count = types
.into_iter()
.iter()
.filter_map(|ty| ty::EffectKind::try_from_ty(cx, ty))
.filter(|&ty| ty == ty::EffectKind::Maybe)
.count();
Expand All @@ -727,7 +727,7 @@ where
if types.len() - maybe_count > 1 {
let mut min = ty::EffectKind::Maybe;

for ty in types {
for ty in types.iter() {
let Some(kind) = ty::EffectKind::try_from_ty(ecx.cx(), ty) else {
return Err(NoSolution);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,18 @@ fn main() {}

struct D;

/* FIXME(effects)
impl const Drop for D {
fn drop(&mut self) {
todo!();
}
}
*/

// Lint this, since it can be dropped in const contexts
// FIXME(effects)
fn d(this: D) {}
//~^ ERROR: this could be a `const fn`

mod msrv {
struct Foo(*const u8, &'static u8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ LL | const fn msrv_1_46() -> i32 {
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:122:9
--> tests/ui/missing_const_for_fn/could_be_const.rs:117:1
|
LL | fn d(this: D) {}
| ^^^^^^^^^^^^^^^^

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:125:9
|
LL | / fn deref_ptr_can_be_const(self) -> usize {
LL | |
Expand All @@ -171,7 +177,7 @@ LL | const fn deref_ptr_can_be_const(self) -> usize {
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:127:9
--> tests/ui/missing_const_for_fn/could_be_const.rs:130:9
|
LL | / fn deref_copied_val(self) -> usize {
LL | |
Expand All @@ -185,7 +191,7 @@ LL | const fn deref_copied_val(self) -> usize {
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:138:5
--> tests/ui/missing_const_for_fn/could_be_const.rs:141:5
|
LL | / fn union_access_can_be_const() {
LL | |
Expand All @@ -200,7 +206,7 @@ LL | const fn union_access_can_be_const() {
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:152:9
--> tests/ui/missing_const_for_fn/could_be_const.rs:155:9
|
LL | / pub fn new(strings: Vec<String>) -> Self {
LL | | Self { strings }
Expand All @@ -213,7 +219,7 @@ LL | pub const fn new(strings: Vec<String>) -> Self {
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:157:9
--> tests/ui/missing_const_for_fn/could_be_const.rs:160:9
|
LL | / pub fn empty() -> Self {
LL | | Self { strings: Vec::new() }
Expand All @@ -226,7 +232,7 @@ LL | pub const fn empty() -> Self {
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:168:9
--> tests/ui/missing_const_for_fn/could_be_const.rs:171:9
|
LL | / pub fn new(text: String) -> Self {
LL | | let vec = Vec::new();
Expand All @@ -239,5 +245,5 @@ help: make the function `const`
LL | pub const fn new(text: String) -> Self {
| +++++

error: aborting due to 17 previous errors
error: aborting due to 18 previous errors

10 changes: 0 additions & 10 deletions tests/crashes/119717.rs

This file was deleted.

4 changes: 0 additions & 4 deletions tests/crashes/123664.rs

This file was deleted.

11 changes: 0 additions & 11 deletions tests/crashes/124857.rs

This file was deleted.

23 changes: 0 additions & 23 deletions tests/crashes/126148.rs

This file was deleted.

3 changes: 2 additions & 1 deletion tests/rustdoc/rfc-2632-const-trait-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
//
// FIXME(effects) add `const_trait` to `Fn` so we use `~const`
// FIXME(effects) restore `const_trait` to `Destruct`
#![feature(const_trait_impl)]
#![allow(incomplete_features)]
#![feature(const_trait_impl, effects)]
#![crate_name = "foo"]

use std::marker::Destruct;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `Trait::{synthetic#0}: Compat` is not satisfied
--> $DIR/assoc-type-const-bound-usage-1.rs:16:44
--> $DIR/assoc-type-const-bound-usage-1.rs:15:44
|
LL | fn unqualified<T: const Trait>() -> Type<{ T::Assoc::func() }> {
| ^^^^^^^^ the trait `Compat` is not implemented for `Trait::{synthetic#0}`
|
note: required by a bound in `Trait::func`
--> $DIR/assoc-type-const-bound-usage-1.rs:8:1
--> $DIR/assoc-type-const-bound-usage-1.rs:7:1
|
LL | #[const_trait]
| ^^^^^^^^^^^^^^ required by this bound in `Trait::func`
Expand All @@ -14,13 +14,13 @@ LL | fn func() -> i32;
| ---- required by a bound in this associated function

error[E0277]: the trait bound `Trait::{synthetic#0}: Compat` is not satisfied
--> $DIR/assoc-type-const-bound-usage-1.rs:20:42
--> $DIR/assoc-type-const-bound-usage-1.rs:19:42
|
LL | fn qualified<T: const Trait>() -> Type<{ <T as Trait>::Assoc::func() }> {
| ^^^^^^^^^^^^^^^^^^^ the trait `Compat` is not implemented for `Trait::{synthetic#0}`
|
note: required by a bound in `Trait::func`
--> $DIR/assoc-type-const-bound-usage-1.rs:8:1
--> $DIR/assoc-type-const-bound-usage-1.rs:7:1
|
LL | #[const_trait]
| ^^^^^^^^^^^^^^ required by this bound in `Trait::func`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | #![feature(const_trait_impl, effects)]
= note: `#[warn(incomplete_features)]` on by default

error[E0277]: the trait bound `Add::{synthetic#0}: Compat` is not satisfied
--> $DIR/assoc-type.rs:40:15
--> $DIR/assoc-type.rs:41:15
|
LL | type Qux: Add;
| ^^^ the trait `Compat` is not implemented for `Add::{synthetic#0}`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![allow(incomplete_features)]
#![feature(const_trait_impl, effects, try_trait_v2)]

use std::ops::FromResidual;

impl<T> const FromResidual for T {
//~^ ERROR const `impl` for trait `FromResidual` which is not marked with `#[const_trait]`
//~| type parameter `T` must be used as the type parameter for some local type
fn from_residual(t: T) -> _ {
//~^ the placeholder `_` is not allowed
t
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
error: const `impl` for trait `FromResidual` which is not marked with `#[const_trait]`
--> $DIR/ice-119717-constant-lifetime.rs:6:15
|
LL | impl<T> const FromResidual for T {
| ^^^^^^^^^^^^
|
= note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
= note: adding a non-const method body in the future would be a breaking change

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/ice-119717-constant-lifetime.rs:6:6
|
LL | impl<T> const FromResidual for T {
| ^ type parameter `T` must be used as the type parameter for some local type
|
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
= note: only traits defined in the current crate can be implemented for a type parameter

error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
--> $DIR/ice-119717-constant-lifetime.rs:9:31
|
LL | fn from_residual(t: T) -> _ {
| ^ not allowed in type signatures
|
help: try replacing `_` with the type in the corresponding trait method signature
|
LL | fn from_residual(t: T) -> T {
| ~

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0121, E0210.
For more information about an error, try `rustc --explain E0121`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs, const_trait_impl, effects)]

const fn with_positive<F: ~const Fn()>() {}
//~^ ERROR `~const` can only be applied to `#[const_trait]` traits

pub fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/ice-123664-unexpected-bound-var.rs:4:34
|
LL | const fn with_positive<F: ~const Fn()>() {}
| ^^^^

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ compile-flags: -Znext-solver=coherence

#![allow(incomplete_features)]
#![feature(const_trait_impl, effects)]

#[const_trait]
trait Foo {}

impl const Foo for i32 {}

impl<T> const Foo for T where T: ~const Foo {}
//~^ ERROR conflicting implementations of trait `Foo` for type `i32`

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0119]: conflicting implementations of trait `Foo` for type `i32`
--> $DIR/ice-124857-combine-effect-const-infer-vars.rs:11:1
|
LL | impl const Foo for i32 {}
| ---------------------- first implementation here
LL |
LL | impl<T> const Foo for T where T: ~const Foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `i32`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0119`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![allow(incomplete_features)]
#![feature(const_trait_impl, effects, try_trait_v2, const_try)]
use std::ops::{FromResidual, Try};

struct TryMe;
struct Error;

impl const FromResidual<Error> for TryMe {}
//~^ ERROR const `impl` for trait `FromResidual` which is not marked with `#[const_trait]`
//~| ERROR not all trait items implemented

impl const Try for TryMe {
//~^ ERROR const `impl` for trait `Try` which is not marked with `#[const_trait]`
//~| ERROR not all trait items implemented
type Output = ();
type Residual = Error;
}

const fn t() -> TryMe {
TryMe?;
TryMe
}

const _: () = {
t();
};

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
error: const `impl` for trait `FromResidual` which is not marked with `#[const_trait]`
--> $DIR/ice-126148-failed-to-normalize.rs:8:12
|
LL | impl const FromResidual<Error> for TryMe {}
| ^^^^^^^^^^^^^^^^^^^
|
= note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
= note: adding a non-const method body in the future would be a breaking change

error[E0046]: not all trait items implemented, missing: `from_residual`
--> $DIR/ice-126148-failed-to-normalize.rs:8:1
|
LL | impl const FromResidual<Error> for TryMe {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `from_residual` in implementation
|
= help: implement the missing item: `fn from_residual(_: Error) -> Self { todo!() }`

error: const `impl` for trait `Try` which is not marked with `#[const_trait]`
--> $DIR/ice-126148-failed-to-normalize.rs:12:12
|
LL | impl const Try for TryMe {
| ^^^
|
= note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
= note: adding a non-const method body in the future would be a breaking change

error[E0046]: not all trait items implemented, missing: `from_output`, `branch`
--> $DIR/ice-126148-failed-to-normalize.rs:12:1
|
LL | impl const Try for TryMe {
| ^^^^^^^^^^^^^^^^^^^^^^^^ missing `from_output`, `branch` in implementation
|
= help: implement the missing item: `fn from_output(_: <Self as Try>::Output) -> Self { todo!() }`
= help: implement the missing item: `fn branch(self) -> ControlFlow<<Self as Try>::Residual, <Self as Try>::Output> { todo!() }`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0046`.

0 comments on commit 8b2fac9

Please sign in to comment.