Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6bf5fd5

Browse files
authoredJul 24, 2024
Rollup merge of #122192 - oli-obk:type_of_opaque_for_const_checks, r=lcnr
Do not try to reveal hidden types when trying to prove auto-traits in the defining scope fixes #99793 this avoids the cycle error by just causing a selection error, which is not fatal. We pessimistically assume that freeze does not hold, which is always a safe assumption.
2 parents 6106b05 + 8ea461d commit 6bf5fd5

31 files changed

+245
-263
lines changed
 

‎compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,33 @@ impl Qualif for HasMutInterior {
100100
}
101101

102102
fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
103-
!ty.is_freeze(cx.tcx, cx.param_env)
103+
// Avoid selecting for simple cases, such as builtin types.
104+
if ty.is_trivially_freeze() {
105+
return false;
106+
}
107+
108+
// We do not use `ty.is_freeze` here, because that requires revealing opaque types, which
109+
// requires borrowck, which in turn will invoke mir_const_qualifs again, causing a cycle error.
110+
// Instead we invoke an obligation context manually, and provide the opaque type inference settings
111+
// that allow the trait solver to just error out instead of cycling.
112+
let freeze_def_id = cx.tcx.require_lang_item(LangItem::Freeze, Some(cx.body.span));
113+
114+
let obligation = Obligation::new(
115+
cx.tcx,
116+
ObligationCause::dummy_with_span(cx.body.span),
117+
cx.param_env,
118+
ty::TraitRef::new(cx.tcx, freeze_def_id, [ty::GenericArg::from(ty)]),
119+
);
120+
121+
let infcx = cx
122+
.tcx
123+
.infer_ctxt()
124+
.with_opaque_type_inference(cx.body.source.def_id().expect_local())
125+
.build();
126+
let ocx = ObligationCtxt::new(&infcx);
127+
ocx.register_obligation(obligation);
128+
let errors = ocx.select_all_or_error();
129+
!errors.is_empty()
104130
}
105131

106132
fn in_adt_inherently<'tcx>(

‎compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ impl<'tcx> Ty<'tcx> {
12681268
///
12691269
/// Returning true means the type is known to be `Freeze`. Returning
12701270
/// `false` means nothing -- could be `Freeze`, might not be.
1271-
fn is_trivially_freeze(self) -> bool {
1271+
pub fn is_trivially_freeze(self) -> bool {
12721272
match self.kind() {
12731273
ty::Int(_)
12741274
| ty::Uint(_)

‎compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
772772
);
773773
}
774774

775-
ty::Alias(ty::Opaque, _) => {
775+
ty::Alias(ty::Opaque, alias) => {
776776
if candidates.vec.iter().any(|c| matches!(c, ProjectionCandidate(_))) {
777777
// We do not generate an auto impl candidate for `impl Trait`s which already
778778
// reference our auto trait.
@@ -787,6 +787,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
787787
// We do not emit auto trait candidates for opaque types in coherence.
788788
// Doing so can result in weird dependency cycles.
789789
candidates.ambiguous = true;
790+
} else if self.infcx.can_define_opaque_ty(alias.def_id) {
791+
// We do not emit auto trait candidates for opaque types in their defining scope, as
792+
// we need to know the hidden type first, which we can't reliably know within the defining
793+
// scope.
794+
candidates.ambiguous = true;
790795
} else {
791796
candidates.vec.push(AutoImplCandidate)
792797
}

‎compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,13 +2386,17 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
23862386
}
23872387

23882388
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
2389-
// We can resolve the `impl Trait` to its concrete type,
2390-
// which enforces a DAG between the functions requiring
2391-
// the auto trait bounds in question.
2392-
match self.tcx().type_of_opaque(def_id) {
2393-
Ok(ty) => t.rebind(vec![ty.instantiate(self.tcx(), args)]),
2394-
Err(_) => {
2395-
return Err(SelectionError::OpaqueTypeAutoTraitLeakageUnknown(def_id));
2389+
if self.infcx.can_define_opaque_ty(def_id) {
2390+
unreachable!()
2391+
} else {
2392+
// We can resolve the `impl Trait` to its concrete type,
2393+
// which enforces a DAG between the functions requiring
2394+
// the auto trait bounds in question.
2395+
match self.tcx().type_of_opaque(def_id) {
2396+
Ok(ty) => t.rebind(vec![ty.instantiate(self.tcx(), args)]),
2397+
Err(_) => {
2398+
return Err(SelectionError::OpaqueTypeAutoTraitLeakageUnknown(def_id));
2399+
}
23962400
}
23972401
}
23982402
}

‎tests/ui/const-generics/opaque_types.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ note: ...which requires const checking `main::{constant#0}`...
122122
|
123123
LL | foo::<42>();
124124
| ^^
125-
= note: ...which requires computing whether `Foo` is freeze...
126-
= note: ...which requires evaluating trait selection obligation `Foo: core::marker::Freeze`...
127125
= note: ...which again requires computing type of opaque `Foo::{opaque#0}`, completing the cycle
128126
note: cycle used when computing type of `Foo::{opaque#0}`
129127
--> $DIR/opaque_types.rs:3:12

‎tests/ui/consts/const-fn-cycle.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
/// to end up revealing opaque types (the RPIT in `many`'s return type),
88
/// which can quickly lead to cycles.
99
10+
//@ check-pass
11+
1012
pub struct Parser<H>(H);
1113

1214
impl<H, T> Parser<H>
@@ -18,7 +20,6 @@ where
1820
}
1921

2022
pub const fn many<'s>(&'s self) -> Parser<impl for<'a> Fn(&'a str) -> Vec<T> + 's> {
21-
//~^ ERROR: cycle detected
2223
Parser::new(|_| unimplemented!())
2324
}
2425
}

‎tests/ui/consts/const-fn-cycle.stderr

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
2-
--> $DIR/const-promoted-opaque.rs:29:25
2+
--> $DIR/const-promoted-opaque.rs:28:25
33
|
44
LL | let _: &'static _ = &FOO;
55
| ^^^^
@@ -9,7 +9,7 @@ LL | let _: &'static _ = &FOO;
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

1111
error[E0493]: destructor of `helper::Foo` cannot be evaluated at compile-time
12-
--> $DIR/const-promoted-opaque.rs:29:26
12+
--> $DIR/const-promoted-opaque.rs:28:26
1313
|
1414
LL | let _: &'static _ = &FOO;
1515
| ^^^ the destructor for this type cannot be evaluated in constants
@@ -18,13 +18,13 @@ LL | };
1818
| - value is dropped here
1919

2020
error[E0492]: constants cannot refer to interior mutable data
21-
--> $DIR/const-promoted-opaque.rs:34:19
21+
--> $DIR/const-promoted-opaque.rs:33:19
2222
|
2323
LL | const BAZ: &Foo = &FOO;
2424
| ^^^^ this borrow of an interior mutable value may end up in the final value
2525

2626
error[E0716]: temporary value dropped while borrowed
27-
--> $DIR/const-promoted-opaque.rs:38:26
27+
--> $DIR/const-promoted-opaque.rs:37:26
2828
|
2929
LL | let _: &'static _ = &FOO;
3030
| ---------- ^^^ creates a temporary value which is freed while still in use
@@ -34,38 +34,7 @@ LL |
3434
LL | }
3535
| - temporary value is freed at the end of this statement
3636

37-
error[E0391]: cycle detected when computing type of opaque `helper::Foo::{opaque#0}`
38-
--> $DIR/const-promoted-opaque.rs:14:20
39-
|
40-
LL | pub type Foo = impl Sized;
41-
| ^^^^^^^^^^
42-
|
43-
note: ...which requires borrow-checking `helper::FOO`...
44-
--> $DIR/const-promoted-opaque.rs:21:5
45-
|
46-
LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42);
47-
| ^^^^^^^^^^^^^^^^^^
48-
note: ...which requires promoting constants in MIR for `helper::FOO`...
49-
--> $DIR/const-promoted-opaque.rs:21:5
50-
|
51-
LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42);
52-
| ^^^^^^^^^^^^^^^^^^
53-
note: ...which requires const checking `helper::FOO`...
54-
--> $DIR/const-promoted-opaque.rs:21:5
55-
|
56-
LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42);
57-
| ^^^^^^^^^^^^^^^^^^
58-
= note: ...which requires computing whether `helper::Foo` is freeze...
59-
= note: ...which requires evaluating trait selection obligation `helper::Foo: core::marker::Freeze`...
60-
= note: ...which again requires computing type of opaque `helper::Foo::{opaque#0}`, completing the cycle
61-
note: cycle used when computing type of `helper::Foo::{opaque#0}`
62-
--> $DIR/const-promoted-opaque.rs:14:20
63-
|
64-
LL | pub type Foo = impl Sized;
65-
| ^^^^^^^^^^
66-
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
67-
68-
error: aborting due to 5 previous errors
37+
error: aborting due to 4 previous errors
6938

70-
Some errors have detailed explanations: E0391, E0492, E0493, E0658, E0716.
71-
For more information about an error, try `rustc --explain E0391`.
39+
Some errors have detailed explanations: E0492, E0493, E0658, E0716.
40+
For more information about an error, try `rustc --explain E0492`.

‎tests/ui/consts/const-promoted-opaque.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
mod helper {
1414
pub type Foo = impl Sized;
15-
//[string,atomic]~^ ERROR cycle detected
1615

1716
#[cfg(string)]
1817
pub const FOO: Foo = String::new();
@@ -28,11 +27,11 @@ use helper::*;
2827
const BAR: () = {
2928
let _: &'static _ = &FOO;
3029
//[string,atomic]~^ ERROR: destructor of `helper::Foo` cannot be evaluated at compile-time
31-
//[string,atomic]~| ERROR: cannot borrow here
30+
//[atomic]~| ERROR: cannot borrow here
3231
};
3332

3433
const BAZ: &Foo = &FOO;
35-
//[string,atomic]~^ ERROR: constants cannot refer to interior mutable data
34+
//[atomic]~^ ERROR: constants cannot refer to interior mutable data
3635

3736
fn main() {
3837
let _: &'static _ = &FOO;
Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
1-
error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
2-
--> $DIR/const-promoted-opaque.rs:29:25
3-
|
4-
LL | let _: &'static _ = &FOO;
5-
| ^^^^
6-
|
7-
= note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information
8-
= help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
9-
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10-
111
error[E0493]: destructor of `helper::Foo` cannot be evaluated at compile-time
12-
--> $DIR/const-promoted-opaque.rs:29:26
2+
--> $DIR/const-promoted-opaque.rs:28:26
133
|
144
LL | let _: &'static _ = &FOO;
155
| ^^^ the destructor for this type cannot be evaluated in constants
166
...
177
LL | };
188
| - value is dropped here
199

20-
error[E0492]: constants cannot refer to interior mutable data
21-
--> $DIR/const-promoted-opaque.rs:34:19
22-
|
23-
LL | const BAZ: &Foo = &FOO;
24-
| ^^^^ this borrow of an interior mutable value may end up in the final value
25-
2610
error[E0716]: temporary value dropped while borrowed
27-
--> $DIR/const-promoted-opaque.rs:38:26
11+
--> $DIR/const-promoted-opaque.rs:37:26
2812
|
2913
LL | let _: &'static _ = &FOO;
3014
| ---------- ^^^ creates a temporary value which is freed while still in use
@@ -34,38 +18,7 @@ LL |
3418
LL | }
3519
| - temporary value is freed at the end of this statement
3620

37-
error[E0391]: cycle detected when computing type of opaque `helper::Foo::{opaque#0}`
38-
--> $DIR/const-promoted-opaque.rs:14:20
39-
|
40-
LL | pub type Foo = impl Sized;
41-
| ^^^^^^^^^^
42-
|
43-
note: ...which requires borrow-checking `helper::FOO`...
44-
--> $DIR/const-promoted-opaque.rs:18:5
45-
|
46-
LL | pub const FOO: Foo = String::new();
47-
| ^^^^^^^^^^^^^^^^^^
48-
note: ...which requires promoting constants in MIR for `helper::FOO`...
49-
--> $DIR/const-promoted-opaque.rs:18:5
50-
|
51-
LL | pub const FOO: Foo = String::new();
52-
| ^^^^^^^^^^^^^^^^^^
53-
note: ...which requires const checking `helper::FOO`...
54-
--> $DIR/const-promoted-opaque.rs:18:5
55-
|
56-
LL | pub const FOO: Foo = String::new();
57-
| ^^^^^^^^^^^^^^^^^^
58-
= note: ...which requires computing whether `helper::Foo` is freeze...
59-
= note: ...which requires evaluating trait selection obligation `helper::Foo: core::marker::Freeze`...
60-
= note: ...which again requires computing type of opaque `helper::Foo::{opaque#0}`, completing the cycle
61-
note: cycle used when computing type of `helper::Foo::{opaque#0}`
62-
--> $DIR/const-promoted-opaque.rs:14:20
63-
|
64-
LL | pub type Foo = impl Sized;
65-
| ^^^^^^^^^^
66-
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
67-
68-
error: aborting due to 5 previous errors
21+
error: aborting due to 2 previous errors
6922

70-
Some errors have detailed explanations: E0391, E0492, E0493, E0658, E0716.
71-
For more information about an error, try `rustc --explain E0391`.
23+
Some errors have detailed explanations: E0493, E0716.
24+
For more information about an error, try `rustc --explain E0493`.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0283]: type annotations needed
2+
--> $DIR/auto-trait-selection-freeze.rs:19:16
3+
|
4+
LL | if false { is_trait(foo()) } else { Default::default() }
5+
| ^^^^^^^^ ----- type must be known at this point
6+
| |
7+
| cannot infer type of the type parameter `T` declared on the function `is_trait`
8+
|
9+
= note: cannot satisfy `_: Trait<_>`
10+
note: required by a bound in `is_trait`
11+
--> $DIR/auto-trait-selection-freeze.rs:11:16
12+
|
13+
LL | fn is_trait<T: Trait<U>, U: Default>(_: T) -> U {
14+
| ^^^^^^^^ required by this bound in `is_trait`
15+
help: consider specifying the generic arguments
16+
|
17+
LL | if false { is_trait::<T, U>(foo()) } else { Default::default() }
18+
| ++++++++
19+
20+
error: aborting due to 1 previous error
21+
22+
For more information about this error, try `rustc --explain E0283`.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0283]: type annotations needed
2+
--> $DIR/auto-trait-selection-freeze.rs:19:16
3+
|
4+
LL | if false { is_trait(foo()) } else { Default::default() }
5+
| ^^^^^^^^ cannot infer type of the type parameter `U` declared on the function `is_trait`
6+
|
7+
note: multiple `impl`s satisfying `impl Sized: Trait<_>` found
8+
--> $DIR/auto-trait-selection-freeze.rs:16:1
9+
|
10+
LL | impl<T: Freeze> Trait<u32> for T {}
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
LL | impl<T> Trait<i32> for T {}
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^
14+
note: required by a bound in `is_trait`
15+
--> $DIR/auto-trait-selection-freeze.rs:11:16
16+
|
17+
LL | fn is_trait<T: Trait<U>, U: Default>(_: T) -> U {
18+
| ^^^^^^^^ required by this bound in `is_trait`
19+
help: consider specifying the generic arguments
20+
|
21+
LL | if false { is_trait::<_, U>(foo()) } else { Default::default() }
22+
| ++++++++
23+
24+
error: aborting due to 1 previous error
25+
26+
For more information about this error, try `rustc --explain E0283`.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! This test shows how we fail selection in a way that can influence
2+
//! selection in a code path that succeeds.
3+
4+
//@ revisions: next old
5+
//@[next] compile-flags: -Znext-solver
6+
7+
#![feature(freeze)]
8+
9+
use std::marker::Freeze;
10+
11+
fn is_trait<T: Trait<U>, U: Default>(_: T) -> U {
12+
Default::default()
13+
}
14+
15+
trait Trait<T> {}
16+
impl<T: Freeze> Trait<u32> for T {}
17+
impl<T> Trait<i32> for T {}
18+
fn foo() -> impl Sized {
19+
if false { is_trait(foo()) } else { Default::default() }
20+
//~^ ERROR: type annotations needed
21+
}
22+
23+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0283]: type annotations needed
2+
--> $DIR/auto-trait-selection.rs:15:16
3+
|
4+
LL | if false { is_trait(foo()) } else { Default::default() }
5+
| ^^^^^^^^ ----- type must be known at this point
6+
| |
7+
| cannot infer type of the type parameter `T` declared on the function `is_trait`
8+
|
9+
= note: cannot satisfy `_: Trait<_>`
10+
note: required by a bound in `is_trait`
11+
--> $DIR/auto-trait-selection.rs:7:16
12+
|
13+
LL | fn is_trait<T: Trait<U>, U: Default>(_: T) -> U {
14+
| ^^^^^^^^ required by this bound in `is_trait`
15+
help: consider specifying the generic arguments
16+
|
17+
LL | if false { is_trait::<T, U>(foo()) } else { Default::default() }
18+
| ++++++++
19+
20+
error: aborting due to 1 previous error
21+
22+
For more information about this error, try `rustc --explain E0283`.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0283]: type annotations needed
2+
--> $DIR/auto-trait-selection.rs:15:16
3+
|
4+
LL | if false { is_trait(foo()) } else { Default::default() }
5+
| ^^^^^^^^ cannot infer type of the type parameter `U` declared on the function `is_trait`
6+
|
7+
note: multiple `impl`s satisfying `impl Sized: Trait<_>` found
8+
--> $DIR/auto-trait-selection.rs:12:1
9+
|
10+
LL | impl<T: Send> Trait<u32> for T {}
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
LL | impl<T> Trait<i32> for T {}
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^
14+
note: required by a bound in `is_trait`
15+
--> $DIR/auto-trait-selection.rs:7:16
16+
|
17+
LL | fn is_trait<T: Trait<U>, U: Default>(_: T) -> U {
18+
| ^^^^^^^^ required by this bound in `is_trait`
19+
help: consider specifying the generic arguments
20+
|
21+
LL | if false { is_trait::<_, U>(foo()) } else { Default::default() }
22+
| ++++++++
23+
24+
error: aborting due to 1 previous error
25+
26+
For more information about this error, try `rustc --explain E0283`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! This test shows how we fail selection in a way that can influence
2+
//! selection in a code path that succeeds.
3+
4+
//@ revisions: next old
5+
//@[next] compile-flags: -Znext-solver
6+
7+
fn is_trait<T: Trait<U>, U: Default>(_: T) -> U {
8+
Default::default()
9+
}
10+
11+
trait Trait<T> {}
12+
impl<T: Send> Trait<u32> for T {}
13+
impl<T> Trait<i32> for T {}
14+
fn foo() -> impl Sized {
15+
if false { is_trait(foo()) } else { Default::default() }
16+
//~^ ERROR: type annotations needed
17+
}
18+
19+
fn main() {}
Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0599]: no method named `my_debug` found for opaque type `impl Debug` in the current scope
2-
--> $DIR/call_method_on_inherent_impl_ref.rs:20:11
2+
--> $DIR/call_method_on_inherent_impl_ref.rs:19:11
33
|
44
LL | fn my_debug(&self);
55
| -------- the method is available for `&impl Debug` here
@@ -14,27 +14,6 @@ note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it
1414
LL | trait MyDebug {
1515
| ^^^^^^^^^^^^^
1616

17-
error[E0391]: cycle detected when computing type of opaque `my_foo::{opaque#0}`
18-
--> $DIR/call_method_on_inherent_impl_ref.rs:15:16
19-
|
20-
LL | fn my_foo() -> impl std::fmt::Debug {
21-
| ^^^^^^^^^^^^^^^^^^^^
22-
|
23-
note: ...which requires type-checking `my_foo`...
24-
--> $DIR/call_method_on_inherent_impl_ref.rs:20:9
25-
|
26-
LL | x.my_debug();
27-
| ^
28-
= note: ...which requires evaluating trait selection obligation `my_foo::{opaque#0}: core::marker::Unpin`...
29-
= note: ...which again requires computing type of opaque `my_foo::{opaque#0}`, completing the cycle
30-
note: cycle used when computing type of `my_foo::{opaque#0}`
31-
--> $DIR/call_method_on_inherent_impl_ref.rs:15:16
32-
|
33-
LL | fn my_foo() -> impl std::fmt::Debug {
34-
| ^^^^^^^^^^^^^^^^^^^^
35-
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
36-
37-
error: aborting due to 2 previous errors
17+
error: aborting due to 1 previous error
3818

39-
Some errors have detailed explanations: E0391, E0599.
40-
For more information about an error, try `rustc --explain E0391`.
19+
For more information about this error, try `rustc --explain E0599`.

‎tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/call_method_on_inherent_impl_ref.rs:18:13
2+
--> $DIR/call_method_on_inherent_impl_ref.rs:17:13
33
|
44
LL | let x = my_foo();
55
| ^
@@ -13,7 +13,7 @@ LL | let x: /* Type */ = my_foo();
1313
| ++++++++++++
1414

1515
error[E0282]: type annotations needed for `&_`
16-
--> $DIR/call_method_on_inherent_impl_ref.rs:28:13
16+
--> $DIR/call_method_on_inherent_impl_ref.rs:27:13
1717
|
1818
LL | let x = &my_bar();
1919
| ^

‎tests/ui/impl-trait/call_method_on_inherent_impl_ref.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ where
1313
}
1414

1515
fn my_foo() -> impl std::fmt::Debug {
16-
//[current]~^ cycle
1716
if false {
1817
let x = my_foo();
1918
//[next]~^ type annotations needed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! This test caused a cycle error when checking whether the
2+
//! return type is `Freeze` during const checking, even though
3+
//! the information is readily available.
4+
5+
//@ revisions: current next
6+
//@[next] compile-flags: -Znext-solver
7+
//@ check-pass
8+
9+
const fn f() -> impl Eq {
10+
g()
11+
}
12+
const fn g() {}
13+
14+
fn main() {}

‎tests/ui/impl-trait/unsized_coercion3.next.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let x = hello();
55
| ^^^^^^^ types differ
66

77
error[E0308]: mismatched types
8-
--> $DIR/unsized_coercion3.rs:19:14
8+
--> $DIR/unsized_coercion3.rs:18:14
99
|
1010
LL | fn hello() -> Box<impl Trait + ?Sized> {
1111
| ------------------- the expected opaque type
@@ -21,7 +21,7 @@ note: associated function defined here
2121
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
2222

2323
error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time
24-
--> $DIR/unsized_coercion3.rs:19:14
24+
--> $DIR/unsized_coercion3.rs:18:14
2525
|
2626
LL | Box::new(1u32)
2727
| -------- ^^^^ doesn't have a size known at compile-time
Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
error: cannot check whether the hidden type of opaque type satisfies auto traits
2-
--> $DIR/unsized_coercion3.rs:15:32
3-
|
4-
LL | let y: Box<dyn Send> = x;
5-
| ^
6-
|
7-
= note: fetching the hidden types of an opaque inside of the defining scope is not supported. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule
8-
note: opaque type is declared here
9-
--> $DIR/unsized_coercion3.rs:11:19
10-
|
11-
LL | fn hello() -> Box<impl Trait + ?Sized> {
12-
| ^^^^^^^^^^^^^^^^^^^
13-
= note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Send>`
14-
151
error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time
162
--> $DIR/unsized_coercion3.rs:15:32
173
|
@@ -21,6 +7,6 @@ LL | let y: Box<dyn Send> = x;
217
= help: the trait `Sized` is not implemented for `impl Trait + ?Sized`
228
= note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Send>`
239

24-
error: aborting due to 2 previous errors
10+
error: aborting due to 1 previous error
2511

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

‎tests/ui/impl-trait/unsized_coercion3.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ fn hello() -> Box<impl Trait + ?Sized> {
1414
//[next]~^ ERROR: type mismatch resolving `impl Trait + ?Sized <: dyn Send`
1515
let y: Box<dyn Send> = x;
1616
//[old]~^ ERROR: the size for values of type `impl Trait + ?Sized` cannot be know
17-
//[old]~| ERROR: cannot check whether the hidden type of opaque type satisfies auto traits
1817
}
1918
Box::new(1u32)
2019
//[next]~^ ERROR: mismatched types

‎tests/ui/impl-trait/unsized_coercion5.old.stderr

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,6 @@ LL | let y: Box<dyn Send> = x as Box<dyn Trait + Send>;
99
= note: expected struct `Box<dyn Send>`
1010
found struct `Box<dyn Trait + Send>`
1111

12-
error: cannot check whether the hidden type of opaque type satisfies auto traits
13-
--> $DIR/unsized_coercion5.rs:16:32
14-
|
15-
LL | let y: Box<dyn Send> = x as Box<dyn Trait + Send>;
16-
| ^
17-
|
18-
= note: fetching the hidden types of an opaque inside of the defining scope is not supported. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule
19-
note: opaque type is declared here
20-
--> $DIR/unsized_coercion5.rs:13:19
21-
|
22-
LL | fn hello() -> Box<impl Trait + ?Sized> {
23-
| ^^^^^^^^^^^^^^^^^^^
24-
= note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Trait + Send>`
25-
2612
error[E0277]: the size for values of type `impl Trait + ?Sized` cannot be known at compilation time
2713
--> $DIR/unsized_coercion5.rs:16:32
2814
|
@@ -32,7 +18,7 @@ LL | let y: Box<dyn Send> = x as Box<dyn Trait + Send>;
3218
= help: the trait `Sized` is not implemented for `impl Trait + ?Sized`
3319
= note: required for the cast from `Box<impl Trait + ?Sized>` to `Box<dyn Trait + Send>`
3420

35-
error: aborting due to 3 previous errors
21+
error: aborting due to 2 previous errors
3622

3723
Some errors have detailed explanations: E0277, E0308.
3824
For more information about an error, try `rustc --explain E0277`.

‎tests/ui/impl-trait/unsized_coercion5.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ fn hello() -> Box<impl Trait + ?Sized> {
1515
let x = hello();
1616
let y: Box<dyn Send> = x as Box<dyn Trait + Send>;
1717
//[old]~^ ERROR: the size for values of type `impl Trait + ?Sized` cannot be know
18-
//[old]~| ERROR: cannot check whether the hidden type of opaque type satisfies auto traits
19-
//~^^^ ERROR: mismatched types
18+
//~^^ ERROR: mismatched types
2019
}
2120
Box::new(1u32)
2221
}

‎tests/ui/rfcs/rfc-2632-const-trait-impl/ice-120503-async-const-method.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ impl MyTrait for i32 {
99
//~| ERROR functions in trait impls cannot be declared const
1010
//~| ERROR functions cannot be both `const` and `async`
1111
//~| ERROR method `bar` is not a member
12-
//~| ERROR cycle detected when computing type
1312
main8().await;
1413
//~^ ERROR cannot find function
1514
}

‎tests/ui/rfcs/rfc-2632-const-trait-impl/ice-120503-async-const-method.stderr

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,46 +61,15 @@ error: using `#![feature(effects)]` without enabling next trait solver globally
6161
= help: use `-Znext-solver` to enable
6262

6363
error[E0425]: cannot find function `main8` in this scope
64-
--> $DIR/ice-120503-async-const-method.rs:13:9
64+
--> $DIR/ice-120503-async-const-method.rs:12:9
6565
|
6666
LL | main8().await;
6767
| ^^^^^ help: a function with a similar name exists: `main`
6868
...
6969
LL | fn main() {}
7070
| --------- similarly named function `main` defined here
7171

72-
error[E0391]: cycle detected when computing type of opaque `<impl at $DIR/ice-120503-async-const-method.rs:6:1: 6:21>::bar::{opaque#0}`
73-
--> $DIR/ice-120503-async-const-method.rs:7:5
74-
|
75-
LL | async const fn bar(&self) {
76-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
77-
|
78-
note: ...which requires borrow-checking `<impl at $DIR/ice-120503-async-const-method.rs:6:1: 6:21>::bar`...
79-
--> $DIR/ice-120503-async-const-method.rs:7:5
80-
|
81-
LL | async const fn bar(&self) {
82-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
83-
note: ...which requires promoting constants in MIR for `<impl at $DIR/ice-120503-async-const-method.rs:6:1: 6:21>::bar`...
84-
--> $DIR/ice-120503-async-const-method.rs:7:5
85-
|
86-
LL | async const fn bar(&self) {
87-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
88-
note: ...which requires const checking `<impl at $DIR/ice-120503-async-const-method.rs:6:1: 6:21>::bar`...
89-
--> $DIR/ice-120503-async-const-method.rs:7:5
90-
|
91-
LL | async const fn bar(&self) {
92-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
93-
= note: ...which requires computing whether `<impl at $DIR/ice-120503-async-const-method.rs:6:1: 6:21>::bar::{opaque#0}` is freeze...
94-
= note: ...which requires evaluating trait selection obligation `<impl at $DIR/ice-120503-async-const-method.rs:6:1: 6:21>::bar::{opaque#0}: core::marker::Freeze`...
95-
= note: ...which again requires computing type of opaque `<impl at $DIR/ice-120503-async-const-method.rs:6:1: 6:21>::bar::{opaque#0}`, completing the cycle
96-
note: cycle used when computing type of `<impl at $DIR/ice-120503-async-const-method.rs:6:1: 6:21>::bar::{opaque#0}`
97-
--> $DIR/ice-120503-async-const-method.rs:7:5
98-
|
99-
LL | async const fn bar(&self) {
100-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
101-
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
102-
103-
error: aborting due to 7 previous errors; 1 warning emitted
72+
error: aborting due to 6 previous errors; 1 warning emitted
10473

105-
Some errors have detailed explanations: E0379, E0391, E0407, E0425.
74+
Some errors have detailed explanations: E0379, E0407, E0425.
10675
For more information about an error, try `rustc --explain E0379`.

‎tests/ui/type-alias-impl-trait/in-where-clause.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
#![feature(type_alias_impl_trait)]
55
type Bar = impl Sized;
66
//~^ ERROR: cycle
7-
//~| ERROR: cycle
87

98
fn foo() -> Bar
109
where
1110
Bar: Send,
1211
{
1312
[0; 1 + 2]
13+
//~^ ERROR: type annotations needed: cannot satisfy `Bar: Send`
1414
}
1515

1616
fn main() {}

‎tests/ui/type-alias-impl-trait/in-where-clause.stderr

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ note: ...which requires computing type of opaque `Bar::{opaque#0}`...
1010
LL | type Bar = impl Sized;
1111
| ^^^^^^^^^^
1212
note: ...which requires type-checking `foo`...
13-
--> $DIR/in-where-clause.rs:9:1
13+
--> $DIR/in-where-clause.rs:8:1
1414
|
1515
LL | / fn foo() -> Bar
1616
LL | | where
@@ -25,26 +25,23 @@ LL | type Bar = impl Sized;
2525
| ^^^^^^^^^^
2626
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
2727

28-
error[E0391]: cycle detected when computing type of opaque `Bar::{opaque#0}`
29-
--> $DIR/in-where-clause.rs:5:12
30-
|
31-
LL | type Bar = impl Sized;
32-
| ^^^^^^^^^^
33-
|
34-
note: ...which requires type-checking `foo`...
35-
--> $DIR/in-where-clause.rs:13:9
28+
error[E0283]: type annotations needed: cannot satisfy `Bar: Send`
29+
--> $DIR/in-where-clause.rs:12:9
3630
|
3731
LL | [0; 1 + 2]
3832
| ^^^^^
39-
= note: ...which requires evaluating trait selection obligation `Bar: core::marker::Send`...
40-
= note: ...which again requires computing type of opaque `Bar::{opaque#0}`, completing the cycle
41-
note: cycle used when computing type of `Bar::{opaque#0}`
42-
--> $DIR/in-where-clause.rs:5:12
4333
|
44-
LL | type Bar = impl Sized;
45-
| ^^^^^^^^^^
46-
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
34+
= note: cannot satisfy `Bar: Send`
35+
note: required by a bound in `foo`
36+
--> $DIR/in-where-clause.rs:10:10
37+
|
38+
LL | fn foo() -> Bar
39+
| --- required by a bound in this function
40+
LL | where
41+
LL | Bar: Send,
42+
| ^^^^ required by this bound in `foo`
4743

4844
error: aborting due to 2 previous errors
4945

50-
For more information about this error, try `rustc --explain E0391`.
46+
Some errors have detailed explanations: E0283, E0391.
47+
For more information about an error, try `rustc --explain E0283`.

‎tests/ui/type-alias-impl-trait/reveal_local.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn not_gooder() -> Foo {
2020
// while we could know this from the hidden type, it would
2121
// need extra roundabout logic to support it.
2222
is_send::<Foo>();
23-
//~^ ERROR: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits
23+
//~^ ERROR: type annotations needed: cannot satisfy `Foo: Send`
2424

2525
x
2626
}

‎tests/ui/type-alias-impl-trait/reveal_local.stderr

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@ note: required by a bound in `is_send`
1616
LL | fn is_send<T: Send>() {}
1717
| ^^^^ required by this bound in `is_send`
1818

19-
error: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits
19+
error[E0283]: type annotations needed: cannot satisfy `Foo: Send`
2020
--> $DIR/reveal_local.rs:22:15
2121
|
2222
LL | is_send::<Foo>();
2323
| ^^^
2424
|
25-
= note: fetching the hidden types of an opaque inside of the defining scope is not supported. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule
26-
note: opaque type is declared here
27-
--> $DIR/reveal_local.rs:5:12
28-
|
29-
LL | type Foo = impl Debug;
30-
| ^^^^^^^^^^
25+
= note: cannot satisfy `Foo: Send`
3126
note: required by a bound in `is_send`
3227
--> $DIR/reveal_local.rs:7:15
3328
|
@@ -36,3 +31,4 @@ LL | fn is_send<T: Send>() {}
3631

3732
error: aborting due to 2 previous errors
3833

34+
For more information about this error, try `rustc --explain E0283`.

0 commit comments

Comments
 (0)
Please sign in to comment.