Skip to content

Commit 9d7525b

Browse files
committed
Rename treat_byte_string_as_slice to make its new usage clear
1 parent 141c3ba commit 9d7525b

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

compiler/rustc_hir_typeck/src/pat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
549549
{
550550
let tcx = self.tcx;
551551
trace!(?hir_id.local_id, "polymorphic byte string lit");
552-
self.typeck_results.borrow_mut().treat_byte_string_as_slice.insert(hir_id.local_id);
552+
self.typeck_results.borrow_mut().lit_pat_type_adjusted.insert(hir_id.local_id);
553553
pat_ty =
554554
Ty::new_imm_ref(tcx, tcx.lifetimes.re_static, Ty::new_slice(tcx, tcx.types.u8));
555555
}
@@ -562,7 +562,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
562562
{
563563
let tcx = self.tcx;
564564
let expected = self.resolve_vars_if_possible(expected);
565-
self.typeck_results.borrow_mut().treat_byte_string_as_slice.insert(hir_id.local_id);
565+
self.typeck_results.borrow_mut().lit_pat_type_adjusted.insert(hir_id.local_id);
566566
pat_ty = match expected.kind() {
567567
ty::Adt(def, _) if tcx.is_lang_item(def.did(), LangItem::String) => expected,
568568
ty::Str => Ty::new_static_str(tcx),

compiler/rustc_hir_typeck/src/writeback.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7979
debug!("used_trait_imports({:?}) = {:?}", item_def_id, used_trait_imports);
8080
wbcx.typeck_results.used_trait_imports = used_trait_imports;
8181

82-
wbcx.typeck_results.treat_byte_string_as_slice =
83-
mem::take(&mut self.typeck_results.borrow_mut().treat_byte_string_as_slice);
82+
wbcx.typeck_results.lit_pat_type_adjusted =
83+
mem::take(&mut self.typeck_results.borrow_mut().lit_pat_type_adjusted);
8484

8585
debug!("writeback: typeck results for {:?} are {:#?}", item_def_id, wbcx.typeck_results);
8686

compiler/rustc_middle/src/ty/typeck_results.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,13 @@ pub struct TypeckResults<'tcx> {
199199
/// formatting modified file tests/ui/coroutine/retain-resume-ref.rs
200200
pub coroutine_stalled_predicates: FxIndexSet<(ty::Predicate<'tcx>, ObligationCause<'tcx>)>,
201201

202-
/// We sometimes treat byte string literals (which are of type `&[u8; N]`)
203-
/// as `&[u8]`, depending on the pattern in which they are used.
202+
/// We sometimes treat
203+
/// * byte string literals (which are of type `&[u8; N]`)
204+
/// as `&[u8]`, depending on the pattern in which they are used.
205+
/// * string literals (which are of type `&str`) as `String`
204206
/// This hashset records all instances where we behave
205207
/// like this to allow `const_to_pat` to reliably handle this situation.
206-
pub treat_byte_string_as_slice: ItemLocalSet,
208+
pub lit_pat_type_adjusted: ItemLocalSet,
207209

208210
/// Contains the data for evaluating the effect of feature `capture_disjoint_fields`
209211
/// on closure size.
@@ -239,7 +241,7 @@ impl<'tcx> TypeckResults<'tcx> {
239241
closure_fake_reads: Default::default(),
240242
rvalue_scopes: Default::default(),
241243
coroutine_stalled_predicates: Default::default(),
242-
treat_byte_string_as_slice: Default::default(),
244+
lit_pat_type_adjusted: Default::default(),
243245
closure_size_eval: Default::default(),
244246
offset_of_data: Default::default(),
245247
}

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct ConstToPat<'tcx> {
5858
span: Span,
5959
id: hir::HirId,
6060

61-
treat_byte_string_as_slice: bool,
61+
lit_pat_type_adjusted: bool,
6262

6363
c: ty::Const<'tcx>,
6464
}
@@ -71,9 +71,9 @@ impl<'tcx> ConstToPat<'tcx> {
7171
typing_env: pat_ctxt.typing_env,
7272
span,
7373
id,
74-
treat_byte_string_as_slice: pat_ctxt
74+
lit_pat_type_adjusted: pat_ctxt
7575
.typeck_results
76-
.treat_byte_string_as_slice
76+
.lit_pat_type_adjusted
7777
.contains(&id.local_id),
7878
c,
7979
}
@@ -108,7 +108,7 @@ impl<'tcx> ConstToPat<'tcx> {
108108
uv: ty::UnevaluatedConst<'tcx>,
109109
ty: Ty<'tcx>,
110110
) -> Box<Pat<'tcx>> {
111-
trace!(self.treat_byte_string_as_slice);
111+
trace!(self.lit_pat_type_adjusted);
112112

113113
// It's not *technically* correct to be revealing opaque types here as borrowcheck has
114114
// not run yet. However, CTFE itself uses `TypingMode::PostAnalysis` unconditionally even
@@ -220,7 +220,7 @@ impl<'tcx> ConstToPat<'tcx> {
220220
let tcx = self.tcx;
221221
let kind = match ty.kind() {
222222
ty::Adt(adt_def, _)
223-
if self.treat_byte_string_as_slice
223+
if self.lit_pat_type_adjusted
224224
&& tcx.is_lang_item(adt_def.did(), LangItem::String) =>
225225
{
226226
let ty = Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, tcx.types.str_);
@@ -320,7 +320,7 @@ impl<'tcx> ConstToPat<'tcx> {
320320
// has no negative effects on pattern matching, even if we're actually matching on
321321
// arrays.
322322
let pointee_ty = match *pointee_ty.kind() {
323-
ty::Array(elem_ty, _) if self.treat_byte_string_as_slice => {
323+
ty::Array(elem_ty, _) if self.lit_pat_type_adjusted => {
324324
Ty::new_slice(tcx, elem_ty)
325325
}
326326
_ => *pointee_ty,

0 commit comments

Comments
 (0)