Skip to content

Commit 101e182

Browse files
committed
Auto merge of #104418 - matthiaskrgr:rollup-y4i6xjc, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - #101967 (Move `unix_socket_abstract` feature API to `SocketAddrExt`.) - #102470 (Stabilize const char convert) - #104223 (Recover from function pointer types with generic parameter list) - #104229 (Don't print full paths in overlap errors) - #104294 (Don't ICE with inline const errors during MIR build) - #104332 (Fixed some `_i32` notation in `maybe_uninit`’s doc) - #104349 (fix some typos in comments) - #104350 (Fix x finding Python on Windows) - #104356 (interpret: make check_mplace public) - #104364 (rustdoc: Resolve doc links in external traits having local impls) - #104378 (Bump chalk to v0.87) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents dedfb9c + c389097 commit 101e182

File tree

82 files changed

+647
-419
lines changed

Some content is hidden

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

82 files changed

+647
-419
lines changed

Cargo.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,9 @@ dependencies = [
502502

503503
[[package]]
504504
name = "chalk-derive"
505-
version = "0.80.0"
505+
version = "0.87.0"
506506
source = "registry+https://github.com/rust-lang/crates.io-index"
507-
checksum = "d0001adf0cf12361e08b65e1898ea138f8f77d8f5177cbf29b6b3b3532252bd6"
507+
checksum = "d552b2fa341f5fc35c6b917b1d289d3c3a34d0b74e579390ea6192d6152a8cdb"
508508
dependencies = [
509509
"proc-macro2",
510510
"quote",
@@ -514,9 +514,9 @@ dependencies = [
514514

515515
[[package]]
516516
name = "chalk-engine"
517-
version = "0.80.0"
517+
version = "0.87.0"
518518
source = "registry+https://github.com/rust-lang/crates.io-index"
519-
checksum = "c44ee96f2d67cb5193d1503f185db1abad9933a1c6e6b4169c176f90baecd393"
519+
checksum = "7e54ac43048cb31c470d7b3e3acd409090ef4a5abddfe02455187aebc3d6879f"
520520
dependencies = [
521521
"chalk-derive",
522522
"chalk-ir",
@@ -527,9 +527,9 @@ dependencies = [
527527

528528
[[package]]
529529
name = "chalk-ir"
530-
version = "0.80.0"
530+
version = "0.87.0"
531531
source = "registry+https://github.com/rust-lang/crates.io-index"
532-
checksum = "92d8a95548f23618fda86426e4304e563ec2bb7ba0216139f0748d63c107b5f1"
532+
checksum = "43aa55deff4e7fbdb09fa014543372f2c95a06835ac487b9ce57b5099b950838"
533533
dependencies = [
534534
"bitflags",
535535
"chalk-derive",
@@ -538,9 +538,9 @@ dependencies = [
538538

539539
[[package]]
540540
name = "chalk-solve"
541-
version = "0.80.0"
541+
version = "0.87.0"
542542
source = "registry+https://github.com/rust-lang/crates.io-index"
543-
checksum = "f37f492dacfafe2e21319b80827da2779932909bb392f0cc86b2bd5c07c1b4e1"
543+
checksum = "61213deefc36ba265ad01c4d997e18bcddf7922862a4594a47ca4575afb3dab4"
544544
dependencies = [
545545
"chalk-derive",
546546
"chalk-ir",

compiler/rustc_const_eval/src/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
376376

377377
/// Read an immediate from a place, asserting that that is possible with the given layout.
378378
///
379-
/// If this suceeds, the `ImmTy` is never `Uninit`.
379+
/// If this succeeds, the `ImmTy` is never `Uninit`.
380380
#[inline(always)]
381381
pub fn read_immediate(
382382
&self,

compiler/rustc_const_eval/src/interpret/place.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,7 @@ where
316316
Ok(MPlaceTy { mplace, layout, align })
317317
}
318318

319-
/// Take an operand, representing a pointer, and dereference it to a place -- that
320-
/// will always be a MemPlace. Lives in `place.rs` because it creates a place.
319+
/// Take an operand, representing a pointer, and dereference it to a place.
321320
#[instrument(skip(self), level = "debug")]
322321
pub fn deref_operand(
323322
&self,
@@ -331,7 +330,7 @@ where
331330
}
332331

333332
let mplace = self.ref_to_mplace(&val)?;
334-
self.check_mplace_access(mplace, CheckInAllocMsg::DerefTest)?;
333+
self.check_mplace(mplace)?;
335334
Ok(mplace)
336335
}
337336

@@ -358,17 +357,18 @@ where
358357
}
359358

360359
/// Check if this mplace is dereferenceable and sufficiently aligned.
361-
fn check_mplace_access(
362-
&self,
363-
mplace: MPlaceTy<'tcx, M::Provenance>,
364-
msg: CheckInAllocMsg,
365-
) -> InterpResult<'tcx> {
360+
pub fn check_mplace(&self, mplace: MPlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx> {
366361
let (size, align) = self
367362
.size_and_align_of_mplace(&mplace)?
368363
.unwrap_or((mplace.layout.size, mplace.layout.align.abi));
369364
assert!(mplace.align <= align, "dynamic alignment less strict than static one?");
370365
let align = M::enforce_alignment(self).then_some(align);
371-
self.check_ptr_access_align(mplace.ptr, size, align.unwrap_or(Align::ONE), msg)?;
366+
self.check_ptr_access_align(
367+
mplace.ptr,
368+
size,
369+
align.unwrap_or(Align::ONE),
370+
CheckInAllocMsg::DerefTest,
371+
)?;
372372
Ok(())
373373
}
374374

compiler/rustc_error_messages/locales/en-US/parser.ftl

+9
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,12 @@ parser_async_move_order_incorrect = the order of `move` and `async` is incorrect
375375
376376
parser_double_colon_in_bound = expected `:` followed by trait or lifetime
377377
.suggestion = use single colon
378+
379+
parser_fn_ptr_with_generics = function pointer types may not have generic parameters
380+
.suggestion = consider moving the lifetime {$arity ->
381+
[one] parameter
382+
*[other] parameters
383+
} to {$for_param_list_exists ->
384+
[true] the
385+
*[false] a
386+
} `for` parameter list

compiler/rustc_errors/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,10 @@ impl HandlerInner {
12541254
}
12551255

12561256
if diagnostic.has_future_breakage() {
1257+
// Future breakages aren't emitted if they're Level::Allowed,
1258+
// but they still need to be constructed and stashed below,
1259+
// so they'll trigger the good-path bug check.
1260+
self.suppressed_expected_diag = true;
12571261
self.future_breakage_diagnostics.push(diagnostic.clone());
12581262
}
12591263

compiler/rustc_expand/src/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ fn expand_macro<'cx>(
333333
assert!(try_success_result.is_err(), "Macro matching returned a success on the second try");
334334

335335
if let Some(result) = tracker.result {
336-
// An irrecoverable error occured and has been emitted.
336+
// An irrecoverable error occurred and has been emitted.
337337
return result;
338338
}
339339

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub enum AttributeDuplicates {
147147
FutureWarnPreceding,
148148
}
149149

150-
/// A conveniece macro to deal with `$($expr)?`.
150+
/// A convenience macro to deal with `$($expr)?`.
151151
macro_rules! or_default {
152152
($default:expr,) => {
153153
$default

compiler/rustc_hir_typeck/src/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct ClosureSignatures<'tcx> {
3535
bound_sig: ty::PolyFnSig<'tcx>,
3636
/// The signature within the function body.
3737
/// This mostly differs in the sense that lifetimes are now early bound and any
38-
/// opaque types from the signature expectation are overriden in case there are
38+
/// opaque types from the signature expectation are overridden in case there are
3939
/// explicit hidden types written by the user in the closure signature.
4040
liberated_sig: ty::FnSig<'tcx>,
4141
}

compiler/rustc_lint/src/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ fn lint_int_literal<'tcx>(
360360
}
361361

362362
if lint_overflowing_range_endpoint(cx, lit, v, max, e, t.name_str()) {
363-
// The overflowing literal lint was emited by `lint_overflowing_range_endpoint`.
363+
// The overflowing literal lint was emitted by `lint_overflowing_range_endpoint`.
364364
return;
365365
}
366366

@@ -429,7 +429,7 @@ fn lint_uint_literal<'tcx>(
429429
}
430430
}
431431
if lint_overflowing_range_endpoint(cx, lit, lit_val, max, e, t.name_str()) {
432-
// The overflowing literal lint was emited by `lint_overflowing_range_endpoint`.
432+
// The overflowing literal lint was emitted by `lint_overflowing_range_endpoint`.
433433
return;
434434
}
435435
if let Some(repr_str) = get_bin_hex_repr(cx, lit) {

compiler/rustc_middle/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ doctest = false
88

99
[dependencies]
1010
bitflags = "1.2.1"
11-
chalk-ir = "0.80.0"
11+
chalk-ir = "0.87.0"
1212
either = "1.5.0"
1313
gsgdt = "0.1.2"
1414
polonius-engine = "0.13.0"

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ impl<'tcx> Place<'tcx> {
15411541
/// If MirPhase >= Derefered and if projection contains Deref,
15421542
/// It's guaranteed to be in the first place
15431543
pub fn has_deref(&self) -> bool {
1544-
// To make sure this is not accidently used in wrong mir phase
1544+
// To make sure this is not accidentally used in wrong mir phase
15451545
debug_assert!(
15461546
self.projection.is_empty() || !self.projection[1..].contains(&PlaceElem::Deref)
15471547
);

compiler/rustc_middle/src/mir/syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub enum MirPhase {
8585
///
8686
/// Also note that the lint pass which reports eg `200_u8 + 200_u8` as an error is run as a part
8787
/// of analysis to runtime MIR lowering. To ensure lints are reported reliably, this means that
88-
/// transformations which may supress such errors should not run on analysis MIR.
88+
/// transformations which may suppress such errors should not run on analysis MIR.
8989
Runtime(RuntimePhase),
9090
}
9191

compiler/rustc_mir_build/src/build/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
118118
else_block: Some(else_block),
119119
} => {
120120
// When lowering the statement `let <pat> = <expr> else { <else> };`,
121-
// the `<else>` block is nested in the parent scope enclosing this statment.
121+
// the `<else>` block is nested in the parent scope enclosing this statement.
122122
// That scope is usually either the enclosing block scope,
123123
// or the remainder scope of the last statement.
124124
// This is to make sure that temporaries instantiated in `<expr>` are dropped

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

+3
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
577577
self.errors.push(PatternError::ConstParamInPattern(span));
578578
return PatKind::Wild;
579579
}
580+
ConstKind::Error(_) => {
581+
return PatKind::Wild;
582+
}
580583
_ => bug!("Expected ConstKind::Param"),
581584
},
582585
mir::ConstantKind::Val(_, _) => self.const_to_pat(value, id, span, false).kind,

compiler/rustc_parse/src/errors.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1280,3 +1280,24 @@ pub(crate) struct DoubleColonInBound {
12801280
#[suggestion(code = ": ", applicability = "machine-applicable")]
12811281
pub between: Span,
12821282
}
1283+
1284+
#[derive(Diagnostic)]
1285+
#[diag(parser_fn_ptr_with_generics)]
1286+
pub(crate) struct FnPtrWithGenerics {
1287+
#[primary_span]
1288+
pub span: Span,
1289+
#[subdiagnostic]
1290+
pub sugg: Option<FnPtrWithGenericsSugg>,
1291+
}
1292+
1293+
#[derive(Subdiagnostic)]
1294+
#[multipart_suggestion(suggestion, applicability = "maybe-incorrect")]
1295+
pub(crate) struct FnPtrWithGenericsSugg {
1296+
#[suggestion_part(code = "{snippet}")]
1297+
pub left: Span,
1298+
pub snippet: String,
1299+
#[suggestion_part(code = "")]
1300+
pub right: Span,
1301+
pub arity: usize,
1302+
pub for_param_list_exists: bool,
1303+
}

compiler/rustc_parse/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![feature(array_windows)]
44
#![feature(box_patterns)]
55
#![feature(if_let_guard)]
6+
#![feature(iter_intersperse)]
67
#![feature(let_chains)]
78
#![feature(never_type)]
89
#![feature(rustc_attrs)]

compiler/rustc_parse/src/parser/ty.rs

+55-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::{Parser, PathStyle, TokenType};
22

3+
use crate::errors::{FnPtrWithGenerics, FnPtrWithGenericsSugg};
34
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
45

56
use rustc_ast::ptr::P;
@@ -270,14 +271,19 @@ impl<'a> Parser<'a> {
270271
TyKind::Infer
271272
} else if self.check_fn_front_matter(false, Case::Sensitive) {
272273
// Function pointer type
273-
self.parse_ty_bare_fn(lo, Vec::new(), recover_return_sign)?
274+
self.parse_ty_bare_fn(lo, Vec::new(), None, recover_return_sign)?
274275
} else if self.check_keyword(kw::For) {
275276
// Function pointer type or bound list (trait object type) starting with a poly-trait.
276277
// `for<'lt> [unsafe] [extern "ABI"] fn (&'lt S) -> T`
277278
// `for<'lt> Trait1<'lt> + Trait2 + 'a`
278279
let lifetime_defs = self.parse_late_bound_lifetime_defs()?;
279280
if self.check_fn_front_matter(false, Case::Sensitive) {
280-
self.parse_ty_bare_fn(lo, lifetime_defs, recover_return_sign)?
281+
self.parse_ty_bare_fn(
282+
lo,
283+
lifetime_defs,
284+
Some(self.prev_token.span.shrink_to_lo()),
285+
recover_return_sign,
286+
)?
281287
} else {
282288
let path = self.parse_path(PathStyle::Type)?;
283289
let parse_plus = allow_plus == AllowPlus::Yes && self.check_plus();
@@ -519,7 +525,8 @@ impl<'a> Parser<'a> {
519525
fn parse_ty_bare_fn(
520526
&mut self,
521527
lo: Span,
522-
params: Vec<GenericParam>,
528+
mut params: Vec<GenericParam>,
529+
param_insertion_point: Option<Span>,
523530
recover_return_sign: RecoverReturnSign,
524531
) -> PResult<'a, TyKind> {
525532
let inherited_vis = rustc_ast::Visibility {
@@ -530,6 +537,9 @@ impl<'a> Parser<'a> {
530537
let span_start = self.token.span;
531538
let ast::FnHeader { ext, unsafety, constness, asyncness } =
532539
self.parse_fn_front_matter(&inherited_vis)?;
540+
if self.may_recover() && self.token.kind == TokenKind::Lt {
541+
self.recover_fn_ptr_with_generics(lo, &mut params, param_insertion_point)?;
542+
}
533543
let decl = self.parse_fn_decl(|_| false, AllowPlus::No, recover_return_sign)?;
534544
let whole_span = lo.to(self.prev_token.span);
535545
if let ast::Const::Yes(span) = constness {
@@ -545,6 +555,48 @@ impl<'a> Parser<'a> {
545555
Ok(TyKind::BareFn(P(BareFnTy { ext, unsafety, generic_params: params, decl, decl_span })))
546556
}
547557

558+
/// Recover from function pointer types with a generic parameter list (e.g. `fn<'a>(&'a str)`).
559+
fn recover_fn_ptr_with_generics(
560+
&mut self,
561+
lo: Span,
562+
params: &mut Vec<GenericParam>,
563+
param_insertion_point: Option<Span>,
564+
) -> PResult<'a, ()> {
565+
let generics = self.parse_generics()?;
566+
let arity = generics.params.len();
567+
568+
let mut lifetimes: Vec<_> = generics
569+
.params
570+
.into_iter()
571+
.filter(|param| matches!(param.kind, ast::GenericParamKind::Lifetime))
572+
.collect();
573+
574+
let sugg = if !lifetimes.is_empty() {
575+
let snippet =
576+
lifetimes.iter().map(|param| param.ident.as_str()).intersperse(", ").collect();
577+
578+
let (left, snippet) = if let Some(span) = param_insertion_point {
579+
(span, if params.is_empty() { snippet } else { format!(", {snippet}") })
580+
} else {
581+
(lo.shrink_to_lo(), format!("for<{snippet}> "))
582+
};
583+
584+
Some(FnPtrWithGenericsSugg {
585+
left,
586+
snippet,
587+
right: generics.span,
588+
arity,
589+
for_param_list_exists: param_insertion_point.is_some(),
590+
})
591+
} else {
592+
None
593+
};
594+
595+
self.sess.emit_err(FnPtrWithGenerics { span: generics.span, sugg });
596+
params.append(&mut lifetimes);
597+
Ok(())
598+
}
599+
548600
/// Emit an error for the given bad function pointer qualifier.
549601
fn error_fn_ptr_bad_qualifier(&self, span: Span, qual_span: Span, qual: &str) {
550602
self.struct_span_err(span, &format!("an `fn` pointer type cannot be `{}`", qual))

compiler/rustc_resolve/src/effective_visibilities.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'r, 'a> EffectiveVisibilitiesVisitor<'r, 'a> {
7272
update(node_id);
7373
if let ImportKind::Single { additional_ids: (id1, id2), .. } = import.kind {
7474
// In theory all the single import IDs have individual visibilities and
75-
// effective visibilities, but in practice these IDs go straigth to HIR
75+
// effective visibilities, but in practice these IDs go straight to HIR
7676
// where all their few uses assume that their (effective) visibility
7777
// applies to the whole syntactic `use` item. So they all get the same
7878
// value which is the maximum of all bindings. Maybe HIR for imports

compiler/rustc_resolve/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,11 @@ impl<'a> Resolver<'a> {
19321932
}
19331933
}
19341934

1935+
/// For rustdoc.
1936+
pub fn get_partial_res(&self, node_id: NodeId) -> Option<PartialRes> {
1937+
self.partial_res_map.get(&node_id).copied()
1938+
}
1939+
19351940
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
19361941
#[inline]
19371942
pub fn opt_span(&self, def_id: DefId) -> Option<Span> {

compiler/rustc_target/src/spec/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub enum Lld {
114114
/// relevant now.
115115
///
116116
/// The second goal is to keep the number of flavors to the minimum if possible.
117-
/// LLD somewhat forces our hand here because that linker is self-sufficent only if its executable
117+
/// LLD somewhat forces our hand here because that linker is self-sufficient only if its executable
118118
/// (`argv[0]`) is named in specific way, otherwise it doesn't work and requires a
119119
/// `-flavor LLD_FLAVOR` argument to choose which logic to use. Our shipped `rust-lld` in
120120
/// particular is not named in such specific way, so it needs the flavor option, so we make our

0 commit comments

Comments
 (0)