|
1 | 1 | use crate::infer::type_variable::TypeVariableOriginKind;
|
2 | 2 | use crate::infer::InferCtxt;
|
| 3 | +use crate::rustc_middle::ty::TypeFoldable; |
3 | 4 | use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
|
4 | 5 | use rustc_hir as hir;
|
5 | 6 | use rustc_hir::def::{DefKind, Namespace};
|
@@ -400,36 +401,75 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
400 | 401 | }
|
401 | 402 | }
|
402 | 403 | GenericArgKind::Const(ct) => {
|
403 |
| - if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.val { |
404 |
| - let origin = |
405 |
| - self.inner.borrow_mut().const_unification_table().probe_value(vid).origin; |
406 |
| - if let ConstVariableOriginKind::ConstParameterDefinition(name, def_id) = |
407 |
| - origin.kind |
408 |
| - { |
409 |
| - return InferenceDiagnosticsData { |
410 |
| - name: name.to_string(), |
| 404 | + match ct.val { |
| 405 | + ty::ConstKind::Infer(InferConst::Var(vid)) => { |
| 406 | + let origin = self |
| 407 | + .inner |
| 408 | + .borrow_mut() |
| 409 | + .const_unification_table() |
| 410 | + .probe_value(vid) |
| 411 | + .origin; |
| 412 | + if let ConstVariableOriginKind::ConstParameterDefinition(name, def_id) = |
| 413 | + origin.kind |
| 414 | + { |
| 415 | + return InferenceDiagnosticsData { |
| 416 | + name: name.to_string(), |
| 417 | + span: Some(origin.span), |
| 418 | + kind: UnderspecifiedArgKind::Const { is_parameter: true }, |
| 419 | + parent: InferenceDiagnosticsParentData::for_def_id( |
| 420 | + self.tcx, def_id, |
| 421 | + ), |
| 422 | + }; |
| 423 | + } |
| 424 | + |
| 425 | + debug_assert!(!origin.span.is_dummy()); |
| 426 | + let mut s = String::new(); |
| 427 | + let mut printer = |
| 428 | + ty::print::FmtPrinter::new(self.tcx, &mut s, Namespace::ValueNS); |
| 429 | + if let Some(highlight) = highlight { |
| 430 | + printer.region_highlight_mode = highlight; |
| 431 | + } |
| 432 | + let _ = ct.print(printer); |
| 433 | + InferenceDiagnosticsData { |
| 434 | + name: s, |
411 | 435 | span: Some(origin.span),
|
412 |
| - kind: UnderspecifiedArgKind::Const { is_parameter: true }, |
413 |
| - parent: InferenceDiagnosticsParentData::for_def_id(self.tcx, def_id), |
414 |
| - }; |
| 436 | + kind: UnderspecifiedArgKind::Const { is_parameter: false }, |
| 437 | + parent: None, |
| 438 | + } |
415 | 439 | }
|
416 |
| - |
417 |
| - debug_assert!(!origin.span.is_dummy()); |
418 |
| - let mut s = String::new(); |
419 |
| - let mut printer = |
420 |
| - ty::print::FmtPrinter::new(self.tcx, &mut s, Namespace::ValueNS); |
421 |
| - if let Some(highlight) = highlight { |
422 |
| - printer.region_highlight_mode = highlight; |
| 440 | + ty::ConstKind::Unevaluated(ty::Unevaluated { |
| 441 | + substs_: Some(substs), .. |
| 442 | + }) => { |
| 443 | + assert!(substs.has_infer_types_or_consts()); |
| 444 | + |
| 445 | + // FIXME: We only use the first inference variable we encounter in |
| 446 | + // `substs` here, this gives insufficiently informative diagnostics |
| 447 | + // in case there are multiple inference variables |
| 448 | + for s in substs.iter() { |
| 449 | + match s.unpack() { |
| 450 | + GenericArgKind::Type(t) => match t.kind() { |
| 451 | + ty::Infer(_) => { |
| 452 | + return self.extract_inference_diagnostics_data(s, None); |
| 453 | + } |
| 454 | + _ => {} |
| 455 | + }, |
| 456 | + GenericArgKind::Const(c) => match c.val { |
| 457 | + ty::ConstKind::Infer(InferConst::Var(_)) => { |
| 458 | + return self.extract_inference_diagnostics_data(s, None); |
| 459 | + } |
| 460 | + _ => {} |
| 461 | + }, |
| 462 | + _ => {} |
| 463 | + } |
| 464 | + } |
| 465 | + bug!( |
| 466 | + "expected an inference variable in substs of unevaluated const {:?}", |
| 467 | + ct |
| 468 | + ); |
423 | 469 | }
|
424 |
| - let _ = ct.print(printer); |
425 |
| - InferenceDiagnosticsData { |
426 |
| - name: s, |
427 |
| - span: Some(origin.span), |
428 |
| - kind: UnderspecifiedArgKind::Const { is_parameter: false }, |
429 |
| - parent: None, |
| 470 | + _ => { |
| 471 | + bug!("unexpect const: {:?}", ct); |
430 | 472 | }
|
431 |
| - } else { |
432 |
| - bug!("unexpect const: {:?}", ct); |
433 | 473 | }
|
434 | 474 | }
|
435 | 475 | GenericArgKind::Lifetime(_) => bug!("unexpected lifetime"),
|
|
0 commit comments