Skip to content

Commit 88b3ecf

Browse files
Plumb through param_env to note_type_err
1 parent a0c2aba commit 88b3ecf

File tree

15 files changed

+122
-47
lines changed

15 files changed

+122
-47
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ impl<'tcx> UniverseInfo<'tcx> {
6161
UniverseInfoInner::RelateTys { expected, found } => {
6262
let err = mbcx.infcx.err_ctxt().report_mismatched_types(
6363
&cause,
64+
mbcx.param_env,
6465
expected,
6566
found,
6667
TypeError::RegionsPlaceholderMismatch,
@@ -481,12 +482,11 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(
481482
.try_report_from_nll()
482483
.or_else(|| {
483484
if let SubregionOrigin::Subtype(trace) = cause {
484-
Some(
485-
infcx.err_ctxt().report_and_explain_type_error(
486-
*trace,
487-
TypeError::RegionsPlaceholderMismatch,
488-
),
489-
)
485+
Some(infcx.err_ctxt().report_and_explain_type_error(
486+
*trace,
487+
infcx.tcx.param_env(generic_param_scope),
488+
TypeError::RegionsPlaceholderMismatch,
489+
))
490490
} else {
491491
None
492492
}

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ fn check_opaque_type_well_formed<'tcx>(
360360
.err_ctxt()
361361
.report_mismatched_types(
362362
&ObligationCause::misc(definition_span, def_id),
363+
param_env,
363364
opaque_ty,
364365
definition_ty,
365366
err,

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+24-12
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ fn compare_method_predicate_entailment<'tcx>(
298298
let emitted = report_trait_method_mismatch(
299299
infcx,
300300
cause,
301+
param_env,
301302
terr,
302303
(trait_m, trait_sig),
303304
(impl_m, impl_sig),
@@ -593,10 +594,13 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
593594
hir.get_if_local(impl_m.def_id)
594595
.and_then(|node| node.fn_decl())
595596
.map(|decl| (decl.output.span(), Cow::from("return type in trait"))),
596-
Some(infer::ValuePairs::Terms(ExpectedFound {
597-
expected: trait_return_ty.into(),
598-
found: impl_return_ty.into(),
599-
})),
597+
Some((
598+
infer::ValuePairs::Terms(ExpectedFound {
599+
expected: trait_return_ty.into(),
600+
found: impl_return_ty.into(),
601+
}),
602+
param_env,
603+
)),
600604
terr,
601605
false,
602606
false,
@@ -621,6 +625,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
621625
let emitted = report_trait_method_mismatch(
622626
infcx,
623627
cause,
628+
param_env,
624629
terr,
625630
(trait_m, trait_sig),
626631
(impl_m, impl_sig),
@@ -934,6 +939,7 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
934939
fn report_trait_method_mismatch<'tcx>(
935940
infcx: &InferCtxt<'tcx>,
936941
mut cause: ObligationCause<'tcx>,
942+
param_env: ty::ParamEnv<'tcx>,
937943
terr: TypeError<'tcx>,
938944
(trait_m, trait_sig): (ty::AssocItem, ty::FnSig<'tcx>),
939945
(impl_m, impl_sig): (ty::AssocItem, ty::FnSig<'tcx>),
@@ -1019,10 +1025,13 @@ fn report_trait_method_mismatch<'tcx>(
10191025
&mut diag,
10201026
&cause,
10211027
trait_err_span.map(|sp| (sp, Cow::from("type in trait"))),
1022-
Some(infer::ValuePairs::PolySigs(ExpectedFound {
1023-
expected: ty::Binder::dummy(trait_sig),
1024-
found: ty::Binder::dummy(impl_sig),
1025-
})),
1028+
Some((
1029+
infer::ValuePairs::PolySigs(ExpectedFound {
1030+
expected: ty::Binder::dummy(trait_sig),
1031+
found: ty::Binder::dummy(impl_sig),
1032+
}),
1033+
param_env,
1034+
)),
10261035
terr,
10271036
false,
10281037
false,
@@ -1826,10 +1835,13 @@ fn compare_const_predicate_entailment<'tcx>(
18261835
&mut diag,
18271836
&cause,
18281837
trait_c_span.map(|span| (span, Cow::from("type in trait"))),
1829-
Some(infer::ValuePairs::Terms(ExpectedFound {
1830-
expected: trait_ty.into(),
1831-
found: impl_ty.into(),
1832-
})),
1838+
Some((
1839+
infer::ValuePairs::Terms(ExpectedFound {
1840+
expected: trait_ty.into(),
1841+
found: impl_ty.into(),
1842+
}),
1843+
param_env,
1844+
)),
18331845
terr,
18341846
false,
18351847
false,

compiler/rustc_hir_analysis/src/check/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,13 @@ pub fn check_function_signature<'tcx>(
646646
&mut diag,
647647
&cause,
648648
None,
649-
Some(infer::ValuePairs::PolySigs(ExpectedFound {
650-
expected: expected_sig,
651-
found: actual_sig,
652-
})),
649+
Some((
650+
infer::ValuePairs::PolySigs(ExpectedFound {
651+
expected: expected_sig,
652+
found: actual_sig,
653+
}),
654+
param_env,
655+
)),
653656
err,
654657
false,
655658
false,

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ pub(crate) fn coerce_unsized_info<'tcx>(
364364
.err_ctxt()
365365
.report_mismatched_types(
366366
&cause,
367+
param_env,
367368
mk_ptr(mt_b.ty),
368369
target,
369370
ty::error::TypeError::Mutability,

compiler/rustc_hir_typeck/src/callee.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
895895
}
896896
Err(e) => {
897897
// FIXME(effects): better diagnostic
898-
self.err_ctxt().report_mismatched_consts(&cause, effect, param, e).emit();
898+
self.err_ctxt()
899+
.report_mismatched_consts(&cause, self.param_env, effect, param, e)
900+
.emit();
899901
}
900902
}
901903
}

compiler/rustc_hir_typeck/src/coercion.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
17041704
}) => {
17051705
err = fcx.err_ctxt().report_mismatched_types(
17061706
cause,
1707+
fcx.param_env,
17071708
expected,
17081709
found,
17091710
coercion_error,
@@ -1733,6 +1734,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
17331734
}) => {
17341735
err = fcx.err_ctxt().report_mismatched_types(
17351736
cause,
1737+
fcx.param_env,
17361738
expected,
17371739
found,
17381740
coercion_error,
@@ -1768,6 +1770,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
17681770
_ => {
17691771
err = fcx.err_ctxt().report_mismatched_types(
17701772
cause,
1773+
fcx.param_env,
17711774
expected,
17721775
found,
17731776
coercion_error,
@@ -1878,7 +1881,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18781881
block_or_return_id: hir::HirId,
18791882
expression: Option<&'tcx hir::Expr<'tcx>>,
18801883
) -> Diag<'infcx> {
1881-
let mut err = fcx.err_ctxt().report_mismatched_types(cause, expected, found, ty_err);
1884+
let mut err =
1885+
fcx.err_ctxt().report_mismatched_types(cause, fcx.param_env, expected, found, ty_err);
18821886

18831887
let due_to_block = matches!(fcx.tcx.hir_node(block_or_return_id), hir::Node::Block(..));
18841888

compiler/rustc_hir_typeck/src/demand.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
191191
self.at(cause, self.param_env)
192192
.sup(DefineOpaqueTypes::Yes, expected, actual)
193193
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
194-
.map_err(|e| self.err_ctxt().report_mismatched_types(cause, expected, actual, e))
194+
.map_err(|e| {
195+
self.err_ctxt().report_mismatched_types(cause, self.param_env, expected, actual, e)
196+
})
195197
}
196198

197199
pub(crate) fn demand_eqtype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>) {
@@ -218,7 +220,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
218220
self.at(cause, self.param_env)
219221
.eq(DefineOpaqueTypes::Yes, expected, actual)
220222
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
221-
.map_err(|e| self.err_ctxt().report_mismatched_types(cause, expected, actual, e))
223+
.map_err(|e| {
224+
self.err_ctxt().report_mismatched_types(cause, self.param_env, expected, actual, e)
225+
})
222226
}
223227

224228
pub(crate) fn demand_coerce(
@@ -271,7 +275,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
271275
let expr = expr.peel_drop_temps();
272276
let cause = self.misc(expr.span);
273277
let expr_ty = self.resolve_vars_if_possible(checked_ty);
274-
let mut err = self.err_ctxt().report_mismatched_types(&cause, expected, expr_ty, e);
278+
let mut err =
279+
self.err_ctxt().report_mismatched_types(&cause, self.param_env, expected, expr_ty, e);
275280

276281
self.emit_coerce_suggestions(&mut err, expr, expr_ty, expected, expected_ty_expr, Some(e));
277282

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
827827
formal_and_expected_inputs[mismatch_idx.into()],
828828
provided_arg_tys[mismatch_idx.into()].0,
829829
),
830+
self.param_env,
830831
terr,
831832
);
832833
err.span_label(
@@ -912,7 +913,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
912913
let trace =
913914
mk_trace(provided_span, formal_and_expected_inputs[*expected_idx], provided_ty);
914915
if !matches!(trace.cause.as_failure_code(*e), FailureCode::Error0308) {
915-
let mut err = self.err_ctxt().report_and_explain_type_error(trace, *e);
916+
let mut err =
917+
self.err_ctxt().report_and_explain_type_error(trace, self.param_env, *e);
916918
suggest_confusable(&mut err);
917919
reported = Some(err.emit());
918920
return false;
@@ -940,7 +942,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
940942
let (formal_ty, expected_ty) = formal_and_expected_inputs[*expected_idx];
941943
let (provided_ty, provided_arg_span) = provided_arg_tys[*provided_idx];
942944
let trace = mk_trace(provided_arg_span, (formal_ty, expected_ty), provided_ty);
943-
let mut err = self.err_ctxt().report_and_explain_type_error(trace, *err);
945+
let mut err =
946+
self.err_ctxt().report_and_explain_type_error(trace, self.param_env, *err);
944947
self.emit_coerce_suggestions(
945948
&mut err,
946949
provided_args[*provided_idx],
@@ -1112,7 +1115,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11121115
&mut err,
11131116
&trace.cause,
11141117
None,
1115-
Some(trace.values),
1118+
Some((trace.values, self.param_env)),
11161119
e,
11171120
false,
11181121
true,

compiler/rustc_hir_typeck/src/method/confirm.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,13 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
538538
// to the feature, like the self type can't reference method args.
539539
if self.tcx.features().arbitrary_self_types {
540540
self.err_ctxt()
541-
.report_mismatched_types(&cause, method_self_ty, self_ty, terr)
541+
.report_mismatched_types(
542+
&cause,
543+
self.param_env,
544+
method_self_ty,
545+
self_ty,
546+
terr,
547+
)
542548
.emit();
543549
} else {
544550
// This has/will have errored in wfcheck, which we cannot depend on from here, as typeck on functions

compiler/rustc_passes/src/check_attr.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2296,10 +2296,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22962296
&mut diag,
22972297
&cause,
22982298
None,
2299-
Some(ValuePairs::PolySigs(ExpectedFound {
2300-
expected: ty::Binder::dummy(expected_sig),
2301-
found: ty::Binder::dummy(sig),
2302-
})),
2299+
Some((
2300+
ValuePairs::PolySigs(ExpectedFound {
2301+
expected: ty::Binder::dummy(expected_sig),
2302+
found: ty::Binder::dummy(sig),
2303+
}),
2304+
param_env,
2305+
)),
23032306
terr,
23042307
false,
23052308
false,

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

+25-5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ use crate::errors::{ObligationCauseFailureCode, TypeErrorAdditionalDiags};
7575
use crate::infer;
7676
use crate::infer::relate::{self, RelateResult, TypeRelation};
7777
use crate::infer::{InferCtxt, TypeTrace, ValuePairs};
78+
use crate::solve::deeply_normalize_for_diagnostics;
7879
use crate::traits::{
7980
IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode,
8081
};
@@ -145,21 +146,31 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
145146
pub fn report_mismatched_types(
146147
&self,
147148
cause: &ObligationCause<'tcx>,
149+
param_env: ty::ParamEnv<'tcx>,
148150
expected: Ty<'tcx>,
149151
actual: Ty<'tcx>,
150152
err: TypeError<'tcx>,
151153
) -> Diag<'a> {
152-
self.report_and_explain_type_error(TypeTrace::types(cause, true, expected, actual), err)
154+
self.report_and_explain_type_error(
155+
TypeTrace::types(cause, true, expected, actual),
156+
param_env,
157+
err,
158+
)
153159
}
154160

155161
pub fn report_mismatched_consts(
156162
&self,
157163
cause: &ObligationCause<'tcx>,
164+
param_env: ty::ParamEnv<'tcx>,
158165
expected: ty::Const<'tcx>,
159166
actual: ty::Const<'tcx>,
160167
err: TypeError<'tcx>,
161168
) -> Diag<'a> {
162-
self.report_and_explain_type_error(TypeTrace::consts(cause, true, expected, actual), err)
169+
self.report_and_explain_type_error(
170+
TypeTrace::consts(cause, true, expected, actual),
171+
param_env,
172+
err,
173+
)
163174
}
164175

165176
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
@@ -1136,7 +1147,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
11361147
diag: &mut Diag<'_>,
11371148
cause: &ObligationCause<'tcx>,
11381149
secondary_span: Option<(Span, Cow<'static, str>)>,
1139-
mut values: Option<ValuePairs<'tcx>>,
1150+
mut values: Option<(ValuePairs<'tcx>, ty::ParamEnv<'tcx>)>,
11401151
terr: TypeError<'tcx>,
11411152
swap_secondary_and_primary: bool,
11421153
prefer_label: bool,
@@ -1245,7 +1256,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
12451256
}
12461257
let (expected_found, exp_found, is_simple_error, values) = match values {
12471258
None => (None, Mismatch::Fixed("type"), false, None),
1248-
Some(values) => {
1259+
Some((values, _param_env)) => {
12491260
let values = self.resolve_vars_if_possible(values);
12501261
let (is_simple_error, exp_found) = match values {
12511262
ValuePairs::Terms(ExpectedFound { expected, found }) => {
@@ -1777,6 +1788,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
17771788
pub fn report_and_explain_type_error(
17781789
&self,
17791790
trace: TypeTrace<'tcx>,
1791+
param_env: ty::ParamEnv<'tcx>,
17801792
terr: TypeError<'tcx>,
17811793
) -> Diag<'a> {
17821794
debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr);
@@ -1788,7 +1800,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
17881800
self.type_error_additional_suggestions(&trace, terr),
17891801
);
17901802
let mut diag = self.dcx().create_err(failure_code);
1791-
self.note_type_err(&mut diag, &trace.cause, None, Some(trace.values), terr, false, false);
1803+
self.note_type_err(
1804+
&mut diag,
1805+
&trace.cause,
1806+
None,
1807+
Some((trace.values, param_env)),
1808+
terr,
1809+
false,
1810+
false,
1811+
);
17921812
diag
17931813
}
17941814

compiler/rustc_trait_selection/src/error_reporting/infer/region.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
295295
let mut err = match origin {
296296
infer::Subtype(box trace) => {
297297
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
298-
let mut err = self.report_and_explain_type_error(trace, terr);
298+
let mut err = self.report_and_explain_type_error(
299+
trace,
300+
self.tcx.param_env(generic_param_scope),
301+
terr,
302+
);
299303
match (*sub, *sup) {
300304
(ty::RePlaceholder(_), ty::RePlaceholder(_)) => {}
301305
(ty::RePlaceholder(_), _) => {
@@ -646,7 +650,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
646650
}
647651
infer::Subtype(box trace) => {
648652
let terr = TypeError::RegionsPlaceholderMismatch;
649-
return self.report_and_explain_type_error(trace, terr);
653+
return self.report_and_explain_type_error(
654+
trace,
655+
self.tcx.param_env(generic_param_scope),
656+
terr,
657+
);
650658
}
651659
_ => {
652660
return self.report_concrete_failure(

0 commit comments

Comments
 (0)