diff options
| author | bors <bors@rust-lang.org> | 2025-02-25 15:23:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-02-25 15:23:37 +0000 |
| commit | 4ecd70ddd1039a3954056c1071e40278048476fa (patch) | |
| tree | f518ec6154dbe5cae2fb80011d47714c437b63c1 /compiler/rustc_hir_analysis/src/check | |
| parent | c51b9b6d5234aa8e50c3b87784113a1af1af47cb (diff) | |
| parent | fb9ae4c018c08ff75fe2f8f4f3832a4995bfd375 (diff) | |
| download | rust-4ecd70ddd1039a3954056c1071e40278048476fa.tar.gz rust-4ecd70ddd1039a3954056c1071e40278048476fa.zip | |
Auto merge of #137611 - fmease:rollup-ln673ux, r=fmease
Rollup of 6 pull requests Successful merges: - #135480 (Don't require method impls for methods with `Self:Sized` bounds for impls for unsized types) - #137360 (Use `as_chunks` in `analyze_source_file_sse2`) - #137460 (downgrade bootstrap `cc`) - #137515 (Update `compiler-builtins` to 0.1.148) - #137522 (use stage 2 on cargo and clippy tests when possible) - #137597 (Revert accidental cargo submodule update) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_hir_analysis/src/check')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/check.rs | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 09320b86878..f2331f3fd8e 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -992,6 +992,32 @@ fn check_impl_items_against_trait<'tcx>( let trait_def = tcx.trait_def(trait_ref.def_id); + let infcx = tcx.infer_ctxt().ignoring_regions().build(TypingMode::non_body_analysis()); + + let ocx = ObligationCtxt::new_with_diagnostics(&infcx); + let cause = ObligationCause::misc(tcx.def_span(impl_id), impl_id); + let param_env = tcx.param_env(impl_id); + + let self_is_guaranteed_unsized = match tcx + .struct_tail_raw( + trait_ref.self_ty(), + |ty| { + ocx.structurally_normalize_ty(&cause, param_env, ty).unwrap_or_else(|_| { + Ty::new_error_with_message( + tcx, + tcx.def_span(impl_id), + "struct tail should be computable", + ) + }) + }, + || (), + ) + .kind() + { + ty::Dynamic(_, _, ty::DynKind::Dyn) | ty::Slice(_) | ty::Str => true, + _ => false, + }; + for &impl_item in impl_item_refs { let ty_impl_item = tcx.associated_item(impl_item); let ty_trait_item = if let Some(trait_item_id) = ty_impl_item.trait_item_def_id { @@ -1021,6 +1047,15 @@ fn check_impl_items_against_trait<'tcx>( } } + if self_is_guaranteed_unsized && tcx.generics_require_sized_self(ty_trait_item.def_id) { + tcx.emit_node_span_lint( + rustc_lint_defs::builtin::DEAD_CODE, + tcx.local_def_id_to_hir_id(ty_impl_item.def_id.expect_local()), + tcx.def_span(ty_impl_item.def_id), + errors::UselessImplItem, + ) + } + check_specialization_validity( tcx, trait_def, @@ -1044,7 +1079,11 @@ fn check_impl_items_against_trait<'tcx>( .as_ref() .is_some_and(|node_item| node_item.item.defaultness(tcx).has_value()); - if !is_implemented && tcx.defaultness(impl_id).is_final() { + if !is_implemented + && tcx.defaultness(impl_id).is_final() + // unsized types don't need to implement methods that have `Self: Sized` bounds. + && !(self_is_guaranteed_unsized && tcx.generics_require_sized_self(trait_item_id)) + { missing_items.push(tcx.associated_item(trait_item_id)); } |
