Skip to content

Commit b6e2dc6

Browse files
committed
Auto merge of rust-lang#78001 - Dylan-DPC:rollup-zq3kxth, r=Dylan-DPC
Rollup of 14 pull requests Successful merges: - rust-lang#75023 (ensure arguments are included in count mismatch span) - rust-lang#75265 (Add `str::{Split,RSplit,SplitN,RSplitN,SplitTerminator,RSplitTerminator,SplitInclusive}::as_str` methods) - rust-lang#75675 (mangling: mangle impl params w/ v0 scheme) - rust-lang#76084 (Refactor io/buffered.rs into submodules) - rust-lang#76119 (Stabilize move_ref_pattern) - rust-lang#77493 (ICEs should always print the top of the query stack) - rust-lang#77619 (Use futex-based thread-parker for Wasm32.) - rust-lang#77646 (For backtrace, use StaticMutex instead of a raw sys Mutex.) - rust-lang#77648 (Static mutex is static) - rust-lang#77657 (Cleanup cloudabi mutexes and condvars) - rust-lang#77672 (Simplify doc-cfg rendering based on the current context) - rust-lang#77780 (rustc_parse: fix spans on cast and range exprs with attrs) - rust-lang#77935 (BTreeMap: make PartialCmp/PartialEq explicit and tested) - rust-lang#77980 (Fix intra doc link for needs_drop) Failed merges: r? `@ghost`
2 parents dd7fc54 + e688b4d commit b6e2dc6

File tree

121 files changed

+2898
-2295
lines changed

Some content is hidden

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

121 files changed

+2898
-2295
lines changed

compiler/rustc_driver/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1258,9 +1258,9 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12581258
// If backtraces are enabled, also print the query stack
12591259
let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
12601260

1261-
if backtrace {
1262-
TyCtxt::try_print_query_stack(&handler);
1263-
}
1261+
let num_frames = if backtrace { None } else { Some(2) };
1262+
1263+
TyCtxt::try_print_query_stack(&handler, num_frames);
12641264

12651265
#[cfg(windows)]
12661266
unsafe {

compiler/rustc_error_codes/src/error_codes/E0007.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
This error indicates that the bindings in a match arm would require a value to
24
be moved into more than one location, thus violating unique ownership. Code
35
like the following is invalid as it requires the entire `Option<String>` to be
@@ -6,11 +8,13 @@ inner `String` to be moved into a variable called `s`.
68

79
Erroneous code example:
810

9-
```compile_fail,E0007
11+
```compile_fail,E0382
12+
#![feature(bindings_after_at)]
13+
1014
let x = Some("s".to_string());
1115
1216
match x {
13-
op_string @ Some(s) => {}, // error: cannot bind by-move with sub-bindings
17+
op_string @ Some(s) => {}, // error: use of moved value
1418
None => {},
1519
}
1620
```

compiler/rustc_feature/src/accepted.rs

+3
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ declare_features! (
270270
(accepted, track_caller, "1.46.0", Some(47809), None),
271271
/// Allows `#[doc(alias = "...")]`.
272272
(accepted, doc_alias, "1.48.0", Some(50146), None),
273+
/// Allows patterns with concurrent by-move and by-ref bindings.
274+
/// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref.
275+
(accepted, move_ref_pattern, "1.48.0", Some(68354), None),
273276

274277
// -------------------------------------------------------------------------
275278
// feature-group-end: accepted features

compiler/rustc_feature/src/active.rs

-4
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,6 @@ declare_features! (
526526
/// For example, you can write `x @ Some(y)`.
527527
(active, bindings_after_at, "1.41.0", Some(65490), None),
528528

529-
/// Allows patterns with concurrent by-move and by-ref bindings.
530-
/// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref.
531-
(active, move_ref_pattern, "1.42.0", Some(68354), None),
532-
533529
/// Allows `impl const Trait for T` syntax.
534530
(active, const_trait_impl, "1.42.0", Some(67792), None),
535531

compiler/rustc_hir/src/hir.rs

+28
Original file line numberDiff line numberDiff line change
@@ -2742,4 +2742,32 @@ impl<'hir> Node<'hir> {
27422742
_ => None,
27432743
}
27442744
}
2745+
2746+
pub fn hir_id(&self) -> Option<HirId> {
2747+
match self {
2748+
Node::Item(Item { hir_id, .. })
2749+
| Node::ForeignItem(ForeignItem { hir_id, .. })
2750+
| Node::TraitItem(TraitItem { hir_id, .. })
2751+
| Node::ImplItem(ImplItem { hir_id, .. })
2752+
| Node::Field(StructField { hir_id, .. })
2753+
| Node::AnonConst(AnonConst { hir_id, .. })
2754+
| Node::Expr(Expr { hir_id, .. })
2755+
| Node::Stmt(Stmt { hir_id, .. })
2756+
| Node::Ty(Ty { hir_id, .. })
2757+
| Node::Binding(Pat { hir_id, .. })
2758+
| Node::Pat(Pat { hir_id, .. })
2759+
| Node::Arm(Arm { hir_id, .. })
2760+
| Node::Block(Block { hir_id, .. })
2761+
| Node::Local(Local { hir_id, .. })
2762+
| Node::MacroDef(MacroDef { hir_id, .. })
2763+
| Node::Lifetime(Lifetime { hir_id, .. })
2764+
| Node::Param(Param { hir_id, .. })
2765+
| Node::GenericParam(GenericParam { hir_id, .. }) => Some(*hir_id),
2766+
Node::TraitRef(TraitRef { hir_ref_id, .. }) => Some(*hir_ref_id),
2767+
Node::PathSegment(PathSegment { hir_id, .. }) => *hir_id,
2768+
Node::Variant(Variant { id, .. }) => Some(*id),
2769+
Node::Ctor(variant) => variant.ctor_hir_id(),
2770+
Node::Crate(_) | Node::Visibility(_) => None,
2771+
}
2772+
}
27452773
}

compiler/rustc_middle/src/ty/instance.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,17 @@ impl<'tcx> Instance<'tcx> {
291291
}
292292

293293
pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> {
294-
Instance::new(def_id, tcx.empty_substs_for_def_id(def_id))
294+
let substs = InternalSubsts::for_item(tcx, def_id, |param, _| match param.kind {
295+
ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
296+
ty::GenericParamDefKind::Type { .. } => {
297+
bug!("Instance::mono: {:?} has type parameters", def_id)
298+
}
299+
ty::GenericParamDefKind::Const { .. } => {
300+
bug!("Instance::mono: {:?} has const parameters", def_id)
301+
}
302+
});
303+
304+
Instance::new(def_id, substs)
295305
}
296306

297307
#[inline]

compiler/rustc_middle/src/ty/query/plumbing.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,23 @@ impl<'tcx> TyCtxt<'tcx> {
124124
})
125125
}
126126

127-
pub fn try_print_query_stack(handler: &Handler) {
127+
pub fn try_print_query_stack(handler: &Handler, num_frames: Option<usize>) {
128128
eprintln!("query stack during panic:");
129129

130130
// Be careful reyling on global state here: this code is called from
131131
// a panic hook, which means that the global `Handler` may be in a weird
132132
// state if it was responsible for triggering the panic.
133+
let mut i = 0;
133134
ty::tls::with_context_opt(|icx| {
134135
if let Some(icx) = icx {
135136
let query_map = icx.tcx.queries.try_collect_active_jobs();
136137

137138
let mut current_query = icx.query;
138-
let mut i = 0;
139139

140140
while let Some(query) = current_query {
141+
if Some(i) == num_frames {
142+
break;
143+
}
141144
let query_info =
142145
if let Some(info) = query_map.as_ref().and_then(|map| map.get(&query)) {
143146
info
@@ -163,7 +166,11 @@ impl<'tcx> TyCtxt<'tcx> {
163166
}
164167
});
165168

166-
eprintln!("end of query stack");
169+
if num_frames == None || num_frames >= Some(i) {
170+
eprintln!("end of query stack");
171+
} else {
172+
eprintln!("we're just showing a limited slice of the query stack");
173+
}
167174
}
168175
}
169176

compiler/rustc_middle/src/ty/util.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use crate::mir::interpret::{sign_extend, truncate};
66
use crate::ty::fold::TypeFolder;
77
use crate::ty::layout::IntegerExt;
88
use crate::ty::query::TyCtxtAt;
9-
use crate::ty::subst::{GenericArgKind, InternalSubsts, Subst, SubstsRef};
9+
use crate::ty::subst::{GenericArgKind, Subst, SubstsRef};
1010
use crate::ty::TyKind::*;
11-
use crate::ty::{self, DefIdTree, GenericParamDefKind, List, Ty, TyCtxt, TypeFoldable};
11+
use crate::ty::{self, DefIdTree, List, Ty, TyCtxt, TypeFoldable};
1212
use rustc_apfloat::Float as _;
1313
use rustc_ast as ast;
1414
use rustc_attr::{self as attr, SignedInt, UnsignedInt};
@@ -509,20 +509,6 @@ impl<'tcx> TyCtxt<'tcx> {
509509
Some(ty::Binder::bind(env_ty))
510510
}
511511

512-
/// Given the `DefId` of some item that has no type or const parameters, make
513-
/// a suitable "empty substs" for it.
514-
pub fn empty_substs_for_def_id(self, item_def_id: DefId) -> SubstsRef<'tcx> {
515-
InternalSubsts::for_item(self, item_def_id, |param, _| match param.kind {
516-
GenericParamDefKind::Lifetime => self.lifetimes.re_erased.into(),
517-
GenericParamDefKind::Type { .. } => {
518-
bug!("empty_substs_for_def_id: {:?} has type parameters", item_def_id)
519-
}
520-
GenericParamDefKind::Const { .. } => {
521-
bug!("empty_substs_for_def_id: {:?} has const parameters", item_def_id)
522-
}
523-
})
524-
}
525-
526512
/// Returns `true` if the node pointed to by `def_id` is a `static` item.
527513
pub fn is_static(self, def_id: DefId) -> bool {
528514
self.static_mutability(def_id).is_some()

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+4-66
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, 'tcx> {
7171
hir::LocalSource::AwaitDesugar => ("`await` future binding", None),
7272
};
7373
self.check_irrefutable(&loc.pat, msg, sp);
74-
self.check_patterns(false, &loc.pat);
74+
self.check_patterns(&loc.pat);
7575
}
7676

7777
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
7878
intravisit::walk_param(self, param);
7979
self.check_irrefutable(&param.pat, "function argument", None);
80-
self.check_patterns(false, &param.pat);
80+
self.check_patterns(&param.pat);
8181
}
8282
}
8383

@@ -119,10 +119,7 @@ impl PatCtxt<'_, '_> {
119119
}
120120

121121
impl<'tcx> MatchVisitor<'_, 'tcx> {
122-
fn check_patterns(&mut self, has_guard: bool, pat: &Pat<'_>) {
123-
if !self.tcx.features().move_ref_pattern {
124-
check_legality_of_move_bindings(self, has_guard, pat);
125-
}
122+
fn check_patterns(&mut self, pat: &Pat<'_>) {
126123
pat.walk_always(|pat| check_borrow_conflicts_in_at_patterns(self, pat));
127124
if !self.tcx.features().bindings_after_at {
128125
check_legality_of_bindings_in_at_patterns(self, pat);
@@ -165,7 +162,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
165162
) {
166163
for arm in arms {
167164
// Check the arm for some things unrelated to exhaustiveness.
168-
self.check_patterns(arm.guard.is_some(), &arm.pat);
165+
self.check_patterns(&arm.pat);
169166
}
170167

171168
let mut cx = self.new_cx(scrut.hir_id);
@@ -601,65 +598,6 @@ fn is_binding_by_move(cx: &MatchVisitor<'_, '_>, hir_id: HirId, span: Span) -> b
601598
!cx.typeck_results.node_type(hir_id).is_copy_modulo_regions(cx.tcx.at(span), cx.param_env)
602599
}
603600

604-
/// Check the legality of legality of by-move bindings.
605-
fn check_legality_of_move_bindings(cx: &mut MatchVisitor<'_, '_>, has_guard: bool, pat: &Pat<'_>) {
606-
let sess = cx.tcx.sess;
607-
let typeck_results = cx.typeck_results;
608-
609-
// Find all by-ref spans.
610-
let mut by_ref_spans = Vec::new();
611-
pat.each_binding(|_, hir_id, span, _| {
612-
if let Some(ty::BindByReference(_)) =
613-
typeck_results.extract_binding_mode(sess, hir_id, span)
614-
{
615-
by_ref_spans.push(span);
616-
}
617-
});
618-
619-
// Find bad by-move spans:
620-
let by_move_spans = &mut Vec::new();
621-
let mut check_move = |p: &Pat<'_>, sub: Option<&Pat<'_>>| {
622-
// Check legality of moving out of the enum.
623-
//
624-
// `x @ Foo(..)` is legal, but `x @ Foo(y)` isn't.
625-
if sub.map_or(false, |p| p.contains_bindings()) {
626-
struct_span_err!(sess, p.span, E0007, "cannot bind by-move with sub-bindings")
627-
.span_label(p.span, "binds an already bound by-move value by moving it")
628-
.emit();
629-
} else if !has_guard && !by_ref_spans.is_empty() {
630-
by_move_spans.push(p.span);
631-
}
632-
};
633-
pat.walk_always(|p| {
634-
if let hir::PatKind::Binding(.., sub) = &p.kind {
635-
if let Some(ty::BindByValue(_)) =
636-
typeck_results.extract_binding_mode(sess, p.hir_id, p.span)
637-
{
638-
if is_binding_by_move(cx, p.hir_id, p.span) {
639-
check_move(p, sub.as_deref());
640-
}
641-
}
642-
}
643-
});
644-
645-
// Found some bad by-move spans, error!
646-
if !by_move_spans.is_empty() {
647-
let mut err = feature_err(
648-
&sess.parse_sess,
649-
sym::move_ref_pattern,
650-
by_move_spans.clone(),
651-
"binding by-move and by-ref in the same pattern is unstable",
652-
);
653-
for span in by_ref_spans.iter() {
654-
err.span_label(*span, "by-ref pattern here");
655-
}
656-
for span in by_move_spans.iter() {
657-
err.span_label(*span, "by-move pattern here");
658-
}
659-
err.emit();
660-
}
661-
}
662-
663601
/// Check that there are no borrow or move conflicts in `binding @ subpat` patterns.
664602
///
665603
/// For example, this would reject:

compiler/rustc_parse/src/parser/expr.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,7 @@ impl<'a> Parser<'a> {
246246
this.parse_assoc_expr_with(prec + prec_adjustment, LhsExpr::NotYetParsed)
247247
})?;
248248

249-
// Make sure that the span of the parent node is larger than the span of lhs and rhs,
250-
// including the attributes.
251-
let lhs_span =
252-
lhs.attrs.iter().find(|a| a.style == AttrStyle::Outer).map_or(lhs_span, |a| a.span);
253-
let span = lhs_span.to(rhs.span);
249+
let span = self.mk_expr_sp(&lhs, lhs_span, rhs.span);
254250
lhs = match op {
255251
AssocOp::Add
256252
| AssocOp::Subtract
@@ -411,7 +407,7 @@ impl<'a> Parser<'a> {
411407
None
412408
};
413409
let rhs_span = rhs.as_ref().map_or(cur_op_span, |x| x.span);
414-
let span = lhs.span.to(rhs_span);
410+
let span = self.mk_expr_sp(&lhs, lhs.span, rhs_span);
415411
let limits =
416412
if op == AssocOp::DotDot { RangeLimits::HalfOpen } else { RangeLimits::Closed };
417413
Ok(self.mk_expr(span, self.mk_range(Some(lhs), rhs, limits)?, AttrVec::new()))
@@ -571,7 +567,11 @@ impl<'a> Parser<'a> {
571567
expr_kind: fn(P<Expr>, P<Ty>) -> ExprKind,
572568
) -> PResult<'a, P<Expr>> {
573569
let mk_expr = |this: &mut Self, rhs: P<Ty>| {
574-
this.mk_expr(lhs_span.to(rhs.span), expr_kind(lhs, rhs), AttrVec::new())
570+
this.mk_expr(
571+
this.mk_expr_sp(&lhs, lhs_span, rhs.span),
572+
expr_kind(lhs, rhs),
573+
AttrVec::new(),
574+
)
575575
};
576576

577577
// Save the state of the parser before parsing type normally, in case there is a
@@ -2324,4 +2324,14 @@ impl<'a> Parser<'a> {
23242324
pub(super) fn mk_expr_err(&self, span: Span) -> P<Expr> {
23252325
self.mk_expr(span, ExprKind::Err, AttrVec::new())
23262326
}
2327+
2328+
/// Create expression span ensuring the span of the parent node
2329+
/// is larger than the span of lhs and rhs, including the attributes.
2330+
fn mk_expr_sp(&self, lhs: &P<Expr>, lhs_span: Span, rhs_span: Span) -> Span {
2331+
lhs.attrs
2332+
.iter()
2333+
.find(|a| a.style == AttrStyle::Outer)
2334+
.map_or(lhs_span, |a| a.span)
2335+
.to(rhs_span)
2336+
}
23272337
}

compiler/rustc_parse/src/parser/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ impl<'a> Parser<'a> {
17441744
}
17451745
};
17461746

1747-
let span = lo.to(self.token.span);
1747+
let span = lo.until(self.token.span);
17481748

17491749
Ok(Param {
17501750
attrs: attrs.into(),

compiler/rustc_symbol_mangling/src/legacy.rs

-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ fn get_symbol_hash<'tcx>(
115115
}
116116

117117
// also include any type parameters (for generic items)
118-
assert!(!substs.has_erasable_regions());
119118
substs.hash_stable(&mut hcx, &mut hasher);
120119

121120
if let Some(instantiating_crate) = instantiating_crate {

compiler/rustc_symbol_mangling/src/test.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use rustc_hir as hir;
88
use rustc_middle::ty::print::with_no_trimmed_paths;
9-
use rustc_middle::ty::{Instance, TyCtxt};
9+
use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt};
1010
use rustc_span::symbol::{sym, Symbol};
1111

1212
const SYMBOL_NAME: Symbol = sym::rustc_symbol_name;
@@ -36,8 +36,11 @@ impl SymbolNamesTest<'tcx> {
3636
let def_id = tcx.hir().local_def_id(hir_id);
3737
for attr in tcx.get_attrs(def_id.to_def_id()).iter() {
3838
if tcx.sess.check_name(attr, SYMBOL_NAME) {
39-
// for now, can only use on monomorphic names
40-
let instance = Instance::mono(tcx, def_id.to_def_id());
39+
let def_id = def_id.to_def_id();
40+
let instance = Instance::new(
41+
def_id,
42+
tcx.erase_regions(&InternalSubsts::identity_for_item(tcx, def_id)),
43+
);
4144
let mangled = tcx.symbol_name(instance);
4245
tcx.sess.span_err(attr.span, &format!("symbol-name({})", mangled));
4346
if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) {

0 commit comments

Comments
 (0)