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 10 pull requests #82330

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f165f49
Slight perf improvement on char::to_ascii_lowercase
gilescope Feb 6, 2021
f30c51a
Pulling out constant.
gilescope Feb 6, 2021
cadcf5e
Unify way to flip 6th bit. (Same assembly generated)
gilescope Feb 8, 2021
0060c91
Make WASI's `hard_link` behavior match other platforms.
sunfishcode Feb 11, 2021
daa55ac
Slightly more explicit
gilescope Feb 12, 2021
eace240
use option<PlaceRef<'tcx>> to clean up mir code a little
henryboisdequin Feb 14, 2021
33d8b04
Move const def nearer usage.
gilescope Feb 14, 2021
c675af8
Add internal `collect_into_array[_unchecked]` to remove duplicate code
LukasKalbertodt Feb 14, 2021
30c5125
update formating
henryboisdequin Feb 16, 2021
5ec4b06
make `visit_projection` take a `PlaceRef`
henryboisdequin Feb 16, 2021
b08bc78
fix MIR fn-ptr pretty-printing
RalfJung Feb 16, 2021
5fd1ebe
Fix panic in 'remove semicolon' when types are not local
osa1 Feb 11, 2021
ad47fb1
Check opaque type def ids before bailing out
osa1 Feb 11, 2021
15fdccc
Update 'match-prev-arm-needing-semi'
osa1 Feb 11, 2021
9ef67e0
Add regression test
osa1 Feb 18, 2021
343b673
Consider auto derefs before warning about write only fields
tmiasko Feb 19, 2021
48b5c09
add s390x-unknown-linux-musl target
kaniini Feb 16, 2021
597118b
add s390x-unknown-linux-musl target to platform support
kaniini Feb 16, 2021
62ee3ec
remove checkboxes from s390x-unknown-linux-musl triplet
kaniini Feb 19, 2021
1abcdfe
x.py fmt
sunfishcode Feb 19, 2021
0fddc2f
Support `pub` on `macro_rules`
petrochenkov Oct 20, 2020
b3000ec
Update pub_macro_rules since version
spastorino Feb 19, 2021
1839748
`impl PartialEq<Punct> for char`; symmetry for #78636
pthariensflame Jan 1, 2021
e906745
fn ptr pretty printing: fall back to raw ptr printing
RalfJung Feb 20, 2021
a9c6188
make `super_projection` take a `PlaceRef`
henryboisdequin Feb 20, 2021
e37adf5
Rollup merge of #80595 - pthariensflame:patch-1, r=m-ou-se
Dylan-DPC Feb 20, 2021
6468333
Rollup merge of #81837 - gilescope:to_ascii_speedups, r=dtolnay
Dylan-DPC Feb 20, 2021
b7b2d58
Rollup merge of #81984 - sunfishcode:wasi-link, r=alexcrichton
Dylan-DPC Feb 20, 2021
71ee3c8
Rollup merge of #81991 - osa1:issue81839, r=estebank
Dylan-DPC Feb 20, 2021
06e04fd
Rollup merge of #82091 - henryboisdequin:use-place-ref-more, r=RalfJung
Dylan-DPC Feb 20, 2021
bb89479
Rollup merge of #82098 - LukasKalbertodt:add-collect-into-array, r=dt…
Dylan-DPC Feb 20, 2021
886e995
Rollup merge of #82166 - kaniini:s390x-musl-target, r=nagisa
Dylan-DPC Feb 20, 2021
7109440
Rollup merge of #82176 - RalfJung:mir-fn-ptr-pretty, r=oli-obk
Dylan-DPC Feb 20, 2021
50272eb
Rollup merge of #82296 - spastorino:pubrules, r=nikomatsakis
Dylan-DPC Feb 20, 2021
3b80aef
Rollup merge of #82297 - tmiasko:write-only, r=oli-obk
Dylan-DPC Feb 20, 2021
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 @@ -665,6 +665,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
// involved, so we only emit errors where there are no other parsing errors.
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
}
gate_all!(pub_macro_rules, "`pub` on `macro_rules` items is unstable");

// All uses of `gate_all!` below this point were added in #65742,
// and subsequently disabled (with the non-early gating readded).
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
}

self.visit_local(&place_ref.local, context, location);
self.visit_projection(place_ref.local, place_ref.projection, context, location);
self.visit_projection(*place_ref, context, location);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,9 @@ declare_features! (
/// Allows macro attributes to observe output of `#[derive]`.
(active, macro_attributes_in_derive_output, "1.51.0", Some(81119), None),

/// Allows `pub` on `macro_rules` items.
(active, pub_macro_rules, "1.52.0", Some(78855), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand Down
15 changes: 7 additions & 8 deletions compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,12 +998,11 @@ macro_rules! visit_place_fns {
() => {
fn visit_projection(
&mut self,
local: Local,
projection: &[PlaceElem<'tcx>],
place_ref: PlaceRef<'tcx>,
context: PlaceContext,
location: Location,
) {
self.super_projection(local, projection, context, location);
self.super_projection(place_ref, context, location);
}

fn visit_projection_elem(
Expand Down Expand Up @@ -1033,20 +1032,20 @@ macro_rules! visit_place_fns {

self.visit_local(&place.local, context, location);

self.visit_projection(place.local, &place.projection, context, location);
self.visit_projection(place.as_ref(), context, location);
}

fn super_projection(
&mut self,
local: Local,
projection: &[PlaceElem<'tcx>],
place_ref: PlaceRef<'tcx>,
context: PlaceContext,
location: Location,
) {
let mut cursor = projection;
// FIXME: Use PlaceRef::iter_projections, once that exists.
let mut cursor = place_ref.projection;
while let &[ref proj_base @ .., elem] = cursor {
cursor = proj_base;
self.visit_projection_elem(local, cursor, elem, context, location);
self.visit_projection_elem(place_ref.local, cursor, elem, context, location);
}
}

Expand Down
21 changes: 12 additions & 9 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ pub trait PrettyPrinter<'tcx>:
p!(write("{:?}", char::try_from(int).unwrap()))
}
// Raw pointers
(Scalar::Int(int), ty::RawPtr(_)) => {
(Scalar::Int(int), ty::RawPtr(_) | ty::FnPtr(_)) => {
let data = int.assert_bits(self.tcx().data_layout.pointer_size);
self = self.typed_value(
|mut this| {
Expand All @@ -1030,15 +1030,18 @@ pub trait PrettyPrinter<'tcx>:
)?;
}
(Scalar::Ptr(ptr), ty::FnPtr(_)) => {
// FIXME: this can ICE when the ptr is dangling or points to a non-function.
// We should probably have a helper method to share code with the "Byte strings"
// FIXME: We should probably have a helper method to share code with the "Byte strings"
// printing above (which also has to handle pointers to all sorts of things).
let instance = self.tcx().global_alloc(ptr.alloc_id).unwrap_fn();
self = self.typed_value(
|this| this.print_value_path(instance.def_id(), instance.substs),
|this| this.print_type(ty),
" as ",
)?;
match self.tcx().get_global_alloc(ptr.alloc_id) {
Some(GlobalAlloc::Function(instance)) => {
self = self.typed_value(
|this| this.print_value_path(instance.def_id(), instance.substs),
|this| this.print_type(ty),
" as ",
)?;
}
_ => self = self.pretty_print_const_pointer(ptr, ty, print_ty)?,
}
}
// For function type zsts just printing the path is enough
(Scalar::Int(int), ty::FnDef(d, s)) if int == ScalarInt::ZST => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/dataflow/impls/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ where

// We purposefully do not call `super_place` here to avoid calling `visit_local` for this
// place with one of the `Projection` variants of `PlaceContext`.
self.visit_projection(local, projection, context, location);
self.visit_projection(place.as_ref(), context, location);

match DefUse::for_place(context) {
// Treat derefs as a use of the base local. `*p = 4` is not a def of `p` but a use.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<Tag: Copy> std::fmt::Display for ImmTy<'tcx, Tag> {
}
ScalarMaybeUninit::Uninit => cx.typed_value(
|mut this| {
this.write_str("{uninit ")?;
this.write_str("uninit ")?;
Ok(this)
},
|this| this.print_type(ty),
Expand Down
23 changes: 12 additions & 11 deletions compiler/rustc_mir/src/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
// Special-case reborrows to be more like a copy of a reference.
match *rvalue {
Rvalue::Ref(_, kind, place) => {
if let Some(reborrowed_proj) = place_as_reborrow(self.tcx, self.body, place) {
if let Some(reborrowed_place_ref) = place_as_reborrow(self.tcx, self.body, place) {
let ctx = match kind {
BorrowKind::Shared => {
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow)
Expand All @@ -530,21 +530,21 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
PlaceContext::MutatingUse(MutatingUseContext::Borrow)
}
};
self.visit_local(&place.local, ctx, location);
self.visit_projection(place.local, reborrowed_proj, ctx, location);
self.visit_local(&reborrowed_place_ref.local, ctx, location);
self.visit_projection(reborrowed_place_ref, ctx, location);
return;
}
}
Rvalue::AddressOf(mutbl, place) => {
if let Some(reborrowed_proj) = place_as_reborrow(self.tcx, self.body, place) {
if let Some(reborrowed_place_ref) = place_as_reborrow(self.tcx, self.body, place) {
let ctx = match mutbl {
Mutability::Not => {
PlaceContext::NonMutatingUse(NonMutatingUseContext::AddressOf)
}
Mutability::Mut => PlaceContext::MutatingUse(MutatingUseContext::AddressOf),
};
self.visit_local(&place.local, ctx, location);
self.visit_projection(place.local, reborrowed_proj, ctx, location);
self.visit_local(&reborrowed_place_ref.local, ctx, location);
self.visit_projection(reborrowed_place_ref, ctx, location);
return;
}
}
Expand Down Expand Up @@ -1039,7 +1039,7 @@ fn place_as_reborrow(
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
place: Place<'tcx>,
) -> Option<&'a [PlaceElem<'tcx>]> {
) -> Option<PlaceRef<'tcx>> {
match place.as_ref().last_projection() {
Some((place_base, ProjectionElem::Deref)) => {
// A borrow of a `static` also looks like `&(*_1)` in the MIR, but `_1` is a `const`
Expand All @@ -1048,13 +1048,14 @@ fn place_as_reborrow(
None
} else {
// Ensure the type being derefed is a reference and not a raw pointer.
//
// This is sufficient to prevent an access to a `static mut` from being marked as a
// reborrow, even if the check above were to disappear.
let inner_ty = place_base.ty(body, tcx).ty;
match inner_ty.kind() {
ty::Ref(..) => Some(place_base.projection),
_ => None,

if let ty::Ref(..) = inner_ty.kind() {
return Some(place_base);
} else {
return None;
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir/src/transform/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,7 @@ impl UsedLocals {
} else {
// A definition. Although, it still might use other locals for indexing.
self.super_projection(
place.local,
&place.projection,
place.as_ref(),
PlaceContext::MutatingUse(MutatingUseContext::Projection),
location,
);
Expand Down
10 changes: 1 addition & 9 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,15 +1475,7 @@ impl<'a> Parser<'a> {
let vstr = pprust::vis_to_string(vis);
let vstr = vstr.trim_end();
if macro_rules {
let msg = format!("can't qualify macro_rules invocation with `{}`", vstr);
self.struct_span_err(vis.span, &msg)
.span_suggestion(
vis.span,
"try exporting the macro",
"#[macro_export]".to_owned(),
Applicability::MaybeIncorrect, // speculative
)
.emit();
self.sess.gated_spans.gate(sym::pub_macro_rules, vis.span);
} else {
self.struct_span_err(vis.span, "can't qualify macro invocation with `pub`")
.span_suggestion(
Expand Down
28 changes: 17 additions & 11 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ fn should_explore(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
)
}

fn base_expr<'a>(mut expr: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> {
loop {
match expr.kind {
hir::ExprKind::Field(base, ..) => expr = base,
_ => return expr,
}
}
}

struct MarkSymbolVisitor<'tcx> {
worklist: Vec<hir::HirId>,
tcx: TyCtxt<'tcx>,
Expand Down Expand Up @@ -143,6 +134,22 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
}
}

fn handle_assign(&mut self, expr: &'tcx hir::Expr<'tcx>) {
if self
.typeck_results()
.expr_adjustments(expr)
.iter()
.any(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(_)))
{
self.visit_expr(expr);
} else if let hir::ExprKind::Field(base, ..) = expr.kind {
// Ignore write to field
self.handle_assign(base);
} else {
self.visit_expr(expr);
}
}

fn handle_field_pattern_match(
&mut self,
lhs: &hir::Pat<'_>,
Expand Down Expand Up @@ -272,8 +279,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
self.lookup_and_handle_method(expr.hir_id);
}
hir::ExprKind::Assign(ref left, ref right, ..) => {
// Ignore write to field
self.visit_expr(base_expr(left));
self.handle_assign(left);
self.visit_expr(right);
return;
}
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,13 +1230,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
};

let res = Res::Def(DefKind::Macro(ext.macro_kind()), def_id.to_def_id());
let is_macro_export = self.r.session.contains_name(&item.attrs, sym::macro_export);
self.r.macro_map.insert(def_id.to_def_id(), ext);
self.r.local_macro_def_scopes.insert(def_id, parent_scope.module);

if macro_rules {
if macro_rules && matches!(item.vis.kind, ast::VisibilityKind::Inherited) {
let ident = ident.normalize_to_macros_2_0();
self.r.macro_names.insert(ident);
let is_macro_export = self.r.session.contains_name(&item.attrs, sym::macro_export);
let vis = if is_macro_export {
ty::Visibility::Public
} else {
Expand All @@ -1261,6 +1261,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
}),
))
} else {
if is_macro_export {
let what = if macro_rules { "`macro_rules` with `pub`" } else { "`macro` items" };
let msg = format!("`#[macro_export]` cannot be used on {what}");
self.r.session.span_err(item.span, &msg);
}
let module = parent_scope.module;
let vis = match item.kind {
// Visibilities must not be resolved non-speculatively twice
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ symbols! {
ptr_guaranteed_eq,
ptr_guaranteed_ne,
ptr_offset_from,
pub_macro_rules,
pub_restricted,
pure,
pushpop_unsafe,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ supported_targets! {
("powerpc64le-unknown-linux-gnu", powerpc64le_unknown_linux_gnu),
("powerpc64le-unknown-linux-musl", powerpc64le_unknown_linux_musl),
("s390x-unknown-linux-gnu", s390x_unknown_linux_gnu),
("s390x-unknown-linux-musl", s390x_unknown_linux_musl),
("sparc-unknown-linux-gnu", sparc_unknown_linux_gnu),
("sparc64-unknown-linux-gnu", sparc64_unknown_linux_gnu),
("arm-unknown-linux-gnueabi", arm_unknown_linux_gnueabi),
Expand Down
24 changes: 24 additions & 0 deletions compiler/rustc_target/src/spec/s390x_unknown_linux_musl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::abi::Endian;
use crate::spec::Target;

pub fn target() -> Target {
let mut base = super::linux_musl_base::opts();
base.endian = Endian::Big;
// z10 is the oldest CPU supported by LLVM
base.cpu = "z10".to_string();
// FIXME: The data_layout string below and the ABI implementation in
// cabi_s390x.rs are for now hard-coded to assume the no-vector ABI.
// Pass the -vector feature string to LLVM to respect this assumption.
base.features = "-vector".to_string();
base.max_atomic_width = Some(64);
base.min_global_align = Some(16);
base.static_position_independent_executables = true;

Target {
llvm_target: "s390x-unknown-linux-musl".to_string(),
pointer_width: 64,
data_layout: "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64".to_string(),
arch: "s390x".to_string(),
options: base,
}
}
17 changes: 15 additions & 2 deletions compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,13 +1074,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
let last_expr_ty = self.node_ty(last_expr.hir_id);
let needs_box = match (last_expr_ty.kind(), expected_ty.kind()) {
(ty::Opaque(last_def_id, _), ty::Opaque(exp_def_id, _))
if last_def_id == exp_def_id =>
{
StatementAsExpression::CorrectType
}
(ty::Opaque(last_def_id, last_bounds), ty::Opaque(exp_def_id, exp_bounds)) => {
debug!(
"both opaque, likely future {:?} {:?} {:?} {:?}",
last_def_id, last_bounds, exp_def_id, exp_bounds
);
let last_hir_id = self.tcx.hir().local_def_id_to_hir_id(last_def_id.expect_local());
let exp_hir_id = self.tcx.hir().local_def_id_to_hir_id(exp_def_id.expect_local());

let (last_local_id, exp_local_id) =
match (last_def_id.as_local(), exp_def_id.as_local()) {
(Some(last_hir_id), Some(exp_hir_id)) => (last_hir_id, exp_hir_id),
(_, _) => return None,
};

let last_hir_id = self.tcx.hir().local_def_id_to_hir_id(last_local_id);
let exp_hir_id = self.tcx.hir().local_def_id_to_hir_id(exp_local_id);

match (
&self.tcx.hir().expect_item(last_hir_id).kind,
&self.tcx.hir().expect_item(exp_hir_id).kind,
Expand Down
6 changes: 4 additions & 2 deletions library/core/benches/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ macro_rules! benches {
use test::black_box;
use test::Bencher;

const ASCII_CASE_MASK: u8 = 0b0010_0000;

benches! {
fn case00_alloc_only(_bytes: &mut [u8]) {}

Expand Down Expand Up @@ -204,7 +206,7 @@ benches! {
}
}
for byte in bytes {
*byte &= !((is_ascii_lowercase(*byte) as u8) << 5)
*byte &= !((is_ascii_lowercase(*byte) as u8) * ASCII_CASE_MASK)
}
}

Expand All @@ -216,7 +218,7 @@ benches! {
}
}
for byte in bytes {
*byte -= (is_ascii_lowercase(*byte) as u8) << 5
*byte -= (is_ascii_lowercase(*byte) as u8) * ASCII_CASE_MASK
}
}

Expand Down
Loading