Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ac63d4a

Browse files
Don't fill non-ty args with ty::Error
1 parent a948229 commit ac63d4a

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs‎

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use rustc_hir as hir;
77
use rustc_hir::def::{DefKind, Res};
88
use rustc_hir::def_id::DefId;
99
use rustc_lint_defs::builtin::UNUSED_ASSOCIATED_TYPE_BOUNDS;
10-
use rustc_middle::ty::{self, Ty};
10+
use rustc_middle::ty::fold::BottomUpFolder;
11+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
1112
use rustc_middle::ty::{DynKind, ToPredicate};
12-
use rustc_span::Span;
13+
use rustc_span::{ErrorGuaranteed,Span};
1314
use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
1415
use rustc_trait_selection::traits::{self, hir_ty_lowering_object_safety_violations};
1516

@@ -267,12 +268,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
267268
if arg == dummy_self.into() {
268269
let param = &generics.params[index];
269270
missing_type_params.push(param.name);
270-
returnTy::new_misc_error(tcx).into();
271+
Ty::new_misc_error(tcx).into()
271272
} else if arg.walk().any(|arg| arg == dummy_self.into()) {
272273
references_self = true;
273-
return Ty::new_misc_error(tcx).into();
274+
let guar = tcx.dcx().span_delayed_bug(
275+
span,
276+
"trait object trait bounds reference `Self`",
277+
);
278+
replace_dummy_self_with_error(tcx, arg, guar)
279+
} else {
280+
arg
274281
}
275-
arg
276282
})
277283
.collect();
278284
let args = tcx.mk_args(&args);
@@ -327,18 +333,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
327333
let guar = tcx
328334
.dcx()
329335
.span_delayed_bug(span, "trait object projection bounds reference `Self`");
330-
let args: Vec<_> = b
331-
.projection_ty
332-
.args
333-
.iter()
334-
.map(|arg| {
335-
if arg.walk().any(|arg| arg == dummy_self.into()) {
336-
return Ty::new_error(tcx, guar).into();
337-
}
338-
arg
339-
})
340-
.collect();
341-
b.projection_ty.args = tcx.mk_args(&args);
336+
b.projection_ty = replace_dummy_self_with_error(tcx, b.projection_ty, guar);
342337
}
343338

344339
ty::ExistentialProjection::erase_self_ty(tcx, b)
@@ -396,3 +391,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
396391
Ty::new_dynamic(tcx, existential_predicates, region_bound, representation)
397392
}
398393
}
394+
395+
fn replace_dummy_self_with_error<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
396+
tcx: TyCtxt<'tcx>,
397+
t: T,
398+
guar: ErrorGuaranteed,
399+
) -> T {
400+
t.fold_with(&mut BottomUpFolder {
401+
tcx,
402+
ty_op: |ty| {
403+
if ty == tcx.types.trait_object_dummy_self { Ty::new_error(tcx, guar) } else { ty }
404+
},
405+
lt_op: |lt| lt,
406+
ct_op: |ct| ct,
407+
})
408+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /