Skip to content

Commit a4e595d

Browse files
committed
Auto merge of rust-lang#82430 - Dylan-DPC:rollup-nu4kfyc, r=Dylan-DPC
Rollup of 12 pull requests Successful merges: - rust-lang#79423 (Enable smart punctuation) - rust-lang#81154 (Improve design of `assert_len`) - rust-lang#81235 (Improve suggestion for tuple struct pattern matching errors.) - rust-lang#81769 (Suggest `return`ing tail expressions that match return type) - rust-lang#81837 (Slight perf improvement on char::to_ascii_lowercase) - rust-lang#81969 (Avoid `cfg_if` in `std::os`) - rust-lang#81984 (Make WASI's `hard_link` behavior match other platforms.) - rust-lang#82091 (use PlaceRef abstractions more consistently) - rust-lang#82128 (add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice) - rust-lang#82166 (add s390x-unknown-linux-musl target) - rust-lang#82234 (Remove query parameters when skipping search results) - rust-lang#82255 (Make `treat_err_as_bug` Option<NonZeroUsize>) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b02a619 + 0e5bca5 commit a4e595d

File tree

68 files changed

+680
-268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+680
-268
lines changed

compiler/rustc_codegen_ssa/src/mir/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
199199
}
200200

201201
self.visit_local(&place_ref.local, context, location);
202-
self.visit_projection(place_ref.local, place_ref.projection, context, location);
202+
self.visit_projection(*place_ref, context, location);
203203
}
204204
}
205205
}

compiler/rustc_errors/src/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use rustc_span::{Loc, MultiSpan, Span};
3030

3131
use std::borrow::Cow;
3232
use std::hash::{Hash, Hasher};
33+
use std::num::NonZeroUsize;
3334
use std::panic;
3435
use std::path::Path;
3536
use std::{error, fmt};
@@ -359,7 +360,7 @@ pub struct HandlerFlags {
359360
pub can_emit_warnings: bool,
360361
/// If true, error-level diagnostics are upgraded to bug-level.
361362
/// (rustc: see `-Z treat-err-as-bug`)
362-
pub treat_err_as_bug: Option<usize>,
363+
pub treat_err_as_bug: Option<NonZeroUsize>,
363364
/// If true, immediately emit diagnostics that would otherwise be buffered.
364365
/// (rustc: see `-Z dont-buffer-diagnostics` and `-Z treat-err-as-bug`)
365366
pub dont_buffer_diagnostics: bool,
@@ -396,7 +397,7 @@ impl Handler {
396397
pub fn with_tty_emitter(
397398
color_config: ColorConfig,
398399
can_emit_warnings: bool,
399-
treat_err_as_bug: Option<usize>,
400+
treat_err_as_bug: Option<NonZeroUsize>,
400401
sm: Option<Lrc<SourceMap>>,
401402
) -> Self {
402403
Self::with_tty_emitter_and_flags(
@@ -424,7 +425,7 @@ impl Handler {
424425

425426
pub fn with_emitter(
426427
can_emit_warnings: bool,
427-
treat_err_as_bug: Option<usize>,
428+
treat_err_as_bug: Option<NonZeroUsize>,
428429
emitter: Box<dyn Emitter + sync::Send>,
429430
) -> Self {
430431
Handler::with_emitter_and_flags(
@@ -841,7 +842,7 @@ impl HandlerInner {
841842
}
842843

843844
fn treat_err_as_bug(&self) -> bool {
844-
self.flags.treat_err_as_bug.map_or(false, |c| self.err_count() >= c)
845+
self.flags.treat_err_as_bug.map_or(false, |c| self.err_count() >= c.get())
845846
}
846847

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

10241025
fn panic_if_treat_err_as_bug(&self) {
10251026
if self.treat_err_as_bug() {
1026-
match (self.err_count(), self.flags.treat_err_as_bug.unwrap_or(0)) {
1027+
match (self.err_count(), self.flags.treat_err_as_bug.map(|c| c.get()).unwrap_or(0)) {
10271028
(1, 1) => panic!("aborting due to `-Z treat-err-as-bug=1`"),
10281029
(0, _) | (1, _) => {}
10291030
(count, as_bug) => panic!(

compiler/rustc_hir/src/hir.rs

+58-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-tidy-filelength
2-
use crate::def::{DefKind, Namespace, Res};
2+
use crate::def::{CtorKind, DefKind, Namespace, Res};
33
use crate::def_id::DefId;
44
crate use crate::hir_id::HirId;
55
use crate::{itemlikevisit, LangItem};
@@ -1576,6 +1576,63 @@ impl Expr<'_> {
15761576
}
15771577
expr
15781578
}
1579+
1580+
pub fn can_have_side_effects(&self) -> bool {
1581+
match self.peel_drop_temps().kind {
1582+
ExprKind::Path(_) | ExprKind::Lit(_) => false,
1583+
ExprKind::Type(base, _)
1584+
| ExprKind::Unary(_, base)
1585+
| ExprKind::Field(base, _)
1586+
| ExprKind::Index(base, _)
1587+
| ExprKind::AddrOf(.., base)
1588+
| ExprKind::Cast(base, _) => {
1589+
// This isn't exactly true for `Index` and all `Unnary`, but we are using this
1590+
// method exclusively for diagnostics and there's a *cultural* pressure against
1591+
// them being used only for its side-effects.
1592+
base.can_have_side_effects()
1593+
}
1594+
ExprKind::Struct(_, fields, init) => fields
1595+
.iter()
1596+
.map(|field| field.expr)
1597+
.chain(init.into_iter())
1598+
.all(|e| e.can_have_side_effects()),
1599+
1600+
ExprKind::Array(args)
1601+
| ExprKind::Tup(args)
1602+
| ExprKind::Call(
1603+
Expr {
1604+
kind:
1605+
ExprKind::Path(QPath::Resolved(
1606+
None,
1607+
Path { res: Res::Def(DefKind::Ctor(_, CtorKind::Fn), _), .. },
1608+
)),
1609+
..
1610+
},
1611+
args,
1612+
) => args.iter().all(|arg| arg.can_have_side_effects()),
1613+
ExprKind::If(..)
1614+
| ExprKind::Match(..)
1615+
| ExprKind::MethodCall(..)
1616+
| ExprKind::Call(..)
1617+
| ExprKind::Closure(..)
1618+
| ExprKind::Block(..)
1619+
| ExprKind::Repeat(..)
1620+
| ExprKind::Break(..)
1621+
| ExprKind::Continue(..)
1622+
| ExprKind::Ret(..)
1623+
| ExprKind::Loop(..)
1624+
| ExprKind::Assign(..)
1625+
| ExprKind::InlineAsm(..)
1626+
| ExprKind::LlvmInlineAsm(..)
1627+
| ExprKind::AssignOp(..)
1628+
| ExprKind::ConstBlock(..)
1629+
| ExprKind::Box(..)
1630+
| ExprKind::Binary(..)
1631+
| ExprKind::Yield(..)
1632+
| ExprKind::DropTemps(..)
1633+
| ExprKind::Err => true,
1634+
}
1635+
}
15791636
}
15801637

15811638
/// Checks if the specified expression is a built-in range literal.

compiler/rustc_interface/src/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_target::spec::{CodeModel, LinkerFlavor, MergeFunctions, PanicStrategy}
2020
use rustc_target::spec::{RelocModel, RelroLevel, SplitDebuginfo, TlsModel};
2121
use std::collections::{BTreeMap, BTreeSet};
2222
use std::iter::FromIterator;
23+
use std::num::NonZeroUsize;
2324
use std::path::{Path, PathBuf};
2425

2526
type CfgSpecs = FxHashSet<(String, Option<String>)>;
@@ -595,7 +596,7 @@ fn test_debugging_options_tracking_hash() {
595596
tracked!(tune_cpu, Some(String::from("abc")));
596597
tracked!(tls_model, Some(TlsModel::GeneralDynamic));
597598
tracked!(trap_unreachable, Some(false));
598-
tracked!(treat_err_as_bug, Some(1));
599+
tracked!(treat_err_as_bug, NonZeroUsize::new(1));
599600
tracked!(unleash_the_miri_inside_of_you, true);
600601
tracked!(use_ctors_section, Some(true));
601602
tracked!(verify_llvm_ir, true);

compiler/rustc_middle/src/mir/visit.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -998,12 +998,11 @@ macro_rules! visit_place_fns {
998998
() => {
999999
fn visit_projection(
10001000
&mut self,
1001-
local: Local,
1002-
projection: &[PlaceElem<'tcx>],
1001+
place_ref: PlaceRef<'tcx>,
10031002
context: PlaceContext,
10041003
location: Location,
10051004
) {
1006-
self.super_projection(local, projection, context, location);
1005+
self.super_projection(place_ref, context, location);
10071006
}
10081007

10091008
fn visit_projection_elem(
@@ -1033,20 +1032,20 @@ macro_rules! visit_place_fns {
10331032

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

1036-
self.visit_projection(place.local, &place.projection, context, location);
1035+
self.visit_projection(place.as_ref(), context, location);
10371036
}
10381037

10391038
fn super_projection(
10401039
&mut self,
1041-
local: Local,
1042-
projection: &[PlaceElem<'tcx>],
1040+
place_ref: PlaceRef<'tcx>,
10431041
context: PlaceContext,
10441042
location: Location,
10451043
) {
1046-
let mut cursor = projection;
1044+
// FIXME: Use PlaceRef::iter_projections, once that exists.
1045+
let mut cursor = place_ref.projection;
10471046
while let &[ref proj_base @ .., elem] = cursor {
10481047
cursor = proj_base;
1049-
self.visit_projection_elem(local, cursor, elem, context, location);
1048+
self.visit_projection_elem(place_ref.local, cursor, elem, context, location);
10501049
}
10511050
}
10521051

compiler/rustc_mir/src/dataflow/impls/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ where
9595

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

100100
match DefUse::for_place(context) {
101101
// Treat derefs as a use of the base local. `*p = 4` is not a def of `p` but a use.

compiler/rustc_mir/src/transform/check_consts/validation.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
515515
// Special-case reborrows to be more like a copy of a reference.
516516
match *rvalue {
517517
Rvalue::Ref(_, kind, place) => {
518-
if let Some(reborrowed_proj) = place_as_reborrow(self.tcx, self.body, place) {
518+
if let Some(reborrowed_place_ref) = place_as_reborrow(self.tcx, self.body, place) {
519519
let ctx = match kind {
520520
BorrowKind::Shared => {
521521
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow)
@@ -530,21 +530,21 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
530530
PlaceContext::MutatingUse(MutatingUseContext::Borrow)
531531
}
532532
};
533-
self.visit_local(&place.local, ctx, location);
534-
self.visit_projection(place.local, reborrowed_proj, ctx, location);
533+
self.visit_local(&reborrowed_place_ref.local, ctx, location);
534+
self.visit_projection(reborrowed_place_ref, ctx, location);
535535
return;
536536
}
537537
}
538538
Rvalue::AddressOf(mutbl, place) => {
539-
if let Some(reborrowed_proj) = place_as_reborrow(self.tcx, self.body, place) {
539+
if let Some(reborrowed_place_ref) = place_as_reborrow(self.tcx, self.body, place) {
540540
let ctx = match mutbl {
541541
Mutability::Not => {
542542
PlaceContext::NonMutatingUse(NonMutatingUseContext::AddressOf)
543543
}
544544
Mutability::Mut => PlaceContext::MutatingUse(MutatingUseContext::AddressOf),
545545
};
546-
self.visit_local(&place.local, ctx, location);
547-
self.visit_projection(place.local, reborrowed_proj, ctx, location);
546+
self.visit_local(&reborrowed_place_ref.local, ctx, location);
547+
self.visit_projection(reborrowed_place_ref, ctx, location);
548548
return;
549549
}
550550
}
@@ -1039,7 +1039,7 @@ fn place_as_reborrow(
10391039
tcx: TyCtxt<'tcx>,
10401040
body: &Body<'tcx>,
10411041
place: Place<'tcx>,
1042-
) -> Option<&'a [PlaceElem<'tcx>]> {
1042+
) -> Option<PlaceRef<'tcx>> {
10431043
match place.as_ref().last_projection() {
10441044
Some((place_base, ProjectionElem::Deref)) => {
10451045
// A borrow of a `static` also looks like `&(*_1)` in the MIR, but `_1` is a `const`
@@ -1048,13 +1048,14 @@ fn place_as_reborrow(
10481048
None
10491049
} else {
10501050
// Ensure the type being derefed is a reference and not a raw pointer.
1051-
//
10521051
// This is sufficient to prevent an access to a `static mut` from being marked as a
10531052
// reborrow, even if the check above were to disappear.
10541053
let inner_ty = place_base.ty(body, tcx).ty;
1055-
match inner_ty.kind() {
1056-
ty::Ref(..) => Some(place_base.projection),
1057-
_ => None,
1054+
1055+
if let ty::Ref(..) = inner_ty.kind() {
1056+
return Some(place_base);
1057+
} else {
1058+
return None;
10581059
}
10591060
}
10601061
}

compiler/rustc_mir/src/transform/simplify.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ impl UsedLocals {
413413
} else {
414414
// A definition. Although, it still might use other locals for indexing.
415415
self.super_projection(
416-
place.local,
417-
&place.projection,
416+
place.as_ref(),
418417
PlaceContext::MutatingUse(MutatingUseContext::Projection),
419418
location,
420419
);

compiler/rustc_parse/src/parser/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ impl<'a> Parser<'a> {
950950
self.bump();
951951
Ok(Ident::new(symbol, self.prev_token.span))
952952
} else {
953-
self.parse_ident_common(false)
953+
self.parse_ident_common(true)
954954
}
955955
}
956956

compiler/rustc_parse/src/parser/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ impl<'a> Parser<'a> {
10281028
let boxed_span = self.token.span;
10291029
let is_ref = self.eat_keyword(kw::Ref);
10301030
let is_mut = self.eat_keyword(kw::Mut);
1031-
let fieldname = self.parse_ident()?;
1031+
let fieldname = self.parse_field_name()?;
10321032
hi = self.prev_token.span;
10331033

10341034
let bind_type = match (is_ref, is_mut) {

compiler/rustc_session/src/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,7 @@ crate mod dep_tracking {
23132313
use std::collections::hash_map::DefaultHasher;
23142314
use std::collections::BTreeMap;
23152315
use std::hash::Hash;
2316+
use std::num::NonZeroUsize;
23162317
use std::path::PathBuf;
23172318

23182319
pub trait DepTrackingHash {
@@ -2353,6 +2354,7 @@ crate mod dep_tracking {
23532354
impl_dep_tracking_hash_via_hash!(lint::Level);
23542355
impl_dep_tracking_hash_via_hash!(Option<bool>);
23552356
impl_dep_tracking_hash_via_hash!(Option<usize>);
2357+
impl_dep_tracking_hash_via_hash!(Option<NonZeroUsize>);
23562358
impl_dep_tracking_hash_via_hash!(Option<String>);
23572359
impl_dep_tracking_hash_via_hash!(Option<(String, u64)>);
23582360
impl_dep_tracking_hash_via_hash!(Option<Vec<String>>);

compiler/rustc_session/src/options.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::collections::BTreeMap;
1616

1717
use std::collections::hash_map::DefaultHasher;
1818
use std::hash::Hasher;
19+
use std::num::NonZeroUsize;
1920
use std::path::PathBuf;
2021
use std::str;
2122

@@ -591,10 +592,10 @@ macro_rules! options {
591592
true
592593
}
593594

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

@@ -1141,7 +1142,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
11411142
"for every macro invocation, print its name and arguments (default: no)"),
11421143
trap_unreachable: Option<bool> = (None, parse_opt_bool, [TRACKED],
11431144
"generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)"),
1144-
treat_err_as_bug: Option<usize> = (None, parse_treat_err_as_bug, [TRACKED],
1145+
treat_err_as_bug: Option<NonZeroUsize> = (None, parse_treat_err_as_bug, [TRACKED],
11451146
"treat error number `val` that occurs as bug"),
11461147
trim_diagnostic_paths: bool = (true, parse_bool, [UNTRACKED],
11471148
"in diagnostics, use heuristics to shorten paths referring to items"),

compiler/rustc_span/src/symbol.rs

+6
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,14 @@ symbols! {
169169
Option,
170170
Ord,
171171
Ordering,
172+
OsStr,
173+
OsString,
172174
Output,
173175
Param,
174176
PartialEq,
175177
PartialOrd,
178+
Path,
179+
PathBuf,
176180
Pending,
177181
Pin,
178182
Poll,
@@ -198,6 +202,8 @@ symbols! {
198202
StructuralPartialEq,
199203
Sync,
200204
Target,
205+
ToOwned,
206+
ToString,
201207
Try,
202208
Ty,
203209
TyCtxt,

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ supported_targets! {
641641
("powerpc64le-unknown-linux-gnu", powerpc64le_unknown_linux_gnu),
642642
("powerpc64le-unknown-linux-musl", powerpc64le_unknown_linux_musl),
643643
("s390x-unknown-linux-gnu", s390x_unknown_linux_gnu),
644+
("s390x-unknown-linux-musl", s390x_unknown_linux_musl),
644645
("sparc-unknown-linux-gnu", sparc_unknown_linux_gnu),
645646
("sparc64-unknown-linux-gnu", sparc64_unknown_linux_gnu),
646647
("arm-unknown-linux-gnueabi", arm_unknown_linux_gnueabi),

0 commit comments

Comments
 (0)