Skip to content

Commit 7f9d9de

Browse files
authored
Rollup merge of rust-lang#108162 - clubby789:issue-108155, r=Nilstrieb
Don't eagerly convert principal to string Fixes rust-lang#108155 ~~I haven't yet been able to reproduce the ICE in a minimal example unfortunately.~~ Added a test
2 parents d9c9040 + eebd31c commit 7f9d9de

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

compiler/rustc_lint/src/deref_into_dyn_supertrait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait {
7878
});
7979
cx.emit_spanned_lint(DEREF_INTO_DYN_SUPERTRAIT, cx.tcx.def_span(item.owner_id.def_id), SupertraitAsDerefTarget {
8080
t,
81-
target_principal: target_principal.to_string(),
81+
target_principal,
8282
label,
8383
});
8484
}

compiler/rustc_lint/src/lints.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_errors::{
88
};
99
use rustc_hir::def_id::DefId;
1010
use rustc_macros::{LintDiagnostic, Subdiagnostic};
11-
use rustc_middle::ty::{Predicate, Ty, TyCtxt};
11+
use rustc_middle::ty::{PolyExistentialTraitRef, Predicate, Ty, TyCtxt};
1212
use rustc_session::parse::ParseSess;
1313
use rustc_span::{edition::Edition, sym, symbol::Ident, Span, Symbol};
1414

@@ -556,8 +556,7 @@ pub struct BuiltinUnexpectedCliConfigValue {
556556
#[diag(lint_supertrait_as_deref_target)]
557557
pub struct SupertraitAsDerefTarget<'a> {
558558
pub t: Ty<'a>,
559-
pub target_principal: String,
560-
// pub target_principal: Binder<'a, ExistentialTraitRef<'b>>,
559+
pub target_principal: PolyExistentialTraitRef<'a>,
561560
#[subdiagnostic]
562561
pub label: Option<SupertraitAsDerefTargetLabel>,
563562
}

compiler/rustc_middle/src/ty/sty.rs

+6
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,12 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
933933
}
934934
}
935935

936+
impl rustc_errors::IntoDiagnosticArg for PolyExistentialTraitRef<'_> {
937+
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
938+
self.to_string().into_diagnostic_arg()
939+
}
940+
}
941+
936942
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
937943
#[derive(HashStable)]
938944
pub enum BoundVariableKind {

tests/ui/lint/issue-108155.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// check-pass
2+
// check that `deref_into_dyn_supertrait` doesn't cause ICE by eagerly converting
3+
// a cancelled lint
4+
5+
#![allow(deref_into_dyn_supertrait)]
6+
7+
trait Trait {}
8+
impl std::ops::Deref for dyn Trait + Send + Sync {
9+
type Target = dyn Trait;
10+
fn deref(&self) -> &Self::Target {
11+
self
12+
}
13+
}
14+
15+
fn main() {}

0 commit comments

Comments
 (0)