Rollup merge of #102472 - lcnr:static-in-eval, r=jackh726

stop special-casing `'static` in evaluation

fixes #102360

I have no idea whether this actually removed all places where `'static` matters. Without canonicalization it's very easy to accidentally rely on `'static` again. Blocked on changing the `order_dependent_trait_objects` future-compat lint to a hard error

r? `@nikomatsakis`
This commit is contained in:
nils 2023-03-28 12:51:12 +02:00 committed by GitHub
commit 4bd33fdb4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 151 additions and 102 deletions

View file

@ -1,4 +1,8 @@
// check-pass
// known-bug: #89515
//
// The trait solver cannot deal with ambiguous marker trait impls
// if there are lifetimes involved. As we must not special-case any
// regions this does not work, even with 'static
#![feature(marker_trait_attr)]
#[marker]

View file

@ -0,0 +1,31 @@
error[E0283]: type annotations needed: cannot satisfy `&'static (): Marker`
--> $DIR/overlap-marker-trait-with-static-lifetime.rs:11:17
|
LL | impl Marker for &'static () {}
| ^^^^^^^^^^^
|
note: multiple `impl`s satisfying `&'static (): Marker` found
--> $DIR/overlap-marker-trait-with-static-lifetime.rs:11:1
|
LL | impl Marker for &'static () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | impl Marker for &'static () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0283]: type annotations needed: cannot satisfy `&'static (): Marker`
--> $DIR/overlap-marker-trait-with-static-lifetime.rs:12:17
|
LL | impl Marker for &'static () {}
| ^^^^^^^^^^^
|
note: multiple `impl`s satisfying `&'static (): Marker` found
--> $DIR/overlap-marker-trait-with-static-lifetime.rs:11:1
|
LL | impl Marker for &'static () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | impl Marker for &'static () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0283`.

View file

@ -1,9 +1,17 @@
// check-pass
// known-bug: #109481
//
// While the `T: Copy` is always applicable when checking
// that the impl `impl<T: Copy> F for T {}` is well formed,
// the old trait solver can only approximate this by checking
// that there are no inference variables in the obligation and
// no region constraints in the evaluation result.
//
// Because of this we end up with ambiguity here.
#![feature(marker_trait_attr)]
#[marker]
pub trait F {}
impl<T> F for T where T: Copy {}
impl<T> F for T where T: 'static {}
impl<T: Copy> F for T {}
impl<T: 'static> F for T {}
fn main() {}

View file

@ -0,0 +1,14 @@
error[E0310]: the parameter type `T` may not live long enough
--> $DIR/overlapping-impl-1-modulo-regions.rs:14:21
|
LL | impl<T: Copy> F for T {}
| ^ ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound...
|
LL | impl<T: Copy + 'static> F for T {}
| +++++++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0310`.