Skip to content

Commit 1920c66

Browse files
Plumb through param_env to note_type_err
1 parent b8bb296 commit 1920c66

File tree

15 files changed

+98
-39
lines changed

15 files changed

+98
-39
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl<'tcx> UniverseInfo<'tcx> {
6565
UniverseInfoInner::RelateTys { expected, found } => {
6666
let err = mbcx.infcx.err_ctxt().report_mismatched_types(
6767
&cause,
68+
mbcx.param_env,
6869
expected,
6970
found,
7071
TypeError::RegionsPlaceholderMismatch,
@@ -480,12 +481,11 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(
480481
.try_report_from_nll()
481482
.or_else(|| {
482483
if let SubregionOrigin::Subtype(trace) = cause {
483-
Some(
484-
infcx.err_ctxt().report_and_explain_type_error(
485-
*trace,
486-
TypeError::RegionsPlaceholderMismatch,
487-
),
488-
)
484+
Some(infcx.err_ctxt().report_and_explain_type_error(
485+
*trace,
486+
infcx.tcx.param_env(generic_param_scope),
487+
TypeError::RegionsPlaceholderMismatch,
488+
))
489489
} else {
490490
None
491491
}

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ fn compare_method_predicate_entailment<'tcx>(
282282
let emitted = report_trait_method_mismatch(
283283
infcx,
284284
cause,
285+
param_env,
285286
terr,
286287
(trait_m, trait_sig),
287288
(impl_m, impl_sig),
@@ -575,10 +576,10 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
575576
hir.get_if_local(impl_m.def_id)
576577
.and_then(|node| node.fn_decl())
577578
.map(|decl| (decl.output.span(), Cow::from("return type in trait"), false)),
578-
Some(infer::ValuePairs::Terms(ExpectedFound {
579+
Some(param_env.and(infer::ValuePairs::Terms(ExpectedFound {
579580
expected: trait_return_ty.into(),
580581
found: impl_return_ty.into(),
581-
})),
582+
}))),
582583
terr,
583584
false,
584585
);
@@ -602,6 +603,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
602603
let emitted = report_trait_method_mismatch(
603604
infcx,
604605
cause,
606+
param_env,
605607
terr,
606608
(trait_m, trait_sig),
607609
(impl_m, impl_sig),
@@ -915,6 +917,7 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
915917
fn report_trait_method_mismatch<'tcx>(
916918
infcx: &InferCtxt<'tcx>,
917919
mut cause: ObligationCause<'tcx>,
920+
param_env: ty::ParamEnv<'tcx>,
918921
terr: TypeError<'tcx>,
919922
(trait_m, trait_sig): (ty::AssocItem, ty::FnSig<'tcx>),
920923
(impl_m, impl_sig): (ty::AssocItem, ty::FnSig<'tcx>),
@@ -1000,10 +1003,10 @@ fn report_trait_method_mismatch<'tcx>(
10001003
&mut diag,
10011004
&cause,
10021005
trait_err_span.map(|sp| (sp, Cow::from("type in trait"), false)),
1003-
Some(infer::ValuePairs::PolySigs(ExpectedFound {
1006+
Some(param_env.and(infer::ValuePairs::PolySigs(ExpectedFound {
10041007
expected: ty::Binder::dummy(trait_sig),
10051008
found: ty::Binder::dummy(impl_sig),
1006-
})),
1009+
}))),
10071010
terr,
10081011
false,
10091012
);
@@ -1797,10 +1800,10 @@ fn compare_const_predicate_entailment<'tcx>(
17971800
&mut diag,
17981801
&cause,
17991802
trait_c_span.map(|span| (span, Cow::from("type in trait"), false)),
1800-
Some(infer::ValuePairs::Terms(ExpectedFound {
1803+
Some(param_env.and(infer::ValuePairs::Terms(ExpectedFound {
18011804
expected: trait_ty.into(),
18021805
found: impl_ty.into(),
1803-
})),
1806+
}))),
18041807
terr,
18051808
false,
18061809
);

compiler/rustc_hir_analysis/src/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,10 @@ pub fn check_function_signature<'tcx>(
646646
&mut diag,
647647
&cause,
648648
None,
649-
Some(infer::ValuePairs::PolySigs(ExpectedFound {
649+
Some(param_env.and(infer::ValuePairs::PolySigs(ExpectedFound {
650650
expected: expected_sig,
651651
found: actual_sig,
652-
})),
652+
}))),
653653
err,
654654
false,
655655
);

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
@@ -862,7 +862,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
862862
}
863863
Err(e) => {
864864
// FIXME(effects): better diagnostic
865-
self.err_ctxt().report_mismatched_consts(&cause, effect, param, e).emit();
865+
self.err_ctxt()
866+
.report_mismatched_consts(&cause, self.param_env, effect, param, e)
867+
.emit();
866868
}
867869
}
868870
}

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],
@@ -1113,7 +1116,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11131116
&mut err,
11141117
&trace.cause,
11151118
None,
1116-
Some(trace.values),
1119+
Some(self.param_env.and(trace.values)),
11171120
e,
11181121
true,
11191122
);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2300,10 +2300,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23002300
&mut diag,
23012301
&cause,
23022302
None,
2303-
Some(ValuePairs::PolySigs(ExpectedFound {
2303+
Some(param_env.and(ValuePairs::PolySigs(ExpectedFound {
23042304
expected: ty::Binder::dummy(expected_sig),
23052305
found: ty::Binder::dummy(sig),
2306-
})),
2306+
}))),
23072307
terr,
23082308
false,
23092309
);

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

+25-6
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<ty::ParamEnvAnd<'tcx, ValuePairs<'tcx>>>,
11371148
terr: TypeError<'tcx>,
11381149
prefer_label: bool,
11391150
) {
@@ -1241,8 +1252,8 @@ 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) => {
1245-
let values = self.resolve_vars_if_possible(values);
1255+
Some(ty::ParamEnvAnd { param_env: _, value: values }) => {
1256+
let mut values = self.resolve_vars_if_possible(values);
12461257
let (is_simple_error, exp_found) = match values {
12471258
ValuePairs::Terms(ExpectedFound { expected, found }) => {
12481259
match (expected.unpack(), found.unpack()) {
@@ -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(param_env.and(trace.values)),
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)