Skip to content

Commit 2f847b8

Browse files
committed
Auto merge of #99892 - JohnTitor:rollup-qi4fem8, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #99686 (add suggestion when there is a impl of external trait on pointer with wrong coherence rules) - #99760 (doc/rustc: describe the uefi target platforms) - #99766 (Htmldocck: Substitute the doc channel when blessing) - #99781 (Use String::from_utf8_lossy in CStr demo) - #99803 (Update mentions to `rustc_metadata::rmeta::Lazy`) - #99845 (Remove `$` prefix for bash scripts in doc) - #99850 (rustdoc: Remove more Clean trait implementations) - #99872 (Clone the `src/llvm-project` submodule if profiling is enabled) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7dfdd64 + a8f77ad commit 2f847b8

File tree

15 files changed

+398
-50
lines changed

15 files changed

+398
-50
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(crate) struct CrateMetadata {
8383

8484
// --- Some data pre-decoded from the metadata blob, usually for performance ---
8585
/// NOTE(eddyb) we pass `'static` to a `'tcx` parameter because this
86-
/// lifetime is only used behind `Lazy`, and therefore acts like a
86+
/// lifetime is only used behind `LazyValue`, `LazyArray`, or `LazyTable`, and therefore acts like a
8787
/// universal (`for<'tcx>`), that is paired up with whichever `TyCtxt`
8888
/// is being used to decode those values.
8989
root: CrateRoot,

compiler/rustc_metadata/src/rmeta/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ pub const METADATA_HEADER: &[u8] = &[b'r', b'u', b's', b't', 0, 0, 0, METADATA_V
6666
///
6767
/// Metadata is effective a tree, encoded in post-order,
6868
/// and with the root's position written next to the header.
69-
/// That means every single `Lazy` points to some previous
69+
/// That means every single `LazyValue` points to some previous
7070
/// location in the metadata and is part of a larger node.
7171
///
72-
/// The first `Lazy` in a node is encoded as the backwards
72+
/// The first `LazyValue` in a node is encoded as the backwards
7373
/// distance from the position where the containing node
74-
/// starts and where the `Lazy` points to, while the rest
75-
/// use the forward distance from the previous `Lazy`.
74+
/// starts and where the `LazyValue` points to, while the rest
75+
/// use the forward distance from the previous `LazyValue`.
7676
/// Distances start at 1, as 0-byte nodes are invalid.
7777
/// Also invalid are nodes being referred in a different
7878
/// order than they were encoded in.
@@ -94,12 +94,12 @@ impl<T> LazyValue<T> {
9494

9595
/// A list of lazily-decoded values.
9696
///
97-
/// Unlike `Lazy<Vec<T>>`, the length is encoded next to the
97+
/// Unlike `LazyValue<Vec<T>>`, the length is encoded next to the
9898
/// position, not at the position, which means that the length
9999
/// doesn't need to be known before encoding all the elements.
100100
///
101101
/// If the length is 0, no position is encoded, but otherwise,
102-
/// the encoding is that of `Lazy`, with the distinction that
102+
/// the encoding is that of `LazyArray`, with the distinction that
103103
/// the minimal distance the length of the sequence, i.e.
104104
/// it's assumed there's no 0-byte element in the sequence.
105105
struct LazyArray<T> {
@@ -167,17 +167,17 @@ impl<I, T> Clone for LazyTable<I, T> {
167167
}
168168
}
169169

170-
/// Encoding / decoding state for `Lazy`.
170+
/// Encoding / decoding state for `Lazy`s (`LazyValue`, `LazyArray`, and `LazyTable`).
171171
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
172172
enum LazyState {
173173
/// Outside of a metadata node.
174174
NoNode,
175175

176-
/// Inside a metadata node, and before any `Lazy`.
176+
/// Inside a metadata node, and before any `Lazy`s.
177177
/// The position is that of the node itself.
178178
NodeStart(NonZeroUsize),
179179

180-
/// Inside a metadata node, with a previous `Lazy`.
180+
/// Inside a metadata node, with a previous `Lazy`s.
181181
/// The position is where that previous `Lazy` would start.
182182
Previous(NonZeroUsize),
183183
}

compiler/rustc_metadata/src/rmeta/table.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fixed_size_enum! {
141141
}
142142
}
143143

144-
// We directly encode `DefPathHash` because a `Lazy` would encur a 25% cost.
144+
// We directly encode `DefPathHash` because a `LazyValue` would incur a 25% cost.
145145
impl FixedSizeEncoding for Option<DefPathHash> {
146146
type ByteArray = [u8; 16];
147147

@@ -159,7 +159,7 @@ impl FixedSizeEncoding for Option<DefPathHash> {
159159
}
160160
}
161161

162-
// We directly encode RawDefId because using a `Lazy` would incur a 50% overhead in the worst case.
162+
// We directly encode RawDefId because using a `LazyValue` would incur a 50% overhead in the worst case.
163163
impl FixedSizeEncoding for Option<RawDefId> {
164164
type ByteArray = [u8; 8];
165165

compiler/rustc_typeck/src/coherence/orphan.rs

+36-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_errors::struct_span_err;
6-
use rustc_errors::ErrorGuaranteed;
6+
use rustc_errors::{Diagnostic, ErrorGuaranteed};
77
use rustc_hir as hir;
88
use rustc_infer::infer::TyCtxtInferExt;
99
use rustc_middle::ty::subst::GenericArgKind;
@@ -107,6 +107,7 @@ fn do_orphan_check_impl<'tcx>(
107107
Err(err) => emit_orphan_check_error(
108108
tcx,
109109
sp,
110+
item.span,
110111
tr.path.span,
111112
trait_ref.self_ty(),
112113
impl_.self_ty.span,
@@ -207,6 +208,7 @@ fn do_orphan_check_impl<'tcx>(
207208
fn emit_orphan_check_error<'tcx>(
208209
tcx: TyCtxt<'tcx>,
209210
sp: Span,
211+
full_impl_span: Span,
210212
trait_span: Span,
211213
self_ty: Ty<'tcx>,
212214
self_ty_span: Span,
@@ -247,8 +249,20 @@ fn emit_orphan_check_error<'tcx>(
247249
ty::Slice(_) => (this, " because slices are always foreign"),
248250
ty::Array(..) => (this, " because arrays are always foreign"),
249251
ty::Tuple(..) => (this, " because tuples are always foreign"),
252+
ty::RawPtr(ptr_ty) => {
253+
emit_newtype_suggestion_for_raw_ptr(
254+
full_impl_span,
255+
self_ty,
256+
self_ty_span,
257+
ptr_ty,
258+
&mut err,
259+
);
260+
261+
(format!("`{}`", ty), " because raw pointers are always foreign")
262+
}
250263
_ => (format!("`{}`", ty), ""),
251264
};
265+
252266
let msg = format!("{} is not defined in the current crate{}", ty, postfix);
253267
if *is_target_ty {
254268
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
@@ -330,6 +344,27 @@ fn emit_orphan_check_error<'tcx>(
330344
})
331345
}
332346

347+
fn emit_newtype_suggestion_for_raw_ptr(
348+
full_impl_span: Span,
349+
self_ty: Ty<'_>,
350+
self_ty_span: Span,
351+
ptr_ty: &ty::TypeAndMut<'_>,
352+
diag: &mut Diagnostic,
353+
) {
354+
if !self_ty.needs_subst() {
355+
let mut_key = if ptr_ty.mutbl == rustc_middle::mir::Mutability::Mut { "mut " } else { "" };
356+
let msg_sugg = "consider introducing a new wrapper type".to_owned();
357+
let sugg = vec![
358+
(
359+
full_impl_span.shrink_to_lo(),
360+
format!("struct WrapperType(*{}{});\n\n", mut_key, ptr_ty.ty),
361+
),
362+
(self_ty_span, "WrapperType".to_owned()),
363+
];
364+
diag.multipart_suggestion(msg_sugg, sugg, rustc_errors::Applicability::MaybeIncorrect);
365+
}
366+
}
367+
333368
/// Lint impls of auto traits if they are likely to have
334369
/// unsound or surprising effects on auto impls.
335370
fn lint_auto_trait_impl<'tcx>(

library/core/src/ffi/c_str.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ use crate::str;
6565
/// extern "C" { fn my_string() -> *const c_char; }
6666
///
6767
/// fn my_string_safe() -> String {
68-
/// unsafe {
69-
/// CStr::from_ptr(my_string()).to_string_lossy().into_owned()
70-
/// }
68+
/// let cstr = unsafe { CStr::from_ptr(my_string()) };
69+
/// // Get copy-on-write Cow<'_, str>, then guarantee a freshly-owned String allocation
70+
/// String::from_utf8_lossy(cstr.to_bytes()).to_string()
7171
/// }
7272
///
7373
/// println!("string: {}", my_string_safe());

src/bootstrap/compile.rs

+5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ impl Step for Std {
111111

112112
builder.update_submodule(&Path::new("library").join("stdarch"));
113113

114+
// Profiler information requires LLVM's compiler-rt
115+
if builder.config.profiler {
116+
builder.update_submodule(&Path::new("src/llvm-project"));
117+
}
118+
114119
let mut target_deps = builder.ensure(StartupObjects { compiler, target });
115120

116121
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [riscv32imac-unknown-xous-elf](platform-support/riscv32imac-unknown-xous-elf.md)
2929
- [*-pc-windows-gnullvm](platform-support/pc-windows-gnullvm.md)
3030
- [*-unknown-openbsd](platform-support/openbsd.md)
31+
- [\*-unknown-uefi](platform-support/unknown-uefi.md)
3132
- [wasm64-unknown-unknown](platform-support/wasm64-unknown-unknown.md)
3233
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
3334
- [Targets](targets/index.md)

0 commit comments

Comments
 (0)