Skip to content

Rollup of 4 pull requests #135159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
3 changes: 0 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ name = "anyhow"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
dependencies = [
"backtrace",
]

[[package]]
name = "ar_archive_writer"
Expand Down
23 changes: 15 additions & 8 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1845,13 +1845,18 @@ pub(super) fn check_coroutine_obligations(

debug!(?typeck_results.coroutine_stalled_predicates);

let mode = if tcx.next_trait_solver_globally() {
TypingMode::post_borrowck_analysis(tcx, def_id)
} else {
TypingMode::analysis_in_body(tcx, def_id)
};

let infcx = tcx
.infer_ctxt()
// typeck writeback gives us predicates with their regions erased.
// As borrowck already has checked lifetimes, we do not need to do it again.
.ignoring_regions()
// FIXME(#132279): This should eventually use the already defined hidden types.
.build(TypingMode::analysis_in_body(tcx, def_id));
.build(mode);

let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
for (predicate, cause) in &typeck_results.coroutine_stalled_predicates {
Expand All @@ -1864,12 +1869,14 @@ pub(super) fn check_coroutine_obligations(
return Err(infcx.err_ctxt().report_fulfillment_errors(errors));
}

// Check that any hidden types found when checking these stalled coroutine obligations
// are valid.
for (key, ty) in infcx.take_opaque_types() {
let hidden_type = infcx.resolve_vars_if_possible(ty.hidden_type);
let key = infcx.resolve_vars_if_possible(key);
sanity_check_found_hidden_type(tcx, key, hidden_type)?;
if !tcx.next_trait_solver_globally() {
// Check that any hidden types found when checking these stalled coroutine obligations
// are valid.
for (key, ty) in infcx.take_opaque_types() {
let hidden_type = infcx.resolve_vars_if_possible(ty.hidden_type);
let key = infcx.resolve_vars_if_possible(key);
sanity_check_found_hidden_type(tcx, key, hidden_type)?;
}
}

Ok(())
Expand Down
19 changes: 18 additions & 1 deletion compiler/rustc_trait_selection/src/solve/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use rustc_infer::traits::{
self, FromSolverError, MismatchedProjectionTypes, Obligation, ObligationCause,
ObligationCauseCode, PredicateObligation, PredicateObligations, SelectionError, TraitEngine,
};
use rustc_middle::bug;
use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::{self, TyCtxt};
use rustc_middle::{bug, span_bug};
use rustc_next_trait_solver::solve::{GenerateProofTree, HasChanged, SolverDelegateEvalExt as _};
use tracing::{instrument, trace};

Expand Down Expand Up @@ -258,6 +258,23 @@ fn fulfillment_error_for_no_solution<'tcx>(
MismatchedProjectionTypes { err: TypeError::Mismatch },
)
}
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, expected_ty)) => {
let ct_ty = match ct.kind() {
ty::ConstKind::Unevaluated(uv) => {
infcx.tcx.type_of(uv.def).instantiate(infcx.tcx, uv.args)
}
ty::ConstKind::Param(param_ct) => param_ct.find_ty_from_env(obligation.param_env),
_ => span_bug!(
obligation.cause.span,
"ConstArgHasWrongType failed but we don't know how to compute type"
),
};
FulfillmentErrorCode::Select(SelectionError::ConstArgHasWrongType {
ct,
ct_ty,
expected_ty,
})
}
ty::PredicateKind::NormalizesTo(..) => {
FulfillmentErrorCode::Project(MismatchedProjectionTypes { err: TypeError::Mismatch })
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ impl OsString {
OsStr::from_inner_mut(self.inner.leak())
}

/// Truncate the the `OsString` to the specified length.
/// Truncate the `OsString` to the specified length.
///
/// # Panics
/// Panics if `len` does not lie on a valid `OsStr` boundary
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl PipeReader {
/// let mut jobs = vec![];
/// let (reader, mut writer) = std::pipe::pipe()?;
///
/// // Write NUM_SLOT characters the the pipe.
/// // Write NUM_SLOT characters the pipe.
/// writer.write_all(&[b'|'; NUM_SLOT as usize])?;
///
/// // Spawn several processes that read a character from the pipe, do some work, then
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sync/poison/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ impl<T: ?Sized> Mutex<T> {
/// # Errors
///
/// If another user of this mutex panicked while holding the mutex, then
/// this call will return an error containing the the underlying data
/// this call will return an error containing the underlying data
/// instead.
///
/// # Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ https://sourceware.org/bugzilla/show_bug.cgi?id=28509
And this is the first version of the proposed binutils patch,
https://sourceware.org/pipermail/binutils/2021-November/118398.html

After applying the binutils patch, I get the the unexpected error when
After applying the binutils patch, I get the unexpected error when
building libgcc,

/scratch/nelsonc/riscv-gnu-toolchain/riscv-gcc/libgcc/config/riscv/div.S:42:
Expand Down
2 changes: 1 addition & 1 deletion src/tools/opt-dist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
build_helper = { path = "../../build_helper" }
env_logger = "0.11"
log = "0.4"
anyhow = { version = "1", features = ["backtrace"] }
anyhow = "1"
humantime = "2"
humansize = "2"
sysinfo = { version = "0.31.2", default-features = false, features = ["disk"] }
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/coroutine/issue-52304.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ check-pass
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)

#![feature(coroutines, coroutine_trait)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Here, there are two types with the same name. One of these has a `derive` annotation, but in the
// expansion these `impl`s are associated to the the *other* type. There is a suggestion to remove
// expansion these `impl`s are associated to the *other* type. There is a suggestion to remove
// unneeded type parameters, but because we're now point at a type with no type parameters, the
// suggestion would suggest removing code from an empty span, which would ICE in nightly.
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0308]: mismatched types
--> $DIR/const-in-impl-fn-return-type.rs:15:39
--> $DIR/const-in-impl-fn-return-type.rs:20:39
|
LL | fn func<const N: u32>() -> [(); { () }] {
| ^^ expected `usize`, found `()`

error: the constant `N` is not of type `usize`
--> $DIR/const-in-impl-fn-return-type.rs:7:32
--> $DIR/const-in-impl-fn-return-type.rs:12:32
|
LL | fn func<const N: u32>() -> [(); N];
| ^^^^^^^ expected `usize`, found `u32`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0308]: mismatched types
--> $DIR/const-in-impl-fn-return-type.rs:20:39
|
LL | fn func<const N: u32>() -> [(); { () }] {
| ^^ expected `usize`, found `()`

error: the constant `N` is not of type `usize`
--> $DIR/const-in-impl-fn-return-type.rs:12:32
|
LL | fn func<const N: u32>() -> [(); N];
| ^^^^^^^ expected `usize`, found `u32`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
5 changes: 5 additions & 0 deletions tests/ui/typeck/issue-114918/const-in-impl-fn-return-type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
//@ revisions: current next
//@[next] compile-flags: -Znext-solver
//@ ignore-compare-mode-next-solver (explicit revisions)

// Regression test for #114918

// Test that a const generic enclosed in a block within the return type
// of an impl fn produces a type mismatch error instead of triggering
// a const eval cycle
Expand Down
Loading