From 9835e2ae736235810b4ea1c162ca5e65c547e770 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:50 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- .../rustc_hir_analysis/src/coherence/orphan.rs | 29 ++++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'compiler/rustc_hir_analysis/src/coherence/orphan.rs') diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 47c47de8c..23beacd2a 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -6,7 +6,7 @@ use rustc_errors::{struct_span_err, DelayDm}; use rustc_errors::{Diagnostic, ErrorGuaranteed}; use rustc_hir as hir; use rustc_middle::ty::subst::InternalSubsts; -use rustc_middle::ty::util::IgnoreRegions; +use rustc_middle::ty::util::CheckRegions; use rustc_middle::ty::{ self, AliasKind, ImplPolarity, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, @@ -210,6 +210,19 @@ fn do_orphan_check_impl<'tcx>( NonlocalImpl::DisallowOther, ), + // ``` + // struct S(T); + // impl S { + // type This = T; + // } + // impl AutoTrait for S::This {} + // ``` + // FIXME(inherent_associated_types): The example code above currently leads to a cycle + ty::Alias(AliasKind::Inherent, _) => ( + LocalImpl::Disallow { problematic_kind: "associated type" }, + NonlocalImpl::DisallowOther, + ), + // type Opaque = impl Trait; // impl AutoTrait for Opaque {} ty::Alias(AliasKind::Opaque, _) => ( @@ -372,10 +385,10 @@ fn emit_orphan_check_error<'tcx>( if is_target_ty { // Point at `D` in `impl for C in D` - err.span_label(self_ty_span, &msg); + err.span_label(self_ty_span, msg); } else { // Point at `C` in `impl for C in D` - err.span_label(trait_span, &msg); + err.span_label(trait_span, msg); } } err.note("define and implement a trait or new type instead"); @@ -457,7 +470,7 @@ fn emit_newtype_suggestion_for_raw_ptr( ptr_ty: &ty::TypeAndMut<'_>, diag: &mut Diagnostic, ) { - if !self_ty.needs_subst() { + if !self_ty.has_param() { let mut_key = ptr_ty.mutbl.prefix_str(); let msg_sugg = "consider introducing a new wrapper type".to_owned(); let sugg = vec![ @@ -494,7 +507,7 @@ fn lint_auto_trait_impl<'tcx>( // Impls which completely cover a given root type are fine as they // disable auto impls entirely. So only lint if the substs // are not a permutation of the identity substs. - let Err(arg) = tcx.uses_unique_generic_params(substs, IgnoreRegions::Yes) else { + let Err(arg) = tcx.uses_unique_generic_params(substs, CheckRegions::No) else { // ok return; }; @@ -531,15 +544,15 @@ fn lint_auto_trait_impl<'tcx>( let self_descr = tcx.def_descr(self_type_did); match arg { ty::util::NotUniqueParam::DuplicateParam(arg) => { - lint.note(&format!("`{}` is mentioned multiple times", arg)); + lint.note(format!("`{}` is mentioned multiple times", arg)); } ty::util::NotUniqueParam::NotParam(arg) => { - lint.note(&format!("`{}` is not a generic parameter", arg)); + lint.note(format!("`{}` is not a generic parameter", arg)); } } lint.span_note( item_span, - &format!( + format!( "try using the same sequence of generic parameters as the {} definition", self_descr, ), -- cgit v1.2.3