remove saw_const_match_error; check if pattern contains an Error instead · rust-lang/rust@303a2db (original) (raw)
`@@ -7,15 +7,14 @@ use rustc_infer::traits::Obligation;
`
7
7
`use rustc_middle::mir;
`
8
8
`use rustc_middle::mir::interpret::ErrorHandled;
`
9
9
`use rustc_middle::thir::{FieldPat, Pat, PatKind};
`
``
10
`+
use rustc_middle::ty::TypeVisitableExt;
`
10
11
`use rustc_middle::ty::{self, Ty, TyCtxt, ValTree};
`
11
``
`-
use rustc_span::{ErrorGuaranteed, Span};
`
``
12
`+
use rustc_span::Span;
`
12
13
`use rustc_target::abi::{FieldIdx, VariantIdx};
`
13
14
`use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
`
14
15
`use rustc_trait_selection::traits::ObligationCause;
`
15
16
`use tracing::{debug, instrument, trace};
`
16
17
``
17
``
`-
use std::cell::Cell;
`
18
``
-
19
18
`use super::PatCtxt;
`
20
19
`use crate::errors::{
`
21
20
`ConstPatternDependsOnGenericParameter, CouldNotEvalConstPattern, InvalidPattern, NaNPattern,
`
`@@ -49,11 +48,6 @@ struct ConstToPat<'tcx> {
`
49
48
`span: Span,
`
50
49
`param_env: ty::ParamEnv<'tcx>,
`
51
50
``
52
``
`-
// This tracks if we emitted some hard error for a given const value, so that
`
53
``
`-
// we will not subsequently issue an irrelevant lint for the same const
`
54
``
`-
// value.
`
55
``
`-
saw_const_match_error: Cell<Option>,
`
56
``
-
57
51
`` // inference context used for checking T: Structural
bounds.
``
58
52
`infcx: InferCtxt<'tcx>,
`
59
53
``
`@@ -73,7 +67,6 @@ impl<'tcx> ConstToPat<'tcx> {
`
73
67
` span,
`
74
68
` infcx,
`
75
69
`param_env: pat_ctxt.param_env,
`
76
``
`-
saw_const_match_error: Cell::new(None),
`
77
70
`treat_byte_string_as_slice: pat_ctxt
`
78
71
`.typeck_results
`
79
72
`.treat_byte_string_as_slice
`
`@@ -131,7 +124,7 @@ impl<'tcx> ConstToPat<'tcx> {
`
131
124
`// Convert the valtree to a const.
`
132
125
`let inlined_const_as_pat = self.valtree_to_pat(valtree, ty);
`
133
126
``
134
``
`-
if self.saw_const_match_error.get().is_none() {
`
``
127
`+
if !inlined_const_as_pat.references_error() {
`
135
128
`` // Always check for PartialEq
if we had no other errors yet.
``
136
129
`if !self.type_has_partial_eq_impl(ty) {
`
137
130
`let err = TypeNotPartialEq { span: self.span, non_peq_ty: ty };
`
`@@ -205,7 +198,6 @@ impl<'tcx> ConstToPat<'tcx> {
`
205
198
`debug!("adt_def {:?} has !type_marked_structural for cv.ty: {:?}", adt_def, ty,);
`
206
199
`let err = TypeNotStructural { span, non_sm_ty: ty };
`
207
200
`let e = tcx.dcx().emit_err(err);
`
208
``
`-
self.saw_const_match_error.set(Some(e));
`
209
201
`// We errored. Signal that in the pattern, so that follow up errors can be silenced.
`
210
202
`PatKind::Error(e)
`
211
203
`}
`
`@@ -273,7 +265,6 @@ impl<'tcx> ConstToPat<'tcx> {
`
273
265
`if !pointee_ty.is_sized(tcx, param_env) && !pointee_ty.is_slice() {
`
274
266
`let err = UnsizedPattern { span, non_sm_ty: *pointee_ty };
`
275
267
`let e = tcx.dcx().emit_err(err);
`
276
``
`-
self.saw_const_match_error.set(Some(e));
`
277
268
`// We errored. Signal that in the pattern, so that follow up errors can be silenced.
`
278
269
`PatKind::Error(e)
`
279
270
`} else {
`
`@@ -307,7 +298,6 @@ impl<'tcx> ConstToPat<'tcx> {
`
307
298
`// NaNs are not ever equal to anything so they make no sense as patterns.
`
308
299
`// Also see https://github.com/rust-lang/rfcs/pull/3535.
`
309
300
`let e = tcx.dcx().emit_err(NaNPattern { span });
`
310
``
`-
self.saw_const_match_error.set(Some(e));
`
311
301
`PatKind::Error(e)
`
312
302
`} else {
`
313
303
`PatKind::Constant {
`
`@@ -328,7 +318,6 @@ impl<'tcx> ConstToPat<'tcx> {
`
328
318
` _ => {
`
329
319
`let err = InvalidPattern { span, non_sm_ty: ty };
`
330
320
`let e = tcx.dcx().emit_err(err);
`
331
``
`-
self.saw_const_match_error.set(Some(e));
`
332
321
`// We errored. Signal that in the pattern, so that follow up errors can be silenced.
`
333
322
`PatKind::Error(e)
`
334
323
`}
`