Skip to content

Commit 3f906ca

Browse files
committed
w
1 parent bfe315d commit 3f906ca

13 files changed

+62
-130
lines changed

compiler/rustc_const_eval/src/check_consts/qualifs.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,17 @@ impl Qualif for HasMutInterior {
106106
// Instead we invoke an obligation context manually, and provide the opaque type inference settings
107107
// that allow the trait solver to just error out instead of cycling.
108108
let freeze_def_id = cx.tcx.require_lang_item(LangItem::Freeze, Some(cx.body.span));
109-
110-
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(cx.typing_env);
109+
// FIXME(#132279): Once we've got a typing mode which reveals opaque types using the HIR
110+
// typeck results without causing query cycles, we should use this here instead of defining
111+
// opaque types.
112+
let typing_env = ty::TypingEnv {
113+
typing_mode: ty::TypingMode::analysis_in_body(
114+
cx.tcx,
115+
cx.body.source.def_id().expect_local(),
116+
),
117+
param_env: cx.typing_env.param_env,
118+
};
119+
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(typing_env);
111120
let ocx = ObligationCtxt::new(&infcx);
112121
let obligation = Obligation::new(
113122
cx.tcx,

compiler/rustc_lint/src/for_loops_over_fallibles.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn suggest_question_mark<'tcx>(
166166
}
167167

168168
let ty = args.type_at(0);
169-
let infcx = cx.tcx.infer_ctxt().build(cx.typing_mode());
169+
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(cx.typing_env());
170170
let ocx = ObligationCtxt::new(&infcx);
171171

172172
let body_def_id = cx.tcx.hir().body_owner_def_id(body_id);
@@ -175,7 +175,7 @@ fn suggest_question_mark<'tcx>(
175175

176176
ocx.register_bound(
177177
cause,
178-
cx.param_env,
178+
param_env,
179179
// Erase any region vids from the type, which may not be resolved
180180
infcx.tcx.erase_regions(ty),
181181
into_iterator_did,

compiler/rustc_lint/src/non_fmt_panic.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,17 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
157157
Some(ty_def) if cx.tcx.is_lang_item(ty_def.did(), LangItem::String),
158158
);
159159

160-
let infcx = cx.tcx.infer_ctxt().build(cx.typing_mode());
160+
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(cx.typing_env());
161161
let suggest_display = is_str
162-
|| cx.tcx.get_diagnostic_item(sym::Display).is_some_and(|t| {
163-
infcx.type_implements_trait(t, [ty], cx.param_env).may_apply()
164-
});
162+
|| cx
163+
.tcx
164+
.get_diagnostic_item(sym::Display)
165+
.is_some_and(|t| infcx.type_implements_trait(t, [ty], param_env).may_apply());
165166
let suggest_debug = !suggest_display
166-
&& cx.tcx.get_diagnostic_item(sym::Debug).is_some_and(|t| {
167-
infcx.type_implements_trait(t, [ty], cx.param_env).may_apply()
168-
});
167+
&& cx
168+
.tcx
169+
.get_diagnostic_item(sym::Debug)
170+
.is_some_and(|t| infcx.type_implements_trait(t, [ty], param_env).may_apply());
169171

170172
let suggest_panic_any = !is_str && panic == sym::std_panic_macro;
171173

tests/ui/consts/const-promoted-opaque.atomic.stderr

+3-32
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,7 @@ LL |
2424
LL | }
2525
| - temporary value is freed at the end of this statement
2626

27-
error[E0391]: cycle detected when computing type of opaque `helper::Foo::{opaque#0}`
28-
--> $DIR/const-promoted-opaque.rs:14:20
29-
|
30-
LL | pub type Foo = impl Sized;
31-
| ^^^^^^^^^^
32-
|
33-
note: ...which requires borrow-checking `helper::FOO`...
34-
--> $DIR/const-promoted-opaque.rs:20:5
35-
|
36-
LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42);
37-
| ^^^^^^^^^^^^^^^^^^
38-
note: ...which requires promoting constants in MIR for `helper::FOO`...
39-
--> $DIR/const-promoted-opaque.rs:20:5
40-
|
41-
LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42);
42-
| ^^^^^^^^^^^^^^^^^^
43-
note: ...which requires const checking `helper::FOO`...
44-
--> $DIR/const-promoted-opaque.rs:20:5
45-
|
46-
LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42);
47-
| ^^^^^^^^^^^^^^^^^^
48-
= note: ...which again requires computing type of opaque `helper::Foo::{opaque#0}`, completing the cycle
49-
note: cycle used when computing type of `helper::Foo::{opaque#0}`
50-
--> $DIR/const-promoted-opaque.rs:14:20
51-
|
52-
LL | pub type Foo = impl Sized;
53-
| ^^^^^^^^^^
54-
= 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
55-
56-
error: aborting due to 4 previous errors
27+
error: aborting due to 3 previous errors
5728

58-
Some errors have detailed explanations: E0391, E0492, E0493, E0716.
59-
For more information about an error, try `rustc --explain E0391`.
29+
Some errors have detailed explanations: E0492, E0493, E0716.
30+
For more information about an error, try `rustc --explain E0492`.

tests/ui/consts/const-promoted-opaque.string.stderr

+3-32
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,7 @@ LL |
1818
LL | }
1919
| - temporary value is freed at the end of this statement
2020

21-
error[E0391]: cycle detected when computing type of opaque `helper::Foo::{opaque#0}`
22-
--> $DIR/const-promoted-opaque.rs:14:20
23-
|
24-
LL | pub type Foo = impl Sized;
25-
| ^^^^^^^^^^
26-
|
27-
note: ...which requires borrow-checking `helper::FOO`...
28-
--> $DIR/const-promoted-opaque.rs:17:5
29-
|
30-
LL | pub const FOO: Foo = String::new();
31-
| ^^^^^^^^^^^^^^^^^^
32-
note: ...which requires promoting constants in MIR for `helper::FOO`...
33-
--> $DIR/const-promoted-opaque.rs:17:5
34-
|
35-
LL | pub const FOO: Foo = String::new();
36-
| ^^^^^^^^^^^^^^^^^^
37-
note: ...which requires const checking `helper::FOO`...
38-
--> $DIR/const-promoted-opaque.rs:17:5
39-
|
40-
LL | pub const FOO: Foo = String::new();
41-
| ^^^^^^^^^^^^^^^^^^
42-
= note: ...which again requires computing type of opaque `helper::Foo::{opaque#0}`, completing the cycle
43-
note: cycle used when computing type of `helper::Foo::{opaque#0}`
44-
--> $DIR/const-promoted-opaque.rs:14:20
45-
|
46-
LL | pub type Foo = impl Sized;
47-
| ^^^^^^^^^^
48-
= 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
49-
50-
error: aborting due to 3 previous errors
21+
error: aborting due to 2 previous errors
5122

52-
Some errors have detailed explanations: E0391, E0493, E0716.
53-
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`.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
error: queries overflow the depth limit!
1+
error: reached the recursion limit finding the struct tail for `Bottom`
22
|
3-
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]` attribute to your crate (`issue_114435_layout_type_err`)
4-
= note: query depth increased by 12 when computing layout of `A`
3+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]`
54

6-
error: aborting due to 1 previous error
5+
error: the type has an unknown layout
6+
7+
error: aborting due to 2 previous errors
78

tests/ui/sized/recursive-type-binding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ build-fail
2-
//~^ ERROR cycle detected when computing layout of `<() as A>::Assoc`
2+
//~^ ERROR cycle detected when computing layout of `Foo<()>`
33

44
trait A { type Assoc: ?Sized; }
55

tests/ui/sized/recursive-type-binding.stderr

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
error[E0391]: cycle detected when computing layout of `<() as A>::Assoc`
1+
error[E0391]: cycle detected when computing layout of `Foo<()>`
22
|
3-
= note: ...which requires computing layout of `Foo<()>`...
4-
= note: ...which again requires computing layout of `<() as A>::Assoc`, completing the cycle
5-
= note: cycle used when computing layout of `Foo<()>`
3+
= note: ...which requires computing layout of `<() as A>::Assoc`...
4+
= note: ...which again requires computing layout of `Foo<()>`, completing the cycle
5+
note: cycle used when elaborating drops for `main`
6+
--> $DIR/recursive-type-binding.rs:11:1
7+
|
8+
LL | fn main() {
9+
| ^^^^^^^^^
610
= 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
711

812
error: aborting due to 1 previous error

tests/ui/sized/recursive-type-coercion-from-never.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ build-fail
2-
//~^ ERROR cycle detected when computing layout of `<() as A>::Assoc`
2+
//~^ ERROR cycle detected when computing layout of `Foo<()>`
33

44
// Regression test for a stack overflow: https://github.com/rust-lang/rust/issues/113197
55

tests/ui/sized/recursive-type-coercion-from-never.stderr

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
error[E0391]: cycle detected when computing layout of `<() as A>::Assoc`
1+
error[E0391]: cycle detected when computing layout of `Foo<()>`
22
|
3-
= note: ...which requires computing layout of `Foo<()>`...
4-
= note: ...which again requires computing layout of `<() as A>::Assoc`, completing the cycle
5-
= note: cycle used when computing layout of `Foo<()>`
3+
= note: ...which requires computing layout of `<() as A>::Assoc`...
4+
= note: ...which again requires computing layout of `Foo<()>`, completing the cycle
5+
note: cycle used when elaborating drops for `main`
6+
--> $DIR/recursive-type-coercion-from-never.rs:14:1
7+
|
8+
LL | fn main() {
9+
| ^^^^^^^^^
610
= 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
711

812
error: aborting due to 1 previous error

tests/ui/traits/const-traits/ice-120503-async-const-method.stderr

+2-31
Original file line numberDiff line numberDiff line change
@@ -55,36 +55,7 @@ LL | main8().await;
5555
LL | fn main() {}
5656
| --------- similarly named function `main` defined here
5757

58-
error[E0391]: cycle detected when computing type of opaque `<impl at $DIR/ice-120503-async-const-method.rs:5:1: 5:21>::bar::{opaque#0}`
59-
--> $DIR/ice-120503-async-const-method.rs:6:5
60-
|
61-
LL | async const fn bar(&self) {
62-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
63-
|
64-
note: ...which requires borrow-checking `<impl at $DIR/ice-120503-async-const-method.rs:5:1: 5:21>::bar`...
65-
--> $DIR/ice-120503-async-const-method.rs:6:5
66-
|
67-
LL | async const fn bar(&self) {
68-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
69-
note: ...which requires promoting constants in MIR for `<impl at $DIR/ice-120503-async-const-method.rs:5:1: 5:21>::bar`...
70-
--> $DIR/ice-120503-async-const-method.rs:6:5
71-
|
72-
LL | async const fn bar(&self) {
73-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
74-
note: ...which requires const checking `<impl at $DIR/ice-120503-async-const-method.rs:5:1: 5:21>::bar`...
75-
--> $DIR/ice-120503-async-const-method.rs:6:5
76-
|
77-
LL | async const fn bar(&self) {
78-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
79-
= note: ...which again requires computing type of opaque `<impl at $DIR/ice-120503-async-const-method.rs:5:1: 5:21>::bar::{opaque#0}`, completing the cycle
80-
note: cycle used when computing type of `<impl at $DIR/ice-120503-async-const-method.rs:5:1: 5:21>::bar::{opaque#0}`
81-
--> $DIR/ice-120503-async-const-method.rs:6:5
82-
|
83-
LL | async const fn bar(&self) {
84-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
85-
= 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
86-
87-
error: aborting due to 6 previous errors
58+
error: aborting due to 5 previous errors
8859

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

tests/ui/type-alias-impl-trait/indirect-recursion-issue-112047.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ trait Recur {
1212
}
1313

1414
async fn recur(t: impl Recur) {
15-
//~^ ERROR recursion in an async fn requires boxing
1615
t.recur().await;
1716
}
1817

@@ -21,6 +20,7 @@ impl Recur for () {
2120

2221
fn recur(self) -> Self::Recur {
2322
async move { recur(self).await; }
23+
//~^ ERROR recursion in an async block requires boxing
2424
}
2525
}
2626

tests/ui/type-alias-impl-trait/indirect-recursion-issue-112047.stderr

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
error[E0733]: recursion in an async fn requires boxing
1+
error[E0733]: recursion in an async block requires boxing
2+
--> $DIR/indirect-recursion-issue-112047.rs:22:9
3+
|
4+
LL | async move { recur(self).await; }
5+
| ^^^^^^^^^^ ----------------- recursive call here
6+
|
7+
note: which leads to this async fn
28
--> $DIR/indirect-recursion-issue-112047.rs:14:1
39
|
410
LL | async fn recur(t: impl Recur) {
511
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
LL |
712
LL | t.recur().await;
8-
| --------------- recursive call here
9-
|
10-
note: which leads to this async block
11-
--> $DIR/indirect-recursion-issue-112047.rs:23:9
12-
|
13-
LL | async move { recur(self).await; }
14-
| ^^^^^^^^^^ ----------------- ...leading to this recursive call
13+
| --------------- ...leading to this recursive call
1514
= note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future
1615

1716
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)