Skip to content

Commit 4bcd67c

Browse files
committed
create suggestions for mismatched consts
1 parent 7bf3dc1 commit 4bcd67c

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ dependencies = [
276276

277277
[[package]]
278278
name = "cargo"
279-
version = "0.60.0"
279+
version = "0.59.0"
280280
dependencies = [
281281
"anyhow",
282282
"atty",
@@ -419,7 +419,7 @@ dependencies = [
419419

420420
[[package]]
421421
name = "cargo-util"
422-
version = "0.1.2"
422+
version = "0.1.1"
423423
dependencies = [
424424
"anyhow",
425425
"core-foundation",
@@ -768,7 +768,7 @@ checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634"
768768

769769
[[package]]
770770
name = "crates-io"
771-
version = "0.33.1"
771+
version = "0.33.0"
772772
dependencies = [
773773
"anyhow",
774774
"curl",

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use super::{
1111
use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
1212
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1313
use crate::infer::{self, InferCtxt, TyCtxtInferExt};
14+
use crate::traits::const_evaluatable::AbstractConst;
1415
use rustc_data_structures::fx::FxHashMap;
1516
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
1617
use rustc_hir as hir;
@@ -19,6 +20,7 @@ use rustc_hir::intravisit::Visitor;
1920
use rustc_hir::GenericParam;
2021
use rustc_hir::Item;
2122
use rustc_hir::Node;
23+
//use rustc_middle::mir::interpret::ConstValue;
2224
use rustc_middle::thir::abstract_const::NotConstEvaluatable;
2325
use rustc_middle::ty::error::ExpectedFound;
2426
use rustc_middle::ty::fast_reject::{self, SimplifyParams, StripReferences};
@@ -1173,6 +1175,11 @@ trait InferCtxtPrivExt<'hir, 'tcx> {
11731175
obligated_types: &mut Vec<&ty::TyS<'tcx>>,
11741176
cause_code: &ObligationCauseCode<'tcx>,
11751177
) -> bool;
1178+
1179+
fn try_create_suggestion_for_mismatched_const(
1180+
&self,
1181+
expected_found: ExpectedFound<&'tcx ty::Const<'tcx>>,
1182+
) -> Option<String>;
11761183
}
11771184

11781185
impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
@@ -1246,6 +1253,11 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
12461253
.emit();
12471254
}
12481255
FulfillmentErrorCode::CodeConstEquateError(ref expected_found, ref err) => {
1256+
debug!(
1257+
"expected: {:?}, found: {:?}",
1258+
expected_found.expected, expected_found.found
1259+
);
1260+
12491261
self.report_mismatched_consts(
12501262
&error.obligation.cause,
12511263
expected_found.expected,
@@ -1489,6 +1501,16 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
14891501
}
14901502
}
14911503

1504+
fn try_create_suggestion_for_mismatched_const(
1505+
&self,
1506+
expected_found: ExpectedFound<&'tcx ty::Const<'tcx>>,
1507+
) -> Option<String> {
1508+
match AbstractConst::from_const(self.tcx, expected_found.found) {
1509+
Ok(Some(f_abstract)) => f_abstract.try_print_with_replacing_substs(self.tcx),
1510+
_ => None,
1511+
}
1512+
}
1513+
14921514
fn report_similar_impl_candidates(
14931515
&self,
14941516
impl_candidates: Vec<ty::TraitRef<'tcx>>,

0 commit comments

Comments
 (0)