Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 15 additions & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2518,15 +2518,29 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
) -> Const<'tcx> {
let tcx = self.tcx();

let found_tuple = || {
tcx.sess
.source_map()
.span_to_snippet(span)
.map(|snippet| format!("`{snippet}`"))
.unwrap_or_else(|_| "const tuple".to_string())
};

let tys = match ty.kind() {
ty::Tuple(tys) => tys,
ty::Error(e) => return Const::new_error(tcx, *e),
_ => {
let e = tcx.dcx().span_err(span, format!("expected `{}`, found const tuple", ty));
let e =
tcx.dcx().span_err(span, format!("expected `{}`, found {}", ty, found_tuple()));
return Const::new_error(tcx, e);
}
};

if exprs.len() != tys.len() {
let e = tcx.dcx().span_err(span, format!("expected `{}`, found {}", ty, found_tuple()));
return Const::new_error(tcx, e);
}

let exprs = exprs
.iter()
.zip(tys.iter())
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx, AmbigArg>) {
intravisit::walk_ty(self, hir_ty);
// If there are type checking errors, Type privacy pass will stop,
// so we may not get the type from hid_id, see #104513
// so we may not get the type from hir_id, see #104513
if let Some(ty) = self.fcx.node_ty_opt(hir_ty.hir_id) {
let ty = self.resolve(ty, &hir_ty.span);
self.write_ty_to_typeck_results(hir_ty.hir_id, ty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![expect(incomplete_features)]

struct Y {
stuff: [u8; { ([1, 2], 3, [4, 5]) }], //~ ERROR expected `usize`, found const tuple
stuff: [u8; { ([1, 2], 3, [4, 5]) }], //~ ERROR expected `usize`, found `([1, 2], 3, [4, 5])`
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: expected `usize`, found const tuple
error: expected `usize`, found `([1, 2], 3, [4, 5])`
--> $DIR/tuple_expr_arg_bad-issue-151048.rs:5:19
|
LL | stuff: [u8; { ([1, 2], 3, [4, 5]) }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![expect(incomplete_features)]

pub fn takes_nested_tuple<const N: u32>() {
takes_nested_tuple::<{ () }> //~ ERROR expected `u32`, found const tuple
takes_nested_tuple::<{ () }> //~ ERROR expected `u32`, found `()`
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: expected `u32`, found const tuple
error: expected `u32`, found `()`
--> $DIR/tuple_expr_arg_mismatch_type.rs:5:28
|
LL | takes_nested_tuple::<{ () }>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(min_generic_const_args, adt_const_params)]

// Regression test for an ICE in privacy checking while walking the `T` qself
// of `T::ASSOC` inside a tuple const argument.

fn takes_tuple<const N: ()>() {}

fn generic_caller<T, const N: u32>() {
takes_tuple::<{ (N, T::ASSOC) }>;
//~^ ERROR expected `()`, found `(N, T::ASSOC)`
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: expected `()`, found `(N, T::ASSOC)`
--> $DIR/tuple_expr_arg_unbounded_assoc_const.rs:9:21
|
LL | takes_tuple::<{ (N, T::ASSOC) }>;
| ^^^^^^^^^^^^^

error: aborting due to 1 previous error

Loading