Skip to content

Commit ee7fe16

Browse files
Plumb through param_env to note_type_err
1 parent 798fb83 commit ee7fe16

File tree

15 files changed

+121
-47
lines changed

15 files changed

+121
-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"), false)),
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
);
@@ -620,6 +624,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
620624
let emitted = report_trait_method_mismatch(
621625
infcx,
622626
cause,
627+
param_env,
623628
terr,
624629
(trait_m, trait_sig),
625630
(impl_m, impl_sig),
@@ -933,6 +938,7 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
933938
fn report_trait_method_mismatch<'tcx>(
934939
infcx: &InferCtxt<'tcx>,
935940
mut cause: ObligationCause<'tcx>,
941+
param_env: ty::ParamEnv<'tcx>,
936942
terr: TypeError<'tcx>,
937943
(trait_m, trait_sig): (ty::AssocItem, ty::FnSig<'tcx>),
938944
(impl_m, impl_sig): (ty::AssocItem, ty::FnSig<'tcx>),
@@ -1018,10 +1024,13 @@ fn report_trait_method_mismatch<'tcx>(
10181024
&mut diag,
10191025
&cause,
10201026
trait_err_span.map(|sp| (sp, Cow::from("type in trait"), false)),
1021-
Some(infer::ValuePairs::PolySigs(ExpectedFound {
1022-
expected: ty::Binder::dummy(trait_sig),
1023-
found: ty::Binder::dummy(impl_sig),
1024-
})),
1027+
Some((
1028+
infer::ValuePairs::PolySigs(ExpectedFound {
1029+
expected: ty::Binder::dummy(trait_sig),
1030+
found: ty::Binder::dummy(impl_sig),
1031+
}),
1032+
param_env,
1033+
)),
10251034
terr,
10261035
false,
10271036
);
@@ -1824,10 +1833,13 @@ fn compare_const_predicate_entailment<'tcx>(
18241833
&mut diag,
18251834
&cause,
18261835
trait_c_span.map(|span| (span, Cow::from("type in trait"), false)),
1827-
Some(infer::ValuePairs::Terms(ExpectedFound {
1828-
expected: trait_ty.into(),
1829-
found: impl_ty.into(),
1830-
})),
1836+
Some((
1837+
infer::ValuePairs::Terms(ExpectedFound {
1838+
expected: trait_ty.into(),
1839+
found: impl_ty.into(),
1840+
}),
1841+
param_env,
1842+
)),
18311843
terr,
18321844
false,
18331845
);

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
);

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
@@ -1723,6 +1723,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
17231723
}) => {
17241724
err = fcx.err_ctxt().report_mismatched_types(
17251725
cause,
1726+
fcx.param_env,
17261727
expected,
17271728
found,
17281729
coercion_error,
@@ -1752,6 +1753,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
17521753
}) => {
17531754
err = fcx.err_ctxt().report_mismatched_types(
17541755
cause,
1756+
fcx.param_env,
17551757
expected,
17561758
found,
17571759
coercion_error,
@@ -1787,6 +1789,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
17871789
_ => {
17881790
err = fcx.err_ctxt().report_mismatched_types(
17891791
cause,
1792+
fcx.param_env,
17901793
expected,
17911794
found,
17921795
coercion_error,
@@ -1897,7 +1900,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18971900
block_or_return_id: hir::HirId,
18981901
expression: Option<&'tcx hir::Expr<'tcx>>,
18991902
) -> Diag<'infcx> {
1900-
let mut err = fcx.err_ctxt().report_mismatched_types(cause, expected, found, ty_err);
1903+
let mut err =
1904+
fcx.err_ctxt().report_mismatched_types(cause, fcx.param_env, expected, found, ty_err);
19011905

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

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
true,
11181121
);

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
);

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

+24-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>> {
@@ -1133,7 +1144,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
11331144
diag: &mut Diag<'_>,
11341145
cause: &ObligationCause<'tcx>,
11351146
secondary_span: Option<(Span, Cow<'static, str>, bool)>,
1136-
mut values: Option<ValuePairs<'tcx>>,
1147+
mut values: Option<(ValuePairs<'tcx>, ty::ParamEnv<'tcx>)>,
11371148
terr: TypeError<'tcx>,
11381149
prefer_label: bool,
11391150
) {
@@ -1241,7 +1252,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
12411252
}
12421253
let (expected_found, exp_found, is_simple_error, values) = match values {
12431254
None => (None, Mismatch::Fixed("type"), false, None),
1244-
Some(values) => {
1255+
Some((values, _param_env)) => {
12451256
let values = self.resolve_vars_if_possible(values);
12461257
let (is_simple_error, exp_found) = match values {
12471258
ValuePairs::Terms(ExpectedFound { expected, found }) => {
@@ -1773,6 +1784,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
17731784
pub fn report_and_explain_type_error(
17741785
&self,
17751786
trace: TypeTrace<'tcx>,
1787+
param_env: ty::ParamEnv<'tcx>,
17761788
terr: TypeError<'tcx>,
17771789
) -> Diag<'a> {
17781790
debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr);
@@ -1784,7 +1796,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
17841796
self.type_error_additional_suggestions(&trace, terr),
17851797
);
17861798
let mut diag = self.dcx().create_err(failure_code);
1787-
self.note_type_err(&mut diag, &trace.cause, None, Some(trace.values), terr, false);
1799+
self.note_type_err(
1800+
&mut diag,
1801+
&trace.cause,
1802+
None,
1803+
Some((trace.values, param_env)),
1804+
terr,
1805+
false,
1806+
);
17881807
diag
17891808
}
17901809

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)