Skip to content

Commit

Permalink
Auto merge of #82430 - Dylan-DPC:rollup-nu4kfyc, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 12 pull requests

Successful merges:

 - #79423 (Enable smart punctuation)
 - #81154 (Improve design of `assert_len`)
 - #81235 (Improve suggestion for tuple struct pattern matching errors.)
 - #81769 (Suggest `return`ing tail expressions that match return type)
 - #81837 (Slight perf improvement on char::to_ascii_lowercase)
 - #81969 (Avoid `cfg_if` in `std::os`)
 - #81984 (Make WASI's `hard_link` behavior match other platforms.)
 - #82091 (use PlaceRef abstractions more consistently)
 - #82128 (add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice)
 - #82166 (add s390x-unknown-linux-musl target)
 - #82234 (Remove query parameters when skipping search results)
 - #82255 (Make `treat_err_as_bug` Option<NonZeroUsize>)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 23, 2021
2 parents b02a619 + 0e5bca5 commit a4e595d
Show file tree
Hide file tree
Showing 68 changed files with 680 additions and 268 deletions.
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
13 changes: 7 additions & 6 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use rustc_span::{Loc, MultiSpan, Span};

use std::borrow::Cow;
use std::hash::{Hash, Hasher};
use std::num::NonZeroUsize;
use std::panic;
use std::path::Path;
use std::{error, fmt};
Expand Down Expand Up @@ -359,7 +360,7 @@ pub struct HandlerFlags {
pub can_emit_warnings: bool,
/// If true, error-level diagnostics are upgraded to bug-level.
/// (rustc: see `-Z treat-err-as-bug`)
pub treat_err_as_bug: Option<usize>,
pub treat_err_as_bug: Option<NonZeroUsize>,
/// If true, immediately emit diagnostics that would otherwise be buffered.
/// (rustc: see `-Z dont-buffer-diagnostics` and `-Z treat-err-as-bug`)
pub dont_buffer_diagnostics: bool,
Expand Down Expand Up @@ -396,7 +397,7 @@ impl Handler {
pub fn with_tty_emitter(
color_config: ColorConfig,
can_emit_warnings: bool,
treat_err_as_bug: Option<usize>,
treat_err_as_bug: Option<NonZeroUsize>,
sm: Option<Lrc<SourceMap>>,
) -> Self {
Self::with_tty_emitter_and_flags(
Expand Down Expand Up @@ -424,7 +425,7 @@ impl Handler {

pub fn with_emitter(
can_emit_warnings: bool,
treat_err_as_bug: Option<usize>,
treat_err_as_bug: Option<NonZeroUsize>,
emitter: Box<dyn Emitter + sync::Send>,
) -> Self {
Handler::with_emitter_and_flags(
Expand Down Expand Up @@ -841,7 +842,7 @@ impl HandlerInner {
}

fn treat_err_as_bug(&self) -> bool {
self.flags.treat_err_as_bug.map_or(false, |c| self.err_count() >= c)
self.flags.treat_err_as_bug.map_or(false, |c| self.err_count() >= c.get())
}

fn print_error_count(&mut self, registry: &Registry) {
Expand Down Expand Up @@ -950,7 +951,7 @@ impl HandlerInner {
// This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before
// incrementing `err_count` by one, so we need to +1 the comparing.
// FIXME: Would be nice to increment err_count in a more coherent way.
if self.flags.treat_err_as_bug.map_or(false, |c| self.err_count() + 1 >= c) {
if self.flags.treat_err_as_bug.map_or(false, |c| self.err_count() + 1 >= c.get()) {
// FIXME: don't abort here if report_delayed_bugs is off
self.span_bug(sp, msg);
}
Expand Down Expand Up @@ -1023,7 +1024,7 @@ impl HandlerInner {

fn panic_if_treat_err_as_bug(&self) {
if self.treat_err_as_bug() {
match (self.err_count(), self.flags.treat_err_as_bug.unwrap_or(0)) {
match (self.err_count(), self.flags.treat_err_as_bug.map(|c| c.get()).unwrap_or(0)) {
(1, 1) => panic!("aborting due to `-Z treat-err-as-bug=1`"),
(0, _) | (1, _) => {}
(count, as_bug) => panic!(
Expand Down
59 changes: 58 additions & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ignore-tidy-filelength
use crate::def::{DefKind, Namespace, Res};
use crate::def::{CtorKind, DefKind, Namespace, Res};
use crate::def_id::DefId;
crate use crate::hir_id::HirId;
use crate::{itemlikevisit, LangItem};
Expand Down Expand Up @@ -1576,6 +1576,63 @@ impl Expr<'_> {
}
expr
}

pub fn can_have_side_effects(&self) -> bool {
match self.peel_drop_temps().kind {
ExprKind::Path(_) | ExprKind::Lit(_) => false,
ExprKind::Type(base, _)
| ExprKind::Unary(_, base)
| ExprKind::Field(base, _)
| ExprKind::Index(base, _)
| ExprKind::AddrOf(.., base)
| ExprKind::Cast(base, _) => {
// This isn't exactly true for `Index` and all `Unnary`, but we are using this
// method exclusively for diagnostics and there's a *cultural* pressure against
// them being used only for its side-effects.
base.can_have_side_effects()
}
ExprKind::Struct(_, fields, init) => fields
.iter()
.map(|field| field.expr)
.chain(init.into_iter())
.all(|e| e.can_have_side_effects()),

ExprKind::Array(args)
| ExprKind::Tup(args)
| ExprKind::Call(
Expr {
kind:
ExprKind::Path(QPath::Resolved(
None,
Path { res: Res::Def(DefKind::Ctor(_, CtorKind::Fn), _), .. },
)),
..
},
args,
) => args.iter().all(|arg| arg.can_have_side_effects()),
ExprKind::If(..)
| ExprKind::Match(..)
| ExprKind::MethodCall(..)
| ExprKind::Call(..)
| ExprKind::Closure(..)
| ExprKind::Block(..)
| ExprKind::Repeat(..)
| ExprKind::Break(..)
| ExprKind::Continue(..)
| ExprKind::Ret(..)
| ExprKind::Loop(..)
| ExprKind::Assign(..)
| ExprKind::InlineAsm(..)
| ExprKind::LlvmInlineAsm(..)
| ExprKind::AssignOp(..)
| ExprKind::ConstBlock(..)
| ExprKind::Box(..)
| ExprKind::Binary(..)
| ExprKind::Yield(..)
| ExprKind::DropTemps(..)
| ExprKind::Err => true,
}
}
}

/// Checks if the specified expression is a built-in range literal.
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use rustc_target::spec::{CodeModel, LinkerFlavor, MergeFunctions, PanicStrategy}
use rustc_target::spec::{RelocModel, RelroLevel, SplitDebuginfo, TlsModel};
use std::collections::{BTreeMap, BTreeSet};
use std::iter::FromIterator;
use std::num::NonZeroUsize;
use std::path::{Path, PathBuf};

type CfgSpecs = FxHashSet<(String, Option<String>)>;
Expand Down Expand Up @@ -595,7 +596,7 @@ fn test_debugging_options_tracking_hash() {
tracked!(tune_cpu, Some(String::from("abc")));
tracked!(tls_model, Some(TlsModel::GeneralDynamic));
tracked!(trap_unreachable, Some(false));
tracked!(treat_err_as_bug, Some(1));
tracked!(treat_err_as_bug, NonZeroUsize::new(1));
tracked!(unleash_the_miri_inside_of_you, true);
tracked!(use_ctors_section, Some(true));
tracked!(verify_llvm_ir, true);
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
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
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
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ impl<'a> Parser<'a> {
self.bump();
Ok(Ident::new(symbol, self.prev_token.span))
} else {
self.parse_ident_common(false)
self.parse_ident_common(true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ impl<'a> Parser<'a> {
let boxed_span = self.token.span;
let is_ref = self.eat_keyword(kw::Ref);
let is_mut = self.eat_keyword(kw::Mut);
let fieldname = self.parse_ident()?;
let fieldname = self.parse_field_name()?;
hi = self.prev_token.span;

let bind_type = match (is_ref, is_mut) {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2313,6 +2313,7 @@ crate mod dep_tracking {
use std::collections::hash_map::DefaultHasher;
use std::collections::BTreeMap;
use std::hash::Hash;
use std::num::NonZeroUsize;
use std::path::PathBuf;

pub trait DepTrackingHash {
Expand Down Expand Up @@ -2353,6 +2354,7 @@ crate mod dep_tracking {
impl_dep_tracking_hash_via_hash!(lint::Level);
impl_dep_tracking_hash_via_hash!(Option<bool>);
impl_dep_tracking_hash_via_hash!(Option<usize>);
impl_dep_tracking_hash_via_hash!(Option<NonZeroUsize>);
impl_dep_tracking_hash_via_hash!(Option<String>);
impl_dep_tracking_hash_via_hash!(Option<(String, u64)>);
impl_dep_tracking_hash_via_hash!(Option<Vec<String>>);
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::collections::BTreeMap;

use std::collections::hash_map::DefaultHasher;
use std::hash::Hasher;
use std::num::NonZeroUsize;
use std::path::PathBuf;
use std::str;

Expand Down Expand Up @@ -591,10 +592,10 @@ macro_rules! options {
true
}

fn parse_treat_err_as_bug(slot: &mut Option<usize>, v: Option<&str>) -> bool {
fn parse_treat_err_as_bug(slot: &mut Option<NonZeroUsize>, v: Option<&str>) -> bool {
match v {
Some(s) => { *slot = s.parse().ok().filter(|&x| x != 0); slot.unwrap_or(0) != 0 }
None => { *slot = Some(1); true }
Some(s) => { *slot = s.parse().ok(); slot.is_some() }
None => { *slot = NonZeroUsize::new(1); true }
}
}

Expand Down Expand Up @@ -1141,7 +1142,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"for every macro invocation, print its name and arguments (default: no)"),
trap_unreachable: Option<bool> = (None, parse_opt_bool, [TRACKED],
"generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)"),
treat_err_as_bug: Option<usize> = (None, parse_treat_err_as_bug, [TRACKED],
treat_err_as_bug: Option<NonZeroUsize> = (None, parse_treat_err_as_bug, [TRACKED],
"treat error number `val` that occurs as bug"),
trim_diagnostic_paths: bool = (true, parse_bool, [UNTRACKED],
"in diagnostics, use heuristics to shorten paths referring to items"),
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,14 @@ symbols! {
Option,
Ord,
Ordering,
OsStr,
OsString,
Output,
Param,
PartialEq,
PartialOrd,
Path,
PathBuf,
Pending,
Pin,
Poll,
Expand All @@ -198,6 +202,8 @@ symbols! {
StructuralPartialEq,
Sync,
Target,
ToOwned,
ToString,
Try,
Ty,
TyCtxt,
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
Loading

0 comments on commit a4e595d

Please sign in to comment.