Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Nov 8, 2024
1 parent bfe315d commit 3f906ca
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 130 deletions.
13 changes: 11 additions & 2 deletions compiler/rustc_const_eval/src/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,17 @@ impl Qualif for HasMutInterior {
// Instead we invoke an obligation context manually, and provide the opaque type inference settings
// that allow the trait solver to just error out instead of cycling.
let freeze_def_id = cx.tcx.require_lang_item(LangItem::Freeze, Some(cx.body.span));

let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(cx.typing_env);
// FIXME(#132279): Once we've got a typing mode which reveals opaque types using the HIR
// typeck results without causing query cycles, we should use this here instead of defining
// opaque types.
let typing_env = ty::TypingEnv {
typing_mode: ty::TypingMode::analysis_in_body(
cx.tcx,
cx.body.source.def_id().expect_local(),
),
param_env: cx.typing_env.param_env,
};
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(typing_env);
let ocx = ObligationCtxt::new(&infcx);
let obligation = Obligation::new(
cx.tcx,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/for_loops_over_fallibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn suggest_question_mark<'tcx>(
}

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

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

ocx.register_bound(
cause,
cx.param_env,
param_env,
// Erase any region vids from the type, which may not be resolved
infcx.tcx.erase_regions(ty),
into_iterator_did,
Expand Down
16 changes: 9 additions & 7 deletions compiler/rustc_lint/src/non_fmt_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,17 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
Some(ty_def) if cx.tcx.is_lang_item(ty_def.did(), LangItem::String),
);

let infcx = cx.tcx.infer_ctxt().build(cx.typing_mode());
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(cx.typing_env());
let suggest_display = is_str
|| cx.tcx.get_diagnostic_item(sym::Display).is_some_and(|t| {
infcx.type_implements_trait(t, [ty], cx.param_env).may_apply()
});
|| cx
.tcx
.get_diagnostic_item(sym::Display)
.is_some_and(|t| infcx.type_implements_trait(t, [ty], param_env).may_apply());
let suggest_debug = !suggest_display
&& cx.tcx.get_diagnostic_item(sym::Debug).is_some_and(|t| {
infcx.type_implements_trait(t, [ty], cx.param_env).may_apply()
});
&& cx
.tcx
.get_diagnostic_item(sym::Debug)
.is_some_and(|t| infcx.type_implements_trait(t, [ty], param_env).may_apply());

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

Expand Down
35 changes: 3 additions & 32 deletions tests/ui/consts/const-promoted-opaque.atomic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,7 @@ LL |
LL | }
| - temporary value is freed at the end of this statement

error[E0391]: cycle detected when computing type of opaque `helper::Foo::{opaque#0}`
--> $DIR/const-promoted-opaque.rs:14:20
|
LL | pub type Foo = impl Sized;
| ^^^^^^^^^^
|
note: ...which requires borrow-checking `helper::FOO`...
--> $DIR/const-promoted-opaque.rs:20:5
|
LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42);
| ^^^^^^^^^^^^^^^^^^
note: ...which requires promoting constants in MIR for `helper::FOO`...
--> $DIR/const-promoted-opaque.rs:20:5
|
LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42);
| ^^^^^^^^^^^^^^^^^^
note: ...which requires const checking `helper::FOO`...
--> $DIR/const-promoted-opaque.rs:20:5
|
LL | pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42);
| ^^^^^^^^^^^^^^^^^^
= note: ...which again requires computing type of opaque `helper::Foo::{opaque#0}`, completing the cycle
note: cycle used when computing type of `helper::Foo::{opaque#0}`
--> $DIR/const-promoted-opaque.rs:14:20
|
LL | pub type Foo = impl Sized;
| ^^^^^^^^^^
= 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

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0391, E0492, E0493, E0716.
For more information about an error, try `rustc --explain E0391`.
Some errors have detailed explanations: E0492, E0493, E0716.
For more information about an error, try `rustc --explain E0492`.
35 changes: 3 additions & 32 deletions tests/ui/consts/const-promoted-opaque.string.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,7 @@ LL |
LL | }
| - temporary value is freed at the end of this statement

error[E0391]: cycle detected when computing type of opaque `helper::Foo::{opaque#0}`
--> $DIR/const-promoted-opaque.rs:14:20
|
LL | pub type Foo = impl Sized;
| ^^^^^^^^^^
|
note: ...which requires borrow-checking `helper::FOO`...
--> $DIR/const-promoted-opaque.rs:17:5
|
LL | pub const FOO: Foo = String::new();
| ^^^^^^^^^^^^^^^^^^
note: ...which requires promoting constants in MIR for `helper::FOO`...
--> $DIR/const-promoted-opaque.rs:17:5
|
LL | pub const FOO: Foo = String::new();
| ^^^^^^^^^^^^^^^^^^
note: ...which requires const checking `helper::FOO`...
--> $DIR/const-promoted-opaque.rs:17:5
|
LL | pub const FOO: Foo = String::new();
| ^^^^^^^^^^^^^^^^^^
= note: ...which again requires computing type of opaque `helper::Foo::{opaque#0}`, completing the cycle
note: cycle used when computing type of `helper::Foo::{opaque#0}`
--> $DIR/const-promoted-opaque.rs:14:20
|
LL | pub type Foo = impl Sized;
| ^^^^^^^^^^
= 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

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0391, E0493, E0716.
For more information about an error, try `rustc --explain E0391`.
Some errors have detailed explanations: E0493, E0716.
For more information about an error, try `rustc --explain E0493`.
9 changes: 5 additions & 4 deletions tests/ui/invalid/issue-114435-layout-type-err.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
error: queries overflow the depth limit!
error: reached the recursion limit finding the struct tail for `Bottom`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]` attribute to your crate (`issue_114435_layout_type_err`)
= note: query depth increased by 12 when computing layout of `A`
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]`

error: aborting due to 1 previous error
error: the type has an unknown layout

error: aborting due to 2 previous errors

2 changes: 1 addition & 1 deletion tests/ui/sized/recursive-type-binding.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ build-fail
//~^ ERROR cycle detected when computing layout of `<() as A>::Assoc`
//~^ ERROR cycle detected when computing layout of `Foo<()>`

trait A { type Assoc: ?Sized; }

Expand Down
12 changes: 8 additions & 4 deletions tests/ui/sized/recursive-type-binding.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
error[E0391]: cycle detected when computing layout of `<() as A>::Assoc`
error[E0391]: cycle detected when computing layout of `Foo<()>`
|
= note: ...which requires computing layout of `Foo<()>`...
= note: ...which again requires computing layout of `<() as A>::Assoc`, completing the cycle
= note: cycle used when computing layout of `Foo<()>`
= note: ...which requires computing layout of `<() as A>::Assoc`...
= note: ...which again requires computing layout of `Foo<()>`, completing the cycle
note: cycle used when elaborating drops for `main`
--> $DIR/recursive-type-binding.rs:11:1
|
LL | fn main() {
| ^^^^^^^^^
= 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

error: aborting due to 1 previous error
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/sized/recursive-type-coercion-from-never.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ build-fail
//~^ ERROR cycle detected when computing layout of `<() as A>::Assoc`
//~^ ERROR cycle detected when computing layout of `Foo<()>`

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

Expand Down
12 changes: 8 additions & 4 deletions tests/ui/sized/recursive-type-coercion-from-never.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
error[E0391]: cycle detected when computing layout of `<() as A>::Assoc`
error[E0391]: cycle detected when computing layout of `Foo<()>`
|
= note: ...which requires computing layout of `Foo<()>`...
= note: ...which again requires computing layout of `<() as A>::Assoc`, completing the cycle
= note: cycle used when computing layout of `Foo<()>`
= note: ...which requires computing layout of `<() as A>::Assoc`...
= note: ...which again requires computing layout of `Foo<()>`, completing the cycle
note: cycle used when elaborating drops for `main`
--> $DIR/recursive-type-coercion-from-never.rs:14:1
|
LL | fn main() {
| ^^^^^^^^^
= 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

error: aborting due to 1 previous error
Expand Down
33 changes: 2 additions & 31 deletions tests/ui/traits/const-traits/ice-120503-async-const-method.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,7 @@ LL | main8().await;
LL | fn main() {}
| --------- similarly named function `main` defined here

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}`
--> $DIR/ice-120503-async-const-method.rs:6:5
|
LL | async const fn bar(&self) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires borrow-checking `<impl at $DIR/ice-120503-async-const-method.rs:5:1: 5:21>::bar`...
--> $DIR/ice-120503-async-const-method.rs:6:5
|
LL | async const fn bar(&self) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires promoting constants in MIR for `<impl at $DIR/ice-120503-async-const-method.rs:5:1: 5:21>::bar`...
--> $DIR/ice-120503-async-const-method.rs:6:5
|
LL | async const fn bar(&self) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires const checking `<impl at $DIR/ice-120503-async-const-method.rs:5:1: 5:21>::bar`...
--> $DIR/ice-120503-async-const-method.rs:6:5
|
LL | async const fn bar(&self) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= 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
note: cycle used when computing type of `<impl at $DIR/ice-120503-async-const-method.rs:5:1: 5:21>::bar::{opaque#0}`
--> $DIR/ice-120503-async-const-method.rs:6:5
|
LL | async const fn bar(&self) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= 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

error: aborting due to 6 previous errors
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0379, E0391, E0407, E0425.
Some errors have detailed explanations: E0379, E0407, E0425.
For more information about an error, try `rustc --explain E0379`.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ trait Recur {
}

async fn recur(t: impl Recur) {
//~^ ERROR recursion in an async fn requires boxing
t.recur().await;
}

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

fn recur(self) -> Self::Recur {
async move { recur(self).await; }
//~^ ERROR recursion in an async block requires boxing
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
error[E0733]: recursion in an async fn requires boxing
error[E0733]: recursion in an async block requires boxing
--> $DIR/indirect-recursion-issue-112047.rs:22:9
|
LL | async move { recur(self).await; }
| ^^^^^^^^^^ ----------------- recursive call here
|
note: which leads to this async fn
--> $DIR/indirect-recursion-issue-112047.rs:14:1
|
LL | async fn recur(t: impl Recur) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | t.recur().await;
| --------------- recursive call here
|
note: which leads to this async block
--> $DIR/indirect-recursion-issue-112047.rs:23:9
|
LL | async move { recur(self).await; }
| ^^^^^^^^^^ ----------------- ...leading to this recursive call
| --------------- ...leading to this recursive call
= note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future

error: aborting due to 1 previous error
Expand Down

0 comments on commit 3f906ca

Please sign in to comment.