From 7e00e9736db89ecef7575622a13b57021ec34493 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 23 Dec 2023 04:02:17 +0000 Subject: [PATCH] Make some non-diagnostic-affecting QPath::LangItem into regular qpaths --- compiler/rustc_ast_lowering/src/expr.rs | 10 ++++------ compiler/rustc_ast_lowering/src/lib.rs | 6 +++++- .../clippy/tests/ui/author/macro_in_closure.stdout | 2 ++ src/tools/clippy/tests/ui/author/macro_in_loop.stdout | 2 ++ tests/pretty/issue-4264.pp | 2 +- tests/ui/unpretty/flattened-format-args.stdout | 5 ++--- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 1f6d47ab453..f0e2c59eb3f 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -639,7 +639,7 @@ pub(super) fn make_async_expr( self.lower_span(span), Some(self.allow_gen_future.clone()), ); - let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span); + let resume_ty = self.make_lang_item_qpath(hir::LangItem::ResumeTy, unstable_span); let input_ty = hir::Ty { hir_id: self.next_id(), kind: hir::TyKind::Path(resume_ty), @@ -777,7 +777,7 @@ pub(super) fn make_async_gen_expr( self.lower_span(span), Some(self.allow_gen_future.clone()), ); - let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span); + let resume_ty = self.make_lang_item_qpath(hir::LangItem::ResumeTy, unstable_span); let input_ty = hir::Ty { hir_id: self.next_id(), kind: hir::TyKind::Path(resume_ty), @@ -2116,11 +2116,9 @@ pub(super) fn expr_lang_item_type_relative( lang_item: hir::LangItem, name: Symbol, ) -> hir::Expr<'hir> { + let qpath = self.make_lang_item_qpath(lang_item, self.lower_span(span)); let path = hir::ExprKind::Path(hir::QPath::TypeRelative( - self.arena.alloc(self.ty( - span, - hir::TyKind::Path(hir::QPath::LangItem(lang_item, self.lower_span(span))), - )), + self.arena.alloc(self.ty(span, hir::TyKind::Path(qpath))), self.arena.alloc(hir::PathSegment::new( Ident::new(name, span), self.next_id(), diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index e35d7d62cad..73ac324d8d0 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -766,6 +766,10 @@ fn expect_full_res_from_use(&mut self, id: NodeId) -> impl Iterator hir::QPath<'hir> { + hir::QPath::Resolved(None, self.make_lang_item_path(lang_item, span, None)) + } + fn make_lang_item_path( &mut self, lang_item: hir::LangItem, @@ -783,7 +787,7 @@ fn make_lang_item_path( hir_id: self.next_id(), res, args, - infer_args: false, + infer_args: args.is_none(), }]), }) } diff --git a/src/tools/clippy/tests/ui/author/macro_in_closure.stdout b/src/tools/clippy/tests/ui/author/macro_in_closure.stdout index 9ab71986f40..5a2542c8628 100644 --- a/src/tools/clippy/tests/ui/author/macro_in_closure.stdout +++ b/src/tools/clippy/tests/ui/author/macro_in_closure.stdout @@ -12,6 +12,7 @@ if let StmtKind::Local(local) = stmt.kind && args.len() == 1 && let ExprKind::Call(func1, args1) = args[0].kind && let ExprKind::Path(ref qpath1) = func1.kind + && match_qpath(qpath1, &["format_arguments", "new_v1"]) && args1.len() == 2 && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = args1[0].kind && let ExprKind::Array(elements) = inner.kind @@ -27,6 +28,7 @@ if let StmtKind::Local(local) = stmt.kind && elements1.len() == 1 && let ExprKind::Call(func2, args2) = elements1[0].kind && let ExprKind::Path(ref qpath2) = func2.kind + && match_qpath(qpath2, &["format_argument", "new_display"]) && args2.len() == 1 && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[0].kind && let ExprKind::Path(ref qpath3) = inner2.kind diff --git a/src/tools/clippy/tests/ui/author/macro_in_loop.stdout b/src/tools/clippy/tests/ui/author/macro_in_loop.stdout index bd054b6abc4..a719e3af7e7 100644 --- a/src/tools/clippy/tests/ui/author/macro_in_loop.stdout +++ b/src/tools/clippy/tests/ui/author/macro_in_loop.stdout @@ -22,6 +22,7 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo && args.len() == 1 && let ExprKind::Call(func1, args1) = args[0].kind && let ExprKind::Path(ref qpath2) = func1.kind + && match_qpath(qpath2, &["format_arguments", "new_v1"]) && args1.len() == 2 && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = args1[0].kind && let ExprKind::Array(elements) = inner.kind @@ -37,6 +38,7 @@ if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::Fo && elements1.len() == 1 && let ExprKind::Call(func2, args2) = elements1[0].kind && let ExprKind::Path(ref qpath3) = func2.kind + && match_qpath(qpath3, &["format_argument", "new_display"]) && args2.len() == 1 && let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[0].kind && let ExprKind::Path(ref qpath4) = inner2.kind diff --git a/tests/pretty/issue-4264.pp b/tests/pretty/issue-4264.pp index 4020a433d62..2d713832dcd 100644 --- a/tests/pretty/issue-4264.pp +++ b/tests/pretty/issue-4264.pp @@ -32,7 +32,7 @@ fn bar() ({ ({ let res = ((::alloc::fmt::format as - for<'a> fn(Arguments<'a>) -> String {format})(((<#[lang = "format_arguments"]>::new_const + for<'a> fn(Arguments<'a>) -> String {format})(((format_arguments::new_const as fn(&[&'static str]) -> Arguments<'_> {Arguments::<'_>::new_const})((&([("test" as &str)] as [&str; 1]) as &[&str; 1])) as Arguments<'_>)) diff --git a/tests/ui/unpretty/flattened-format-args.stdout b/tests/ui/unpretty/flattened-format-args.stdout index a8fe8da0024..7fc5d266059 100644 --- a/tests/ui/unpretty/flattened-format-args.stdout +++ b/tests/ui/unpretty/flattened-format-args.stdout @@ -9,8 +9,7 @@ fn main() { let x = 1; // Should flatten to println!("a 123 b {x} xyz\n"): { - ::std::io::_print(<#[lang = "format_arguments"]>::new_v1(&["a 123 b ", - " xyz\n"], - &[<#[lang = "format_argument"]>::new_display(&x)])); + ::std::io::_print(format_arguments::new_v1(&["a 123 b ", + " xyz\n"], &[format_argument::new_display(&x)])); }; }