Skip to content

Commit f940188

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

File tree

34 files changed

+274
-126
lines changed

34 files changed

+274
-126
lines changed

compiler/rustc_borrowck/messages.ftl

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

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

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

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

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

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

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

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

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

Lines changed: 6 additions & 2 deletions
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)]

0 commit comments

Comments
 (0)