Skip to content

Commit f940188

Browse files
committed
Auto merge of #136041 - matthiaskrgr:rollup-5r1k45x, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #135971 (Properly report error when object type param default references self) - #135977 (Fix `FormattingOptions` instantiation with `Default`) - #135985 (Rename test to `unresolvable-upvar-issue-87987.rs` and add some notes) - #135991 (Fix set_name in thread mod for NuttX) - #136009 (bootstrap: Handle bootstrap lockfile race condition better) - #136018 (Use short ty string for move errors) - #136027 (Skip suggestions in `derive`d code) - #136029 (Bootstrap: Don't move ownership of job object) - #136034 (fix(bootstrap): deserialize null as `f64::NAN`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6365178 + a330c7e commit f940188

34 files changed

+274
-126
lines changed

compiler/rustc_borrowck/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ borrowck_lifetime_constraints_error =
9292
borrowck_limitations_implies_static =
9393
due to current limitations in the borrow checker, this implies a `'static` lifetime
9494
95+
borrowck_long_type_consider_verbose = consider using `--verbose` to print the full type name to the console
96+
borrowck_long_type_full_path = the full type name has been written to '{$path}'
97+
9598
borrowck_move_closure_suggestion =
9699
consider adding 'move' keyword before the nested closure
97100

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
289289
None => "value".to_owned(),
290290
};
291291
if needs_note {
292+
let mut path = None;
293+
let ty = self.infcx.tcx.short_ty_string(ty, &mut path);
292294
if let Some(local) = place.as_local() {
293295
let span = self.body.local_decls[local].source_info.span;
294296
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
@@ -304,6 +306,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
304306
place: &note_msg,
305307
});
306308
};
309+
if let Some(path) = path {
310+
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
311+
path: path.display().to_string(),
312+
});
313+
}
307314
}
308315

309316
if let UseSpans::FnSelfUse {

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
596596
self.suggest_cloning(err, place_ty, expr, None);
597597
}
598598

599+
let mut path = None;
600+
let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path);
599601
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
600602
is_partial_move: false,
601-
ty: place_ty,
603+
ty,
602604
place: &place_desc,
603605
span,
604606
});
607+
if let Some(path) = path {
608+
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
609+
path: path.display().to_string(),
610+
});
611+
}
605612
} else {
606613
binds_to.sort();
607614
binds_to.dedup();
@@ -628,12 +635,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
628635
self.suggest_cloning(err, place_ty, expr, Some(use_spans));
629636
}
630637

638+
let mut path = None;
639+
let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path);
631640
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
632641
is_partial_move: false,
633-
ty: place_ty,
642+
ty,
634643
place: &place_desc,
635644
span: use_span,
636645
});
646+
if let Some(path) = path {
647+
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
648+
path: path.display().to_string(),
649+
});
650+
}
637651

638652
use_spans.args_subdiag(err, |args_span| {
639653
crate::session_diagnostics::CaptureArgLabel::MoveOutPlace {
@@ -831,12 +845,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
831845
self.suggest_cloning(err, bind_to.ty, expr, None);
832846
}
833847

848+
let mut path = None;
849+
let ty = self.infcx.tcx.short_ty_string(bind_to.ty, &mut path);
834850
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
835851
is_partial_move: false,
836-
ty: bind_to.ty,
852+
ty,
837853
place: place_desc,
838854
span: binding_span,
839855
});
856+
if let Some(path) = path {
857+
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
858+
path: path.display().to_string(),
859+
});
860+
}
840861
}
841862
}
842863

compiler/rustc_borrowck/src/session_diagnostics.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,24 @@ pub(crate) enum OnClosureNote<'a> {
459459
}
460460

461461
#[derive(Subdiagnostic)]
462-
pub(crate) enum TypeNoCopy<'a, 'tcx> {
462+
#[note(borrowck_long_type_full_path)]
463+
#[note(borrowck_long_type_consider_verbose)]
464+
pub(crate) struct LongTypePath {
465+
pub(crate) path: String,
466+
}
467+
468+
#[derive(Subdiagnostic)]
469+
pub(crate) enum TypeNoCopy<'a> {
463470
#[label(borrowck_ty_no_impl_copy)]
464471
Label {
465472
is_partial_move: bool,
466-
ty: Ty<'tcx>,
473+
ty: String,
467474
place: &'a str,
468475
#[primary_span]
469476
span: Span,
470477
},
471478
#[note(borrowck_ty_no_impl_copy)]
472-
Note { is_partial_move: bool, ty: Ty<'tcx>, place: &'a str },
479+
Note { is_partial_move: bool, ty: String, place: &'a str },
473480
}
474481

475482
#[derive(Diagnostic)]

compiler/rustc_error_codes/src/error_codes/E0393.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ A type parameter which references `Self` in its default value was not specified.
33
Erroneous code example:
44

55
```compile_fail,E0393
6-
trait A<T=Self> {}
6+
trait A<T = Self> {}
77
8-
fn together_we_will_rule_the_galaxy(son: &A) {}
9-
// error: the type parameter `T` must be explicitly specified in an
10-
// object type because its default value `Self` references the
11-
// type `Self`
8+
fn together_we_will_rule_the_galaxy(son: &dyn A) {}
9+
// error: the type parameter `T` must be explicitly specified
1210
```
1311

1412
A trait object is defined over a single, fully-defined trait. With a regular
@@ -23,7 +21,7 @@ disallowed. Making the trait concrete by explicitly specifying the value of the
2321
defaulted parameter will fix this issue. Fixed example:
2422

2523
```
26-
trait A<T=Self> {}
24+
trait A<T = Self> {}
2725
28-
fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok!
26+
fn together_we_will_rule_the_galaxy(son: &dyn A<i32>) {} // Ok!
2927
```

compiler/rustc_hir_analysis/messages.ftl

+7-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,13 @@ hir_analysis_missing_type_params =
353353
[one] reference
354354
*[other] references
355355
} to {$parameters}
356-
.note = because of the default `Self` reference, type parameters must be specified on object types
356+
.note = because the parameter {$parameterCount ->
357+
[one] default references
358+
*[other] defaults reference
359+
} `Self`, the {$parameterCount ->
360+
[one] parameter
361+
*[other] parameters
362+
} must be specified on the object type
357363
358364
hir_analysis_multiple_relaxed_default_bounds =
359365
type parameter has more than one relaxed default bound, only one is supported

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
237237
// Skip `Self`
238238
.skip(1)
239239
.map(|(index, arg)| {
240-
if arg == dummy_self.into() {
240+
if arg.walk().any(|arg| arg == dummy_self.into()) {
241241
let param = &generics.own_params[index];
242242
missing_type_params.push(param.name);
243243
Ty::new_misc_error(tcx).into()
244-
} else if arg.walk().any(|arg| arg == dummy_self.into()) {
245-
let guar = self.dcx().span_delayed_bug(
246-
span,
247-
"trait object trait bounds reference `Self`",
248-
);
249-
replace_dummy_self_with_error(tcx, arg, guar)
250244
} else {
251245
arg
252246
}

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+3
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
185185
rhs_ty: Ty<'tcx>,
186186
can_satisfy: impl FnOnce(Ty<'tcx>, Ty<'tcx>) -> bool,
187187
) -> bool {
188+
if lhs_expr.span.in_derive_expansion() || rhs_expr.span.in_derive_expansion() {
189+
return false;
190+
}
188191
let Some((_, lhs_output_ty, lhs_inputs)) = self.extract_callable_info(lhs_ty) else {
189192
return false;
190193
};

compiler/rustc_mir_build/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ mir_build_borrow_of_moved_value = borrow of moved value
2525
.occurs_because_label = move occurs because `{$name}` has type `{$ty}`, which does not implement the `Copy` trait
2626
.value_borrowed_label = value borrowed here after move
2727
.suggestion = borrow this binding in the pattern to avoid moving the value
28+
.full_type_name = the full type name has been written to '{$path}'
29+
.consider_verbose = consider using `--verbose` to print the full type name to the console
2830
2931
mir_build_call_to_deprecated_safe_fn_requires_unsafe =
3032
call to deprecated safe function `{$function}` is unsafe and requires unsafe block

compiler/rustc_mir_build/src/errors.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -790,17 +790,21 @@ pub(crate) struct IrrefutableLetPatternsWhileLet {
790790

791791
#[derive(Diagnostic)]
792792
#[diag(mir_build_borrow_of_moved_value)]
793-
pub(crate) struct BorrowOfMovedValue<'tcx> {
793+
pub(crate) struct BorrowOfMovedValue {
794794
#[primary_span]
795795
#[label]
796796
#[label(mir_build_occurs_because_label)]
797797
pub(crate) binding_span: Span,
798798
#[label(mir_build_value_borrowed_label)]
799799
pub(crate) conflicts_ref: Vec<Span>,
800800
pub(crate) name: Symbol,
801-
pub(crate) ty: Ty<'tcx>,
801+
pub(crate) ty: String,
802802
#[suggestion(code = "ref ", applicability = "machine-applicable")]
803803
pub(crate) suggest_borrowing: Option<Span>,
804+
#[note(mir_build_full_type_name)]
805+
#[note(mir_build_consider_verbose)]
806+
pub(crate) has_path: bool,
807+
pub(crate) path: String,
804808
}
805809

806810
#[derive(Diagnostic)]

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

+4
Original file line numberDiff line numberDiff line change
@@ -795,12 +795,16 @@ fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, 'tcx>, pat:
795795
}
796796
});
797797
if !conflicts_ref.is_empty() {
798+
let mut path = None;
799+
let ty = cx.tcx.short_ty_string(ty, &mut path);
798800
sess.dcx().emit_err(BorrowOfMovedValue {
799801
binding_span: pat.span,
800802
conflicts_ref,
801803
name,
802804
ty,
803805
suggest_borrowing: Some(pat.span.shrink_to_lo()),
806+
has_path: path.is_some(),
807+
path: path.map(|p| p.display().to_string()).unwrap_or_default(),
804808
});
805809
}
806810
return;

library/core/src/fmt/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ pub enum DebugAsHex {
288288
///
289289
/// `FormattingOptions` is a [`Formatter`] without an attached [`Write`] trait.
290290
/// It is mainly used to construct `Formatter` instances.
291-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
291+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
292292
#[unstable(feature = "formatting_options", issue = "118117")]
293293
pub struct FormattingOptions {
294294
flags: u32,
@@ -508,6 +508,15 @@ impl FormattingOptions {
508508
}
509509
}
510510

511+
#[unstable(feature = "formatting_options", issue = "118117")]
512+
impl Default for FormattingOptions {
513+
/// Same as [`FormattingOptions::new()`].
514+
fn default() -> Self {
515+
// The `#[derive(Default)]` implementation would set `fill` to `\0` instead of space.
516+
Self::new()
517+
}
518+
}
519+
511520
/// Configuration for formatting.
512521
///
513522
/// A `Formatter` represents various options related to formatting. Users do not

library/core/tests/fmt/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ fn test_maybe_uninit_short() {
5151
assert_eq!(format!("{x:?}"), "MaybeUninit<u32>");
5252
}
5353

54+
#[test]
55+
fn formatting_options_ctor() {
56+
use core::fmt::FormattingOptions;
57+
assert_eq!(FormattingOptions::new(), FormattingOptions::default());
58+
}
59+
5460
#[test]
5561
fn formatting_options_flags() {
5662
use core::fmt::*;

library/std/src/sys/pal/unix/thread.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ impl Thread {
130130
}
131131
}
132132

133-
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly"))]
133+
#[cfg(any(
134+
target_os = "linux",
135+
target_os = "freebsd",
136+
target_os = "dragonfly",
137+
target_os = "nuttx"
138+
))]
134139
pub fn set_name(name: &CStr) {
135140
unsafe {
136141
cfg_if::cfg_if! {
@@ -139,7 +144,7 @@ impl Thread {
139144
const TASK_COMM_LEN: usize = 16;
140145
let name = truncate_cstr::<{ TASK_COMM_LEN }>(name);
141146
} else {
142-
// FreeBSD and DragonFly BSD do not enforce length limits.
147+
// FreeBSD, DragonFly, FreeBSD and NuttX do not enforce length limits.
143148
}
144149
};
145150
// Available since glibc 2.12, musl 1.1.16, and uClibc 1.0.20 for Linux,
@@ -150,7 +155,7 @@ impl Thread {
150155
}
151156
}
152157

153-
#[cfg(any(target_os = "openbsd", target_os = "nuttx"))]
158+
#[cfg(target_os = "openbsd")]
154159
pub fn set_name(name: &CStr) {
155160
unsafe {
156161
libc::pthread_set_name_np(libc::pthread_self(), name.as_ptr());

src/bootstrap/bootstrap.py

-3
Original file line numberDiff line numberDiff line change
@@ -1310,9 +1310,6 @@ def bootstrap(args):
13101310
args = [build.bootstrap_binary()]
13111311
args.extend(sys.argv[1:])
13121312
env = os.environ.copy()
1313-
# The Python process ID is used when creating a Windows job object
1314-
# (see src\bootstrap\src\utils\job.rs)
1315-
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
13161313
env["BOOTSTRAP_PYTHON"] = sys.executable
13171314
run(args, env=env, verbose=build.verbose, is_bootstrap=True)
13181315

src/bootstrap/src/bin/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ fn main() {
5757
}
5858
err => {
5959
drop(err);
60-
if let Ok(pid) = pid {
60+
// #135972: We can reach this point when the lock has been taken,
61+
// but the locker has not yet written its PID to the file
62+
if let Some(pid) = pid.ok().filter(|pid| !pid.is_empty()) {
6163
println!("WARNING: build directory locked by process {pid}, waiting for lock");
6264
} else {
6365
println!("WARNING: build directory locked, waiting for lock");

0 commit comments

Comments
 (0)