diff options
| author | bors <bors@rust-lang.org> | 2025-01-25 08:56:41 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-01-25 08:56:41 +0000 | 
| commit | f94018810c6c0f59df013c9c418e994b94cf1805 (patch) | |
| tree | a9bba926836b86bd7bd0df4b7cc94e08e8a7bda4 /compiler | |
| parent | 6365178a6bee1ccf2a4960ecc9285c245e8978a9 (diff) | |
| parent | a330c7ee858a03dacaf10a7f88abb38eb4f1858a (diff) | |
| download | rust-f94018810c6c0f59df013c9c418e994b94cf1805.tar.gz rust-f94018810c6c0f59df013c9c418e994b94cf1805.zip  | |
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
Diffstat (limited to 'compiler')
11 files changed, 72 insertions, 23 deletions
diff --git a/compiler/rustc_borrowck/messages.ftl b/compiler/rustc_borrowck/messages.ftl index ada20e5c614..c00e6dde919 100644 --- a/compiler/rustc_borrowck/messages.ftl +++ b/compiler/rustc_borrowck/messages.ftl @@ -92,6 +92,9 @@ borrowck_lifetime_constraints_error = borrowck_limitations_implies_static = due to current limitations in the borrow checker, this implies a `'static` lifetime +borrowck_long_type_consider_verbose = consider using `--verbose` to print the full type name to the console +borrowck_long_type_full_path = the full type name has been written to '{$path}' + borrowck_move_closure_suggestion = consider adding 'move' keyword before the nested closure diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index d020244bf55..07dcbba019a 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -289,6 +289,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { None => "value".to_owned(), }; if needs_note { + let mut path = None; + let ty = self.infcx.tcx.short_ty_string(ty, &mut path); if let Some(local) = place.as_local() { let span = self.body.local_decls[local].source_info.span; err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label { @@ -304,6 +306,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { place: ¬e_msg, }); }; + if let Some(path) = path { + err.subdiagnostic(crate::session_diagnostics::LongTypePath { + path: path.display().to_string(), + }); + } } if let UseSpans::FnSelfUse { diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index beacbdbd3fa..14a900f38e9 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -596,12 +596,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { self.suggest_cloning(err, place_ty, expr, None); } + let mut path = None; + let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path); err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label { is_partial_move: false, - ty: place_ty, + ty, place: &place_desc, span, }); + if let Some(path) = path { + err.subdiagnostic(crate::session_diagnostics::LongTypePath { + path: path.display().to_string(), + }); + } } else { binds_to.sort(); binds_to.dedup(); @@ -628,12 +635,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { self.suggest_cloning(err, place_ty, expr, Some(use_spans)); } + let mut path = None; + let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path); err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label { is_partial_move: false, - ty: place_ty, + ty, place: &place_desc, span: use_span, }); + if let Some(path) = path { + err.subdiagnostic(crate::session_diagnostics::LongTypePath { + path: path.display().to_string(), + }); + } use_spans.args_subdiag(err, |args_span| { crate::session_diagnostics::CaptureArgLabel::MoveOutPlace { @@ -831,12 +845,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { self.suggest_cloning(err, bind_to.ty, expr, None); } + let mut path = None; + let ty = self.infcx.tcx.short_ty_string(bind_to.ty, &mut path); err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label { is_partial_move: false, - ty: bind_to.ty, + ty, place: place_desc, span: binding_span, }); + if let Some(path) = path { + err.subdiagnostic(crate::session_diagnostics::LongTypePath { + path: path.display().to_string(), + }); + } } } diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index 4be5d0dbf42..2c37d2bc123 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -459,17 +459,24 @@ pub(crate) enum OnClosureNote<'a> { } #[derive(Subdiagnostic)] -pub(crate) enum TypeNoCopy<'a, 'tcx> { +#[note(borrowck_long_type_full_path)] +#[note(borrowck_long_type_consider_verbose)] +pub(crate) struct LongTypePath { + pub(crate) path: String, +} + +#[derive(Subdiagnostic)] +pub(crate) enum TypeNoCopy<'a> { #[label(borrowck_ty_no_impl_copy)] Label { is_partial_move: bool, - ty: Ty<'tcx>, + ty: String, place: &'a str, #[primary_span] span: Span, }, #[note(borrowck_ty_no_impl_copy)] - Note { is_partial_move: bool, ty: Ty<'tcx>, place: &'a str }, + Note { is_partial_move: bool, ty: String, place: &'a str }, } #[derive(Diagnostic)] diff --git a/compiler/rustc_error_codes/src/error_codes/E0393.md b/compiler/rustc_error_codes/src/error_codes/E0393.md index 50225b25163..c7260815905 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0393.md +++ b/compiler/rustc_error_codes/src/error_codes/E0393.md @@ -3,12 +3,10 @@ A type parameter which references `Self` in its default value was not specified. Erroneous code example: ```compile_fail,E0393 -trait A<T=Self> {} +trait A<T = Self> {} -fn together_we_will_rule_the_galaxy(son: &A) {} -// error: the type parameter `T` must be explicitly specified in an -// object type because its default value `Self` references the -// type `Self` +fn together_we_will_rule_the_galaxy(son: &dyn A) {} +// error: the type parameter `T` must be explicitly specified ``` 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 defaulted parameter will fix this issue. Fixed example: ``` -trait A<T=Self> {} +trait A<T = Self> {} -fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok! +fn together_we_will_rule_the_galaxy(son: &dyn A<i32>) {} // Ok! ``` diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index 512d379687b..be4004f5904 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -353,7 +353,13 @@ hir_analysis_missing_type_params = [one] reference *[other] references } to {$parameters} - .note = because of the default `Self` reference, type parameters must be specified on object types + .note = because the parameter {$parameterCount -> + [one] default references + *[other] defaults reference + } `Self`, the {$parameterCount -> + [one] parameter + *[other] parameters + } must be specified on the object type hir_analysis_multiple_relaxed_default_bounds = type parameter has more than one relaxed default bound, only one is supported diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs index 72ad190df7e..e59ff02642c 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs @@ -237,16 +237,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { // Skip `Self` .skip(1) .map(|(index, arg)| { - if arg == dummy_self.into() { + if arg.walk().any(|arg| arg == dummy_self.into()) { let param = &generics.own_params[index]; missing_type_params.push(param.name); Ty::new_misc_error(tcx).into() - } else if arg.walk().any(|arg| arg == dummy_self.into()) { - let guar = self.dcx().span_delayed_bug( - span, - "trait object trait bounds reference `Self`", - ); - replace_dummy_self_with_error(tcx, arg, guar) } else { arg } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 16294970f05..928010c03c2 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -185,6 +185,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { rhs_ty: Ty<'tcx>, can_satisfy: impl FnOnce(Ty<'tcx>, Ty<'tcx>) -> bool, ) -> bool { + if lhs_expr.span.in_derive_expansion() || rhs_expr.span.in_derive_expansion() { + return false; + } let Some((_, lhs_output_ty, lhs_inputs)) = self.extract_callable_info(lhs_ty) else { return false; }; diff --git a/compiler/rustc_mir_build/messages.ftl b/compiler/rustc_mir_build/messages.ftl index ffdb721fb18..053775b4937 100644 --- a/compiler/rustc_mir_build/messages.ftl +++ b/compiler/rustc_mir_build/messages.ftl @@ -25,6 +25,8 @@ mir_build_borrow_of_moved_value = borrow of moved value .occurs_because_label = move occurs because `{$name}` has type `{$ty}`, which does not implement the `Copy` trait .value_borrowed_label = value borrowed here after move .suggestion = borrow this binding in the pattern to avoid moving the value + .full_type_name = the full type name has been written to '{$path}' + .consider_verbose = consider using `--verbose` to print the full type name to the console mir_build_call_to_deprecated_safe_fn_requires_unsafe = call to deprecated safe function `{$function}` is unsafe and requires unsafe block diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index 83aec9ccdef..c3bf5868eec 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -790,7 +790,7 @@ pub(crate) struct IrrefutableLetPatternsWhileLet { #[derive(Diagnostic)] #[diag(mir_build_borrow_of_moved_value)] -pub(crate) struct BorrowOfMovedValue<'tcx> { +pub(crate) struct BorrowOfMovedValue { #[primary_span] #[label] #[label(mir_build_occurs_because_label)] @@ -798,9 +798,13 @@ pub(crate) struct BorrowOfMovedValue<'tcx> { #[label(mir_build_value_borrowed_label)] pub(crate) conflicts_ref: Vec<Span>, pub(crate) name: Symbol, - pub(crate) ty: Ty<'tcx>, + pub(crate) ty: String, #[suggestion(code = "ref ", applicability = "machine-applicable")] pub(crate) suggest_borrowing: Option<Span>, + #[note(mir_build_full_type_name)] + #[note(mir_build_consider_verbose)] + pub(crate) has_path: bool, + pub(crate) path: String, } #[derive(Diagnostic)] diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index b5b7b54a1cc..d8b04398d9a 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -795,12 +795,16 @@ fn check_borrow_conflicts_in_at_patterns<'tcx>(cx: &MatchVisitor<'_, 'tcx>, pat: } }); if !conflicts_ref.is_empty() { + let mut path = None; + let ty = cx.tcx.short_ty_string(ty, &mut path); sess.dcx().emit_err(BorrowOfMovedValue { binding_span: pat.span, conflicts_ref, name, ty, suggest_borrowing: Some(pat.span.shrink_to_lo()), + has_path: path.is_some(), + path: path.map(|p| p.display().to_string()).unwrap_or_default(), }); } return;  | 
