Skip to content

Commit 38ed36b

Browse files
committed
hir: Preserve used syntax in TyKind::TraitObject
1 parent dac96d4 commit 38ed36b

File tree

15 files changed

+23
-17
lines changed

15 files changed

+23
-17
lines changed

compiler/rustc_ast/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,7 @@ impl TyKind {
19641964
}
19651965

19661966
/// Syntax used to declare a trait object.
1967-
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)]
1967+
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
19681968
pub enum TraitObjectSyntax {
19691969
Dyn,
19701970
None,

compiler/rustc_ast_lowering/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13961396
if kind != TraitObjectSyntax::Dyn {
13971397
self.maybe_lint_bare_trait(t.span, t.id, false);
13981398
}
1399-
hir::TyKind::TraitObject(bounds, lifetime_bound)
1399+
hir::TyKind::TraitObject(bounds, lifetime_bound, kind)
14001400
}
14011401
TyKind::ImplTrait(def_node_id, ref bounds) => {
14021402
let span = t.span;
@@ -2648,6 +2648,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26482648
hir::TyKind::TraitObject(
26492649
arena_vec![self; principal],
26502650
self.elided_dyn_bound(span),
2651+
TraitObjectSyntax::None,
26512652
)
26522653
}
26532654
_ => hir::TyKind::Path(hir::QPath::Resolved(None, path)),

compiler/rustc_hir/src/hir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{itemlikevisit, LangItem};
66

77
use rustc_ast::util::parser::ExprPrecedence;
88
use rustc_ast::{self as ast, CrateSugar, LlvmAsmDialect};
9-
use rustc_ast::{Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy};
9+
use rustc_ast::{Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, TraitObjectSyntax, UintTy};
1010
pub use rustc_ast::{BorrowKind, ImplPolarity, IsAuto};
1111
pub use rustc_ast::{CaptureBy, Movability, Mutability};
1212
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
@@ -2327,7 +2327,7 @@ pub enum TyKind<'hir> {
23272327
OpaqueDef(ItemId, &'hir [GenericArg<'hir>]),
23282328
/// A trait object type `Bound1 + Bound2 + Bound3`
23292329
/// where `Bound` is a trait or a lifetime.
2330-
TraitObject(&'hir [PolyTraitRef<'hir>], Lifetime),
2330+
TraitObject(&'hir [PolyTraitRef<'hir>], Lifetime, TraitObjectSyntax),
23312331
/// Unused for now.
23322332
Typeof(AnonConst),
23332333
/// `TyKind::Infer` means the type should be inferred instead of it having been

compiler/rustc_hir/src/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
709709
visitor.visit_ty(ty);
710710
visitor.visit_anon_const(length)
711711
}
712-
TyKind::TraitObject(bounds, ref lifetime) => {
712+
TyKind::TraitObject(bounds, ref lifetime, _syntax) => {
713713
for bound in bounds {
714714
visitor.visit_poly_trait_ref(bound, TraitBoundModifier::None);
715715
}

compiler/rustc_hir_pretty/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,10 @@ impl<'a> State<'a> {
410410
}
411411
hir::TyKind::OpaqueDef(..) => self.s.word("/*impl Trait*/"),
412412
hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false),
413-
hir::TyKind::TraitObject(bounds, ref lifetime) => {
413+
hir::TyKind::TraitObject(bounds, ref lifetime, syntax) => {
414+
if syntax == ast::TraitObjectSyntax::Dyn {
415+
self.word_space("dyn");
416+
}
414417
let mut first = true;
415418
for bound in bounds {
416419
if first {

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
9999
return;
100100
}
101101

102-
hir::TyKind::TraitObject(bounds, _) => {
102+
hir::TyKind::TraitObject(bounds, ..) => {
103103
for bound in bounds {
104104
self.current_index.shift_in(1);
105105
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
292292
);
293293
}
294294
}
295-
TyKind::TraitObject(_, lt) => match lt.name {
295+
TyKind::TraitObject(_, lt, _) => match lt.name {
296296
LifetimeName::ImplicitObjectLifetimeDefault => {
297297
err.span_suggestion_verbose(
298298
fn_return.span.shrink_to_hi(),
@@ -498,6 +498,7 @@ impl<'tcx> Visitor<'tcx> for HirTraitObjectVisitor {
498498
if let TyKind::TraitObject(
499499
poly_trait_refs,
500500
Lifetime { name: LifetimeName::ImplicitObjectLifetimeDefault, .. },
501+
_,
501502
) = t.kind
502503
{
503504
for ptr in poly_trait_refs {

compiler/rustc_middle/src/ty/diagnostics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ impl<'v> hir::intravisit::Visitor<'v> for TraitObjectVisitor<'v> {
314314
hir::LifetimeName::ImplicitObjectLifetimeDefault | hir::LifetimeName::Static,
315315
..
316316
},
317+
_,
317318
) => {
318319
self.0.push(ty);
319320
}

compiler/rustc_resolve/src/late/lifetimes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
540540
self.missing_named_lifetime_spots.pop();
541541
self.is_in_fn_syntax = was_in_fn_syntax;
542542
}
543-
hir::TyKind::TraitObject(bounds, ref lifetime) => {
543+
hir::TyKind::TraitObject(bounds, ref lifetime, _) => {
544544
debug!("visit_ty: TraitObject(bounds={:?}, lifetime={:?})", bounds, lifetime);
545545
for bound in bounds {
546546
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
@@ -2299,7 +2299,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
22992299
self.outer_index.shift_in(1);
23002300
}
23012301
match ty.kind {
2302-
hir::TyKind::TraitObject(bounds, ref lifetime) => {
2302+
hir::TyKind::TraitObject(bounds, ref lifetime, _) => {
23032303
for bound in bounds {
23042304
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
23052305
}

compiler/rustc_typeck/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2201,7 +2201,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22012201
Some(ast_ty),
22022202
))
22032203
}
2204-
hir::TyKind::TraitObject(ref bounds, ref lifetime) => {
2204+
hir::TyKind::TraitObject(ref bounds, ref lifetime, _) => {
22052205
self.conv_object_ty_poly_trait_ref(ast_ty.span, bounds, lifetime, borrowed)
22062206
}
22072207
hir::TyKind::Path(hir::QPath::Resolved(ref maybe_qself, ref path)) => {

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ impl Clean<Type> for hir::Ty<'_> {
14771477
}
14781478
}
14791479
TyKind::Path(_) => clean_qpath(&self, cx),
1480-
TyKind::TraitObject(ref bounds, ref lifetime) => {
1480+
TyKind::TraitObject(ref bounds, ref lifetime, _) => {
14811481
match bounds[0].clean(cx).trait_ {
14821482
ResolvedPath { path, param_names: None, did, is_generic } => {
14831483
let mut bounds: Vec<self::GenericBound> = bounds[1..]

src/tools/clippy/clippy_lints/src/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
387387
self.nested_elision_site_lts.append(&mut sub_visitor.all_lts());
388388
return;
389389
},
390-
TyKind::TraitObject(bounds, ref lt) => {
390+
TyKind::TraitObject(bounds, ref lt, _) => {
391391
if !lt.is_elided() {
392392
self.unelided_trait_object_lifetime = true;
393393
}

src/tools/clippy/clippy_lints/src/types/borrowed_box.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
5050
// Originally reported as the issue #3128.
5151
let inner_snippet = snippet(cx, inner.span, "..");
5252
let suggestion = match &inner.kind {
53-
TyKind::TraitObject(bounds, lt_bound) if bounds.len() > 1 || !lt_bound.is_elided() => {
53+
TyKind::TraitObject(bounds, lt_bound, _) if bounds.len() > 1 || !lt_bound.is_elided() => {
5454
format!("&{}({})", ltopt, &inner_snippet)
5555
},
5656
TyKind::Path(qpath)
@@ -86,7 +86,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
8686
// Returns true if given type is `Any` trait.
8787
fn is_any_trait(t: &hir::Ty<'_>) -> bool {
8888
if_chain! {
89-
if let TyKind::TraitObject(ref traits, _) = t.kind;
89+
if let TyKind::TraitObject(ref traits, ..) = t.kind;
9090
if !traits.is_empty();
9191
// Only Send/Sync can be used as additional traits, so it is enough to
9292
// check only the first trait.

src/tools/clippy/clippy_lints/src/types/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
911911
// function types bring a lot of overhead
912912
TyKind::BareFn(ref bare) if bare.abi == Abi::Rust => (50 * self.nest, 1),
913913

914-
TyKind::TraitObject(ref param_bounds, _) => {
914+
TyKind::TraitObject(ref param_bounds, ..) => {
915915
let has_lifetime_parameters = param_bounds.iter().any(|bound| {
916916
bound
917917
.bound_generic_params

src/tools/clippy/clippy_utils/src/hir_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
892892
TyKind::OpaqueDef(_, arg_list) => {
893893
self.hash_generic_args(arg_list);
894894
},
895-
TyKind::TraitObject(_, lifetime) => {
895+
TyKind::TraitObject(_, lifetime, _) => {
896896
self.hash_lifetime(lifetime);
897897
},
898898
TyKind::Typeof(anon_const) => {

0 commit comments

Comments
 (0)