Skip to content

Commit e7bd402

Browse files
authoredDec 26, 2023
Rollup merge of #119240 - compiler-errors:lang-item-more, r=petrochenkov
Make some non-diagnostic-affecting `QPath::LangItem` into regular `QPath`s The rest of 'em affect diagnostics, so leave them alone... for now. cc #115178
2 parents 50e380c + 7e00e97 commit e7bd402

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed
 

‎compiler/rustc_ast_lowering/src/expr.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
638638
self.lower_span(span),
639639
Some(self.allow_gen_future.clone()),
640640
);
641-
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span);
641+
let resume_ty = self.make_lang_item_qpath(hir::LangItem::ResumeTy, unstable_span);
642642
let input_ty = hir::Ty {
643643
hir_id: self.next_id(),
644644
kind: hir::TyKind::Path(resume_ty),
@@ -774,7 +774,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
774774
self.lower_span(span),
775775
Some(self.allow_gen_future.clone()),
776776
);
777-
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span);
777+
let resume_ty = self.make_lang_item_qpath(hir::LangItem::ResumeTy, unstable_span);
778778
let input_ty = hir::Ty {
779779
hir_id: self.next_id(),
780780
kind: hir::TyKind::Path(resume_ty),
@@ -2126,11 +2126,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
21262126
lang_item: hir::LangItem,
21272127
name: Symbol,
21282128
) -> hir::Expr<'hir> {
2129+
let qpath = self.make_lang_item_qpath(lang_item, self.lower_span(span));
21292130
let path = hir::ExprKind::Path(hir::QPath::TypeRelative(
2130-
self.arena.alloc(self.ty(
2131-
span,
2132-
hir::TyKind::Path(hir::QPath::LangItem(lang_item, self.lower_span(span))),
2133-
)),
2131+
self.arena.alloc(self.ty(span, hir::TyKind::Path(qpath))),
21342132
self.arena.alloc(hir::PathSegment::new(
21352133
Ident::new(name, span),
21362134
self.next_id(),

‎compiler/rustc_ast_lowering/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
770770
self.resolver.get_import_res(id).present_items()
771771
}
772772

773+
fn make_lang_item_qpath(&mut self, lang_item: hir::LangItem, span: Span) -> hir::QPath<'hir> {
774+
hir::QPath::Resolved(None, self.make_lang_item_path(lang_item, span, None))
775+
}
776+
773777
fn make_lang_item_path(
774778
&mut self,
775779
lang_item: hir::LangItem,
@@ -787,7 +791,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
787791
hir_id: self.next_id(),
788792
res,
789793
args,
790-
infer_args: false,
794+
infer_args: args.is_none(),
791795
}]),
792796
})
793797
}

‎src/tools/clippy/tests/ui/author/macro_in_closure.stdout

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ if let StmtKind::Local(local) = stmt.kind
1212
&& args.len() == 1
1313
&& let ExprKind::Call(func1, args1) = args[0].kind
1414
&& let ExprKind::Path(ref qpath1) = func1.kind
15+
&& match_qpath(qpath1, &["format_arguments", "new_v1"])
1516
&& args1.len() == 2
1617
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = args1[0].kind
1718
&& let ExprKind::Array(elements) = inner.kind
@@ -27,6 +28,7 @@ if let StmtKind::Local(local) = stmt.kind
2728
&& elements1.len() == 1
2829
&& let ExprKind::Call(func2, args2) = elements1[0].kind
2930
&& let ExprKind::Path(ref qpath2) = func2.kind
31+
&& match_qpath(qpath2, &["format_argument", "new_display"])
3032
&& args2.len() == 1
3133
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[0].kind
3234
&& let ExprKind::Path(ref qpath3) = inner2.kind

‎src/tools/clippy/tests/ui/author/macro_in_loop.stdout

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo
2222
&& args.len() == 1
2323
&& let ExprKind::Call(func1, args1) = args[0].kind
2424
&& let ExprKind::Path(ref qpath2) = func1.kind
25+
&& match_qpath(qpath2, &["format_arguments", "new_v1"])
2526
&& args1.len() == 2
2627
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = args1[0].kind
2728
&& let ExprKind::Array(elements) = inner.kind
@@ -37,6 +38,7 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo
3738
&& elements1.len() == 1
3839
&& let ExprKind::Call(func2, args2) = elements1[0].kind
3940
&& let ExprKind::Path(ref qpath3) = func2.kind
41+
&& match_qpath(qpath3, &["format_argument", "new_display"])
4042
&& args2.len() == 1
4143
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[0].kind
4244
&& let ExprKind::Path(ref qpath4) = inner2.kind

‎tests/pretty/issue-4264.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
({
3333
let res =
3434
((::alloc::fmt::format as
35-
for<'a> fn(Arguments<'a>) -> String {format})(((<#[lang = "format_arguments"]>::new_const
35+
for<'a> fn(Arguments<'a>) -> String {format})(((format_arguments::new_const
3636
as
3737
fn(&[&'static str]) -> Arguments<'_> {Arguments::<'_>::new_const})((&([("test"
3838
as &str)] as [&str; 1]) as &[&str; 1])) as Arguments<'_>))

‎tests/ui/unpretty/flattened-format-args.stdout

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ fn main() {
99
let x = 1;
1010
// Should flatten to println!("a 123 b {x} xyz\n"):
1111
{
12-
::std::io::_print(<#[lang = "format_arguments"]>::new_v1(&["a 123 b ",
13-
" xyz\n"],
14-
&[<#[lang = "format_argument"]>::new_display(&x)]));
12+
::std::io::_print(format_arguments::new_v1(&["a 123 b ",
13+
" xyz\n"], &[format_argument::new_display(&x)]));
1514
};
1615
}

0 commit comments

Comments
 (0)
Please sign in to comment.