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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ James Hinshelwood <jameshinshelwood1@gmail.com> <james.hinshelwood@bigpayme.com>
292292
James Miller <bladeon@gmail.com> <james@aatch.net>
293293
James Perry <james.austin.perry@gmail.com>
294294
James Sanderson <zofrex@gmail.com>
295+
Jamie Hill-Daniel <jamie@hill-daniel.co.uk> <clubby789@gmail.com>
295296
Jana Dönszelmann <jana@donsz.nl>
296297
Jana Dönszelmann <jana@donsz.nl> <jonathan@donsz.nl>
297298
Jana Dönszelmann <jana@donsz.nl> <jonabent@gmail.com>

compiler/rustc_ast/src/ast.rs

Lines changed: 11 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 12 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 0 additions & 14 deletions
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

Lines changed: 21 additions & 0 deletions
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

Lines changed: 12 additions & 0 deletions
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

0 commit comments

Comments
 (0)