From 3eb1d9d473bf9a1d0cc50c9a952b45a7a1483f73 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 7 Apr 2020 18:40:35 +0300 Subject: [PATCH 1/3] Suffix "str" and "str_alloc" lang items with "_impl". --- src/liballoc/str.rs | 3 ++- src/libcore/str/mod.rs | 3 ++- src/librustc_hir/lang_items.rs | 4 ++-- src/librustc_typeck/coherence/inherent_impls.rs | 2 +- src/test/rustdoc/issue-23511.rs | 2 +- src/test/ui/single-primitive-inherent-impl.rs | 4 ++-- src/test/ui/single-primitive-inherent-impl.stderr | 2 +- 7 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 70860c09a2c31..914fda10c7a74 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -213,7 +213,8 @@ impl ToOwned for str { } /// Methods for string slices. -#[lang = "str_alloc"] +#[cfg_attr(bootstrap, lang = "str_alloc")] +#[cfg_attr(not(bootstrap), lang = "str_alloc_impl")] #[cfg(not(test))] impl str { /// Converts a `Box` into a `Box<[u8]>` without copying or allocating. diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index dc7637cfdb934..91da1e3f2f62f 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -2224,7 +2224,8 @@ fn slice_error_fail(s: &str, begin: usize, end: usize) -> ! { ); } -#[lang = "str"] +#[cfg_attr(bootstrap, lang = "str")] +#[cfg_attr(not(bootstrap), lang = "str_impl")] #[cfg(not(test))] impl str { /// Returns the length of `self`. diff --git a/src/librustc_hir/lang_items.rs b/src/librustc_hir/lang_items.rs index 89457009a8bfa..babc9e8369a82 100644 --- a/src/librustc_hir/lang_items.rs +++ b/src/librustc_hir/lang_items.rs @@ -127,10 +127,10 @@ language_item_table! { // Variant name, Name, Method name, Target; BoolImplItem, "bool", bool_impl, Target::Impl; CharImplItem, "char", char_impl, Target::Impl; - StrImplItem, "str", str_impl, Target::Impl; + StrImplItem, "str_impl", str_impl, Target::Impl; SliceImplItem, "slice", slice_impl, Target::Impl; SliceU8ImplItem, "slice_u8", slice_u8_impl, Target::Impl; - StrAllocImplItem, "str_alloc", str_alloc_impl, Target::Impl; + StrAllocImplItem, "str_alloc_impl", str_alloc_impl, Target::Impl; SliceAllocImplItem, "slice_alloc", slice_alloc_impl, Target::Impl; SliceU8AllocImplItem, "slice_u8_alloc", slice_u8_alloc_impl, Target::Impl; ConstPtrImplItem, "const_ptr", const_ptr_impl, Target::Impl; diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index 9ace9f424b74d..d2b11f790d403 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -87,7 +87,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> { def_id, lang_items.str_impl(), lang_items.str_alloc_impl(), - "str", + "str_impl", "str", item.span, ); diff --git a/src/test/rustdoc/issue-23511.rs b/src/test/rustdoc/issue-23511.rs index 4972a9fb47fff..e1a2614c53ec9 100644 --- a/src/test/rustdoc/issue-23511.rs +++ b/src/test/rustdoc/issue-23511.rs @@ -4,7 +4,7 @@ pub mod str { #![doc(primitive = "str")] - #[lang = "str_alloc"] + #[lang = "str_alloc_impl"] impl str { // @has search-index.js foo pub fn foo(&self) {} diff --git a/src/test/ui/single-primitive-inherent-impl.rs b/src/test/ui/single-primitive-inherent-impl.rs index baa23396c1624..3bfac3d51e7b9 100644 --- a/src/test/ui/single-primitive-inherent-impl.rs +++ b/src/test/ui/single-primitive-inherent-impl.rs @@ -5,9 +5,9 @@ #![no_std] // OK -#[lang = "str_alloc"] +#[lang = "str_alloc_impl"] impl str {} impl str { -//~^ error: only a single inherent implementation marked with `#[lang = "str"]` is allowed for the `str` primitive +//~^ error: only a single inherent implementation marked with `#[lang = "str_impl"]` is allowed for the `str` primitive } diff --git a/src/test/ui/single-primitive-inherent-impl.stderr b/src/test/ui/single-primitive-inherent-impl.stderr index d357afa3b3841..3e22d19078f14 100644 --- a/src/test/ui/single-primitive-inherent-impl.stderr +++ b/src/test/ui/single-primitive-inherent-impl.stderr @@ -1,4 +1,4 @@ -error[E0390]: only a single inherent implementation marked with `#[lang = "str"]` is allowed for the `str` primitive +error[E0390]: only a single inherent implementation marked with `#[lang = "str_impl"]` is allowed for the `str` primitive --> $DIR/single-primitive-inherent-impl.rs:11:1 | LL | / impl str { From a35355cf437a05d8bfafeac893c15cc0bc81fc7e Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 7 Apr 2020 18:41:19 +0300 Subject: [PATCH 2/3] Add newtype of `[u8]` as "str" lang item. --- src/libcore/str/mod.rs | 5 +++++ src/librustc_hir/lang_items.rs | 1 + 2 files changed, 6 insertions(+) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 91da1e3f2f62f..6f20faa51c7f2 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -26,6 +26,11 @@ pub mod pattern; #[allow(missing_docs)] pub mod lossy; +// HACK(eddyb) private and not named `str` to avoid changing name resolution. +#[cfg(not(bootstrap))] +#[lang = "str"] +struct Str([u8]); + /// Parse a value from a string /// /// `FromStr`'s [`from_str`] method is often used implicitly, through diff --git a/src/librustc_hir/lang_items.rs b/src/librustc_hir/lang_items.rs index babc9e8369a82..06bf0ffc88089 100644 --- a/src/librustc_hir/lang_items.rs +++ b/src/librustc_hir/lang_items.rs @@ -127,6 +127,7 @@ language_item_table! { // Variant name, Name, Method name, Target; BoolImplItem, "bool", bool_impl, Target::Impl; CharImplItem, "char", char_impl, Target::Impl; + StrItem, "str", str_type, Target::Struct; StrImplItem, "str_impl", str_impl, Target::Impl; SliceImplItem, "slice", slice_impl, Target::Impl; SliceU8ImplItem, "slice_u8", slice_u8_impl, Target::Impl; From 137c171fe1b65cda9eb01472bb4ced840d05d06d Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 8 Apr 2020 03:52:58 +0300 Subject: [PATCH 3/3] Move `str` to libcore. --- src/libcore/str/mod.rs | 18 +++++++-- .../debuginfo/metadata.rs | 8 +++- src/librustc_codegen_llvm/type_of.rs | 3 +- .../debuginfo/type_names.rs | 2 +- src/librustc_codegen_ssa/glue.rs | 2 +- src/librustc_codegen_ssa/mir/place.rs | 2 +- src/librustc_codegen_ssa/traits/type_.rs | 2 +- .../infer/canonical/canonicalizer.rs | 1 - src/librustc_infer/infer/freshen.rs | 1 - src/librustc_lint/types.rs | 12 +++--- src/librustc_middle/traits/query.rs | 1 - src/librustc_middle/ty/context.rs | 6 ++- src/librustc_middle/ty/diagnostics.rs | 4 +- src/librustc_middle/ty/error.rs | 5 ++- src/librustc_middle/ty/fast_reject.rs | 4 -- src/librustc_middle/ty/flags.rs | 1 - src/librustc_middle/ty/layout.rs | 13 +----- src/librustc_middle/ty/mod.rs | 11 +++++ src/librustc_middle/ty/outlives.rs | 1 - src/librustc_middle/ty/print/mod.rs | 1 - src/librustc_middle/ty/print/obsolete.rs | 2 +- src/librustc_middle/ty/print/pretty.rs | 14 ++++--- src/librustc_middle/ty/relate.rs | 1 - src/librustc_middle/ty/structural_impls.rs | 2 - src/librustc_middle/ty/sty.rs | 18 ++------- src/librustc_middle/ty/util.rs | 4 +- src/librustc_middle/ty/walk.rs | 1 - src/librustc_mir/const_eval/eval_queries.rs | 2 +- src/librustc_mir/interpret/eval_context.rs | 2 +- .../interpret/intrinsics/type_name.rs | 2 +- src/librustc_mir/interpret/operand.rs | 5 ++- src/librustc_mir/interpret/place.rs | 2 +- src/librustc_mir/interpret/validity.rs | 6 +-- src/librustc_mir/monomorphize/collector.rs | 2 +- src/librustc_mir/transform/add_retag.rs | 1 - .../build/expr/as_rvalue.rs | 7 +++- src/librustc_mir_build/hair/constant.rs | 4 +- src/librustc_mir_build/hair/pattern/_match.rs | 4 +- src/librustc_mir_build/hair/pattern/mod.rs | 4 +- src/librustc_privacy/lib.rs | 1 - src/librustc_symbol_mangling/v0.rs | 4 +- .../traits/coherence.rs | 1 - .../traits/error_reporting/mod.rs | 1 - .../traits/query/dropck_outlives.rs | 1 - src/librustc_trait_selection/traits/select.rs | 4 +- src/librustc_trait_selection/traits/wf.rs | 1 - src/librustc_traits/dropck_outlives.rs | 1 - src/librustc_traits/lowering/environment.rs | 1 - src/librustc_ty/ty.rs | 2 +- src/librustc_typeck/check/cast.rs | 2 +- src/librustc_typeck/check/demand.rs | 10 +++-- src/librustc_typeck/check/method/probe.rs | 14 +++---- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/check/op.rs | 13 +++--- src/librustc_typeck/check/regionck.rs | 2 +- .../coherence/inherent_impls.rs | 20 +++++----- src/librustc_typeck/variance/constraints.rs | 1 - src/librustdoc/clean/mod.rs | 2 +- src/test/ui/consts/const-unsized.stderr | 10 +++-- .../dst/dst-object-from-unsized-type.stderr | 5 ++- .../feature-gate-trivial_bounds.stderr | 10 +++-- src/test/ui/generator/sized-yield.stderr | 10 +++-- src/test/ui/issues/issue-10412.rs | 2 +- src/test/ui/issues/issue-10412.stderr | 5 ++- src/test/ui/issues/issue-14366.stderr | 5 ++- src/test/ui/issues/issue-14721.stderr | 2 +- src/test/ui/issues/issue-30240.rs | 4 +- src/test/ui/issues/issue-30240.stderr | 8 ++-- src/test/ui/issues/issue-33525.stderr | 4 +- src/test/ui/issues/issue-38954.stderr | 5 ++- src/test/ui/issues/issue-41229-ref-str.stderr | 5 ++- .../ui/mismatched_types/cast-rfc0401-str.rs | 8 ++++ .../mismatched_types/cast-rfc0401-str.stderr | 14 +++++++ src/test/ui/mismatched_types/cast-rfc0401.rs | 3 -- .../ui/mismatched_types/cast-rfc0401.stderr | 20 +++------- src/test/ui/no-type-for-node-ice.stderr | 2 +- src/test/ui/str/str-array-assignment.stderr | 9 ++--- src/test/ui/str/str-mut-idx.rs | 1 - src/test/ui/str/str-mut-idx.stderr | 29 ++++---------- src/test/ui/substs-ppaux.normal.stderr | 5 ++- src/test/ui/substs-ppaux.verbose.stderr | 5 ++- src/test/ui/symbol-names/basic.legacy.stderr | 4 +- src/test/ui/symbol-names/impl1.legacy.stderr | 12 +++--- .../ui/symbol-names/issue-60925.legacy.stderr | 4 +- .../trivial-bounds/trivial-bounds-leak.stderr | 5 ++- src/test/ui/union/union-unsized.stderr | 10 +++-- .../issue-50940-with-feature.rs | 2 +- .../issue-50940-with-feature.stderr | 5 ++- src/test/ui/unsized-locals/issue-50940.rs | 2 +- src/test/ui/unsized-locals/issue-50940.stderr | 5 ++- src/test/ui/unsized/unsized-enum2-str.rs | 12 ++++++ src/test/ui/unsized/unsized-enum2-str.stderr | 27 +++++++++++++ src/test/ui/unsized/unsized-enum2.rs | 4 +- src/test/ui/unsized/unsized-enum2.stderr | 40 +++++++------------ src/test/ui/unsized/unsized-fn-param.stderr | 20 ++++++---- src/test/ui/unsized5.stderr | 5 ++- 96 files changed, 314 insertions(+), 278 deletions(-) create mode 100644 src/test/ui/mismatched_types/cast-rfc0401-str.rs create mode 100644 src/test/ui/mismatched_types/cast-rfc0401-str.stderr create mode 100644 src/test/ui/unsized/unsized-enum2-str.rs create mode 100644 src/test/ui/unsized/unsized-enum2-str.stderr diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 6f20faa51c7f2..abbcb773efbad 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -26,10 +26,20 @@ pub mod pattern; #[allow(missing_docs)] pub mod lossy; -// HACK(eddyb) private and not named `str` to avoid changing name resolution. -#[cfg(not(bootstrap))] -#[lang = "str"] -struct Str([u8]); +mod sealed { + // HACK(eddyb) sealed away and not named `str` to avoid changing name resolution. + // Only `pub` to avoid the privacy checker producing errors. + #[cfg(not(bootstrap))] + #[lang = "str"] + #[stable(feature = "rust1", since = "1.0.0")] + pub struct Str([u8]); + + #[unstable(feature = "structural_match", issue = "31434")] + impl crate::marker::StructuralPartialEq for str {} + + #[unstable(feature = "structural_match", issue = "31434")] + impl crate::marker::StructuralEq for str {} +} /// Parse a value from a string /// diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 82cd858932747..b882ad8577000 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -573,7 +573,9 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp let ptr_metadata = |ty: Ty<'tcx>| match ty.kind { ty::Slice(typ) => Ok(vec_slice_metadata(cx, t, typ, unique_type_id, usage_site_span)), - ty::Str => Ok(vec_slice_metadata(cx, t, cx.tcx.types.u8, unique_type_id, usage_site_span)), + ty::Adt(def, _) if def.is_str() => { + Ok(vec_slice_metadata(cx, t, cx.tcx.types.u8, unique_type_id, usage_site_span)) + } ty::Dynamic(..) => Ok(MetadataCreationResult::new( trait_pointer_metadata(cx, ty, Some(t), unique_type_id), false, @@ -601,7 +603,9 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp ty::Array(typ, _) | ty::Slice(typ) => { fixed_vec_metadata(cx, unique_type_id, t, typ, usage_site_span) } - ty::Str => fixed_vec_metadata(cx, unique_type_id, t, cx.tcx.types.i8, usage_site_span), + ty::Adt(def, _) if def.is_str() => { + fixed_vec_metadata(cx, unique_type_id, t, cx.tcx.types.i8, usage_site_span) + } ty::Dynamic(..) => { MetadataCreationResult::new(trait_pointer_metadata(cx, t, None, unique_type_id), false) } diff --git a/src/librustc_codegen_llvm/type_of.rs b/src/librustc_codegen_llvm/type_of.rs index f475ea741c893..2f727fc3a1b59 100644 --- a/src/librustc_codegen_llvm/type_of.rs +++ b/src/librustc_codegen_llvm/type_of.rs @@ -58,8 +58,7 @@ fn uncached_llvm_type<'a, 'tcx>( // FIXME(eddyb) producing readable type names for trait objects can result // in problematically distinct types due to HRTB and subtyping (see #47638). // ty::Dynamic(..) | - ty::Foreign(..) | - ty::Str => { + ty::Foreign(..) => { let mut name = String::with_capacity(32); let printer = DefPathBasedNames::new(cx.tcx, true, true); printer.push_type_name(layout.ty, &mut name, false); diff --git a/src/librustc_codegen_ssa/debuginfo/type_names.rs b/src/librustc_codegen_ssa/debuginfo/type_names.rs index 6c0e4128e30f5..b163c1a3f5452 100644 --- a/src/librustc_codegen_ssa/debuginfo/type_names.rs +++ b/src/librustc_codegen_ssa/debuginfo/type_names.rs @@ -36,7 +36,7 @@ pub fn push_debuginfo_type_name<'tcx>( match t.kind { ty::Bool => output.push_str("bool"), ty::Char => output.push_str("char"), - ty::Str => output.push_str("str"), + ty::Adt(def, _) if def.is_str() => output.push_str("str"), ty::Never => output.push_str("!"), ty::Int(int_ty) => output.push_str(int_ty.name_str()), ty::Uint(uint_ty) => output.push_str(uint_ty.name_str()), diff --git a/src/librustc_codegen_ssa/glue.rs b/src/librustc_codegen_ssa/glue.rs index 5b086bc43ff35..b954e8aea750a 100644 --- a/src/librustc_codegen_ssa/glue.rs +++ b/src/librustc_codegen_ssa/glue.rs @@ -25,7 +25,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let vtable = info.unwrap(); (meth::SIZE.get_usize(bx, vtable), meth::ALIGN.get_usize(bx, vtable)) } - ty::Slice(_) | ty::Str => { + ty::Slice(_) => { let unit = layout.field(bx, 0); // The info in this case is the length of the str, so the size is that // times the unit size. diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs index 461695129c2f3..76a68e330c37b 100644 --- a/src/librustc_codegen_ssa/mir/place.rs +++ b/src/librustc_codegen_ssa/mir/place.rs @@ -125,7 +125,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { return simple(); } _ if !field.is_unsized() => return simple(), - ty::Slice(..) | ty::Str | ty::Foreign(..) => return simple(), + ty::Slice(..) | ty::Foreign(..) => return simple(), ty::Adt(def, _) => { if def.repr.packed() { // FIXME(eddyb) generalize the adjustment when we diff --git a/src/librustc_codegen_ssa/traits/type_.rs b/src/librustc_codegen_ssa/traits/type_.rs index 703479b74bef8..d61fcdf36298c 100644 --- a/src/librustc_codegen_ssa/traits/type_.rs +++ b/src/librustc_codegen_ssa/traits/type_.rs @@ -86,7 +86,7 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> { let tail = self.tcx().struct_tail_erasing_lifetimes(ty, param_env); match tail.kind { ty::Foreign(..) => false, - ty::Str | ty::Slice(..) | ty::Dynamic(..) => true, + ty::Slice(..) | ty::Dynamic(..) => true, _ => bug!("unexpected unsized tail: {:?}", tail), } } diff --git a/src/librustc_infer/infer/canonical/canonicalizer.rs b/src/librustc_infer/infer/canonical/canonicalizer.rs index 347a5ff6d56a4..fc1e83200a702 100644 --- a/src/librustc_infer/infer/canonical/canonicalizer.rs +++ b/src/librustc_infer/infer/canonical/canonicalizer.rs @@ -403,7 +403,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> { | ty::Uint(..) | ty::Float(..) | ty::Adt(..) - | ty::Str | ty::Error | ty::Array(..) | ty::Slice(..) diff --git a/src/librustc_infer/infer/freshen.rs b/src/librustc_infer/infer/freshen.rs index eeaa4c1661e4e..cb4f38ff757a8 100644 --- a/src/librustc_infer/infer/freshen.rs +++ b/src/librustc_infer/infer/freshen.rs @@ -194,7 +194,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> { | ty::Uint(..) | ty::Float(..) | ty::Adt(..) - | ty::Str | ty::Error | ty::Array(..) | ty::Slice(..) diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index aa805a2f2dbc0..77325b7f80db2 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -617,6 +617,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { } match ty.kind { + ty::Adt(def, _) if def.is_str() => FfiUnsafe { + ty, + reason: "string slices have no C equivalent", + help: Some("consider using `*const u8` and a length instead"), + }, + ty::Adt(def, substs) => { if def.is_phantom_data() { return FfiPhantom(ty); @@ -822,12 +828,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { FfiUnsafe { ty, reason: "trait objects have no C equivalent", help: None } } - ty::Str => FfiUnsafe { - ty, - reason: "string slices have no C equivalent", - help: Some("consider using `*const u8` and a length instead"), - }, - ty::Tuple(..) => FfiUnsafe { ty, reason: "tuples have unspecified layout", diff --git a/src/librustc_middle/traits/query.rs b/src/librustc_middle/traits/query.rs index 67f4b15f9194d..284310601cabb 100644 --- a/src/librustc_middle/traits/query.rs +++ b/src/librustc_middle/traits/query.rs @@ -219,7 +219,6 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { | ty::GeneratorWitness(..) | ty::RawPtr(_) | ty::Ref(..) - | ty::Str | ty::Foreign(..) | ty::Error => true, diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index 95d0c758d08de..18cdd4caaf9ea 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -1838,7 +1838,7 @@ macro_rules! sty_debug_print { for &Interned(t) in types { let variant = match t.kind { ty::Bool | ty::Char | ty::Int(..) | ty::Uint(..) | - ty::Float(..) | ty::Str | ty::Never => continue, + ty::Float(..) | ty::Never => continue, ty::Error => /* unimportant */ continue, $(ty::$variant(..) => &mut $variant,)* }; @@ -2165,7 +2165,9 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_str(self) -> Ty<'tcx> { - self.mk_ty(Str) + let def_id = self.require_lang_item(lang_items::StrItem, None); + let adt_def = self.adt_def(def_id); + self.mk_ty(Adt(adt_def, InternalSubsts::empty())) } #[inline] diff --git a/src/librustc_middle/ty/diagnostics.rs b/src/librustc_middle/ty/diagnostics.rs index d1eb21e25ffaf..3245e105b0ddc 100644 --- a/src/librustc_middle/ty/diagnostics.rs +++ b/src/librustc_middle/ty/diagnostics.rs @@ -10,7 +10,6 @@ impl<'tcx> TyS<'tcx> { match self.kind { Bool | Char - | Str | Int(_) | Uint(_) | Float(_) @@ -18,6 +17,7 @@ impl<'tcx> TyS<'tcx> { | Infer(InferTy::FloatVar(_)) | Infer(InferTy::FreshIntTy(_)) | Infer(InferTy::FreshFloatTy(_)) => true, + Adt(def, _) if def.is_str() => true, _ => false, } } @@ -28,7 +28,6 @@ impl<'tcx> TyS<'tcx> { match self.kind { Bool | Char - | Str | Int(_) | Uint(_) | Float(_) @@ -36,6 +35,7 @@ impl<'tcx> TyS<'tcx> { | Infer(InferTy::FloatVar(_)) | Infer(InferTy::FreshIntTy(_)) | Infer(InferTy::FreshFloatTy(_)) => true, + Adt(def, _) if def.is_str() => true, Ref(_, x, _) | Array(x, _) | Slice(x) => x.peel_refs().is_simple_ty(), Tuple(tys) if tys.is_empty() => true, _ => false, diff --git a/src/librustc_middle/ty/error.rs b/src/librustc_middle/ty/error.rs index d0bc0d5fabfae..a75ffc6cc3927 100644 --- a/src/librustc_middle/ty/error.rs +++ b/src/librustc_middle/ty/error.rs @@ -216,9 +216,10 @@ impl<'tcx> TypeError<'tcx> { impl<'tcx> ty::TyS<'tcx> { pub fn sort_string(&self, tcx: TyCtxt<'_>) -> Cow<'static, str> { match self.kind { - ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str | ty::Never => { + ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Never => { format!("`{}`", self).into() } + ty::Adt(def, _) if def.is_str() => "`str`".into(), ty::Tuple(ref tys) if tys.is_empty() => format!("`{}`", self).into(), ty::Adt(def, _) => format!("{} `{}`", def.descr(), tcx.def_path_str(def.did)).into(), @@ -288,8 +289,8 @@ impl<'tcx> ty::TyS<'tcx> { | ty::Int(_) | ty::Uint(_) | ty::Float(_) - | ty::Str | ty::Never => "type".into(), + ty::Adt(def, _) if def.is_str() => "type".into(), ty::Tuple(ref tys) if tys.is_empty() => "unit type".into(), ty::Adt(def, _) => def.descr().into(), ty::Foreign(_) => "extern type".into(), diff --git a/src/librustc_middle/ty/fast_reject.rs b/src/librustc_middle/ty/fast_reject.rs index 2a937d6581d6a..7bb73e58405f0 100644 --- a/src/librustc_middle/ty/fast_reject.rs +++ b/src/librustc_middle/ty/fast_reject.rs @@ -28,7 +28,6 @@ where UintSimplifiedType(ast::UintTy), FloatSimplifiedType(ast::FloatTy), AdtSimplifiedType(D), - StrSimplifiedType, ArraySimplifiedType, PtrSimplifiedType, NeverSimplifiedType, @@ -67,7 +66,6 @@ pub fn simplify_type( ty::Uint(uint_type) => Some(UintSimplifiedType(uint_type)), ty::Float(float_type) => Some(FloatSimplifiedType(float_type)), ty::Adt(def, _) => Some(AdtSimplifiedType(def.did)), - ty::Str => Some(StrSimplifiedType), ty::Array(..) | ty::Slice(_) => Some(ArraySimplifiedType), ty::RawPtr(_) => Some(PtrSimplifiedType), ty::Dynamic(ref trait_info, ..) => match trait_info.principal_def_id() { @@ -122,7 +120,6 @@ impl SimplifiedTypeGen { UintSimplifiedType(t) => UintSimplifiedType(t), FloatSimplifiedType(t) => FloatSimplifiedType(t), AdtSimplifiedType(d) => AdtSimplifiedType(map(d)), - StrSimplifiedType => StrSimplifiedType, ArraySimplifiedType => ArraySimplifiedType, PtrSimplifiedType => PtrSimplifiedType, NeverSimplifiedType => NeverSimplifiedType, @@ -149,7 +146,6 @@ where match *self { BoolSimplifiedType | CharSimplifiedType - | StrSimplifiedType | ArraySimplifiedType | PtrSimplifiedType | NeverSimplifiedType diff --git a/src/librustc_middle/ty/flags.rs b/src/librustc_middle/ty/flags.rs index 99a6511b297ac..f22543949309f 100644 --- a/src/librustc_middle/ty/flags.rs +++ b/src/librustc_middle/ty/flags.rs @@ -67,7 +67,6 @@ impl FlagComputation { | &ty::Float(_) | &ty::Uint(_) | &ty::Never - | &ty::Str | &ty::Foreign(..) => {} // You might think that we could just return Error for diff --git a/src/librustc_middle/ty/layout.rs b/src/librustc_middle/ty/layout.rs index 5740f8cc091c4..876cdb55caa68 100644 --- a/src/librustc_middle/ty/layout.rs +++ b/src/librustc_middle/ty/layout.rs @@ -542,7 +542,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { ty::Foreign(..) => { return Ok(tcx.intern_layout(Layout::scalar(self, data_ptr))); } - ty::Slice(_) | ty::Str => scalar_unit(Int(dl.ptr_sized_integer(), false)), + ty::Slice(_) => scalar_unit(Int(dl.ptr_sized_integer(), false)), ty::Dynamic(..) => { let mut vtable = scalar_unit(Pointer); vtable.valid_range = 1..=*vtable.valid_range.end(); @@ -597,14 +597,6 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { size: Size::ZERO, }) } - ty::Str => tcx.intern_layout(Layout { - variants: Variants::Single { index: VariantIdx::new(0) }, - fields: FieldsShape::Array { stride: Size::from_bytes(1), count: 0 }, - abi: Abi::Aggregate { sized: false }, - largest_niche: None, - align: dl.i8_align, - size: Size::ZERO, - }), // Odd unit types. ty::FnDef(..) => univariant(&[], &ReprOptions::default(), StructKind::AlwaysSized)?, @@ -2069,7 +2061,7 @@ where } match tcx.struct_tail_erasing_lifetimes(pointee, cx.param_env()).kind { - ty::Slice(_) | ty::Str => tcx.types.usize, + ty::Slice(_) => tcx.types.usize, ty::Dynamic(_, _) => { tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_array(tcx.types.usize, 3)) /* FIXME: use actual fn pointers @@ -2092,7 +2084,6 @@ where // Arrays and slices. ty::Array(element, _) | ty::Slice(element) => element, - ty::Str => tcx.types.u8, // Tuples, generators and closures. ty::Closure(_, ref substs) => substs.as_closure().upvar_tys().nth(i).unwrap(), diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 1870856150f50..7a196216d7f45 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1864,6 +1864,8 @@ bitflags! { /// Indicates whether the variant list of this ADT is `#[non_exhaustive]`. /// (i.e., this flag is never set unless this ADT is an enum). const IS_VARIANT_LIST_NON_EXHAUSTIVE = 1 << 10; + /// Indicates whether the type is `str`. + const IS_STR = 1 << 11; } } @@ -2254,6 +2256,9 @@ impl<'tcx> AdtDef { if Some(did) == tcx.lang_items().rc() { flags |= AdtFlags::IS_RC; } + if Some(did) == tcx.lang_items().str_type() { + flags |= AdtFlags::IS_STR; + } AdtDef { did, variants, flags, repr } } @@ -2354,6 +2359,12 @@ impl<'tcx> AdtDef { self.flags.contains(AdtFlags::IS_MANUALLY_DROP) } + /// Returns `true` if this is `str`. + #[inline] + pub fn is_str(&self) -> bool { + self.flags.contains(AdtFlags::IS_STR) + } + /// Returns `true` if this type has a destructor. pub fn has_dtor(&self, tcx: TyCtxt<'tcx>) -> bool { self.destructor(tcx).is_some() diff --git a/src/librustc_middle/ty/outlives.rs b/src/librustc_middle/ty/outlives.rs index 950539fbb0a16..b9fba116ce0b4 100644 --- a/src/librustc_middle/ty/outlives.rs +++ b/src/librustc_middle/ty/outlives.rs @@ -138,7 +138,6 @@ fn compute_components(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, out: &mut SmallVec<[Compo ty::Adt(..) | // OutlivesNominalType ty::Opaque(..) | // OutlivesNominalType (ish) ty::Foreign(..) | // OutlivesNominalType - ty::Str | // OutlivesScalar (ish) ty::Array(..) | // ... ty::Slice(..) | // ... ty::RawPtr(..) | // ... diff --git a/src/librustc_middle/ty/print/mod.rs b/src/librustc_middle/ty/print/mod.rs index a932f334dde68..5ae52106632ba 100644 --- a/src/librustc_middle/ty/print/mod.rs +++ b/src/librustc_middle/ty/print/mod.rs @@ -290,7 +290,6 @@ pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option { | ty::Char | ty::Int(_) | ty::Uint(_) - | ty::Str | ty::FnPtr(_) | ty::Projection(_) | ty::Placeholder(..) diff --git a/src/librustc_middle/ty/print/obsolete.rs b/src/librustc_middle/ty/print/obsolete.rs index 757a8bd23f62b..d4115870ca9fc 100644 --- a/src/librustc_middle/ty/print/obsolete.rs +++ b/src/librustc_middle/ty/print/obsolete.rs @@ -36,7 +36,7 @@ impl DefPathBasedNames<'tcx> { match t.kind { ty::Bool => output.push_str("bool"), ty::Char => output.push_str("char"), - ty::Str => output.push_str("str"), + ty::Adt(def, _) if def.is_str() => output.push_str("str"), ty::Never => output.push_str("!"), ty::Int(ty) => output.push_str(ty.name_str()), ty::Uint(ty) => output.push_str(ty.name_str()), diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs index a8b7b6a4b97a4..8f26404171113 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -242,7 +242,12 @@ pub trait PrettyPrinter<'tcx>: /// If possible, this returns a global path resolving to `def_id` that is visible /// from at least one local module, and returns `true`. If the crate defining `def_id` is /// declared with an `extern crate`, the path is guaranteed to use the `extern crate`. - fn try_print_visible_def_path(self, def_id: DefId) -> Result<(Self, bool), Self::Error> { + fn try_print_visible_def_path(mut self, def_id: DefId) -> Result<(Self, bool), Self::Error> { + if Some(def_id) == self.tcx().lang_items().str_type() { + write!(self, "str")?; + return Ok((self, true)); + } + let mut callers = Vec::new(); self.try_print_visible_def_path_recur(def_id, &mut callers) } @@ -427,7 +432,6 @@ pub trait PrettyPrinter<'tcx>: | ty::Foreign(_) | ty::Bool | ty::Char - | ty::Str | ty::Int(_) | ty::Uint(_) | ty::Float(_) => { @@ -479,6 +483,7 @@ pub trait PrettyPrinter<'tcx>: ty::Int(t) => p!(write("{}", t.name_str())), ty::Uint(t) => p!(write("{}", t.name_str())), ty::Float(t) => p!(write("{}", t.name_str())), + ty::Adt(def, _) if def.is_str() => p!(write("str")), ty::RawPtr(ref tm) => { p!(write( "*{} ", @@ -612,7 +617,6 @@ pub trait PrettyPrinter<'tcx>: Ok(self) })?); } - ty::Str => p!(write("str")), ty::Generator(did, substs, movability) => { match movability { hir::Movability::Movable => p!(write("[generator")), @@ -1154,8 +1158,8 @@ pub trait PrettyPrinter<'tcx>: } ( ConstValue::Slice { data, start, end }, - ty::Ref(_, ty::TyS { kind: ty::Str, .. }, _), - ) => { + ty::Ref(_, ty::TyS { kind: ty::Adt(def, _), .. }, _), + ) if def.is_str() => { // The `inspect` here is okay since we checked the bounds, and there are no // relocations (we have an active `str` reference here). We don't use this // result to affect interpreter execution. diff --git a/src/librustc_middle/ty/relate.rs b/src/librustc_middle/ty/relate.rs index 5ff77d073d388..3901f2ad03349 100644 --- a/src/librustc_middle/ty/relate.rs +++ b/src/librustc_middle/ty/relate.rs @@ -362,7 +362,6 @@ pub fn super_relate_tys>( | (&ty::Int(_), _) | (&ty::Uint(_), _) | (&ty::Float(_), _) - | (&ty::Str, _) if a == b => { Ok(a) diff --git a/src/librustc_middle/ty/structural_impls.rs b/src/librustc_middle/ty/structural_impls.rs index 0ac4466d34f5c..67583e5bd9800 100644 --- a/src/librustc_middle/ty/structural_impls.rs +++ b/src/librustc_middle/ty/structural_impls.rs @@ -894,7 +894,6 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> { ty::Bool | ty::Char - | ty::Str | ty::Int(_) | ty::Uint(_) | ty::Float(_) @@ -937,7 +936,6 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> { ty::Bool | ty::Char - | ty::Str | ty::Int(_) | ty::Uint(_) | ty::Float(_) diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index f09327886872c..e845c492416b1 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -116,9 +116,6 @@ pub enum TyKind<'tcx> { /// An unsized FFI type that is opaque to Rust. Written as `extern type T`. Foreign(DefId), - /// The pointee of a string slice. Written as `str`. - Str, - /// An array with the given length. Written as `[T; n]`. Array(Ty<'tcx>, &'tcx ty::Const<'tcx>), @@ -1770,7 +1767,7 @@ impl<'tcx> TyS<'tcx> { /// Returns `true` if this type is a `str`. #[inline] pub fn is_str(&self) -> bool { - self.kind == Str + if let Adt(def, _) = self.kind { def.is_str() } else { false } } #[inline] @@ -1785,7 +1782,8 @@ impl<'tcx> TyS<'tcx> { pub fn is_slice(&self) -> bool { match self.kind { RawPtr(TypeAndMut { ty, .. }) | Ref(_, ty, _) => match ty.kind { - Slice(_) | Str => true, + Slice(_) => true, + Adt(def, _) if def.is_str() => true, _ => false, }, _ => false, @@ -1800,14 +1798,6 @@ impl<'tcx> TyS<'tcx> { } } - pub fn sequence_element_type(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { - match self.kind { - Array(ty, _) | Slice(ty) => ty, - Str => tcx.mk_mach_uint(ast::UintTy::U8), - _ => bug!("`sequence_element_type` called on non-sequence value: {}", self), - } - } - pub fn simd_type(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match self.kind { Adt(def, substs) => def.non_enum_variant().fields[0].ty(tcx, substs), @@ -2190,7 +2180,7 @@ impl<'tcx> TyS<'tcx> { | ty::Never | ty::Error => true, - ty::Str | ty::Slice(_) | ty::Dynamic(..) | ty::Foreign(..) => false, + ty::Slice(_) | ty::Dynamic(..) | ty::Foreign(..) => false, ty::Tuple(tys) => tys.iter().all(|ty| ty.expect_ty().is_trivially_sized(tcx)), diff --git a/src/librustc_middle/ty/util.rs b/src/librustc_middle/ty/util.rs index 86575b013335c..ecbbbe3b4bafc 100644 --- a/src/librustc_middle/ty/util.rs +++ b/src/librustc_middle/ty/util.rs @@ -722,7 +722,6 @@ impl<'tcx> ty::TyS<'tcx> { | ty::Float(_) | ty::Bool | ty::Char - | ty::Str | ty::Never | ty::Ref(..) | ty::RawPtr(_) @@ -1041,8 +1040,7 @@ pub fn needs_drop_components( | ty::Char | ty::GeneratorWitness(..) | ty::RawPtr(_) - | ty::Ref(..) - | ty::Str => Ok(SmallVec::new()), + | ty::Ref(..) => Ok(SmallVec::new()), // Foreign types can never have destructors. ty::Foreign(..) => Ok(SmallVec::new()), diff --git a/src/librustc_middle/ty/walk.rs b/src/librustc_middle/ty/walk.rs index c7a317f39ad71..4816bcc5e4968 100644 --- a/src/librustc_middle/ty/walk.rs +++ b/src/librustc_middle/ty/walk.rs @@ -104,7 +104,6 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) | ty::Int(_) | ty::Uint(_) | ty::Float(_) - | ty::Str | ty::Infer(_) | ty::Param(_) | ty::Never diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs index 97cdb32e2cdf7..d7d28bbed9782 100644 --- a/src/librustc_mir/const_eval/eval_queries.rs +++ b/src/librustc_mir/const_eval/eval_queries.rs @@ -110,7 +110,7 @@ pub(super) fn op_to_const<'tcx>( Abi::ScalarPair(..) => match op.layout.ty.kind { ty::Ref(_, inner, _) => match inner.kind { ty::Slice(elem) => elem == ecx.tcx.types.u8, - ty::Str => true, + ty::Adt(def, _) if def.is_str() => true, _ => false, }, _ => false, diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 72d20644fe8b2..8888057d780e0 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -548,7 +548,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Ok(Some(self.read_size_and_align_from_vtable(vtable)?)) } - ty::Slice(_) | ty::Str => { + ty::Slice(_) => { let len = metadata.unwrap_meta().to_machine_usize(self)?; let elem = layout.field(self, 0)?; diff --git a/src/librustc_mir/interpret/intrinsics/type_name.rs b/src/librustc_mir/interpret/intrinsics/type_name.rs index b81a454cac408..ecaab964dc07e 100644 --- a/src/librustc_mir/interpret/intrinsics/type_name.rs +++ b/src/librustc_mir/interpret/intrinsics/type_name.rs @@ -39,7 +39,6 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { | ty::Int(_) | ty::Uint(_) | ty::Float(_) - | ty::Str | ty::Array(_, _) | ty::Slice(_) | ty::RawPtr(_) @@ -48,6 +47,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { | ty::Never | ty::Tuple(_) | ty::Dynamic(_, _) => self.pretty_print_type(ty), + ty::Adt(def, _) if def.is_str() => self.pretty_print_type(ty), // Placeholders (all printed as `_` to uniformize them). ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error => { diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 3741f31927e94..f9d7c3b128814 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -314,8 +314,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Turn the wide MPlace into a string (must already be dereferenced!) pub fn read_str(&self, mplace: MPlaceTy<'tcx, M::PointerTag>) -> InterpResult<'tcx, &str> { - let len = mplace.len(self)?; - let bytes = self.memory.read_bytes(mplace.ptr, Size::from_bytes(len))?; + let bytes_mplace = self.mplace_field(mplace, 0)?; + let len = bytes_mplace.len(self)?; + let bytes = self.memory.read_bytes(bytes_mplace.ptr, Size::from_bytes(len))?; let str = ::std::str::from_utf8(bytes) .map_err(|err| err_ub_format!("this string is not valid UTF-8: {}", err))?; Ok(str) diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 828df9a0930f5..a350adf987914 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -211,7 +211,7 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> { if self.layout.is_unsized() { // We need to consult `meta` metadata match self.layout.ty.kind { - ty::Slice(..) | ty::Str => self.mplace.meta.unwrap_meta().to_machine_usize(cx), + ty::Slice(..) => self.mplace.meta.unwrap_meta().to_machine_usize(cx), _ => bug!("len not supported on unsized type {:?}", self.layout.ty), } } else { diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index 701e394415bbd..7aa0e744bc959 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -294,7 +294,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M ); // FIXME: More checks for the vtable. } - ty::Slice(..) | ty::Str => { + ty::Slice(..) => { let _len = try_validation!( meta.unwrap_meta().to_machine_usize(self.ecx), "non-integer slice length in wide pointer", @@ -519,7 +519,6 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M | ty::Tuple(..) | ty::Array(..) | ty::Slice(..) - | ty::Str | ty::Dynamic(..) | ty::Closure(..) | ty::Generator(..) => Ok(false), @@ -715,7 +714,8 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> fields: impl Iterator>, ) -> InterpResult<'tcx> { match op.layout.ty.kind { - ty::Str => { + // FIXME(eddyb) does this belong here? + ty::Adt(def, _) if def.is_str() => { let mplace = op.assert_mem_place(self.ecx); // strings are never immediate try_validation!( self.ecx.read_str(mplace), diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index d8ceda96a25e1..ced884bc5167d 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -809,7 +809,7 @@ fn find_vtable_types_for_unsizing<'tcx>( let tail = tcx.struct_tail_erasing_lifetimes(ty, param_env); match tail.kind { ty::Foreign(..) => false, - ty::Str | ty::Slice(..) | ty::Dynamic(..) => true, + ty::Slice(..) | ty::Dynamic(..) => true, _ => bug!("unexpected unsized tail: {:?}", tail), } }; diff --git a/src/librustc_mir/transform/add_retag.rs b/src/librustc_mir/transform/add_retag.rs index 5c016b0c515af..2903fed73a258 100644 --- a/src/librustc_mir/transform/add_retag.rs +++ b/src/librustc_mir/transform/add_retag.rs @@ -44,7 +44,6 @@ fn may_be_reference(ty: Ty<'tcx>) -> bool { | ty::Uint(_) | ty::RawPtr(..) | ty::FnPtr(..) - | ty::Str | ty::FnDef(..) | ty::Never => false, // References diff --git a/src/librustc_mir_build/build/expr/as_rvalue.rs b/src/librustc_mir_build/build/expr/as_rvalue.rs index 20ef763e90cb4..b6eab388d61fd 100644 --- a/src/librustc_mir_build/build/expr/as_rvalue.rs +++ b/src/librustc_mir_build/build/expr/as_rvalue.rs @@ -154,13 +154,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // to the same MIR as `let x = ();`. // first process the set of fields - let el_ty = expr.ty.sequence_element_type(this.hir.tcx()); + let elem_ty = match expr.ty.kind { + ty::Array(elem_ty, _) => elem_ty, + _ => span_bug!(expr_span, "`ExprKind::Array` of non-aray type `{}`", expr.ty), + }; let fields: Vec<_> = fields .into_iter() .map(|f| unpack!(block = this.as_operand(block, scope, f))) .collect(); - block.and(Rvalue::Aggregate(box AggregateKind::Array(el_ty), fields)) + block.and(Rvalue::Aggregate(box AggregateKind::Array(elem_ty), fields)) } ExprKind::Tuple { fields } => { // see (*) above diff --git a/src/librustc_mir_build/hair/constant.rs b/src/librustc_mir_build/hair/constant.rs index e5af0b5bd6bed..94becb5f319ea 100644 --- a/src/librustc_mir_build/hair/constant.rs +++ b/src/librustc_mir_build/hair/constant.rs @@ -22,7 +22,9 @@ crate fn lit_to_const<'tcx>( }; let lit = match (lit, &ty.kind) { - (ast::LitKind::Str(s, _), ty::Ref(_, TyS { kind: ty::Str, .. }, _)) => { + (ast::LitKind::Str(s, _), ty::Ref(_, TyS { kind: ty::Adt(def, _), .. }, _)) + if def.is_str() => + { let s = s.as_str(); let allocation = Allocation::from_byte_aligned_bytes(s.as_bytes()); let allocation = tcx.intern_const_alloc(allocation); diff --git a/src/librustc_mir_build/hair/pattern/_match.rs b/src/librustc_mir_build/hair/pattern/_match.rs index 51ba84416d64d..914d08c7b41b1 100644 --- a/src/librustc_mir_build/hair/pattern/_match.rs +++ b/src/librustc_mir_build/hair/pattern/_match.rs @@ -311,9 +311,7 @@ impl<'tcx> LiteralExpander<'tcx> { } } // fat pointers stay the same - (ConstValue::Slice { .. }, _, _) - | (_, ty::Slice(_), ty::Slice(_)) - | (_, ty::Str, ty::Str) => val, + (ConstValue::Slice { .. }, _, _) | (_, ty::Slice(_), ty::Slice(_)) => val, // FIXME(oli-obk): this is reachable for `const FOO: &&&u32 = &&&42;` being used _ => bug!("cannot deref {:#?}, {} -> {}", val, crty, rty), } diff --git a/src/librustc_mir_build/hair/pattern/mod.rs b/src/librustc_mir_build/hair/pattern/mod.rs index 2b6d8e920f5ed..8657911ef4d88 100644 --- a/src/librustc_mir_build/hair/pattern/mod.rs +++ b/src/librustc_mir_build/hair/pattern/mod.rs @@ -1033,7 +1033,7 @@ crate fn compare_const_vals<'tcx>( let b_bits = b.try_eval_bits(tcx, param_env, ty); if let (Some(a), Some(b)) = (a_bits, b_bits) { - use ::rustc_apfloat::Float; + use rustc_apfloat::Float; return match ty.kind { ty::Float(ast::FloatTy::F32) => { let l = ::rustc_apfloat::ieee::Single::from_bits(a); @@ -1057,7 +1057,7 @@ crate fn compare_const_vals<'tcx>( }; } - if let ty::Str = ty.kind { + if ty.is_str() { if let ( ty::ConstKind::Value(a_val @ ConstValue::Slice { .. }), ty::ConstKind::Value(b_val @ ConstValue::Slice { .. }), diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 567022fe4052f..04d6962eef980 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -211,7 +211,6 @@ where | ty::Int(..) | ty::Uint(..) | ty::Float(..) - | ty::Str | ty::Never | ty::Array(..) | ty::Slice(..) diff --git a/src/librustc_symbol_mangling/v0.rs b/src/librustc_symbol_mangling/v0.rs index e3358c5706f53..10d99ace4c034 100644 --- a/src/librustc_symbol_mangling/v0.rs +++ b/src/librustc_symbol_mangling/v0.rs @@ -326,7 +326,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> { let basic_type = match ty.kind { ty::Bool => "b", ty::Char => "c", - ty::Str => "e", + ty::Adt(def, _) if def.is_str() => "e", ty::Tuple(_) if ty.is_unit() => "u", ty::Int(IntTy::I8) => "a", ty::Int(IntTy::I16) => "s", @@ -361,7 +361,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> { match ty.kind { // Basic types, handled above. - ty::Bool | ty::Char | ty::Str | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Never => { + ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Never => { unreachable!() } ty::Tuple(_) if ty.is_unit() => unreachable!(), diff --git a/src/librustc_trait_selection/traits/coherence.rs b/src/librustc_trait_selection/traits/coherence.rs index f1311382c5447..c52169229133d 100644 --- a/src/librustc_trait_selection/traits/coherence.rs +++ b/src/librustc_trait_selection/traits/coherence.rs @@ -495,7 +495,6 @@ fn ty_is_non_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> Option> | ty::Int(..) | ty::Uint(..) | ty::Float(..) - | ty::Str | ty::FnDef(..) | ty::FnPtr(_) | ty::Array(..) diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index f0a157b377076..97d657d34204d 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -1123,7 +1123,6 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { match t.kind { ty::Bool => Some(0), ty::Char => Some(1), - ty::Str => Some(2), ty::Int(..) | ty::Uint(..) | ty::Infer(ty::IntVar(..)) => Some(3), ty::Float(..) | ty::Infer(ty::FloatVar(..)) => Some(4), ty::Ref(..) | ty::RawPtr(..) => Some(5), diff --git a/src/librustc_trait_selection/traits/query/dropck_outlives.rs b/src/librustc_trait_selection/traits/query/dropck_outlives.rs index 64cc5fadeab0e..479bb7fd032b1 100644 --- a/src/librustc_trait_selection/traits/query/dropck_outlives.rs +++ b/src/librustc_trait_selection/traits/query/dropck_outlives.rs @@ -99,7 +99,6 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { | ty::GeneratorWitness(..) | ty::RawPtr(_) | ty::Ref(..) - | ty::Str | ty::Foreign(..) | ty::Error => true, diff --git a/src/librustc_trait_selection/traits/select.rs b/src/librustc_trait_selection/traits/select.rs index 84c264f06db28..4ce75f472e519 100644 --- a/src/librustc_trait_selection/traits/select.rs +++ b/src/librustc_trait_selection/traits/select.rs @@ -2160,7 +2160,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { Where(ty::Binder::dummy(Vec::new())) } - ty::Str | ty::Slice(_) | ty::Dynamic(..) | ty::Foreign(..) => None, + ty::Slice(_) | ty::Dynamic(..) | ty::Foreign(..) => None, ty::Tuple(tys) => { Where(ty::Binder::bind(tys.last().into_iter().map(|k| k.expect_ty()).collect())) @@ -2217,7 +2217,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } ty::Dynamic(..) - | ty::Str | ty::Slice(..) | ty::Generator(..) | ty::GeneratorWitness(..) @@ -2281,7 +2280,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Float(_) | ty::FnDef(..) | ty::FnPtr(_) - | ty::Str | ty::Error | ty::Infer(ty::IntVar(_)) | ty::Infer(ty::FloatVar(_)) diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index 6b38749e1e70a..4a604aa7251fd 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -413,7 +413,6 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { | ty::Uint(..) | ty::Float(..) | ty::Error - | ty::Str | ty::GeneratorWitness(..) | ty::Never | ty::Param(_) diff --git a/src/librustc_traits/dropck_outlives.rs b/src/librustc_traits/dropck_outlives.rs index 93b15e146ec10..c68b775296b1e 100644 --- a/src/librustc_traits/dropck_outlives.rs +++ b/src/librustc_traits/dropck_outlives.rs @@ -178,7 +178,6 @@ fn dtorck_constraint_for_ty<'tcx>( | ty::Int(_) | ty::Uint(_) | ty::Float(_) - | ty::Str | ty::Never | ty::Foreign(..) | ty::RawPtr(..) diff --git a/src/librustc_traits/lowering/environment.rs b/src/librustc_traits/lowering/environment.rs index 612ab9b70ebc9..0d9edbcf7c712 100644 --- a/src/librustc_traits/lowering/environment.rs +++ b/src/librustc_traits/lowering/environment.rs @@ -61,7 +61,6 @@ impl ClauseVisitor<'a, 'tcx> { | ty::Int(..) | ty::Uint(..) | ty::Float(..) - | ty::Str | ty::Array(..) | ty::Slice(..) | ty::RawPtr(..) diff --git a/src/librustc_ty/ty.rs b/src/librustc_ty/ty.rs index aefe61f60b87a..3b112a7dfd220 100644 --- a/src/librustc_ty/ty.rs +++ b/src/librustc_ty/ty.rs @@ -20,7 +20,7 @@ fn sized_constraint_for_ty<'tcx>( Bool | Char | Int(..) | Uint(..) | Float(..) | RawPtr(..) | Ref(..) | FnDef(..) | FnPtr(_) | Array(..) | Closure(..) | Generator(..) | Never => vec![], - Str | Dynamic(..) | Slice(_) | Foreign(..) | Error | GeneratorWitness(..) => { + Dynamic(..) | Slice(_) | Foreign(..) | Error | GeneratorWitness(..) => { // these are never sized - return the target type vec![ty] } diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 5de0184f2bba9..bac87529f78ce 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -97,7 +97,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } Ok(match t.kind { - ty::Slice(_) | ty::Str => Some(PointerKind::Length), + ty::Slice(_) => Some(PointerKind::Length), ty::Dynamic(ref tty, ..) => Some(PointerKind::Vtable(tty.principal_def_id())), ty::Adt(def, substs) if def.is_struct() => match def.non_enum_variant().fields.last() { None => Some(PointerKind::Thin), diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 369bb183bcd73..ae2d6c6fef2e5 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -396,8 +396,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match (&expr.kind, &expected.kind, &checked_ty.kind) { (_, &ty::Ref(_, exp, _), &ty::Ref(_, check, _)) => match (&exp.kind, &check.kind) { - (&ty::Str, &ty::Array(arr, _)) | (&ty::Str, &ty::Slice(arr)) - if arr == self.tcx.types.u8 => + (&ty::Adt(def, _), &ty::Array(arr_elem, _)) + | (&ty::Adt(def, _), &ty::Slice(arr_elem)) + if def.is_str() && arr_elem == self.tcx.types.u8 => { if let hir::ExprKind::Lit(_) = expr.kind { if let Ok(src) = sm.span_to_snippet(sp) { @@ -411,8 +412,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } } - (&ty::Array(arr, _), &ty::Str) | (&ty::Slice(arr), &ty::Str) - if arr == self.tcx.types.u8 => + (&ty::Array(arr_elem, _), &ty::Adt(def, _)) + | (&ty::Slice(arr_elem), &ty::Adt(def, _)) + if def.is_str() && arr_elem == self.tcx.types.u8 => { if let hir::ExprKind::Lit(_) = expr.kind { if let Ok(src) = sm.span_to_snippet(sp) { diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 7e7d84c199676..3e2ee873e86e8 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -613,6 +613,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { self.assemble_inherent_impl_candidates_for_type(p.def_id()); } } + ty::Adt(def, _) if def.is_str() => { + let lang_def_id = lang_items.str_impl(); + self.assemble_inherent_impl_for_primitive(lang_def_id); + + let lang_def_id = lang_items.str_alloc_impl(); + self.assemble_inherent_impl_for_primitive(lang_def_id); + } ty::Adt(def, _) => { self.assemble_inherent_impl_candidates_for_type(def.did); } @@ -630,13 +637,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let lang_def_id = lang_items.char_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } - ty::Str => { - let lang_def_id = lang_items.str_impl(); - self.assemble_inherent_impl_for_primitive(lang_def_id); - - let lang_def_id = lang_items.str_alloc_impl(); - self.assemble_inherent_impl_for_primitive(lang_def_id); - } ty::Slice(_) => { for &lang_def_id in &[ lang_items.slice_impl(), diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index eebc34d3db8ea..90ab7998bc154 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -337,7 +337,7 @@ impl<'a, 'tcx> Expectation<'tcx> { /// for examples of where this comes up,. fn rvalue_hint(fcx: &FnCtxt<'a, 'tcx>, ty: Ty<'tcx>) -> Expectation<'tcx> { match fcx.tcx.struct_tail_without_normalization(ty).kind { - ty::Slice(_) | ty::Str | ty::Dynamic(..) => ExpectRvalueLikeUnsized(ty), + ty::Slice(_) | ty::Dynamic(..) => ExpectRvalueLikeUnsized(ty), _ => ExpectHasType(ty), } } diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index cac9113fd5d30..2269d95335e32 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -9,7 +9,7 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi use rustc_middle::ty::adjustment::{ Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, }; -use rustc_middle::ty::TyKind::{Adt, Array, Char, FnDef, Never, Ref, Str, Tuple, Uint}; +use rustc_middle::ty::TyKind::{Adt, Array, Char, FnDef, Never, Ref, Tuple, Uint}; use rustc_middle::ty::{self, Ty, TypeFoldable}; use rustc_span::Span; use rustc_trait_selection::infer::InferCtxtExt; @@ -564,8 +564,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match (&lhs_ty.kind, &rhs_ty.kind) { (&Ref(_, l_ty, _), &Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str - if (l_ty.kind == Str || is_std_string(l_ty)) && ( - r_ty.kind == Str || is_std_string(r_ty) || + if (l_ty.is_str() || is_std_string(l_ty)) && ( + r_ty.is_str() || is_std_string(r_ty) || &format!("{:?}", rhs_ty) == "&&str" ) => { @@ -599,7 +599,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { true } (&Ref(_, l_ty, _), &Adt(..)) // Handle `&str` & `&String` + `String` - if (l_ty.kind == Str || is_std_string(l_ty)) && is_std_string(rhs_ty) => + if (l_ty.is_str() || is_std_string(l_ty)) && is_std_string(rhs_ty) => { err.span_label( op.span, @@ -672,8 +672,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Uint(_) if op == hir::UnOp::UnNeg => { err.note("unsigned values cannot be negated"); } - Str | Never | Char | Tuple(_) | Array(_, _) => {} - Ref(_, ref lty, _) if lty.kind == Str => {} + Never | Char | Tuple(_) | Array(_, _) => {} + Adt(def, _) if def.is_str() => {} + Ref(_, ref lty, _) if lty.is_str() => {} _ => { let missing_trait = match op { hir::UnOp::UnNeg => "std::ops::Neg", diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 393f9f8bdfbaf..67a93492854d1 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -884,7 +884,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { }); if let ty::Ref(r_ptr, r_ty, _) = indexed_ty.kind { match r_ty.kind { - ty::Slice(_) | ty::Str => { + ty::Slice(_) => { self.sub_regions( infer::IndexSlice(index_expr.span), self.tcx.mk_region(r_index_expr), diff --git a/src/librustc_typeck/coherence/inherent_impls.rs b/src/librustc_typeck/coherence/inherent_impls.rs index d2b11f790d403..1f4468c0c1cae 100644 --- a/src/librustc_typeck/coherence/inherent_impls.rs +++ b/src/librustc_typeck/coherence/inherent_impls.rs @@ -53,6 +53,16 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> { let self_ty = self.tcx.type_of(def_id); let lang_items = self.tcx.lang_items(); match self_ty.kind { + ty::Adt(def, _) if def.is_str() => { + self.check_primitive_impl( + def_id, + lang_items.str_impl(), + lang_items.str_alloc_impl(), + "str_impl", + "str", + item.span, + ); + } ty::Adt(def, _) => { self.check_def_id(item, def.did); } @@ -82,16 +92,6 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> { item.span, ); } - ty::Str => { - self.check_primitive_impl( - def_id, - lang_items.str_impl(), - lang_items.str_alloc_impl(), - "str_impl", - "str", - item.span, - ); - } ty::Slice(slice_item) if slice_item == self.tcx.types.u8 => { self.check_primitive_impl( def_id, diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 2871fa606b570..c24aef9121d1f 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -262,7 +262,6 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { | ty::Int(_) | ty::Uint(_) | ty::Float(_) - | ty::Str | ty::Never | ty::Foreign(..) => { // leaf type -- noop diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5c35dc5513266..a73febc183ff9 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1532,7 +1532,7 @@ impl<'tcx> Clean for Ty<'tcx> { ty::Int(int_ty) => Primitive(int_ty.into()), ty::Uint(uint_ty) => Primitive(uint_ty.into()), ty::Float(float_ty) => Primitive(float_ty.into()), - ty::Str => Primitive(PrimitiveType::Str), + ty::Adt(def, _) if def.is_str() => Primitive(PrimitiveType::Str), ty::Slice(ty) => Slice(box ty.clean(cx)), ty::Array(ty, n) => { let mut n = cx.tcx.lift(&n).expect("array lift failed"); diff --git a/src/test/ui/consts/const-unsized.stderr b/src/test/ui/consts/const-unsized.stderr index beeea87bfb1d3..b7924935f3c9e 100644 --- a/src/test/ui/consts/const-unsized.stderr +++ b/src/test/ui/consts/const-unsized.stderr @@ -7,14 +7,15 @@ LL | const CONST_0: dyn Debug + Sync = *(&0 as &(dyn Debug + Sync)); = help: the trait `std::marker::Sized` is not implemented for `(dyn std::fmt::Debug + std::marker::Sync + 'static)` = note: to learn more, visit -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/const-unsized.rs:6:18 | LL | const CONST_FOO: str = *"foo"; | ^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` error[E0277]: the size for values of type `(dyn std::fmt::Debug + std::marker::Sync + 'static)` cannot be known at compilation time --> $DIR/const-unsized.rs:9:18 @@ -25,14 +26,15 @@ LL | static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync)); = help: the trait `std::marker::Sized` is not implemented for `(dyn std::fmt::Debug + std::marker::Sync + 'static)` = note: to learn more, visit -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/const-unsized.rs:12:20 | LL | static STATIC_BAR: str = *"bar"; | ^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` error: aborting due to 4 previous errors diff --git a/src/test/ui/dst/dst-object-from-unsized-type.stderr b/src/test/ui/dst/dst-object-from-unsized-type.stderr index 80d188bf2f89b..72555a89c98ad 100644 --- a/src/test/ui/dst/dst-object-from-unsized-type.stderr +++ b/src/test/ui/dst/dst-object-from-unsized-type.stderr @@ -22,14 +22,15 @@ LL | let v: &dyn Foo = t as &dyn Foo; = note: to learn more, visit = note: required for the cast to the object type `dyn Foo` -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/dst-object-from-unsized-type.rs:18:28 | LL | let _: &[&dyn Foo] = &["hi"]; | ^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: required for the cast to the object type `dyn Foo` error[E0277]: the size for values of type `[u8]` cannot be known at compilation time diff --git a/src/test/ui/feature-gates/feature-gate-trivial_bounds.stderr b/src/test/ui/feature-gates/feature-gate-trivial_bounds.stderr index b4d4c992c9086..59a4b8241ecc9 100644 --- a/src/test/ui/feature-gates/feature-gate-trivial_bounds.stderr +++ b/src/test/ui/feature-gates/feature-gate-trivial_bounds.stderr @@ -88,14 +88,15 @@ LL | | } = help: see issue #48214 = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/feature-gate-trivial_bounds.rs:52:1 | LL | struct TwoStrs(str, str) where str: Sized; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = help: see issue #48214 = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable @@ -113,7 +114,7 @@ LL | | } = help: see issue #48214 = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/feature-gate-trivial_bounds.rs:59:1 | LL | / fn return_str() -> str where str: Sized { @@ -121,8 +122,9 @@ LL | | *"Sized".to_string().into_boxed_str() LL | | } | |_^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = help: see issue #48214 = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable diff --git a/src/test/ui/generator/sized-yield.stderr b/src/test/ui/generator/sized-yield.stderr index 79aeec2ec0280..31b452a3163f6 100644 --- a/src/test/ui/generator/sized-yield.stderr +++ b/src/test/ui/generator/sized-yield.stderr @@ -1,4 +1,4 @@ -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/sized-yield.rs:8:26 | LL | let mut gen = move || { @@ -8,18 +8,20 @@ LL | | yield s[..]; LL | | }; | |____^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: the yield type of a generator must have a statically known size -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/sized-yield.rs:12:23 | LL | Pin::new(&mut gen).resume(()); | ^^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-10412.rs b/src/test/ui/issues/issue-10412.rs index 020585136856b..a24994ab635ac 100644 --- a/src/test/ui/issues/issue-10412.rs +++ b/src/test/ui/issues/issue-10412.rs @@ -6,7 +6,7 @@ trait Serializable<'self, T> { //~ ERROR lifetimes cannot use keyword names impl<'self> Serializable for &'self str { //~ ERROR lifetimes cannot use keyword names //~^ ERROR lifetimes cannot use keyword names //~| ERROR implicit elided lifetime not allowed here - //~| ERROR the size for values of type `str` cannot be known at compilation time + //~| ERROR the size for values of type `[u8]` cannot be known at compilation time fn serialize(val : &'self str) -> Vec { //~ ERROR lifetimes cannot use keyword names vec![1] } diff --git a/src/test/ui/issues/issue-10412.stderr b/src/test/ui/issues/issue-10412.stderr index 0793dd99b4d12..b943012808fc4 100644 --- a/src/test/ui/issues/issue-10412.stderr +++ b/src/test/ui/issues/issue-10412.stderr @@ -46,14 +46,15 @@ error[E0726]: implicit elided lifetime not allowed here LL | impl<'self> Serializable for &'self str { | ^^^^^^^^^^^^^^^^^ help: indicate the anonymous lifetime: `Serializable<'_, str>` -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/issue-10412.rs:6:13 | LL | impl<'self> Serializable for &'self str { | ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` error: aborting due to 9 previous errors diff --git a/src/test/ui/issues/issue-14366.stderr b/src/test/ui/issues/issue-14366.stderr index 542d8a904c4e3..fabc1239aa524 100644 --- a/src/test/ui/issues/issue-14366.stderr +++ b/src/test/ui/issues/issue-14366.stderr @@ -1,11 +1,12 @@ -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/issue-14366.rs:2:14 | LL | let _x = "test" as &dyn (::std::any::Any); | ^^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: required for the cast to the object type `dyn std::any::Any` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-14721.stderr b/src/test/ui/issues/issue-14721.stderr index 49ebb2976e8ad..f07bc7ad4f18b 100644 --- a/src/test/ui/issues/issue-14721.stderr +++ b/src/test/ui/issues/issue-14721.stderr @@ -2,7 +2,7 @@ error[E0609]: no field `desc` on type `&str` --> $DIR/issue-14721.rs:3:24 | LL | println!("{}", foo.desc); - | ^^^^ + | ^^^^ unknown field error: aborting due to previous error diff --git a/src/test/ui/issues/issue-30240.rs b/src/test/ui/issues/issue-30240.rs index a0c0d1626ec45..7e08e3c2ba260 100644 --- a/src/test/ui/issues/issue-30240.rs +++ b/src/test/ui/issues/issue-30240.rs @@ -1,9 +1,9 @@ fn main() { - match "world" { //~ ERROR non-exhaustive patterns: `&_` + match "world" { //~ ERROR non-exhaustive patterns: `&Str(_)` "hello" => {} } - match "world" { //~ ERROR non-exhaustive patterns: `&_` + match "world" { //~ ERROR non-exhaustive patterns: `&Str(_)` ref _x if false => {} "hello" => {} } diff --git a/src/test/ui/issues/issue-30240.stderr b/src/test/ui/issues/issue-30240.stderr index a2c58d6e051b5..e9e09e76b3df1 100644 --- a/src/test/ui/issues/issue-30240.stderr +++ b/src/test/ui/issues/issue-30240.stderr @@ -1,17 +1,17 @@ -error[E0004]: non-exhaustive patterns: `&_` not covered +error[E0004]: non-exhaustive patterns: `&Str(_)` not covered --> $DIR/issue-30240.rs:2:11 | LL | match "world" { - | ^^^^^^^ pattern `&_` not covered + | ^^^^^^^ pattern `&Str(_)` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `&str` -error[E0004]: non-exhaustive patterns: `&_` not covered +error[E0004]: non-exhaustive patterns: `&Str(_)` not covered --> $DIR/issue-30240.rs:6:11 | LL | match "world" { - | ^^^^^^^ pattern `&_` not covered + | ^^^^^^^ pattern `&Str(_)` not covered | = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms = note: the matched value is of type `&str` diff --git a/src/test/ui/issues/issue-33525.stderr b/src/test/ui/issues/issue-33525.stderr index f8d703dc3b169..ee9f4d4c3016d 100644 --- a/src/test/ui/issues/issue-33525.stderr +++ b/src/test/ui/issues/issue-33525.stderr @@ -8,13 +8,13 @@ error[E0609]: no field `lorem` on type `&'static str` --> $DIR/issue-33525.rs:3:8 | LL | "".lorem; - | ^^^^^ + | ^^^^^ unknown field error[E0609]: no field `ipsum` on type `&'static str` --> $DIR/issue-33525.rs:4:8 | LL | "".ipsum; - | ^^^^^ + | ^^^^^ unknown field error: aborting due to 3 previous errors diff --git a/src/test/ui/issues/issue-38954.stderr b/src/test/ui/issues/issue-38954.stderr index d3168ef9e4aaf..c120e74cc845b 100644 --- a/src/test/ui/issues/issue-38954.stderr +++ b/src/test/ui/issues/issue-38954.stderr @@ -1,11 +1,12 @@ -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/issue-38954.rs:1:10 | LL | fn _test(ref _p: str) {} | ^^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: all function arguments must have a statically known size = help: unsized locals are gated as an unstable feature diff --git a/src/test/ui/issues/issue-41229-ref-str.stderr b/src/test/ui/issues/issue-41229-ref-str.stderr index 9d854e4be9ead..90a5c2ec8b597 100644 --- a/src/test/ui/issues/issue-41229-ref-str.stderr +++ b/src/test/ui/issues/issue-41229-ref-str.stderr @@ -1,11 +1,12 @@ -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/issue-41229-ref-str.rs:1:16 | LL | pub fn example(ref s: str) {} | ^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: all function arguments must have a statically known size = help: unsized locals are gated as an unstable feature diff --git a/src/test/ui/mismatched_types/cast-rfc0401-str.rs b/src/test/ui/mismatched_types/cast-rfc0401-str.rs new file mode 100644 index 0000000000000..baae0d6ef980c --- /dev/null +++ b/src/test/ui/mismatched_types/cast-rfc0401-str.rs @@ -0,0 +1,8 @@ +trait Foo { fn foo(&self) {} } +impl Foo for T {} + +fn main() +{ + let a : *const str = "hello"; + let _ = a as *const dyn Foo; //~ ERROR the size for values of type +} diff --git a/src/test/ui/mismatched_types/cast-rfc0401-str.stderr b/src/test/ui/mismatched_types/cast-rfc0401-str.stderr new file mode 100644 index 0000000000000..b4cb873ed833c --- /dev/null +++ b/src/test/ui/mismatched_types/cast-rfc0401-str.stderr @@ -0,0 +1,14 @@ +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time + --> $DIR/cast-rfc0401-str.rs:7:13 + | +LL | let _ = a as *const dyn Foo; + | ^ doesn't have a size known at compile-time + | + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` + = note: to learn more, visit + = note: required because it appears within the type `str` + = note: required for the cast to the object type `dyn Foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/mismatched_types/cast-rfc0401.rs b/src/test/ui/mismatched_types/cast-rfc0401.rs index b8d12fb9809ce..eea797cf15e67 100644 --- a/src/test/ui/mismatched_types/cast-rfc0401.rs +++ b/src/test/ui/mismatched_types/cast-rfc0401.rs @@ -58,9 +58,6 @@ fn main() let _ = &f as *const f64; //~ ERROR is invalid let _ = fat_sv as usize; //~ ERROR is invalid - let a : *const str = "hello"; - let _ = a as *const dyn Foo; //~ ERROR the size for values of type - // check no error cascade let _ = main.f as *const u32; //~ ERROR no field diff --git a/src/test/ui/mismatched_types/cast-rfc0401.stderr b/src/test/ui/mismatched_types/cast-rfc0401.stderr index f94dfd100a6f4..4dc8fc684e1b8 100644 --- a/src/test/ui/mismatched_types/cast-rfc0401.stderr +++ b/src/test/ui/mismatched_types/cast-rfc0401.stderr @@ -15,7 +15,7 @@ LL | u as *const str = note: vtable kinds may not match error[E0609]: no field `f` on type `fn() {main}` - --> $DIR/cast-rfc0401.rs:65:18 + --> $DIR/cast-rfc0401.rs:62:18 | LL | let _ = main.f as *const u32; | ^ @@ -197,7 +197,7 @@ LL | let _ = fat_sv as usize; = help: cast through a thin pointer first error[E0606]: casting `*const dyn Foo` as `*const [u16]` is invalid - --> $DIR/cast-rfc0401.rs:68:13 + --> $DIR/cast-rfc0401.rs:65:13 | LL | let _ = cf as *const [u16]; | ^^^^^^^^^^^^^^^^^^ @@ -205,7 +205,7 @@ LL | let _ = cf as *const [u16]; = note: vtable kinds may not match error[E0606]: casting `*const dyn Foo` as `*const dyn Bar` is invalid - --> $DIR/cast-rfc0401.rs:69:13 + --> $DIR/cast-rfc0401.rs:66:13 | LL | let _ = cf as *const dyn Bar; | ^^^^^^^^^^^^^^^^^^^^ @@ -222,18 +222,8 @@ LL | let _ = fat_v as *const dyn Foo; = note: to learn more, visit = note: required for the cast to the object type `dyn Foo` -error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/cast-rfc0401.rs:62:13 - | -LL | let _ = a as *const dyn Foo; - | ^ doesn't have a size known at compile-time - | - = help: the trait `std::marker::Sized` is not implemented for `str` - = note: to learn more, visit - = note: required for the cast to the object type `dyn Foo` - error[E0606]: casting `&{float}` as `f32` is invalid - --> $DIR/cast-rfc0401.rs:71:30 + --> $DIR/cast-rfc0401.rs:68:30 | LL | vec![0.0].iter().map(|s| s as f32).collect::>(); | -^^^^^^^ @@ -241,7 +231,7 @@ LL | vec![0.0].iter().map(|s| s as f32).collect::>(); | cannot cast `&{float}` as `f32` | help: dereference the expression: `*s` -error: aborting due to 34 previous errors +error: aborting due to 33 previous errors Some errors have detailed explanations: E0054, E0277, E0604, E0605, E0606, E0607, E0609. For more information about an error, try `rustc --explain E0054`. diff --git a/src/test/ui/no-type-for-node-ice.stderr b/src/test/ui/no-type-for-node-ice.stderr index b50241fb1a059..b990b5f951f25 100644 --- a/src/test/ui/no-type-for-node-ice.stderr +++ b/src/test/ui/no-type-for-node-ice.stderr @@ -2,7 +2,7 @@ error[E0609]: no field `homura` on type `&'static str` --> $DIR/no-type-for-node-ice.rs:4:8 | LL | "".homura[""]; - | ^^^^^^ + | ^^^^^^ unknown field error: aborting due to previous error diff --git a/src/test/ui/str/str-array-assignment.stderr b/src/test/ui/str/str-array-assignment.stderr index cc767de3845d2..0da5c4485cee7 100644 --- a/src/test/ui/str/str-array-assignment.stderr +++ b/src/test/ui/str/str-array-assignment.stderr @@ -15,16 +15,15 @@ LL | let u: &str = if true { s[..2] } else { s }; | expected `&str`, found `str` | help: consider borrowing here: `&s[..2]` -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/str-array-assignment.rs:7:7 | LL | let v = s[..2]; - | ^ ------ help: consider borrowing here: `&s[..2]` - | | - | doesn't have a size known at compile-time + | ^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature diff --git a/src/test/ui/str/str-mut-idx.rs b/src/test/ui/str/str-mut-idx.rs index 575a9eae85946..89318b46679e4 100644 --- a/src/test/ui/str/str-mut-idx.rs +++ b/src/test/ui/str/str-mut-idx.rs @@ -3,7 +3,6 @@ fn bot() -> T { loop {} } fn mutate(s: &mut str) { s[1..2] = bot(); //~^ ERROR the size for values of type - //~| ERROR the size for values of type s[1usize] = bot(); //~^ ERROR the type `str` cannot be indexed by `usize` s.get_mut(1); diff --git a/src/test/ui/str/str-mut-idx.stderr b/src/test/ui/str/str-mut-idx.stderr index d0afb2ae7af74..1ce70b81c5f96 100644 --- a/src/test/ui/str/str-mut-idx.stderr +++ b/src/test/ui/str/str-mut-idx.stderr @@ -1,4 +1,4 @@ -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/str-mut-idx.rs:4:15 | LL | fn bot() -> T { loop {} } @@ -7,25 +7,12 @@ LL | fn bot() -> T { loop {} } LL | s[1..2] = bot(); | ^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit -help: consider relaxing the implicit `Sized` restriction - | -LL | fn bot() -> T { loop {} } - | ^^^^^^^^ - -error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/str-mut-idx.rs:4:5 - | -LL | s[1..2] = bot(); - | ^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `std::marker::Sized` is not implemented for `str` - = note: to learn more, visit - = note: the left-hand-side of an assignment must have a statically known size + = note: required because it appears within the type `str` error[E0277]: the type `str` cannot be indexed by `usize` - --> $DIR/str-mut-idx.rs:7:5 + --> $DIR/str-mut-idx.rs:6:5 | LL | s[1usize] = bot(); | ^^^^^^^^^ string indices are ranges of `usize` @@ -34,7 +21,7 @@ LL | s[1usize] = bot(); = note: required because of the requirements on the impl of `std::ops::Index` for `str` error[E0277]: the type `str` cannot be indexed by `{integer}` - --> $DIR/str-mut-idx.rs:9:15 + --> $DIR/str-mut-idx.rs:8:15 | LL | s.get_mut(1); | ^ string indices are ranges of `usize` @@ -44,7 +31,7 @@ LL | s.get_mut(1); see chapter in The Book error[E0277]: the type `str` cannot be indexed by `{integer}` - --> $DIR/str-mut-idx.rs:11:25 + --> $DIR/str-mut-idx.rs:10:25 | LL | s.get_unchecked_mut(1); | ^ string indices are ranges of `usize` @@ -54,7 +41,7 @@ LL | s.get_unchecked_mut(1); see chapter in The Book error[E0277]: the type `str` cannot be indexed by `char` - --> $DIR/str-mut-idx.rs:13:5 + --> $DIR/str-mut-idx.rs:12:5 | LL | s['c']; | ^^^^^^ string indices are ranges of `usize` @@ -62,6 +49,6 @@ LL | s['c']; = help: the trait `std::slice::SliceIndex` is not implemented for `char` = note: required because of the requirements on the impl of `std::ops::Index` for `str` -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/substs-ppaux.normal.stderr b/src/test/ui/substs-ppaux.normal.stderr index 3ad2a1414f969..c6199e528c5cb 100644 --- a/src/test/ui/substs-ppaux.normal.stderr +++ b/src/test/ui/substs-ppaux.normal.stderr @@ -70,7 +70,7 @@ help: use parentheses to call this function LL | let x: () = foo::<'static>(); | ^^ -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/substs-ppaux.rs:49:5 | LL | fn bar<'a, T>() where T: 'a {} @@ -79,8 +79,9 @@ LL | fn bar<'a, T>() where T: 'a {} LL | >::bar; | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: required because of the requirements on the impl of `Foo<'_, '_, u8>` for `str` error: aborting due to 5 previous errors diff --git a/src/test/ui/substs-ppaux.verbose.stderr b/src/test/ui/substs-ppaux.verbose.stderr index e23f06a3ef590..db9aa6640988c 100644 --- a/src/test/ui/substs-ppaux.verbose.stderr +++ b/src/test/ui/substs-ppaux.verbose.stderr @@ -70,7 +70,7 @@ help: use parentheses to call this function LL | let x: () = foo::<'static>(); | ^^ -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/substs-ppaux.rs:49:5 | LL | fn bar<'a, T>() where T: 'a {} @@ -79,8 +79,9 @@ LL | fn bar<'a, T>() where T: 'a {} LL | >::bar; | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: required because of the requirements on the impl of `Foo<'_#0r, '_#1r, u8>` for `str` error: aborting due to 5 previous errors diff --git a/src/test/ui/symbol-names/basic.legacy.stderr b/src/test/ui/symbol-names/basic.legacy.stderr index 895ff5ae54fde..ec3ae4c2bce7e 100644 --- a/src/test/ui/symbol-names/basic.legacy.stderr +++ b/src/test/ui/symbol-names/basic.legacy.stderr @@ -1,10 +1,10 @@ -error: symbol-name(_ZN5basic4main17h81759b0695851718E) +error: symbol-name(_ZN5basic4main17hd263377fb03de691E) --> $DIR/basic.rs:8:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(basic::main::h81759b0695851718) +error: demangling(basic::main::hd263377fb03de691) --> $DIR/basic.rs:8:1 | LL | #[rustc_symbol_name] diff --git a/src/test/ui/symbol-names/impl1.legacy.stderr b/src/test/ui/symbol-names/impl1.legacy.stderr index 33cacaf212855..38b32c0705327 100644 --- a/src/test/ui/symbol-names/impl1.legacy.stderr +++ b/src/test/ui/symbol-names/impl1.legacy.stderr @@ -1,10 +1,10 @@ -error: symbol-name(_ZN5impl13foo3Foo3bar17h92cf46db76791039E) +error: symbol-name(_ZN5impl13foo3Foo3bar17h6b96efde0dc9f361E) --> $DIR/impl1.rs:16:9 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(impl1::foo::Foo::bar::h92cf46db76791039) +error: demangling(impl1::foo::Foo::bar::h6b96efde0dc9f361) --> $DIR/impl1.rs:16:9 | LL | #[rustc_symbol_name] @@ -22,13 +22,13 @@ error: def-path(foo::Foo::bar) LL | #[rustc_def_path] | ^^^^^^^^^^^^^^^^^ -error: symbol-name(_ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz17h90c4a800b1aa0df0E) +error: symbol-name(_ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz17hcf43c877e8d88c40E) --> $DIR/impl1.rs:34:9 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(impl1::bar::::baz::h90c4a800b1aa0df0) +error: demangling(impl1::bar::::baz::hcf43c877e8d88c40) --> $DIR/impl1.rs:34:9 | LL | #[rustc_symbol_name] @@ -46,13 +46,13 @@ error: def-path(bar::::baz) LL | #[rustc_def_path] | ^^^^^^^^^^^^^^^^^ -error: symbol-name(_ZN209_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$C$$u20$...$RP$$u2b$impl1..AutoTrait$u3b$$u20$3$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method17SYMBOL_HASHE) +error: symbol-name(_ZN209_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$C$$u20$...$RP$$u2b$impl1..AutoTrait$u3b$$u20$3$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method17hceda8dce2f13fc4bE) --> $DIR/impl1.rs:64:13 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; 3] as impl1::main::{{closure}}::Bar>::method::SYMBOL_HASH) +error: demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; 3] as impl1::main::{{closure}}::Bar>::method::hceda8dce2f13fc4b) --> $DIR/impl1.rs:64:13 | LL | #[rustc_symbol_name] diff --git a/src/test/ui/symbol-names/issue-60925.legacy.stderr b/src/test/ui/symbol-names/issue-60925.legacy.stderr index 0e3a34adbc7cf..17fa176ca7f2f 100644 --- a/src/test/ui/symbol-names/issue-60925.legacy.stderr +++ b/src/test/ui/symbol-names/issue-60925.legacy.stderr @@ -1,10 +1,10 @@ -error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17hc86312d25b60f6eeE) +error: symbol-name(_ZN11issue_609253foo37Foo$LT$issue_60925..llv$u6d$..Foo$GT$3foo17ha8d9c456ba0ed969E) --> $DIR/issue-60925.rs:22:9 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ -error: demangling(issue_60925::foo::Foo::foo::hc86312d25b60f6ee) +error: demangling(issue_60925::foo::Foo::foo::ha8d9c456ba0ed969) --> $DIR/issue-60925.rs:22:9 | LL | #[rustc_symbol_name] diff --git a/src/test/ui/trivial-bounds/trivial-bounds-leak.stderr b/src/test/ui/trivial-bounds/trivial-bounds-leak.stderr index 4e153081d9fe9..2d56ff8dbd68f 100644 --- a/src/test/ui/trivial-bounds/trivial-bounds-leak.stderr +++ b/src/test/ui/trivial-bounds/trivial-bounds-leak.stderr @@ -1,11 +1,12 @@ -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/trivial-bounds-leak.rs:12:25 | LL | fn cant_return_str() -> str { | ^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: the return type of a function must have a statically known size error[E0599]: no method named `test` found for type `i32` in the current scope diff --git a/src/test/ui/union/union-unsized.stderr b/src/test/ui/union/union-unsized.stderr index e702f2c61bee3..58283912abbe6 100644 --- a/src/test/ui/union/union-unsized.stderr +++ b/src/test/ui/union/union-unsized.stderr @@ -1,21 +1,23 @@ -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/union-unsized.rs:4:5 | LL | a: str, | ^^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: no field of a union may have a dynamically sized type -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/union-unsized.rs:12:5 | LL | b: str, | ^^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: no field of a union may have a dynamically sized type error: aborting due to 2 previous errors diff --git a/src/test/ui/unsized-locals/issue-50940-with-feature.rs b/src/test/ui/unsized-locals/issue-50940-with-feature.rs index 3e5d39ab31150..f087239804e18 100644 --- a/src/test/ui/unsized-locals/issue-50940-with-feature.rs +++ b/src/test/ui/unsized-locals/issue-50940-with-feature.rs @@ -3,5 +3,5 @@ fn main() { struct A(X); A as fn(str) -> A; - //~^ERROR the size for values of type `str` cannot be known at compilation time + //~^ERROR the size for values of type `[u8]` cannot be known at compilation time } diff --git a/src/test/ui/unsized-locals/issue-50940-with-feature.stderr b/src/test/ui/unsized-locals/issue-50940-with-feature.stderr index 7b6c2d11ea169..d1dae752eafd9 100644 --- a/src/test/ui/unsized-locals/issue-50940-with-feature.stderr +++ b/src/test/ui/unsized-locals/issue-50940-with-feature.stderr @@ -1,11 +1,12 @@ -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/issue-50940-with-feature.rs:5:5 | LL | A as fn(str) -> A; | ^ doesn't have a size known at compile-time | - = help: within `main::A`, the trait `std::marker::Sized` is not implemented for `str` + = help: within `main::A`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: required because it appears within the type `main::A` = note: the return type of a function must have a statically known size diff --git a/src/test/ui/unsized-locals/issue-50940.rs b/src/test/ui/unsized-locals/issue-50940.rs index 7ba809b7e83e3..549f153049a62 100644 --- a/src/test/ui/unsized-locals/issue-50940.rs +++ b/src/test/ui/unsized-locals/issue-50940.rs @@ -1,5 +1,5 @@ fn main() { struct A(X); A as fn(str) -> A; - //~^ERROR the size for values of type `str` cannot be known at compilation time + //~^ERROR the size for values of type `[u8]` cannot be known at compilation time } diff --git a/src/test/ui/unsized-locals/issue-50940.stderr b/src/test/ui/unsized-locals/issue-50940.stderr index be006c09d6f5c..434947b724f88 100644 --- a/src/test/ui/unsized-locals/issue-50940.stderr +++ b/src/test/ui/unsized-locals/issue-50940.stderr @@ -1,11 +1,12 @@ -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/issue-50940.rs:3:5 | LL | A as fn(str) -> A; | ^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: all function arguments must have a statically known size = help: unsized locals are gated as an unstable feature diff --git a/src/test/ui/unsized/unsized-enum2-str.rs b/src/test/ui/unsized/unsized-enum2-str.rs new file mode 100644 index 0000000000000..14e8d693fc837 --- /dev/null +++ b/src/test/ui/unsized/unsized-enum2-str.rs @@ -0,0 +1,12 @@ +enum E { + // parameter + VA(W), + //~^ ERROR the size for values of type + + // slice / str + VF{x: str}, + //~^ ERROR the size for values of type +} + + +fn main() { } diff --git a/src/test/ui/unsized/unsized-enum2-str.stderr b/src/test/ui/unsized/unsized-enum2-str.stderr new file mode 100644 index 0000000000000..7c42784c49bab --- /dev/null +++ b/src/test/ui/unsized/unsized-enum2-str.stderr @@ -0,0 +1,27 @@ +error[E0277]: the size for values of type `W` cannot be known at compilation time + --> $DIR/unsized-enum2-str.rs:3:8 + | +LL | enum E { + | - this type parameter needs to be `std::marker::Sized` +LL | // parameter +LL | VA(W), + | ^ doesn't have a size known at compile-time + | + = help: the trait `std::marker::Sized` is not implemented for `W` + = note: to learn more, visit + = note: no field of an enum variant may have a dynamically sized type + +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time + --> $DIR/unsized-enum2-str.rs:7:8 + | +LL | VF{x: str}, + | ^^^^^^ doesn't have a size known at compile-time + | + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` + = note: to learn more, visit + = note: required because it appears within the type `str` + = note: no field of an enum variant may have a dynamically sized type + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unsized/unsized-enum2.rs b/src/test/ui/unsized/unsized-enum2.rs index d589f5ae582c6..76368a60bd721 100644 --- a/src/test/ui/unsized/unsized-enum2.rs +++ b/src/test/ui/unsized/unsized-enum2.rs @@ -29,11 +29,9 @@ enum E { VD{u: isize, x: Z}, //~^ ERROR the size for values of type - // slice / str + // slice VE([u8]), //~^ ERROR the size for values of type - VF{x: str}, - //~^ ERROR the size for values of type VG(isize, [f32]), //~^ ERROR the size for values of type VH{u: isize, x: [u32]}, diff --git a/src/test/ui/unsized/unsized-enum2.stderr b/src/test/ui/unsized/unsized-enum2.stderr index bc3b3831f3269..91f61a662bdd6 100644 --- a/src/test/ui/unsized/unsized-enum2.stderr +++ b/src/test/ui/unsized/unsized-enum2.stderr @@ -60,18 +60,8 @@ LL | VE([u8]), = note: to learn more, visit = note: no field of an enum variant may have a dynamically sized type -error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:35:8 - | -LL | VF{x: str}, - | ^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `std::marker::Sized` is not implemented for `str` - = note: to learn more, visit - = note: no field of an enum variant may have a dynamically sized type - error[E0277]: the size for values of type `[f32]` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:37:15 + --> $DIR/unsized-enum2.rs:35:15 | LL | VG(isize, [f32]), | ^^^^^ doesn't have a size known at compile-time @@ -81,7 +71,7 @@ LL | VG(isize, [f32]), = note: no field of an enum variant may have a dynamically sized type error[E0277]: the size for values of type `[u32]` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:39:18 + --> $DIR/unsized-enum2.rs:37:18 | LL | VH{u: isize, x: [u32]}, | ^^^^^^^^ doesn't have a size known at compile-time @@ -91,7 +81,7 @@ LL | VH{u: isize, x: [u32]}, = note: no field of an enum variant may have a dynamically sized type error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:53:8 + --> $DIR/unsized-enum2.rs:51:8 | LL | VM(dyn Foo), | ^^^^^^^ doesn't have a size known at compile-time @@ -101,7 +91,7 @@ LL | VM(dyn Foo), = note: no field of an enum variant may have a dynamically sized type error[E0277]: the size for values of type `(dyn Bar + 'static)` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:55:8 + --> $DIR/unsized-enum2.rs:53:8 | LL | VN{x: dyn Bar}, | ^^^^^^^^^^ doesn't have a size known at compile-time @@ -111,7 +101,7 @@ LL | VN{x: dyn Bar}, = note: no field of an enum variant may have a dynamically sized type error[E0277]: the size for values of type `(dyn FooBar + 'static)` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:57:15 + --> $DIR/unsized-enum2.rs:55:15 | LL | VO(isize, dyn FooBar), | ^^^^^^^^^^ doesn't have a size known at compile-time @@ -121,7 +111,7 @@ LL | VO(isize, dyn FooBar), = note: no field of an enum variant may have a dynamically sized type error[E0277]: the size for values of type `(dyn BarFoo + 'static)` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:59:18 + --> $DIR/unsized-enum2.rs:57:18 | LL | VP{u: isize, x: dyn BarFoo}, | ^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -131,7 +121,7 @@ LL | VP{u: isize, x: dyn BarFoo}, = note: no field of an enum variant may have a dynamically sized type error[E0277]: the size for values of type `[i8]` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:63:8 + --> $DIR/unsized-enum2.rs:61:8 | LL | VQ(<&'static [i8] as Deref>::Target), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -141,7 +131,7 @@ LL | VQ(<&'static [i8] as Deref>::Target), = note: no field of an enum variant may have a dynamically sized type error[E0277]: the size for values of type `[char]` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:65:8 + --> $DIR/unsized-enum2.rs:63:8 | LL | VR{x: <&'static [char] as Deref>::Target}, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -151,7 +141,7 @@ LL | VR{x: <&'static [char] as Deref>::Target}, = note: no field of an enum variant may have a dynamically sized type error[E0277]: the size for values of type `[f64]` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:67:15 + --> $DIR/unsized-enum2.rs:65:15 | LL | VS(isize, <&'static [f64] as Deref>::Target), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -161,7 +151,7 @@ LL | VS(isize, <&'static [f64] as Deref>::Target), = note: no field of an enum variant may have a dynamically sized type error[E0277]: the size for values of type `[i32]` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:69:18 + --> $DIR/unsized-enum2.rs:67:18 | LL | VT{u: isize, x: <&'static [i32] as Deref>::Target}, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -171,7 +161,7 @@ LL | VT{u: isize, x: <&'static [i32] as Deref>::Target}, = note: no field of an enum variant may have a dynamically sized type error[E0277]: the size for values of type `(dyn PathHelper1 + 'static)` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:43:8 + --> $DIR/unsized-enum2.rs:41:8 | LL | VI(Path1), | ^^^^^ doesn't have a size known at compile-time @@ -182,7 +172,7 @@ LL | VI(Path1), = note: no field of an enum variant may have a dynamically sized type error[E0277]: the size for values of type `(dyn PathHelper2 + 'static)` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:45:8 + --> $DIR/unsized-enum2.rs:43:8 | LL | VJ{x: Path2}, | ^^^^^^^^ doesn't have a size known at compile-time @@ -193,7 +183,7 @@ LL | VJ{x: Path2}, = note: no field of an enum variant may have a dynamically sized type error[E0277]: the size for values of type `(dyn PathHelper3 + 'static)` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:47:15 + --> $DIR/unsized-enum2.rs:45:15 | LL | VK(isize, Path3), | ^^^^^ doesn't have a size known at compile-time @@ -204,7 +194,7 @@ LL | VK(isize, Path3), = note: no field of an enum variant may have a dynamically sized type error[E0277]: the size for values of type `(dyn PathHelper4 + 'static)` cannot be known at compilation time - --> $DIR/unsized-enum2.rs:49:18 + --> $DIR/unsized-enum2.rs:47:18 | LL | VL{u: isize, x: Path4}, | ^^^^^^^^ doesn't have a size known at compile-time @@ -214,6 +204,6 @@ LL | VL{u: isize, x: Path4}, = note: required because it appears within the type `Path4` = note: no field of an enum variant may have a dynamically sized type -error: aborting due to 20 previous errors +error: aborting due to 19 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unsized/unsized-fn-param.stderr b/src/test/ui/unsized/unsized-fn-param.stderr index ed2c2e75cbd44..48cc594a373e2 100644 --- a/src/test/ui/unsized/unsized-fn-param.stderr +++ b/src/test/ui/unsized/unsized-fn-param.stderr @@ -1,41 +1,45 @@ -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/unsized-fn-param.rs:11:11 | LL | foo11("bar", &"baz"); | ^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: required for the cast to the object type `dyn std::convert::AsRef` -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/unsized-fn-param.rs:13:19 | LL | foo12(&"bar", "baz"); | ^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: required for the cast to the object type `dyn std::convert::AsRef` -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/unsized-fn-param.rs:16:11 | LL | foo21("bar", &"baz"); | ^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: required for the cast to the object type `dyn std::convert::AsRef` -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/unsized-fn-param.rs:18:19 | LL | foo22(&"bar", "baz"); | ^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: required for the cast to the object type `dyn std::convert::AsRef` error: aborting due to 4 previous errors diff --git a/src/test/ui/unsized5.stderr b/src/test/ui/unsized5.stderr index de4da309791c0..cdd9089355c15 100644 --- a/src/test/ui/unsized5.stderr +++ b/src/test/ui/unsized5.stderr @@ -23,14 +23,15 @@ LL | g: X, = note: to learn more, visit = note: only the last field of a struct may have a dynamically sized type -error[E0277]: the size for values of type `str` cannot be known at compilation time +error[E0277]: the size for values of type `[u8]` cannot be known at compilation time --> $DIR/unsized5.rs:15:5 | LL | f: str, | ^^^^^^ doesn't have a size known at compile-time | - = help: the trait `std::marker::Sized` is not implemented for `str` + = help: within `str`, the trait `std::marker::Sized` is not implemented for `[u8]` = note: to learn more, visit + = note: required because it appears within the type `str` = note: only the last field of a struct may have a dynamically sized type error[E0277]: the size for values of type `[u8]` cannot be known at compilation time