Skip to content

Rollup of 13 pull requests #77038

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

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
28db521
More implementations of Write for immutable refs
Sep 2, 2020
ec7f9b9
Deduplicates io::Write implementations
Sep 11, 2020
8f27e3c
Make some methods of `Pin` unstable const
CDirkx Sep 12, 2020
e5447a2
Fix #76432
simonvandel Sep 13, 2020
eede953
Only get ImplKind::Impl once
tesuji Sep 10, 2020
7e24136
Pass --target to lint docs
Mark-Simulacrum Sep 16, 2020
bd4e0af
Build rustdoc for cross-compiled targets
Mark-Simulacrum Sep 16, 2020
363aff0
Add test for x.py build cross-compilation
Mark-Simulacrum Sep 17, 2020
e3c6e46
Make some methods of `Pin<&mut T>` unstable const
CDirkx Sep 18, 2020
2a00dda
miri: correctly deal with `ConstKind::Bound`
lcnr Sep 10, 2020
6734230
do not ICE on `ty::Bound` in Layout::compute
lcnr Sep 11, 2020
65b3419
update stderr file
lcnr Sep 20, 2020
c690c82
use if let instead of single match arm expressions to compact code an…
matthiaskrgr Sep 18, 2020
88a29e6
Updates stability attributes to the current nightly version
Sep 21, 2020
0acb0ed
Update library/std/src/process.rs
FedericoPonzi Sep 21, 2020
60b102d
Don't recommend ManuallyDrop to customize drop order
matklad Aug 31, 2020
fe6fc55
Add a changelog for x.py
jyn514 Sep 12, 2020
b4b4a2f
Reduce boilerplate for BytePos and CharPos
Juici Sep 21, 2020
9a1f177
Remove cast to usize for BytePos and CharPos
Juici Sep 21, 2020
63195ec
Add explanation for E0756
GuillaumeGomez Sep 8, 2020
f5d71a9
Don't use `zip` to compare iterators during pretty-print hack
Aaron1011 Aug 30, 2020
40a5dc8
MIR pass to remove unneeded drops on types not needing drop
simonvandel Sep 13, 2020
e6942ae
Suggestion from review
simonvandel Sep 14, 2020
9b61fbc
Get LocalDefId from source instead of passing in
simonvandel Sep 19, 2020
d372455
The optimization should also apply for DropAndReplace
simonvandel Sep 19, 2020
1b2da2e
cleanup cfg after optimization
simonvandel Sep 19, 2020
dfb9f3a
rebless after rebase
simonvandel Sep 21, 2020
6be8212
Rollup merge of #76131 - Aaron1011:fix/pretty-print-zip, r=lcnr
Dylan-DPC Sep 22, 2020
e9aaa3b
Rollup merge of #76150 - matklad:droporder, r=withoutboats
Dylan-DPC Sep 22, 2020
b062780
Rollup merge of #76275 - FedericoPonzi:immutable-write-impl-73836, r=…
Dylan-DPC Sep 22, 2020
b7a6aae
Rollup merge of #76489 - GuillaumeGomez:add-explanation-e0756, r=jyn514
Dylan-DPC Sep 22, 2020
7a91e17
Rollup merge of #76581 - lcnr:bound-too-generic, r=eddyb
Dylan-DPC Sep 22, 2020
a65a244
Rollup merge of #76626 - jyn514:x.py-changelog, r=Mark-Simulacrum
Dylan-DPC Sep 22, 2020
4b4cfdd
Rollup merge of #76655 - CDirkx:const-pin, r=ecstatic-morse
Dylan-DPC Sep 22, 2020
8d641ce
Rollup merge of #76659 - simonvandel:76432, r=oli-obk
Dylan-DPC Sep 22, 2020
0e5bcba
Rollup merge of #76673 - simonvandel:remove-unneeded-drops, r=oli-obk
Dylan-DPC Sep 22, 2020
5e46051
Rollup merge of #76783 - lzutao:rd_impl_kind, r=GuillaumeGomez
Dylan-DPC Sep 22, 2020
a282d1e
Rollup merge of #76799 - Mark-Simulacrum:fix-cross-compile-dist, r=al…
Dylan-DPC Sep 22, 2020
42b3303
Rollup merge of #76888 - matthiaskrgr:clippy_single_match_2, r=Dylan-DPC
Dylan-DPC Sep 22, 2020
b441d26
Rollup merge of #77022 - Juici:master, r=lcnr
Dylan-DPC Sep 22, 2020
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
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ E0752: include_str!("./error_codes/E0752.md"),
E0753: include_str!("./error_codes/E0753.md"),
E0754: include_str!("./error_codes/E0754.md"),
E0755: include_str!("./error_codes/E0755.md"),
E0756: include_str!("./error_codes/E0756.md"),
E0758: include_str!("./error_codes/E0758.md"),
E0759: include_str!("./error_codes/E0759.md"),
E0760: include_str!("./error_codes/E0760.md"),
Expand Down Expand Up @@ -633,7 +634,6 @@ E0774: include_str!("./error_codes/E0774.md"),
E0722, // Malformed `#[optimize]` attribute
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
E0756, // `#[ffi_const]` is only allowed on foreign functions
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
}
29 changes: 29 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0756.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
The `ffi_const` attribute was used on something other than a foreign function
declaration.

Erroneous code example:

```compile_fail,E0756
#![feature(ffi_const)]

#[ffi_const] // error!
pub fn foo() {}
# fn main() {}
```

The `ffi_const` attribute can only be used on foreign function declarations
which have no side effects except for their return value:

```
#![feature(ffi_const)]

extern "C" {
#[ffi_const] // ok!
pub fn strlen(s: *const i8) -> i32;
}
# fn main() {}
```

You can get more information about it in the [unstable Rust Book].

[unstable Rust Book]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-const.html
Original file line number Diff line number Diff line change
Expand Up @@ -488,18 +488,16 @@ impl<'tcx> Visitor<'tcx> for HirTraitObjectVisitor {
}

fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) {
match t.kind {
TyKind::TraitObject(
poly_trait_refs,
Lifetime { name: LifetimeName::ImplicitObjectLifetimeDefault, .. },
) => {
for ptr in poly_trait_refs {
if Some(self.1) == ptr.trait_ref.trait_def_id() {
self.0.push(ptr.span);
}
if let TyKind::TraitObject(
poly_trait_refs,
Lifetime { name: LifetimeName::ImplicitObjectLifetimeDefault, .. },
) = t.kind
{
for ptr in poly_trait_refs {
if Some(self.1) == ptr.trait_ref.trait_def_id() {
self.0.push(ptr.span);
}
}
_ => {}
}
walk_ty(self, t);
}
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,14 +834,11 @@ fn foo(&self) -> Self::T { String::new() }
kind: hir::ItemKind::Impl { items, .. }, ..
})) => {
for item in &items[..] {
match item.kind {
hir::AssocItemKind::Type => {
if self.type_of(self.hir().local_def_id(item.id.hir_id)) == found {
db.span_label(item.span, "expected this associated type");
return true;
}
if let hir::AssocItemKind::Type = item.kind {
if self.type_of(self.hir().local_def_id(item.id.hir_id)) == found {
db.span_label(item.span, "expected this associated type");
return true;
}
_ => {}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,11 +1259,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
tcx.layout_raw(param_env.and(normalized))?
}

ty::Bound(..) | ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Infer(_) => {
ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Infer(_) => {
bug!("Layout::compute: unexpected type `{}`", ty)
}

ty::Param(_) | ty::Error(_) => {
ty::Bound(..) | ty::Param(_) | ty::Error(_) => {
return Err(LayoutError::Unknown(ty));
}
})
Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2125,17 +2125,10 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
// Iterate all local crate items no matter where they are defined.
let hir = tcx.hir();
for item in hir.krate().items.values() {
if item.ident.name.as_str().is_empty() {
if item.ident.name.as_str().is_empty() || matches!(item.kind, ItemKind::Use(_, _)) {
continue;
}

match item.kind {
ItemKind::Use(_, _) => {
continue;
}
_ => {}
}

if let Some(local_def_id) = hir.definitions().opt_hir_id_to_local_def_id(item.hir_id) {
let def_id = local_def_id.to_def_id();
let ns = tcx.def_kind(def_id).ns().unwrap_or(Namespace::TypeNS);
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_mir/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
};
// Early-return cases.
let val_val = match val.val {
ty::ConstKind::Param(_) => throw_inval!(TooGeneric),
ty::ConstKind::Param(_) | ty::ConstKind::Bound(..) => throw_inval!(TooGeneric),
ty::ConstKind::Error(_) => throw_inval!(TypeckError(ErrorReported)),
ty::ConstKind::Unevaluated(def, substs, promoted) => {
let instance = self.resolve(def, substs)?;
return Ok(self.eval_to_allocation(GlobalId { instance, promoted })?.into());
}
ty::ConstKind::Infer(..)
| ty::ConstKind::Bound(..)
| ty::ConstKind::Placeholder(..) => {
ty::ConstKind::Infer(..) | ty::ConstKind::Placeholder(..) => {
span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", val)
}
ty::ConstKind::Value(val_val) => val_val,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_mir/src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub mod nrvo;
pub mod promote_consts;
pub mod qualify_min_const_fn;
pub mod remove_noop_landing_pads;
pub mod remove_unneeded_drops;
pub mod required_consts;
pub mod rustc_peek;
pub mod simplify;
Expand Down Expand Up @@ -461,6 +462,7 @@ fn run_optimization_passes<'tcx>(

// The main optimizations that we do on MIR.
let optimizations: &[&dyn MirPass<'tcx>] = &[
&remove_unneeded_drops::RemoveUnneededDrops,
&match_branches::MatchBranchSimplification,
// inst combine is after MatchBranchSimplification to clean up Ne(_1, false)
&instcombine::InstCombine,
Expand Down
16 changes: 5 additions & 11 deletions compiler/rustc_mir/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,8 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
}
TerminatorKind::InlineAsm { ref operands, .. } => {
for (index, op) in operands.iter().enumerate() {
match op {
InlineAsmOperand::Const { .. } => {
self.candidates.push(Candidate::InlineAsm { bb: location.block, index })
}
_ => {}
if let InlineAsmOperand::Const { .. } = op {
self.candidates.push(Candidate::InlineAsm { bb: location.block, index })
}
}
}
Expand Down Expand Up @@ -612,12 +609,9 @@ impl<'tcx> Validator<'_, 'tcx> {
let operand_ty = operand.ty(self.body, self.tcx);
let cast_in = CastTy::from_ty(operand_ty).expect("bad input type for cast");
let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast");
match (cast_in, cast_out) {
(CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) => {
// ptr-to-int casts are not possible in consts and thus not promotable
return Err(Unpromotable);
}
_ => {}
if let (CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) = (cast_in, cast_out) {
// ptr-to-int casts are not possible in consts and thus not promotable
return Err(Unpromotable);
}
}

Expand Down
59 changes: 59 additions & 0 deletions compiler/rustc_mir/src/transform/remove_unneeded_drops.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//! This pass replaces a drop of a type that does not need dropping, with a goto

use crate::transform::{MirPass, MirSource};
use rustc_hir::def_id::LocalDefId;
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;

use super::simplify::simplify_cfg;

pub struct RemoveUnneededDrops;

impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) {
trace!("Running RemoveUnneededDrops on {:?}", source);
let mut opt_finder = RemoveUnneededDropsOptimizationFinder {
tcx,
body,
optimizations: vec![],
def_id: source.def_id().expect_local(),
};
opt_finder.visit_body(body);
let should_simplify = !opt_finder.optimizations.is_empty();
for (loc, target) in opt_finder.optimizations {
let terminator = body.basic_blocks_mut()[loc.block].terminator_mut();
debug!("SUCCESS: replacing `drop` with goto({:?})", target);
terminator.kind = TerminatorKind::Goto { target };
}

// if we applied optimizations, we potentially have some cfg to cleanup to
// make it easier for further passes
if should_simplify {
simplify_cfg(body);
}
}
}

impl<'a, 'tcx> Visitor<'tcx> for RemoveUnneededDropsOptimizationFinder<'a, 'tcx> {
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
match terminator.kind {
TerminatorKind::Drop { place, target, .. }
| TerminatorKind::DropAndReplace { place, target, .. } => {
let ty = place.ty(self.body, self.tcx);
let needs_drop = ty.ty.needs_drop(self.tcx, self.tcx.param_env(self.def_id));
if !needs_drop {
self.optimizations.push((location, target));
}
}
_ => {}
}
self.super_terminator(terminator, location);
}
}
pub struct RemoveUnneededDropsOptimizationFinder<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
body: &'a Body<'tcx>,
optimizations: Vec<(Location, BasicBlock)>,
def_id: LocalDefId,
}
43 changes: 22 additions & 21 deletions compiler/rustc_mir/src/transform/simplify_comparison_integral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,6 @@ impl<'tcx> MirPass<'tcx> for SimplifyComparisonIntegral {
_ => unreachable!(),
}

let terminator = bb.terminator_mut();

// add StorageDead for the place switched on at the top of each target
for bb_idx in new_targets.iter() {
storage_deads_to_insert.push((
*bb_idx,
Statement {
source_info: terminator.source_info,
kind: StatementKind::StorageDead(opt.to_switch_on.local),
},
));
}

terminator.kind = TerminatorKind::SwitchInt {
discr: Operand::Move(opt.to_switch_on),
switch_ty: opt.branch_value_ty,
values: vec![new_value].into(),
targets: new_targets,
};

// delete comparison statement if it the value being switched on was moved, which means it can not be user later on
if opt.can_remove_bin_op_stmt {
bb.statements[opt.bin_op_stmt_idx].make_nop();
Expand All @@ -106,14 +86,35 @@ impl<'tcx> MirPass<'tcx> for SimplifyComparisonIntegral {
}
}

let terminator = bb.terminator();

// remove StorageDead (if it exists) being used in the assign of the comparison
for (stmt_idx, stmt) in bb.statements.iter().enumerate() {
if !matches!(stmt.kind, StatementKind::StorageDead(local) if local == opt.to_switch_on.local)
{
continue;
}
storage_deads_to_remove.push((stmt_idx, opt.bb_idx))
storage_deads_to_remove.push((stmt_idx, opt.bb_idx));
// if we have StorageDeads to remove then make sure to insert them at the top of each target
for bb_idx in new_targets.iter() {
storage_deads_to_insert.push((
*bb_idx,
Statement {
source_info: terminator.source_info,
kind: StatementKind::StorageDead(opt.to_switch_on.local),
},
));
}
}

let terminator = bb.terminator_mut();

terminator.kind = TerminatorKind::SwitchInt {
discr: Operand::Move(opt.to_switch_on),
switch_ty: opt.branch_value_ty,
values: vec![new_value].into(),
targets: new_targets,
};
}

for (idx, bb_idx) in storage_deads_to_remove {
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_parse/src/lexer/tokentrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,9 @@ impl<'a> TokenTreesReader<'a> {
}
}

match (open_brace, delim) {
//only add braces
(DelimToken::Brace, DelimToken::Brace) => {
self.matching_block_spans.push((open_brace_span, close_brace_span));
}
_ => {}
//only add braces
if let (DelimToken::Brace, DelimToken::Brace) = (open_brace, delim) {
self.matching_block_spans.push((open_brace_span, close_brace_span));
}

if self.open_braces.is_empty() {
Expand Down
13 changes: 5 additions & 8 deletions compiler/rustc_parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![feature(bool_to_option)]
#![feature(crate_visibility_modifier)]
#![feature(bindings_after_at)]
#![feature(iter_order_by)]
#![feature(or_patterns)]

use rustc_ast as ast;
Expand Down Expand Up @@ -459,14 +460,10 @@ pub fn tokenstream_probably_equal_for_proc_macro(

// Break tokens after we expand any nonterminals, so that we break tokens
// that are produced as a result of nonterminal expansion.
let mut t1 = first.trees().filter(semantic_tree).flat_map(expand_nt).flat_map(break_tokens);
let mut t2 = other.trees().filter(semantic_tree).flat_map(expand_nt).flat_map(break_tokens);
for (t1, t2) in t1.by_ref().zip(t2.by_ref()) {
if !tokentree_probably_equal_for_proc_macro(&t1, &t2, sess) {
return false;
}
}
t1.next().is_none() && t2.next().is_none()
let t1 = first.trees().filter(semantic_tree).flat_map(expand_nt).flat_map(break_tokens);
let t2 = other.trees().filter(semantic_tree).flat_map(expand_nt).flat_map(break_tokens);

t1.eq_by(t2, |t1, t2| tokentree_probably_equal_for_proc_macro(&t1, &t2, sess))
}

// See comments in `Nonterminal::to_tokenstream` for why we care about
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,9 @@ impl<'a> Parser<'a> {

// fill character
if let Some(&(_, c)) = self.cur.peek() {
match self.cur.clone().nth(1) {
Some((_, '>' | '<' | '^')) => {
spec.fill = Some(c);
self.cur.next();
}
_ => {}
if let Some((_, '>' | '<' | '^')) = self.cur.clone().nth(1) {
spec.fill = Some(c);
self.cur.next();
}
}
// Alignment
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,8 @@ impl<'a> ModuleData<'a> {
if ns != TypeNS {
return;
}
match binding.res() {
Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
collected_traits.push((name, binding))
}
_ => (),
if let Res::Def(DefKind::Trait | DefKind::TraitAlias, _) = binding.res() {
collected_traits.push((name, binding))
}
});
*traits = Some(collected_traits.into_boxed_slice());
Expand Down
Loading