Skip to content

Commit ca5c68a

Browse files
committedDec 15, 2023
Auto merge of #119002 - workingjubilee:rollup-dbfet7s, r=workingjubilee
Rollup of 5 pull requests Successful merges: - #118396 (Collect lang items from AST, get rid of `GenericBound::LangItemTrait`) - #118727 (Don't pass lint back out of lint decorator) - #118956 (Make CStr documentation consistent ("nul" instead of "null")) - #118981 (Remove an unneeded allocation) - #118998 (Link to is_benchmark from the Ipv6Addr::is_global documentation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a96d57b + 4b447b8 commit ca5c68a

File tree

70 files changed

+559
-567
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+559
-567
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,6 +2845,28 @@ impl Item {
28452845
pub fn span_with_attributes(&self) -> Span {
28462846
self.attrs.iter().fold(self.span, |acc, attr| acc.to(attr.span))
28472847
}
2848+
2849+
pub fn opt_generics(&self) -> Option<&Generics> {
2850+
match &self.kind {
2851+
ItemKind::ExternCrate(_)
2852+
| ItemKind::Use(_)
2853+
| ItemKind::Mod(_, _)
2854+
| ItemKind::ForeignMod(_)
2855+
| ItemKind::GlobalAsm(_)
2856+
| ItemKind::MacCall(_)
2857+
| ItemKind::MacroDef(_) => None,
2858+
ItemKind::Static(_) => None,
2859+
ItemKind::Const(i) => Some(&i.generics),
2860+
ItemKind::Fn(i) => Some(&i.generics),
2861+
ItemKind::TyAlias(i) => Some(&i.generics),
2862+
ItemKind::TraitAlias(generics, _)
2863+
| ItemKind::Enum(_, generics)
2864+
| ItemKind::Struct(_, generics)
2865+
| ItemKind::Union(_, generics) => Some(&generics),
2866+
ItemKind::Trait(i) => Some(&i.generics),
2867+
ItemKind::Impl(i) => Some(&i.generics),
2868+
}
2869+
}
28482870
}
28492871

28502872
/// `extern` qualifier on a function item or function type.

‎compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
453453
tcx.ensure_with_value().output_filenames(());
454454
tcx.ensure_with_value().early_lint_checks(());
455455
tcx.ensure_with_value().debugger_visualizers(LOCAL_CRATE);
456+
tcx.ensure_with_value().get_lang_items(());
456457
let (mut resolver, krate) = tcx.resolver_for_lowering(()).steal();
457458

458459
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);
@@ -765,6 +766,28 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
765766
self.resolver.get_import_res(id).present_items()
766767
}
767768

769+
fn make_lang_item_path(
770+
&mut self,
771+
lang_item: hir::LangItem,
772+
span: Span,
773+
args: Option<&'hir hir::GenericArgs<'hir>>,
774+
) -> &'hir hir::Path<'hir> {
775+
let def_id = self.tcx.require_lang_item(lang_item, Some(span));
776+
let def_kind = self.tcx.def_kind(def_id);
777+
let res = Res::Def(def_kind, def_id);
778+
self.arena.alloc(hir::Path {
779+
span,
780+
res,
781+
segments: self.arena.alloc_from_iter([hir::PathSegment {
782+
ident: Ident::new(lang_item.name(), span),
783+
hir_id: self.next_id(),
784+
res,
785+
args,
786+
infer_args: false,
787+
}]),
788+
})
789+
}
790+
768791
/// Reuses the span but adds information like the kind of the desugaring and features that are
769792
/// allowed inside this span.
770793
fn mark_span_with_reason(
@@ -1976,18 +1999,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19761999
CoroutineKind::AsyncGen { .. } => (sym::Item, hir::LangItem::AsyncIterator),
19772000
};
19782001

1979-
let future_args = self.arena.alloc(hir::GenericArgs {
2002+
let bound_args = self.arena.alloc(hir::GenericArgs {
19802003
args: &[],
19812004
bindings: arena_vec![self; self.assoc_ty_binding(assoc_ty_name, opaque_ty_span, output_ty)],
19822005
parenthesized: hir::GenericArgsParentheses::No,
19832006
span_ext: DUMMY_SP,
19842007
});
19852008

1986-
hir::GenericBound::LangItemTrait(
1987-
trait_lang_item,
1988-
opaque_ty_span,
1989-
self.next_id(),
1990-
future_args,
2009+
hir::GenericBound::Trait(
2010+
hir::PolyTraitRef {
2011+
bound_generic_params: &[],
2012+
trait_ref: hir::TraitRef {
2013+
path: self.make_lang_item_path(
2014+
trait_lang_item,
2015+
opaque_ty_span,
2016+
Some(bound_args),
2017+
),
2018+
hir_ref_id: self.next_id(),
2019+
},
2020+
span: opaque_ty_span,
2021+
},
2022+
hir::TraitBoundModifier::None,
19912023
)
19922024
}
19932025

0 commit comments

Comments
 (0)