Skip to content

Commit 990039e

Browse files
committed
Auto merge of rust-lang#139814 - matthiaskrgr:rollup-lxkkcz6, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#139127 (Fix up partial res of segment in primitive resolution hack) - rust-lang#139392 (Detect and provide suggestion for `&raw EXPR`) - rust-lang#139767 (Visit place in `BackwardIncompatibleDropHint` statement) - rust-lang#139777 (Remove `define_debug_via_print` for `ExistentialProjection`, use regular structural debug impl) - rust-lang#139796 (ptr docs: add missing backtics around 'usize') - rust-lang#139801 (Add myself to mailmap) - rust-lang#139804 (use `realpath` in `bootstrap.py` when creating build-dir) - rust-lang#139807 (Improve wording of post-merge report) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 07d3fd1 + 47e5b18 commit 990039e

File tree

24 files changed

+259
-41
lines changed

24 files changed

+259
-41
lines changed

.mailmap

+1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ James Hinshelwood <[email protected]> <[email protected]>
292292
293293
James Perry <[email protected]>
294294
James Sanderson <[email protected]>
295+
295296
Jana Dönszelmann <[email protected]>
296297
297298

compiler/rustc_ast/src/ast.rs

+11
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ impl Path {
120120
Path { segments: thin_vec![PathSegment::from_ident(ident)], span: ident.span, tokens: None }
121121
}
122122

123+
pub fn is_ident(&self, name: Symbol) -> bool {
124+
if let [segment] = self.segments.as_ref()
125+
&& segment.args.is_none()
126+
&& segment.ident.name == name
127+
{
128+
true
129+
} else {
130+
false
131+
}
132+
}
133+
123134
pub fn is_global(&self) -> bool {
124135
self.segments.first().is_some_and(|segment| segment.ident.name == kw::PathRoot)
125136
}

compiler/rustc_borrowck/src/def_use.rs

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ pub(crate) fn categorize(context: PlaceContext) -> Option<DefUse> {
7777
// Debug info is neither def nor use.
7878
PlaceContext::NonUse(NonUseContext::VarDebugInfo) => None,
7979

80+
// Backwards incompatible drop hint is not a use, just a marker for linting.
81+
PlaceContext::NonUse(NonUseContext::BackwardIncompatibleDropHint) => None,
82+
8083
PlaceContext::MutatingUse(MutatingUseContext::Deinit | MutatingUseContext::SetDiscriminant) => {
8184
bug!("These statements are not allowed in this MIR phase")
8285
}

compiler/rustc_borrowck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
12861286
error_reported
12871287
}
12881288

1289-
/// Through #123739, backward incompatible drops (BIDs) are introduced.
1289+
/// Through #123739, `BackwardIncompatibleDropHint`s (BIDs) are introduced.
12901290
/// We would like to emit lints whether borrow checking fails at these future drop locations.
12911291
#[instrument(level = "debug", skip(self, state))]
12921292
fn check_backward_incompatible_drop(

compiler/rustc_middle/src/mir/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ impl Debug for Statement<'_> {
859859
BackwardIncompatibleDropHint { ref place, reason: _ } => {
860860
// For now, we don't record the reason because there is only one use case,
861861
// which is to report breaking change in drop order by Edition 2024
862-
write!(fmt, "backward incompatible drop({place:?})")
862+
write!(fmt, "BackwardIncompatibleDropHint({place:?})")
863863
}
864864
}
865865
}

compiler/rustc_middle/src/mir/visit.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,15 @@ macro_rules! make_mir_visitor {
457457
}
458458
}
459459
}
460+
StatementKind::BackwardIncompatibleDropHint { place, .. } => {
461+
self.visit_place(
462+
place,
463+
PlaceContext::NonUse(NonUseContext::BackwardIncompatibleDropHint),
464+
location
465+
);
466+
}
460467
StatementKind::ConstEvalCounter => {}
461468
StatementKind::Nop => {}
462-
StatementKind::BackwardIncompatibleDropHint { .. } => {}
463469
}
464470
}
465471

@@ -1348,6 +1354,8 @@ pub enum NonUseContext {
13481354
AscribeUserTy(ty::Variance),
13491355
/// The data of a user variable, for debug info.
13501356
VarDebugInfo,
1357+
/// A `BackwardIncompatibleDropHint` statement, meant for edition 2024 lints.
1358+
BackwardIncompatibleDropHint,
13511359
}
13521360

13531361
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -1422,7 +1430,9 @@ impl PlaceContext {
14221430
use NonUseContext::*;
14231431
match self {
14241432
PlaceContext::MutatingUse(_) => ty::Invariant,
1425-
PlaceContext::NonUse(StorageDead | StorageLive | VarDebugInfo) => ty::Invariant,
1433+
PlaceContext::NonUse(
1434+
StorageDead | StorageLive | VarDebugInfo | BackwardIncompatibleDropHint,
1435+
) => ty::Invariant,
14261436
PlaceContext::NonMutatingUse(
14271437
Inspect | Copy | Move | PlaceMention | SharedBorrow | FakeBorrow | RawBorrow
14281438
| Projection,

compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ impl<'tcx> crate::MirPass<'tcx> for CleanupPostBorrowck {
3535
// MIR building, and are not needed after InstrumentCoverage.
3636
CoverageKind::BlockMarker { .. } | CoverageKind::SpanMarker { .. },
3737
)
38-
| StatementKind::FakeRead(..) => statement.make_nop(),
38+
| StatementKind::FakeRead(..)
39+
| StatementKind::BackwardIncompatibleDropHint { .. } => statement.make_nop(),
3940
StatementKind::Assign(box (
4041
_,
4142
Rvalue::Cast(

compiler/rustc_mir_transform/src/simplify.rs

-14
Original file line numberDiff line numberDiff line change
@@ -597,20 +597,6 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater<'tcx> {
597597
self.tcx
598598
}
599599

600-
fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) {
601-
if let StatementKind::BackwardIncompatibleDropHint { place, reason: _ } =
602-
&mut statement.kind
603-
{
604-
self.visit_local(
605-
&mut place.local,
606-
PlaceContext::MutatingUse(MutatingUseContext::Store),
607-
location,
608-
);
609-
} else {
610-
self.super_statement(statement, location);
611-
}
612-
}
613-
614600
fn visit_local(&mut self, l: &mut Local, _: PlaceContext, _: Location) {
615601
*l = self.map[*l].unwrap();
616602
}

compiler/rustc_parse/src/parser/diagnostics.rs

+21
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ impl<'a> Parser<'a> {
609609
// FIXME: translation requires list formatting (for `expect`)
610610
let mut err = self.dcx().struct_span_err(self.token.span, msg_exp);
611611

612+
self.label_expected_raw_ref(&mut err);
613+
612614
// Look for usages of '=>' where '>=' was probably intended
613615
if self.token == token::FatArrow
614616
&& expected.iter().any(|tok| matches!(tok, TokenType::Operator | TokenType::Le))
@@ -750,6 +752,25 @@ impl<'a> Parser<'a> {
750752
Err(err)
751753
}
752754

755+
/// Adds a label when `&raw EXPR` was written instead of `&raw const EXPR`/`&raw mut EXPR`.
756+
///
757+
/// Given that not all parser diagnostics flow through `expected_one_of_not_found`, this
758+
/// label may need added to other diagnostics emission paths as needed.
759+
pub(super) fn label_expected_raw_ref(&mut self, err: &mut Diag<'_>) {
760+
if self.prev_token.is_keyword(kw::Raw)
761+
&& self.expected_token_types.contains(TokenType::KwMut)
762+
&& self.expected_token_types.contains(TokenType::KwConst)
763+
&& self.token.can_begin_expr()
764+
{
765+
err.span_suggestions(
766+
self.prev_token.span.shrink_to_hi(),
767+
"`&raw` must be followed by `const` or `mut` to be a raw reference expression",
768+
[" const".to_string(), " mut".to_string()],
769+
Applicability::MaybeIncorrect,
770+
);
771+
}
772+
}
773+
753774
/// Checks if the current token or the previous token are misspelled keywords
754775
/// and adds a helpful suggestion.
755776
fn check_for_misspelled_kw(&self, err: &mut Diag<'_>, expected: &[TokenType]) {

compiler/rustc_parse/src/parser/expr.rs

+12
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,18 @@ impl<'a> Parser<'a> {
827827
if let Some(lt) = lifetime {
828828
self.error_remove_borrow_lifetime(span, lt.ident.span.until(expr.span));
829829
}
830+
831+
// Add expected tokens if we parsed `&raw` as an expression.
832+
// This will make sure we see "expected `const`, `mut`", and
833+
// guides recovery in case we write `&raw expr`.
834+
if borrow_kind == ast::BorrowKind::Ref
835+
&& mutbl == ast::Mutability::Not
836+
&& matches!(&expr.kind, ExprKind::Path(None, p) if p.is_ident(kw::Raw))
837+
{
838+
self.expected_token_types.insert(TokenType::KwMut);
839+
self.expected_token_types.insert(TokenType::KwConst);
840+
}
841+
830842
Ok((span, ExprKind::AddrOf(borrow_kind, mutbl, expr)))
831843
}
832844

compiler/rustc_parse/src/parser/stmt.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,11 @@ impl<'a> Parser<'a> {
518518
let prev = self.prev_token.span;
519519
let sp = self.token.span;
520520
let mut e = self.dcx().struct_span_err(sp, msg);
521-
let do_not_suggest_help = self.token.is_keyword(kw::In) || self.token == token::Colon;
521+
self.label_expected_raw_ref(&mut e);
522+
523+
let do_not_suggest_help = self.token.is_keyword(kw::In)
524+
|| self.token == token::Colon
525+
|| self.prev_token.is_keyword(kw::Raw);
522526

523527
// Check to see if the user has written something like
524528
//

compiler/rustc_resolve/src/late.rs

+5
Original file line numberDiff line numberDiff line change
@@ -4606,6 +4606,11 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
46064606
}
46074607
};
46084608

4609+
// Fix up partial res of segment from `resolve_path` call.
4610+
if let Some(id) = path[0].id {
4611+
self.r.partial_res_map.insert(id, PartialRes::new(Res::PrimTy(prim)));
4612+
}
4613+
46094614
PartialRes::with_unresolved_segments(Res::PrimTy(prim), path.len() - 1)
46104615
}
46114616
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {

compiler/rustc_type_ir/src/ir_print.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ define_display_via_print!(
6060
PatternKind,
6161
);
6262

63-
define_debug_via_print!(TraitRef, ExistentialTraitRef, ExistentialProjection, PatternKind);
63+
define_debug_via_print!(TraitRef, ExistentialTraitRef, PatternKind);
6464

6565
impl<I: Interner, T> fmt::Display for OutlivesPredicate<I, T>
6666
where

compiler/rustc_type_ir/src/predicate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl<I: Interner> ty::Binder<I, ExistentialTraitRef<I>> {
374374
}
375375

376376
/// A `ProjectionPredicate` for an `ExistentialTraitRef`.
377-
#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)]
377+
#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)]
378378
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)]
379379
#[cfg_attr(
380380
feature = "nightly",

library/core/src/ptr/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
//! ### Using Strict Provenance
279279
//!
280280
//! Most code needs no changes to conform to strict provenance, as the only really concerning
281-
//! operation is casts from usize to a pointer. For code which *does* cast a `usize` to a pointer,
281+
//! operation is casts from `usize` to a pointer. For code which *does* cast a `usize` to a pointer,
282282
//! the scope of the change depends on exactly what you're doing.
283283
//!
284284
//! In general, you just need to make sure that if you want to convert a `usize` address to a

src/bootstrap/bootstrap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ def bootstrap(args):
13311331
build.check_vendored_status()
13321332

13331333
if not os.path.exists(build.build_dir):
1334-
os.makedirs(build.build_dir)
1334+
os.makedirs(os.path.realpath(build.build_dir))
13351335

13361336
# Fetch/build the bootstrap
13371337
build.download_toolchain()

src/ci/citool/src/analysis.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -520,23 +520,27 @@ fn report_test_diffs(
520520
}
521521

522522
if doctest_count > 0 {
523+
let prefix =
524+
if doctest_count < original_diff_count { "Additionally, " } else { "" };
523525
println!(
524-
"\nAdditionally, {doctest_count} doctest {} were found. These are ignored, as they are noisy.",
526+
"\n{prefix}{doctest_count} doctest {} were found. These are ignored, as they are noisy.",
525527
pluralize("diff", doctest_count)
526528
);
527529
}
528530

529531
// Now print the job group index
530-
println!("\n**Job group index**\n");
531-
for (group, jobs) in job_index.into_iter().enumerate() {
532-
println!(
533-
"- {}: {}",
534-
format_job_group(group as u64),
535-
jobs.iter()
536-
.map(|j| format_job_link(job_info_resolver, job_metrics, j))
537-
.collect::<Vec<_>>()
538-
.join(", ")
539-
);
532+
if !job_index.is_empty() {
533+
println!("\n**Job group index**\n");
534+
for (group, jobs) in job_index.into_iter().enumerate() {
535+
println!(
536+
"- {}: {}",
537+
format_job_group(group as u64),
538+
jobs.iter()
539+
.map(|j| format_job_link(job_info_resolver, job_metrics, j))
540+
.collect::<Vec<_>>()
541+
.join(", ")
542+
);
543+
}
540544
}
541545
},
542546
);

tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-abort.mir

-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ fn method_1(_1: Guard) -> () {
7373
}
7474

7575
bb7: {
76-
backward incompatible drop(_2);
77-
backward incompatible drop(_4);
78-
backward incompatible drop(_5);
7976
goto -> bb21;
8077
}
8178

tests/mir-opt/tail_expr_drop_order_unwind.method_1.ElaborateDrops.after.panic-unwind.mir

-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ fn method_1(_1: Guard) -> () {
7373
}
7474

7575
bb7: {
76-
backward incompatible drop(_2);
77-
backward incompatible drop(_4);
78-
backward incompatible drop(_5);
7976
goto -> bb21;
8077
}
8178

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
fn a() {
2+
let x = &raw 1;
3+
//~^ ERROR expected one of
4+
}
5+
6+
fn b() {
7+
[&raw const 1, &raw 2]
8+
//~^ ERROR expected one of
9+
//~| ERROR cannot find value `raw` in this scope
10+
//~| ERROR cannot take address of a temporary
11+
}
12+
13+
fn c() {
14+
if x == &raw z {}
15+
//~^ ERROR expected `{`
16+
}
17+
18+
fn d() {
19+
f(&raw 2);
20+
//~^ ERROR expected one of
21+
//~| ERROR cannot find value `raw` in this scope
22+
//~| ERROR cannot find function `f` in this scope
23+
}
24+
25+
fn e() {
26+
let x;
27+
x = &raw 1;
28+
//~^ ERROR expected one of
29+
}
30+
31+
fn main() {}

0 commit comments

Comments
 (0)