Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #99892

Merged
merged 19 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d411a08
Htmldocck: Substitute the doc channel when blessing
fmease Jul 26, 2022
79e0543
Use String::from_utf8_lossy in CStr demo
workingjubilee Jul 26, 2022
d48a869
Force the Cow into a String
workingjubilee Jul 26, 2022
645a883
Update mentions to `rustc_metadata::rmeta::Lazy`
JohnTitor Jul 27, 2022
e849f9b
doc/rustc: describe the uefi target platforms
dvdhrm Jul 26, 2022
1e584d2
add suggestion when there is a impl of external trait on pointer
vincenzopalazzo Jul 24, 2022
957fe0b
Update custom.md
Jul 28, 2022
c2c70e2
Remove Clean trait implementation for ty::Visibility
GuillaumeGomez Jul 28, 2022
961dce4
Remove Clean trait implementation for VariantStruct
GuillaumeGomez Jul 28, 2022
660dc6f
Remove Clean trait implementation for VariantData fields
GuillaumeGomez Jul 28, 2022
e1e736b
Clone the `src/llvm-project` submodule if profiling is enabled
Nilstrieb Jul 28, 2022
a573adf
Rollup merge of #99686 - vincenzopalazzo:macros/impl_on_ptr, r=compil…
JohnTitor Jul 29, 2022
b7beec9
Rollup merge of #99760 - dvdhrm:rw/uefiplat, r=ehuss
JohnTitor Jul 29, 2022
55296c4
Rollup merge of #99766 - fmease:htmldocck-subst-channel-when-blessing…
JohnTitor Jul 29, 2022
9b3f49f
Rollup merge of #99781 - workingjubilee:demo-string-from-cstr, r=thomcc
JohnTitor Jul 29, 2022
fd3610e
Rollup merge of #99803 - JohnTitor:update-lazy-docs, r=compiler-errors
JohnTitor Jul 29, 2022
da3f951
Rollup merge of #99845 - xtexChooser:patch-1, r=GuillaumeGomez
JohnTitor Jul 29, 2022
51dda50
Rollup merge of #99850 - GuillaumeGomez:clean-more-items, r=notriddle
JohnTitor Jul 29, 2022
a8f77ad
Rollup merge of #99872 - Nilstrieb:bootstrap-llvm, r=jyn514
JohnTitor Jul 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder.rs
Expand Up @@ -83,7 +83,7 @@ pub(crate) struct CrateMetadata {

// --- Some data pre-decoded from the metadata blob, usually for performance ---
/// NOTE(eddyb) we pass `'static` to a `'tcx` parameter because this
/// lifetime is only used behind `Lazy`, and therefore acts like a
/// lifetime is only used behind `LazyValue`, `LazyArray`, or `LazyTable`, and therefore acts like a
/// universal (`for<'tcx>`), that is paired up with whichever `TyCtxt`
/// is being used to decode those values.
root: CrateRoot,
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Expand Up @@ -66,13 +66,13 @@ pub const METADATA_HEADER: &[u8] = &[b'r', b'u', b's', b't', 0, 0, 0, METADATA_V
///
/// Metadata is effective a tree, encoded in post-order,
/// and with the root's position written next to the header.
/// That means every single `Lazy` points to some previous
/// That means every single `LazyValue` points to some previous
/// location in the metadata and is part of a larger node.
///
/// The first `Lazy` in a node is encoded as the backwards
/// The first `LazyValue` in a node is encoded as the backwards
/// distance from the position where the containing node
/// starts and where the `Lazy` points to, while the rest
/// use the forward distance from the previous `Lazy`.
/// starts and where the `LazyValue` points to, while the rest
/// use the forward distance from the previous `LazyValue`.
/// Distances start at 1, as 0-byte nodes are invalid.
/// Also invalid are nodes being referred in a different
/// order than they were encoded in.
Expand All @@ -94,12 +94,12 @@ impl<T> LazyValue<T> {

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

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

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

/// Inside a metadata node, with a previous `Lazy`.
/// Inside a metadata node, with a previous `Lazy`s.
/// The position is where that previous `Lazy` would start.
Previous(NonZeroUsize),
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/table.rs
Expand Up @@ -141,7 +141,7 @@ fixed_size_enum! {
}
}

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

Expand All @@ -159,7 +159,7 @@ impl FixedSizeEncoding for Option<DefPathHash> {
}
}

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

Expand Down
37 changes: 36 additions & 1 deletion compiler/rustc_typeck/src/coherence/orphan.rs
Expand Up @@ -3,7 +3,7 @@

use rustc_data_structures::fx::FxHashSet;
use rustc_errors::struct_span_err;
use rustc_errors::ErrorGuaranteed;
use rustc_errors::{Diagnostic, ErrorGuaranteed};
use rustc_hir as hir;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::ty::subst::GenericArgKind;
Expand Down Expand Up @@ -107,6 +107,7 @@ fn do_orphan_check_impl<'tcx>(
Err(err) => emit_orphan_check_error(
tcx,
sp,
item.span,
tr.path.span,
trait_ref.self_ty(),
impl_.self_ty.span,
Expand Down Expand Up @@ -207,6 +208,7 @@ fn do_orphan_check_impl<'tcx>(
fn emit_orphan_check_error<'tcx>(
tcx: TyCtxt<'tcx>,
sp: Span,
full_impl_span: Span,
trait_span: Span,
self_ty: Ty<'tcx>,
self_ty_span: Span,
Expand Down Expand Up @@ -247,8 +249,20 @@ fn emit_orphan_check_error<'tcx>(
ty::Slice(_) => (this, " because slices are always foreign"),
ty::Array(..) => (this, " because arrays are always foreign"),
ty::Tuple(..) => (this, " because tuples are always foreign"),
ty::RawPtr(ptr_ty) => {
emit_newtype_suggestion_for_raw_ptr(
full_impl_span,
self_ty,
self_ty_span,
ptr_ty,
&mut err,
);

(format!("`{}`", ty), " because raw pointers are always foreign")
}
_ => (format!("`{}`", ty), ""),
};

let msg = format!("{} is not defined in the current crate{}", ty, postfix);
if *is_target_ty {
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
Expand Down Expand Up @@ -330,6 +344,27 @@ fn emit_orphan_check_error<'tcx>(
})
}

fn emit_newtype_suggestion_for_raw_ptr(
full_impl_span: Span,
self_ty: Ty<'_>,
self_ty_span: Span,
ptr_ty: &ty::TypeAndMut<'_>,
diag: &mut Diagnostic,
) {
if !self_ty.needs_subst() {
let mut_key = if ptr_ty.mutbl == rustc_middle::mir::Mutability::Mut { "mut " } else { "" };
let msg_sugg = "consider introducing a new wrapper type".to_owned();
let sugg = vec![
(
full_impl_span.shrink_to_lo(),
format!("struct WrapperType(*{}{});\n\n", mut_key, ptr_ty.ty),
),
(self_ty_span, "WrapperType".to_owned()),
];
diag.multipart_suggestion(msg_sugg, sugg, rustc_errors::Applicability::MaybeIncorrect);
}
}

/// Lint impls of auto traits if they are likely to have
/// unsound or surprising effects on auto impls.
fn lint_auto_trait_impl<'tcx>(
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/ffi/c_str.rs
Expand Up @@ -65,9 +65,9 @@ use crate::str;
/// extern "C" { fn my_string() -> *const c_char; }
///
/// fn my_string_safe() -> String {
/// unsafe {
/// CStr::from_ptr(my_string()).to_string_lossy().into_owned()
/// }
/// let cstr = unsafe { CStr::from_ptr(my_string()) };
/// // Get copy-on-write Cow<'_, str>, then guarantee a freshly-owned String allocation
/// String::from_utf8_lossy(cstr.to_bytes()).to_string()
/// }
///
/// println!("string: {}", my_string_safe());
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/compile.rs
Expand Up @@ -111,6 +111,11 @@ impl Step for Std {

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

// Profiler information requires LLVM's compiler-rt
if builder.config.profiler {
builder.update_submodule(&Path::new("src/llvm-project"));
}

let mut target_deps = builder.ensure(StartupObjects { compiler, target });

let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Expand Up @@ -28,6 +28,7 @@
- [riscv32imac-unknown-xous-elf](platform-support/riscv32imac-unknown-xous-elf.md)
- [*-pc-windows-gnullvm](platform-support/pc-windows-gnullvm.md)
- [*-unknown-openbsd](platform-support/openbsd.md)
- [\*-unknown-uefi](platform-support/unknown-uefi.md)
- [wasm64-unknown-unknown](platform-support/wasm64-unknown-unknown.md)
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
- [Targets](targets/index.md)
Expand Down