Skip to content
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

Rollup of 6 pull requests #117103

Merged
merged 13 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
return unfixed len if pat has reported error
  • Loading branch information
bvanjoi committed Oct 23, 2023
commit 6de40abc890ef1f9d89f36f4309695de19b60d5e
15 changes: 14 additions & 1 deletion compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator;
use rustc_hir::{HirId, Pat, PatKind};
use rustc_infer::infer;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::{self, Adt, BindingMode, Ty, TypeVisitableExt};
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
use rustc_span::edit_distance::find_best_match_for_name;
Expand Down Expand Up @@ -2164,7 +2165,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
len: ty::Const<'tcx>,
min_len: u64,
) -> (Option<Ty<'tcx>>, Ty<'tcx>) {
let guar = if let Some(len) = len.try_eval_target_usize(self.tcx, self.param_env) {
let len = match len.eval(self.tcx, self.param_env, None) {
Ok(val) => val
.try_to_scalar()
.and_then(|scalar| scalar.try_to_int().ok())
.and_then(|int| int.try_to_target_usize(self.tcx).ok()),
Err(ErrorHandled::Reported(..)) => {
let guar = self.error_scrutinee_unfixed_length(span);
return (Some(Ty::new_error(self.tcx, guar)), arr_ty);
}
Err(ErrorHandled::TooGeneric(..)) => None,
};

let guar = if let Some(len) = len {
// Now we know the length...
if slice.is_none() {
// ...and since there is no variable-length pattern,
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/consts/issue-116186.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

fn something(path: [usize; N]) -> impl Clone {
//~^ ERROR cannot find value `N` in this scope
match path {
[] => 0, //~ ERROR cannot pattern-match on an array without a fixed length
_ => 1,
};
}

fn main() {}
21 changes: 21 additions & 0 deletions tests/ui/consts/issue-116186.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0425]: cannot find value `N` in this scope
--> $DIR/issue-116186.rs:4:28
|
LL | fn something(path: [usize; N]) -> impl Clone {
| ^ not found in this scope
|
help: you might be missing a const parameter
|
LL | fn something<const N: /* Type */>(path: [usize; N]) -> impl Clone {
| +++++++++++++++++++++

error[E0730]: cannot pattern-match on an array without a fixed length
--> $DIR/issue-116186.rs:7:9
|
LL | [] => 0,
| ^^

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0425, E0730.
For more information about an error, try `rustc --explain E0425`.
Loading