Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e838059

Browse files
committed
Auto merge of rust-lang#97632 - JohnTitor:rollup-d2ucrjw, r=JohnTitor
Rollup of 6 pull requests Successful merges: - rust-lang#95594 (Additional `*mut [T]` methods) - rust-lang#97130 (rustdoc: avoid including impl blocks with filled-in generics) - rust-lang#97166 (Move conditions out of recover/report functions.) - rust-lang#97605 (Mention filename in suggestion when it differs from primary span) - rust-lang#97613 (rustdoc: Improve calculation of "Impls on Foreign Types") - rust-lang#97626 (rename PointerAddress → PointerExposeAddress) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 12cd71f + b78c118 commit e838059

File tree

31 files changed

+293
-82
lines changed

31 files changed

+293
-82
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21472147
}
21482148
}
21492149

2150-
CastKind::PointerAddress => {
2150+
CastKind::PointerExposeAddress => {
21512151
let ty_from = op.ty(body, tcx);
21522152
let cast_ty_from = CastTy::from_ty(ty_from);
21532153
let cast_ty_to = CastTy::from_ty(*ty);

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,11 @@ fn codegen_stmt<'tcx>(
607607
let operand = codegen_operand(fx, operand);
608608
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
609609
}
610-
Rvalue::Cast(CastKind::Misc | CastKind::PointerAddress, ref operand, to_ty) => {
610+
Rvalue::Cast(
611+
CastKind::Misc | CastKind::PointerExposeAddress,
612+
ref operand,
613+
to_ty,
614+
) => {
611615
let operand = codegen_operand(fx, operand);
612616
let from_ty = operand.layout().ty;
613617
let to_ty = fx.monomorphize(to_ty);

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
181181
let cast = bx.cx().layout_of(self.monomorphize(mir_cast_ty));
182182

183183
let val = match *kind {
184-
mir::CastKind::PointerAddress => {
184+
mir::CastKind::PointerExposeAddress => {
185185
assert!(bx.cx().is_backend_immediate(cast));
186186
let llptr = operand.immediate();
187187
let llcast_ty = bx.cx().immediate_backend_type(cast);

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
3131
self.unsize_into(src, cast_ty, dest)?;
3232
}
3333

34-
PointerAddress => {
34+
PointerExposeAddress => {
3535
let src = self.read_immediate(src)?;
36-
let res = self.pointer_address_cast(&src, cast_ty)?;
36+
let res = self.pointer_expose_address_cast(&src, cast_ty)?;
3737
self.write_immediate(res, dest)?;
3838
}
3939

@@ -184,7 +184,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
184184
Ok(self.cast_from_int_like(scalar, src.layout, cast_ty)?.into())
185185
}
186186

187-
pub fn pointer_address_cast(
187+
pub fn pointer_expose_address_cast(
188188
&mut self,
189189
src: &ImmTy<'tcx, M::PointerTag>,
190190
cast_ty: Ty<'tcx>,

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
542542
// in the type of any local, which also excludes casts).
543543
}
544544

545-
Rvalue::Cast(CastKind::PointerAddress, _, _) => {
545+
Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => {
546546
self.check_op(ops::RawPtrToIntCast);
547547
}
548548

compiler/rustc_const_eval/src/transform/promote_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ impl<'tcx> Validator<'_, 'tcx> {
502502
Rvalue::ThreadLocalRef(_) => return Err(Unpromotable),
503503

504504
// ptr-to-int casts are not possible in consts and thus not promotable
505-
Rvalue::Cast(CastKind::PointerAddress, _, _) => return Err(Unpromotable),
505+
Rvalue::Cast(CastKind::PointerExposeAddress, _, _) => return Err(Unpromotable),
506506

507507
// int-to-ptr casts are fine, they just use the integer value at pointer type.
508508
Rvalue::Cast(_, operand, _) => {

compiler/rustc_errors/src/emitter.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,7 @@ impl EmitterWriter {
17151715

17161716
fn emit_suggestion_default(
17171717
&mut self,
1718+
span: &MultiSpan,
17181719
suggestion: &CodeSuggestion,
17191720
args: &FluentArgs<'_>,
17201721
level: &Level,
@@ -1766,6 +1767,30 @@ impl EmitterWriter {
17661767
None,
17671768
}
17681769

1770+
if let Some(span) = span.primary_span() {
1771+
// Compare the primary span of the diagnostic with the span of the suggestion
1772+
// being emitted. If they belong to the same file, we don't *need* to show the
1773+
// file name, saving in verbosity, but if it *isn't* we do need it, otherwise we're
1774+
// telling users to make a change but not clarifying *where*.
1775+
let loc = sm.lookup_char_pos(parts[0].span.lo());
1776+
if loc.file.name != sm.span_to_filename(span) && loc.file.name.is_real() {
1777+
buffer.puts(row_num - 1, 0, "--> ", Style::LineNumber);
1778+
buffer.append(
1779+
row_num - 1,
1780+
&format!(
1781+
"{}:{}:{}",
1782+
sm.filename_for_diagnostics(&loc.file.name),
1783+
sm.doctest_offset_line(&loc.file.name, loc.line),
1784+
loc.col.0 + 1,
1785+
),
1786+
Style::LineAndColumn,
1787+
);
1788+
for _ in 0..max_line_num_len {
1789+
buffer.prepend(row_num - 1, " ", Style::NoStyle);
1790+
}
1791+
row_num += 1;
1792+
}
1793+
}
17691794
let show_code_change = if has_deletion && !is_multiline {
17701795
DisplaySuggestion::Diff
17711796
} else if (parts.len() != 1 || parts[0].snippet.trim() != complete.trim())
@@ -1787,7 +1812,7 @@ impl EmitterWriter {
17871812
assert!(!file_lines.lines.is_empty() || parts[0].span.is_dummy());
17881813

17891814
let line_start = sm.lookup_char_pos(parts[0].span.lo()).line;
1790-
draw_col_separator_no_space(&mut buffer, 1, max_line_num_len + 1);
1815+
draw_col_separator_no_space(&mut buffer, row_num - 1, max_line_num_len + 1);
17911816
let mut lines = complete.lines();
17921817
if lines.clone().next().is_none() {
17931818
// Account for a suggestion to completely remove a line(s) with whitespace (#94192).
@@ -2046,9 +2071,13 @@ impl EmitterWriter {
20462071
) {
20472072
panic!("failed to emit error: {}", e);
20482073
}
2049-
} else if let Err(e) =
2050-
self.emit_suggestion_default(sugg, args, &Level::Help, max_line_num_len)
2051-
{
2074+
} else if let Err(e) = self.emit_suggestion_default(
2075+
span,
2076+
sugg,
2077+
args,
2078+
&Level::Help,
2079+
max_line_num_len,
2080+
) {
20522081
panic!("failed to emit error: {}", e);
20532082
};
20542083
}

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,16 +2607,17 @@ static_assert_size!(Rvalue<'_>, 40);
26072607
impl<'tcx> Rvalue<'tcx> {
26082608
#[inline]
26092609
pub fn is_pointer_int_cast(&self) -> bool {
2610-
matches!(self, Rvalue::Cast(CastKind::PointerAddress, _, _))
2610+
matches!(self, Rvalue::Cast(CastKind::PointerExposeAddress, _, _))
26112611
}
26122612
}
26132613

26142614
#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
26152615
pub enum CastKind {
26162616
Misc,
2617-
/// A pointer to address cast. A cast between a pointer and an integer type,
2618-
/// or between a function pointer and an integer type.
2619-
PointerAddress,
2617+
/// An exposing pointer to address cast. A cast between a pointer and an integer type, or
2618+
/// between a function pointer and an integer type.
2619+
/// See the docs on `expose_addr` for more details.
2620+
PointerExposeAddress,
26202621
Pointer(PointerCast),
26212622
}
26222623

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
194194
let cast_ty = CastTy::from_ty(expr.ty);
195195
let cast_kind = match (from_ty, cast_ty) {
196196
(Some(CastTy::Ptr(_) | CastTy::FnPtr), Some(CastTy::Int(_))) => {
197-
CastKind::PointerAddress
197+
CastKind::PointerExposeAddress
198198
}
199199
(_, _) => CastKind::Misc,
200200
};

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use super::pat::Expected;
2-
use super::ty::{AllowPlus, RecoverQuestionMark};
32
use super::{
4-
BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverColon, RecoverComma, Restrictions,
5-
SemiColonMode, SeqSep, TokenExpectType, TokenType,
3+
BlockMode, CommaRecoveryMode, Parser, PathStyle, Restrictions, SemiColonMode, SeqSep,
4+
TokenExpectType, TokenType,
65
};
76

87
use crate::lexer::UnmatchedBrace;
@@ -1233,26 +1232,14 @@ impl<'a> Parser<'a> {
12331232
}
12341233
}
12351234

1236-
pub(super) fn maybe_report_ambiguous_plus(
1237-
&mut self,
1238-
allow_plus: AllowPlus,
1239-
impl_dyn_multi: bool,
1240-
ty: &Ty,
1241-
) {
1242-
if matches!(allow_plus, AllowPlus::No) && impl_dyn_multi {
1235+
pub(super) fn maybe_report_ambiguous_plus(&mut self, impl_dyn_multi: bool, ty: &Ty) {
1236+
if impl_dyn_multi {
12431237
self.sess.emit_err(AmbiguousPlus { sum_ty: pprust::ty_to_string(&ty), span: ty.span });
12441238
}
12451239
}
12461240

12471241
/// Swift lets users write `Ty?` to mean `Option<Ty>`. Parse the construct and recover from it.
1248-
pub(super) fn maybe_recover_from_question_mark(
1249-
&mut self,
1250-
ty: P<Ty>,
1251-
recover_question_mark: RecoverQuestionMark,
1252-
) -> P<Ty> {
1253-
if let RecoverQuestionMark::No = recover_question_mark {
1254-
return ty;
1255-
}
1242+
pub(super) fn maybe_recover_from_question_mark(&mut self, ty: P<Ty>) -> P<Ty> {
12561243
if self.token == token::Question {
12571244
self.bump();
12581245
self.struct_span_err(self.prev_token.span, "invalid `?` in type")
@@ -1272,13 +1259,9 @@ impl<'a> Parser<'a> {
12721259
}
12731260
}
12741261

1275-
pub(super) fn maybe_recover_from_bad_type_plus(
1276-
&mut self,
1277-
allow_plus: AllowPlus,
1278-
ty: &Ty,
1279-
) -> PResult<'a, ()> {
1262+
pub(super) fn maybe_recover_from_bad_type_plus(&mut self, ty: &Ty) -> PResult<'a, ()> {
12801263
// Do not add `+` to expected tokens.
1281-
if matches!(allow_plus, AllowPlus::No) || !self.token.is_like_plus() {
1264+
if !self.token.is_like_plus() {
12821265
return Ok(());
12831266
}
12841267

@@ -1444,10 +1427,9 @@ impl<'a> Parser<'a> {
14441427
pub(super) fn maybe_recover_from_bad_qpath<T: RecoverQPath>(
14451428
&mut self,
14461429
base: P<T>,
1447-
allow_recovery: bool,
14481430
) -> PResult<'a, P<T>> {
14491431
// Do not add `::` to expected tokens.
1450-
if allow_recovery && self.token == token::ModSep {
1432+
if self.token == token::ModSep {
14511433
if let Some(ty) = base.to_ty() {
14521434
return self.maybe_recover_from_bad_qpath_stage_2(ty.span, ty);
14531435
}
@@ -1593,7 +1575,7 @@ impl<'a> Parser<'a> {
15931575
_ => ExprKind::Await(expr),
15941576
};
15951577
let expr = self.mk_expr(lo.to(sp), kind, attrs);
1596-
self.maybe_recover_from_bad_qpath(expr, true)
1578+
self.maybe_recover_from_bad_qpath(expr)
15971579
}
15981580

15991581
fn recover_await_macro(&mut self) -> PResult<'a, (Span, P<Expr>, bool)> {
@@ -2457,10 +2439,9 @@ impl<'a> Parser<'a> {
24572439
pub(crate) fn maybe_recover_colon_colon_in_pat_typo(
24582440
&mut self,
24592441
mut first_pat: P<Pat>,
2460-
ra: RecoverColon,
24612442
expected: Expected,
24622443
) -> P<Pat> {
2463-
if RecoverColon::Yes != ra || token::Colon != self.token.kind {
2444+
if token::Colon != self.token.kind {
24642445
return first_pat;
24652446
}
24662447
if !matches!(first_pat.kind, PatKind::Ident(_, _, None) | PatKind::Path(..))
@@ -2594,10 +2575,9 @@ impl<'a> Parser<'a> {
25942575
pub(crate) fn maybe_recover_unexpected_comma(
25952576
&mut self,
25962577
lo: Span,
2597-
rc: RecoverComma,
25982578
rt: CommaRecoveryMode,
25992579
) -> PResult<'a, ()> {
2600-
if rc == RecoverComma::No || self.token != token::Comma {
2580+
if self.token != token::Comma {
26012581
return Ok(());
26022582
}
26032583

0 commit comments

Comments
 (0)