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 7 pull requests #111380

Merged
merged 33 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cb4f815
Add GNU Property Note
Apr 22, 2023
fd8aa5e
tweak "make mut" spans when assigning to locals
Ezrashaw Apr 19, 2023
9624d2b
tweak "make mut" spans (No. 2)
Ezrashaw Apr 19, 2023
57c6a31
tweak "make mut" spans (No. 3)
Ezrashaw Apr 19, 2023
336a656
tweak "make mut" spans (No. 4)
Ezrashaw Apr 19, 2023
87a1b38
tweak spans for `ref mut` suggestion
Ezrashaw Apr 20, 2023
d2608df
implement review comment
Ezrashaw Apr 21, 2023
3e64e98
fix trait definition spans in "make mut" suggestion
Ezrashaw Apr 21, 2023
bd928a0
Disallow (min) specialization imps with no items
matthewjasper May 5, 2023
fafe9e7
Normalize consistently for specializations
matthewjasper May 5, 2023
68a5bb4
Add GNU Property Note
May 5, 2023
1fc0442
rewriting match on endianness
May 5, 2023
59ecbd2
Add parsing for builtin # in expression and item context
est31 Jan 19, 2023
5eb29c7
Migrate offset_of from a macro to builtin # syntax
est31 Apr 22, 2023
83b4df4
Add feature gate
est31 Apr 29, 2023
37f3e2f
rewriting match on endianness
May 5, 2023
f46eabb
Report nicer lifetime errors for specialization
matthewjasper May 5, 2023
0bb43c6
Suggest let for possible binding with ty
chenyukang May 3, 2023
20e6e6a
cleanup
chenyukang May 3, 2023
a7fc32c
fix ice in suggesting
chenyukang May 8, 2023
a9051d8
Tweak borrow suggestion
compiler-errors Apr 18, 2023
a283f58
Rename some suggestion/note functions
compiler-errors Apr 18, 2023
4731a25
Make suggest_deref_or_ref return a multipart suggestion
compiler-errors Apr 18, 2023
5e94b5f
code refactor and fix wrong suggestion
chenyukang May 8, 2023
bf7e07f
Update books
rustbot May 8, 2023
4d219d0
move sugg to derive session diagnostic
chenyukang May 9, 2023
02a85bd
Rollup merge of #110304 - cchiw:master, r=davidtwco
Dylan-DPC May 9, 2023
2ecc722
Rollup merge of #110504 - compiler-errors:tweak-borrow-sugg, r=cjgillot
Dylan-DPC May 9, 2023
ff30b8c
Rollup merge of #110583 - Ezrashaw:tweak-make-mut-spans, r=estebank
Dylan-DPC May 9, 2023
dbd090c
Rollup merge of #110694 - est31:builtin, r=petrochenkov
Dylan-DPC May 9, 2023
8c51701
Rollup merge of #111120 - chenyukang:yukang-suggest-let, r=Nilstrieb
Dylan-DPC May 9, 2023
f748bb1
Rollup merge of #111252 - matthewjasper:min-spec-improvements, r=comp…
Dylan-DPC May 9, 2023
9d913eb
Rollup merge of #111361 - rustbot:docs-update, r=ehuss
Dylan-DPC May 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
gate_all!(yeet_expr, "`do yeet` expression is experimental");
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
gate_all!(const_closures, "const closures are experimental");
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");

if !visitor.features.negative_bounds {
for &span in spans.get(&sym::negative_bounds).iter().copied().flatten() {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,7 @@ impl<'a> State<'a> {
self.pclose();
}
ast::ExprKind::OffsetOf(container, fields) => {
// FIXME: This should have its own syntax, distinct from a macro invocation.
self.word("offset_of!");
self.word("builtin # offset_of");
self.popen();
self.rbox(0, Inconsistent);
self.print_type(container);
Expand Down
509 changes: 264 additions & 245 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions compiler/rustc_builtin_macros/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ builtin_macros_format_pos_mismatch = {$n} positional {$n ->
*[more] arguments
} in format string, but {$desc}

builtin_macros_offset_of_expected_field = expected field

builtin_macros_offset_of_expected_two_args = expected 2 arguments

builtin_macros_test_case_non_item = `#[test_case]` attribute is only allowed on items

builtin_macros_test_bad_fn = {$kind} functions cannot be used for tests
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_builtin_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ mod format;
mod format_foreign;
mod global_allocator;
mod log_syntax;
mod offset_of;
mod source_util;
mod test;
mod trace_macros;
Expand Down Expand Up @@ -92,7 +91,6 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
line: source_util::expand_line,
log_syntax: log_syntax::expand_log_syntax,
module_path: source_util::expand_mod,
offset_of: offset_of::expand_offset_of,
option_env: env::expand_option_env,
core_panic: edition_panic::expand_panic,
std_panic: edition_panic::expand_panic,
Expand Down
99 changes: 0 additions & 99 deletions compiler/rustc_builtin_macros/src/offset_of.rs

This file was deleted.

50 changes: 50 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use object::{

use snap::write::FrameEncoder;

use object::elf::NT_GNU_PROPERTY_TYPE_0;
use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::owned_slice::try_slice_owned;
use rustc_data_structures::sync::MetadataRef;
Expand Down Expand Up @@ -93,6 +94,54 @@ pub(super) fn search_for_section<'a>(
.map_err(|e| format!("failed to read {} section in '{}': {}", section, path.display(), e))
}

fn add_gnu_property_note(
file: &mut write::Object<'static>,
architecture: Architecture,
binary_format: BinaryFormat,
endianness: Endianness,
) {
// check bti protection
if binary_format != BinaryFormat::Elf
|| !matches!(architecture, Architecture::X86_64 | Architecture::Aarch64)
{
return;
}

let section = file.add_section(
file.segment_name(StandardSegment::Data).to_vec(),
b".note.gnu.property".to_vec(),
SectionKind::Note,
);
let mut data: Vec<u8> = Vec::new();
let n_namsz: u32 = 4; // Size of the n_name field
let n_descsz: u32 = 16; // Size of the n_desc field
let n_type: u32 = NT_GNU_PROPERTY_TYPE_0; // Type of note descriptor
let header_values = [n_namsz, n_descsz, n_type];
header_values.iter().for_each(|v| {
data.extend_from_slice(&match endianness {
Endianness::Little => v.to_le_bytes(),
Endianness::Big => v.to_be_bytes(),
})
});
data.extend_from_slice(b"GNU\0"); // Owner of the program property note
let pr_type: u32 = match architecture {
Architecture::X86_64 => 0xc0000002,
Architecture::Aarch64 => 0xc0000000,
_ => unreachable!(),
};
let pr_datasz: u32 = 4; //size of the pr_data field
let pr_data: u32 = 3; //program property descriptor
let pr_padding: u32 = 0;
let property_values = [pr_type, pr_datasz, pr_data, pr_padding];
property_values.iter().for_each(|v| {
data.extend_from_slice(&match endianness {
Endianness::Little => v.to_le_bytes(),
Endianness::Big => v.to_be_bytes(),
})
});
file.append_section_data(section, &data, 8);
}

pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static>> {
let endianness = match sess.target.options.endian {
Endian::Little => Endianness::Little,
Expand Down Expand Up @@ -205,6 +254,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
_ => elf::ELFOSABI_NONE,
};
let abi_version = 0;
add_gnu_property_note(&mut file, architecture, binary_format, endianness);
file.flags = FileFlags::Elf { os_abi, abi_version, e_flags };
Some(file)
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_data_structures/src/owned_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ impl Borrow<[u8]> for OwnedSlice {
}

// Safety: `OwnedSlice` is conceptually `(&'self.1 [u8], Box<dyn Send + Sync>)`, which is `Send`
#[cfg(parallel_compiler)]
unsafe impl Send for OwnedSlice {}

// Safety: `OwnedSlice` is conceptually `(&'self.1 [u8], Box<dyn Send + Sync>)`, which is `Sync`
#[cfg(parallel_compiler)]
unsafe impl Sync for OwnedSlice {}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ declare_features! (
(active, async_closure, "1.37.0", Some(62290), None),
/// Allows async functions to be declared, implemented, and used in traits.
(active, async_fn_in_trait, "1.66.0", Some(91611), None),
/// Allows builtin # foo() syntax
(active, builtin_syntax, "CURRENT_RUSTC_VERSION", Some(110680), None),
/// Allows `c"foo"` literals.
(active, c_str_literals, "CURRENT_RUSTC_VERSION", Some(105723), None),
/// Treat `extern "C"` function as nounwind.
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ hir_analysis_specialization_trait = implementing `rustc_specialization_trait` tr
hir_analysis_closure_implicit_hrtb = implicit types in closure signatures are forbidden when `for<...>` is present
.label = `for<...>` is here
hir_analysis_empty_specialization = specialization impl does not specialize any associated items
.note = impl is a specialization of this impl
hir_analysis_const_specialize = cannot specialize on const impl with non-const impl
hir_analysis_static_specialize = cannot specialize on `'static` lifetime
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,15 @@ pub(crate) struct ClosureImplicitHrtb {
pub for_sp: Span,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_empty_specialization)]
pub(crate) struct EmptySpecialization {
#[primary_span]
pub span: Span,
#[note]
pub base_impl_span: Span,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_const_specialize)]
pub(crate) struct ConstSpecialize {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
use rustc_span::Span;
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
use rustc_trait_selection::traits::{self, translate_substs, wf, ObligationCtxt};
use rustc_trait_selection::traits::{self, translate_substs_with_cause, wf, ObligationCtxt};

pub(super) fn check_min_specialization(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) {
if let Some(node) = parent_specialization_node(tcx, impl_def_id) {
Expand All @@ -100,12 +100,19 @@ fn parent_specialization_node(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId) -> Opti
// Implementing a normal trait isn't a specialization.
return None;
}
if trait_def.is_marker {
// Overlapping marker implementations are not really specializations.
return None;
}
Some(impl2_node)
}

/// Check that `impl1` is a sound specialization
#[instrument(level = "debug", skip(tcx))]
fn check_always_applicable(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId, impl2_node: Node) {
let span = tcx.def_span(impl1_def_id);
check_has_items(tcx, impl1_def_id, impl2_node, span);

if let Some((impl1_substs, impl2_substs)) = get_impl_substs(tcx, impl1_def_id, impl2_node) {
let impl2_def_id = impl2_node.def_id();
debug!(?impl2_def_id, ?impl2_substs);
Expand All @@ -116,14 +123,20 @@ fn check_always_applicable(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId, impl2_node
unconstrained_parent_impl_substs(tcx, impl2_def_id, impl2_substs)
};

let span = tcx.def_span(impl1_def_id);
check_constness(tcx, impl1_def_id, impl2_node, span);
check_static_lifetimes(tcx, &parent_substs, span);
check_duplicate_params(tcx, impl1_substs, &parent_substs, span);
check_predicates(tcx, impl1_def_id, impl1_substs, impl2_node, impl2_substs, span);
}
}

fn check_has_items(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId, impl2_node: Node, span: Span) {
if let Node::Impl(impl2_id) = impl2_node && tcx.associated_item_def_ids(impl1_def_id).is_empty() {
let base_impl_span = tcx.def_span(impl2_id);
tcx.sess.emit_err(errors::EmptySpecialization { span, base_impl_span });
}
}

/// Check that the specializing impl `impl1` is at least as const as the base
/// impl `impl2`
fn check_constness(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId, impl2_node: Node, span: Span) {
Expand Down Expand Up @@ -167,8 +180,21 @@ fn get_impl_substs(
ocx.assumed_wf_types(param_env, tcx.def_span(impl1_def_id), impl1_def_id);

let impl1_substs = InternalSubsts::identity_for_item(tcx, impl1_def_id);
let impl2_substs =
translate_substs(infcx, param_env, impl1_def_id.to_def_id(), impl1_substs, impl2_node);
let impl1_span = tcx.def_span(impl1_def_id);
let impl2_substs = translate_substs_with_cause(
infcx,
param_env,
impl1_def_id.to_def_id(),
impl1_substs,
impl2_node,
|_, span| {
traits::ObligationCause::new(
impl1_span,
impl1_def_id,
traits::ObligationCauseCode::BindingObligation(impl2_node.def_id(), span),
)
},
);

let errors = ocx.select_all_or_error();
if !errors.is_empty() {
Expand Down
Loading