Skip to content

Commit 137c171

Browse files
committed
Move str to libcore.
1 parent a35355c commit 137c171

File tree

96 files changed

+314
-278
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+314
-278
lines changed

src/libcore/str/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@ pub mod pattern;
2626
#[allow(missing_docs)]
2727
pub mod lossy;
2828

29-
// HACK(eddyb) private and not named `str` to avoid changing name resolution.
30-
#[cfg(not(bootstrap))]
31-
#[lang = "str"]
32-
struct Str([u8]);
29+
mod sealed {
30+
// HACK(eddyb) sealed away and not named `str` to avoid changing name resolution.
31+
// Only `pub` to avoid the privacy checker producing errors.
32+
#[cfg(not(bootstrap))]
33+
#[lang = "str"]
34+
#[stable(feature = "rust1", since = "1.0.0")]
35+
pub struct Str([u8]);
36+
37+
#[unstable(feature = "structural_match", issue = "31434")]
38+
impl crate::marker::StructuralPartialEq for str {}
39+
40+
#[unstable(feature = "structural_match", issue = "31434")]
41+
impl crate::marker::StructuralEq for str {}
42+
}
3343

3444
/// Parse a value from a string
3545
///

src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,9 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp
573573

574574
let ptr_metadata = |ty: Ty<'tcx>| match ty.kind {
575575
ty::Slice(typ) => Ok(vec_slice_metadata(cx, t, typ, unique_type_id, usage_site_span)),
576-
ty::Str => Ok(vec_slice_metadata(cx, t, cx.tcx.types.u8, unique_type_id, usage_site_span)),
576+
ty::Adt(def, _) if def.is_str() => {
577+
Ok(vec_slice_metadata(cx, t, cx.tcx.types.u8, unique_type_id, usage_site_span))
578+
}
577579
ty::Dynamic(..) => Ok(MetadataCreationResult::new(
578580
trait_pointer_metadata(cx, ty, Some(t), unique_type_id),
579581
false,
@@ -601,7 +603,9 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp
601603
ty::Array(typ, _) | ty::Slice(typ) => {
602604
fixed_vec_metadata(cx, unique_type_id, t, typ, usage_site_span)
603605
}
604-
ty::Str => fixed_vec_metadata(cx, unique_type_id, t, cx.tcx.types.i8, usage_site_span),
606+
ty::Adt(def, _) if def.is_str() => {
607+
fixed_vec_metadata(cx, unique_type_id, t, cx.tcx.types.i8, usage_site_span)
608+
}
605609
ty::Dynamic(..) => {
606610
MetadataCreationResult::new(trait_pointer_metadata(cx, t, None, unique_type_id), false)
607611
}

src/librustc_codegen_llvm/type_of.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ fn uncached_llvm_type<'a, 'tcx>(
5858
// FIXME(eddyb) producing readable type names for trait objects can result
5959
// in problematically distinct types due to HRTB and subtyping (see #47638).
6060
// ty::Dynamic(..) |
61-
ty::Foreign(..) |
62-
ty::Str => {
61+
ty::Foreign(..) => {
6362
let mut name = String::with_capacity(32);
6463
let printer = DefPathBasedNames::new(cx.tcx, true, true);
6564
printer.push_type_name(layout.ty, &mut name, false);

src/librustc_codegen_ssa/debuginfo/type_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn push_debuginfo_type_name<'tcx>(
3636
match t.kind {
3737
ty::Bool => output.push_str("bool"),
3838
ty::Char => output.push_str("char"),
39-
ty::Str => output.push_str("str"),
39+
ty::Adt(def, _) if def.is_str() => output.push_str("str"),
4040
ty::Never => output.push_str("!"),
4141
ty::Int(int_ty) => output.push_str(int_ty.name_str()),
4242
ty::Uint(uint_ty) => output.push_str(uint_ty.name_str()),

src/librustc_codegen_ssa/glue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2525
let vtable = info.unwrap();
2626
(meth::SIZE.get_usize(bx, vtable), meth::ALIGN.get_usize(bx, vtable))
2727
}
28-
ty::Slice(_) | ty::Str => {
28+
ty::Slice(_) => {
2929
let unit = layout.field(bx, 0);
3030
// The info in this case is the length of the str, so the size is that
3131
// times the unit size.

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
125125
return simple();
126126
}
127127
_ if !field.is_unsized() => return simple(),
128-
ty::Slice(..) | ty::Str | ty::Foreign(..) => return simple(),
128+
ty::Slice(..) | ty::Foreign(..) => return simple(),
129129
ty::Adt(def, _) => {
130130
if def.repr.packed() {
131131
// FIXME(eddyb) generalize the adjustment when we

src/librustc_codegen_ssa/traits/type_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
8686
let tail = self.tcx().struct_tail_erasing_lifetimes(ty, param_env);
8787
match tail.kind {
8888
ty::Foreign(..) => false,
89-
ty::Str | ty::Slice(..) | ty::Dynamic(..) => true,
89+
ty::Slice(..) | ty::Dynamic(..) => true,
9090
_ => bug!("unexpected unsized tail: {:?}", tail),
9191
}
9292
}

src/librustc_infer/infer/canonical/canonicalizer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
403403
| ty::Uint(..)
404404
| ty::Float(..)
405405
| ty::Adt(..)
406-
| ty::Str
407406
| ty::Error
408407
| ty::Array(..)
409408
| ty::Slice(..)

src/librustc_infer/infer/freshen.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
194194
| ty::Uint(..)
195195
| ty::Float(..)
196196
| ty::Adt(..)
197-
| ty::Str
198197
| ty::Error
199198
| ty::Array(..)
200199
| ty::Slice(..)

src/librustc_lint/types.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
617617
}
618618

619619
match ty.kind {
620+
ty::Adt(def, _) if def.is_str() => FfiUnsafe {
621+
ty,
622+
reason: "string slices have no C equivalent",
623+
help: Some("consider using `*const u8` and a length instead"),
624+
},
625+
620626
ty::Adt(def, substs) => {
621627
if def.is_phantom_data() {
622628
return FfiPhantom(ty);
@@ -822,12 +828,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
822828
FfiUnsafe { ty, reason: "trait objects have no C equivalent", help: None }
823829
}
824830

825-
ty::Str => FfiUnsafe {
826-
ty,
827-
reason: "string slices have no C equivalent",
828-
help: Some("consider using `*const u8` and a length instead"),
829-
},
830-
831831
ty::Tuple(..) => FfiUnsafe {
832832
ty,
833833
reason: "tuples have unspecified layout",

0 commit comments

Comments
 (0)