From 65409c46096886a6f25bf0d327e23613c821f0ea Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Mon, 15 Jan 2024 12:26:45 -0500 Subject: [PATCH 01/10] Ensure `callee_id`s are body owners --- src/tools/clippy/clippy_lints/src/derive.rs | 4 +-- .../src/loops/explicit_iter_loop.rs | 2 +- src/tools/clippy/clippy_utils/src/ty.rs | 30 +++++++------------ 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/tools/clippy/clippy_lints/src/derive.rs b/src/tools/clippy/clippy_lints/src/derive.rs index d8abe411030..a8217d0602a 100644 --- a/src/tools/clippy/clippy_lints/src/derive.rs +++ b/src/tools/clippy/clippy_lints/src/derive.rs @@ -450,12 +450,12 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r && let Some(def_id) = trait_ref.trait_def_id() && cx.tcx.is_diagnostic_item(sym::PartialEq, def_id) && let param_env = param_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id) - && !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, adt.did(),&[]) + && !implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, None, &[]) // If all of our fields implement `Eq`, we can implement `Eq` too && adt .all_fields() .map(|f| f.ty(cx.tcx, args)) - .all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, adt.did(), &[])) + .all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, None, &[])) { span_lint_and_sugg( cx, diff --git a/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs b/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs index c7980060807..814ccaa36f5 100644 --- a/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs @@ -118,7 +118,7 @@ fn is_ref_iterable<'tcx>( .liberate_late_bound_regions(fn_id, cx.tcx.fn_sig(fn_id).skip_binder()) && let &[req_self_ty, req_res_ty] = &**sig.inputs_and_output && let param_env = cx.tcx.param_env(fn_id) - && implements_trait_with_env(cx.tcx, param_env, req_self_ty, trait_id, fn_id, &[]) + && implements_trait_with_env(cx.tcx, param_env, req_self_ty, trait_id, Some(fn_id), &[]) && let Some(into_iter_ty) = make_normalized_projection_with_regions(cx.tcx, param_env, trait_id, sym!(IntoIter), [req_self_ty]) && let req_res_ty = normalize_with_regions(cx.tcx, param_env, req_res_ty) diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index 61d0663aa83..a07d6587bf9 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -214,36 +214,21 @@ pub fn implements_trait<'tcx>( trait_id: DefId, args: &[GenericArg<'tcx>], ) -> bool { - let callee_id = cx - .enclosing_body - .map(|body| cx.tcx.hir().body_owner(body).owner.to_def_id()); - implements_trait_with_env_from_iter( - cx.tcx, - cx.param_env, - ty, - trait_id, - callee_id, - args.iter().map(|&x| Some(x)), - ) + implements_trait_with_env_from_iter(cx.tcx, cx.param_env, ty, trait_id, None, args.iter().map(|&x| Some(x))) } /// Same as `implements_trait` but allows using a `ParamEnv` different from the lint context. +/// +/// The `callee_id` argument is used to determine the "effect arg", if one is needed. pub fn implements_trait_with_env<'tcx>( tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, trait_id: DefId, - callee_id: DefId, + callee_id: Option, args: &[GenericArg<'tcx>], ) -> bool { - implements_trait_with_env_from_iter( - tcx, - param_env, - ty, - trait_id, - Some(callee_id), - args.iter().map(|&x| Some(x)), - ) + implements_trait_with_env_from_iter(tcx, param_env, ty, trait_id, callee_id, args.iter().map(|&x| Some(x))) } /// Same as `implements_trait_from_env` but takes the arguments as an iterator. @@ -258,6 +243,11 @@ pub fn implements_trait_with_env_from_iter<'tcx>( // Clippy shouldn't have infer types assert!(!ty.has_infer()); + // If a `callee_id` is passed, then "assert" it is a body owner. + if let Some(callee_id) = callee_id { + let _ = tcx.hir().body_owner_kind(callee_id); + } + let ty = tcx.erase_regions(ty); if ty.has_escaping_bound_vars() { return false; From b9ebeee4da258f1ed8bb93f0273180572a839058 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Wed, 17 Jan 2024 21:16:22 +0000 Subject: [PATCH 02/10] Remove `box ` recovery --- compiler/rustc_parse/src/parser/expr.rs | 28 +++++++------------------ 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 8ca02452342..a1e4fc7876d 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -33,7 +33,6 @@ use rustc_session::errors::{report_lit_error, ExprParenthesesNeeded}; use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP; use rustc_session::lint::BuiltinLintDiagnostics; use rustc_span::source_map::{self, Spanned}; -use rustc_span::symbol::kw::PathRoot; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{BytePos, Pos, Span}; use thin_vec::{thin_vec, ThinVec}; @@ -642,26 +641,13 @@ impl<'a> Parser<'a> { } /// Parse `box expr` - this syntax has been removed, but we still parse this - /// for now to provide an automated way to fix usages of it - fn parse_expr_box(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> { - let (span, expr) = self.parse_expr_prefix_common(lo)?; - let code = self.sess.source_map().span_to_snippet(span.with_lo(lo.hi())).unwrap(); - self.dcx().emit_err(errors::BoxSyntaxRemoved { span, code: code.trim() }); - // So typechecking works, parse `box ` as `::std::boxed::Box::new(expr)` - let path = Path { - span, - segments: [ - PathSegment::from_ident(Ident::with_dummy_span(PathRoot)), - PathSegment::from_ident(Ident::with_dummy_span(sym::std)), - PathSegment::from_ident(Ident::from_str("boxed")), - PathSegment::from_ident(Ident::from_str("Box")), - PathSegment::from_ident(Ident::with_dummy_span(sym::new)), - ] - .into(), - tokens: None, - }; - let path = self.mk_expr(span, ExprKind::Path(None, path)); - Ok((span, self.mk_call(path, ThinVec::from([expr])))) + /// for now to provide a more useful error + fn parse_expr_box(&mut self, box_kw: Span) -> PResult<'a, (Span, ExprKind)> { + let (span, _) = self.parse_expr_prefix_common(box_kw)?; + let inner_span = span.with_lo(box_kw.hi()); + let code = self.sess.source_map().span_to_snippet(inner_span).unwrap(); + self.dcx().emit_err(errors::BoxSyntaxRemoved { span: span, code: code.trim() }); + Ok((span, ExprKind::Err)) } fn is_mistaken_not_ident_negation(&self) -> bool { From 3f7c7842e6dd0dfc713c52fe7ffd24cd6a54fa87 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Wed, 17 Jan 2024 15:59:04 +0000 Subject: [PATCH 03/10] Move `removed-syntax` tests to their own directory --- tests/ui/parser/{ => removed-syntax}/removed-syntax-box.fixed | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-box.rs | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-box.stderr | 0 .../{ => removed-syntax}/removed-syntax-closure-lifetime.rs | 0 .../{ => removed-syntax}/removed-syntax-closure-lifetime.stderr | 0 .../ui/parser/{ => removed-syntax}/removed-syntax-enum-newtype.rs | 0 .../{ => removed-syntax}/removed-syntax-enum-newtype.stderr | 0 .../ui/parser/{ => removed-syntax}/removed-syntax-field-let-2.rs | 0 .../parser/{ => removed-syntax}/removed-syntax-field-let-2.stderr | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-field-let.rs | 0 .../parser/{ => removed-syntax}/removed-syntax-field-let.stderr | 0 .../parser/{ => removed-syntax}/removed-syntax-field-semicolon.rs | 0 .../{ => removed-syntax}/removed-syntax-field-semicolon.stderr | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-fixed-vec.rs | 0 .../parser/{ => removed-syntax}/removed-syntax-fixed-vec.stderr | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-fn-sigil.rs | 0 .../ui/parser/{ => removed-syntax}/removed-syntax-fn-sigil.stderr | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-mode.rs | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-mode.stderr | 0 .../ui/parser/{ => removed-syntax}/removed-syntax-mut-vec-expr.rs | 0 .../{ => removed-syntax}/removed-syntax-mut-vec-expr.stderr | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-mut-vec-ty.rs | 0 .../parser/{ => removed-syntax}/removed-syntax-mut-vec-ty.stderr | 0 .../ui/parser/{ => removed-syntax}/removed-syntax-ptr-lifetime.rs | 0 .../{ => removed-syntax}/removed-syntax-ptr-lifetime.stderr | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-record.rs | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-record.stderr | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-static-fn.rs | 0 .../parser/{ => removed-syntax}/removed-syntax-static-fn.stderr | 0 .../parser/{ => removed-syntax}/removed-syntax-uniq-mut-expr.rs | 0 .../{ => removed-syntax}/removed-syntax-uniq-mut-expr.stderr | 0 .../ui/parser/{ => removed-syntax}/removed-syntax-uniq-mut-ty.rs | 0 .../parser/{ => removed-syntax}/removed-syntax-uniq-mut-ty.stderr | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-with-1.rs | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-with-1.stderr | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-with-2.rs | 0 tests/ui/parser/{ => removed-syntax}/removed-syntax-with-2.stderr | 0 37 files changed, 0 insertions(+), 0 deletions(-) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-box.fixed (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-box.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-box.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-closure-lifetime.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-closure-lifetime.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-enum-newtype.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-enum-newtype.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-field-let-2.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-field-let-2.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-field-let.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-field-let.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-field-semicolon.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-field-semicolon.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-fixed-vec.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-fixed-vec.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-fn-sigil.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-fn-sigil.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-mode.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-mode.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-mut-vec-expr.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-mut-vec-expr.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-mut-vec-ty.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-mut-vec-ty.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-ptr-lifetime.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-ptr-lifetime.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-record.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-record.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-static-fn.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-static-fn.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-uniq-mut-expr.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-uniq-mut-expr.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-uniq-mut-ty.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-uniq-mut-ty.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-with-1.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-with-1.stderr (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-with-2.rs (100%) rename tests/ui/parser/{ => removed-syntax}/removed-syntax-with-2.stderr (100%) diff --git a/tests/ui/parser/removed-syntax-box.fixed b/tests/ui/parser/removed-syntax/removed-syntax-box.fixed similarity index 100% rename from tests/ui/parser/removed-syntax-box.fixed rename to tests/ui/parser/removed-syntax/removed-syntax-box.fixed diff --git a/tests/ui/parser/removed-syntax-box.rs b/tests/ui/parser/removed-syntax/removed-syntax-box.rs similarity index 100% rename from tests/ui/parser/removed-syntax-box.rs rename to tests/ui/parser/removed-syntax/removed-syntax-box.rs diff --git a/tests/ui/parser/removed-syntax-box.stderr b/tests/ui/parser/removed-syntax/removed-syntax-box.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-box.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-box.stderr diff --git a/tests/ui/parser/removed-syntax-closure-lifetime.rs b/tests/ui/parser/removed-syntax/removed-syntax-closure-lifetime.rs similarity index 100% rename from tests/ui/parser/removed-syntax-closure-lifetime.rs rename to tests/ui/parser/removed-syntax/removed-syntax-closure-lifetime.rs diff --git a/tests/ui/parser/removed-syntax-closure-lifetime.stderr b/tests/ui/parser/removed-syntax/removed-syntax-closure-lifetime.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-closure-lifetime.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-closure-lifetime.stderr diff --git a/tests/ui/parser/removed-syntax-enum-newtype.rs b/tests/ui/parser/removed-syntax/removed-syntax-enum-newtype.rs similarity index 100% rename from tests/ui/parser/removed-syntax-enum-newtype.rs rename to tests/ui/parser/removed-syntax/removed-syntax-enum-newtype.rs diff --git a/tests/ui/parser/removed-syntax-enum-newtype.stderr b/tests/ui/parser/removed-syntax/removed-syntax-enum-newtype.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-enum-newtype.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-enum-newtype.stderr diff --git a/tests/ui/parser/removed-syntax-field-let-2.rs b/tests/ui/parser/removed-syntax/removed-syntax-field-let-2.rs similarity index 100% rename from tests/ui/parser/removed-syntax-field-let-2.rs rename to tests/ui/parser/removed-syntax/removed-syntax-field-let-2.rs diff --git a/tests/ui/parser/removed-syntax-field-let-2.stderr b/tests/ui/parser/removed-syntax/removed-syntax-field-let-2.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-field-let-2.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-field-let-2.stderr diff --git a/tests/ui/parser/removed-syntax-field-let.rs b/tests/ui/parser/removed-syntax/removed-syntax-field-let.rs similarity index 100% rename from tests/ui/parser/removed-syntax-field-let.rs rename to tests/ui/parser/removed-syntax/removed-syntax-field-let.rs diff --git a/tests/ui/parser/removed-syntax-field-let.stderr b/tests/ui/parser/removed-syntax/removed-syntax-field-let.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-field-let.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-field-let.stderr diff --git a/tests/ui/parser/removed-syntax-field-semicolon.rs b/tests/ui/parser/removed-syntax/removed-syntax-field-semicolon.rs similarity index 100% rename from tests/ui/parser/removed-syntax-field-semicolon.rs rename to tests/ui/parser/removed-syntax/removed-syntax-field-semicolon.rs diff --git a/tests/ui/parser/removed-syntax-field-semicolon.stderr b/tests/ui/parser/removed-syntax/removed-syntax-field-semicolon.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-field-semicolon.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-field-semicolon.stderr diff --git a/tests/ui/parser/removed-syntax-fixed-vec.rs b/tests/ui/parser/removed-syntax/removed-syntax-fixed-vec.rs similarity index 100% rename from tests/ui/parser/removed-syntax-fixed-vec.rs rename to tests/ui/parser/removed-syntax/removed-syntax-fixed-vec.rs diff --git a/tests/ui/parser/removed-syntax-fixed-vec.stderr b/tests/ui/parser/removed-syntax/removed-syntax-fixed-vec.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-fixed-vec.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-fixed-vec.stderr diff --git a/tests/ui/parser/removed-syntax-fn-sigil.rs b/tests/ui/parser/removed-syntax/removed-syntax-fn-sigil.rs similarity index 100% rename from tests/ui/parser/removed-syntax-fn-sigil.rs rename to tests/ui/parser/removed-syntax/removed-syntax-fn-sigil.rs diff --git a/tests/ui/parser/removed-syntax-fn-sigil.stderr b/tests/ui/parser/removed-syntax/removed-syntax-fn-sigil.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-fn-sigil.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-fn-sigil.stderr diff --git a/tests/ui/parser/removed-syntax-mode.rs b/tests/ui/parser/removed-syntax/removed-syntax-mode.rs similarity index 100% rename from tests/ui/parser/removed-syntax-mode.rs rename to tests/ui/parser/removed-syntax/removed-syntax-mode.rs diff --git a/tests/ui/parser/removed-syntax-mode.stderr b/tests/ui/parser/removed-syntax/removed-syntax-mode.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-mode.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-mode.stderr diff --git a/tests/ui/parser/removed-syntax-mut-vec-expr.rs b/tests/ui/parser/removed-syntax/removed-syntax-mut-vec-expr.rs similarity index 100% rename from tests/ui/parser/removed-syntax-mut-vec-expr.rs rename to tests/ui/parser/removed-syntax/removed-syntax-mut-vec-expr.rs diff --git a/tests/ui/parser/removed-syntax-mut-vec-expr.stderr b/tests/ui/parser/removed-syntax/removed-syntax-mut-vec-expr.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-mut-vec-expr.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-mut-vec-expr.stderr diff --git a/tests/ui/parser/removed-syntax-mut-vec-ty.rs b/tests/ui/parser/removed-syntax/removed-syntax-mut-vec-ty.rs similarity index 100% rename from tests/ui/parser/removed-syntax-mut-vec-ty.rs rename to tests/ui/parser/removed-syntax/removed-syntax-mut-vec-ty.rs diff --git a/tests/ui/parser/removed-syntax-mut-vec-ty.stderr b/tests/ui/parser/removed-syntax/removed-syntax-mut-vec-ty.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-mut-vec-ty.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-mut-vec-ty.stderr diff --git a/tests/ui/parser/removed-syntax-ptr-lifetime.rs b/tests/ui/parser/removed-syntax/removed-syntax-ptr-lifetime.rs similarity index 100% rename from tests/ui/parser/removed-syntax-ptr-lifetime.rs rename to tests/ui/parser/removed-syntax/removed-syntax-ptr-lifetime.rs diff --git a/tests/ui/parser/removed-syntax-ptr-lifetime.stderr b/tests/ui/parser/removed-syntax/removed-syntax-ptr-lifetime.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-ptr-lifetime.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-ptr-lifetime.stderr diff --git a/tests/ui/parser/removed-syntax-record.rs b/tests/ui/parser/removed-syntax/removed-syntax-record.rs similarity index 100% rename from tests/ui/parser/removed-syntax-record.rs rename to tests/ui/parser/removed-syntax/removed-syntax-record.rs diff --git a/tests/ui/parser/removed-syntax-record.stderr b/tests/ui/parser/removed-syntax/removed-syntax-record.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-record.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-record.stderr diff --git a/tests/ui/parser/removed-syntax-static-fn.rs b/tests/ui/parser/removed-syntax/removed-syntax-static-fn.rs similarity index 100% rename from tests/ui/parser/removed-syntax-static-fn.rs rename to tests/ui/parser/removed-syntax/removed-syntax-static-fn.rs diff --git a/tests/ui/parser/removed-syntax-static-fn.stderr b/tests/ui/parser/removed-syntax/removed-syntax-static-fn.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-static-fn.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-static-fn.stderr diff --git a/tests/ui/parser/removed-syntax-uniq-mut-expr.rs b/tests/ui/parser/removed-syntax/removed-syntax-uniq-mut-expr.rs similarity index 100% rename from tests/ui/parser/removed-syntax-uniq-mut-expr.rs rename to tests/ui/parser/removed-syntax/removed-syntax-uniq-mut-expr.rs diff --git a/tests/ui/parser/removed-syntax-uniq-mut-expr.stderr b/tests/ui/parser/removed-syntax/removed-syntax-uniq-mut-expr.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-uniq-mut-expr.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-uniq-mut-expr.stderr diff --git a/tests/ui/parser/removed-syntax-uniq-mut-ty.rs b/tests/ui/parser/removed-syntax/removed-syntax-uniq-mut-ty.rs similarity index 100% rename from tests/ui/parser/removed-syntax-uniq-mut-ty.rs rename to tests/ui/parser/removed-syntax/removed-syntax-uniq-mut-ty.rs diff --git a/tests/ui/parser/removed-syntax-uniq-mut-ty.stderr b/tests/ui/parser/removed-syntax/removed-syntax-uniq-mut-ty.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-uniq-mut-ty.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-uniq-mut-ty.stderr diff --git a/tests/ui/parser/removed-syntax-with-1.rs b/tests/ui/parser/removed-syntax/removed-syntax-with-1.rs similarity index 100% rename from tests/ui/parser/removed-syntax-with-1.rs rename to tests/ui/parser/removed-syntax/removed-syntax-with-1.rs diff --git a/tests/ui/parser/removed-syntax-with-1.stderr b/tests/ui/parser/removed-syntax/removed-syntax-with-1.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-with-1.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-with-1.stderr diff --git a/tests/ui/parser/removed-syntax-with-2.rs b/tests/ui/parser/removed-syntax/removed-syntax-with-2.rs similarity index 100% rename from tests/ui/parser/removed-syntax-with-2.rs rename to tests/ui/parser/removed-syntax/removed-syntax-with-2.rs diff --git a/tests/ui/parser/removed-syntax-with-2.stderr b/tests/ui/parser/removed-syntax/removed-syntax-with-2.stderr similarity index 100% rename from tests/ui/parser/removed-syntax-with-2.stderr rename to tests/ui/parser/removed-syntax/removed-syntax-with-2.stderr From 96b8eb78febe0ff146573b6e7557425a853e612e Mon Sep 17 00:00:00 2001 From: Samuel Moelius <35515885+smoelius@users.noreply.github.com> Date: Thu, 18 Jan 2024 10:32:57 -0500 Subject: [PATCH 04/10] Apply suggestions from code review Co-authored-by: fee1-dead --- src/tools/clippy/clippy_utils/src/ty.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index a07d6587bf9..59ebe685c11 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -219,7 +219,7 @@ pub fn implements_trait<'tcx>( /// Same as `implements_trait` but allows using a `ParamEnv` different from the lint context. /// -/// The `callee_id` argument is used to determine the "effect arg", if one is needed. +/// The `callee_id` argument is used to determine whether this is a function call in a `const fn` environment, used for checking const traits. pub fn implements_trait_with_env<'tcx>( tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, @@ -243,7 +243,9 @@ pub fn implements_trait_with_env_from_iter<'tcx>( // Clippy shouldn't have infer types assert!(!ty.has_infer()); - // If a `callee_id` is passed, then "assert" it is a body owner. + // If a `callee_id` is passed, then we assert that it is a body owner + // through calling `body_owner_kind`, which would panic if the callee + // does not have a body. if let Some(callee_id) = callee_id { let _ = tcx.hir().body_owner_kind(callee_id); } From b28a95391b85e17b1d2f7edc1115291d8a86bcd2 Mon Sep 17 00:00:00 2001 From: The 8472 Date: Thu, 18 Jan 2024 22:47:20 +0100 Subject: [PATCH 05/10] update internal ASCII art comment for vec specializations --- library/alloc/src/vec/spec_from_iter.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index e976552cf2b..33dd4139bc0 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -13,13 +13,13 @@ use super::{IntoIter, SpecExtend, SpecFromIterNested, Vec}; /// +-+-----------+ /// | /// v -/// +-+-------------------------------+ +---------------------+ -/// |SpecFromIter +---->+SpecFromIterNested | -/// |where I: | | |where I: | -/// | Iterator (default)----------+ | | Iterator (default) | -/// | vec::IntoIter | | | TrustedLen | -/// | SourceIterMarker---fallback-+ | +---------------------+ -/// +---------------------------------+ +/// +-+---------------------------------+ +---------------------+ +/// |SpecFromIter +---->+SpecFromIterNested | +/// |where I: | | |where I: | +/// | Iterator (default)------------+ | | Iterator (default) | +/// | vec::IntoIter | | | TrustedLen | +/// | InPlaceCollect--(fallback to)-+ | +---------------------+ +/// +-----------------------------------+ /// ``` pub(super) trait SpecFromIter { fn from_iter(iter: I) -> Self; From 85d17879623116be76a68c2170c4cb6ff58f4ceb Mon Sep 17 00:00:00 2001 From: The 8472 Date: Thu, 18 Jan 2024 22:50:14 +0100 Subject: [PATCH 06/10] remove alignment-changing in-place collect Currently stable users can't benefit from this because GlobaAlloc doesn't support alignment-changing realloc and neither do most posix allocators. So in practice it always results in an extra memcpy. --- library/alloc/src/vec/in_place_collect.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index ec5f32539f2..5a783e66752 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -168,7 +168,9 @@ const fn in_place_collectible( step_merge: Option, step_expand: Option, ) -> bool { - if const { SRC::IS_ZST || DEST::IS_ZST || mem::align_of::() < mem::align_of::() } { + // Require matching alignments because an alignment-changing realloc is inefficient on many + // system allocators and better implementations would require the unstable Allocator trait. + if const { SRC::IS_ZST || DEST::IS_ZST || mem::align_of::() != mem::align_of::() } { return false; } @@ -188,7 +190,8 @@ const fn in_place_collectible( const fn needs_realloc(src_cap: usize, dst_cap: usize) -> bool { if const { mem::align_of::() != mem::align_of::() } { - return src_cap > 0; + // FIXME: use unreachable! once that works in const + panic!("in_place_collectible() prevents this"); } // If src type size is an integer multiple of the destination type size then @@ -276,8 +279,8 @@ where let dst_guard = InPlaceDstBufDrop { ptr: dst_buf, len, cap: dst_cap }; src.forget_allocation_drop_remaining(); - // Adjust the allocation if the alignment didn't match or the source had a capacity in bytes - // that wasn't a multiple of the destination type size. + // Adjust the allocation if the source had a capacity in bytes that wasn't a multiple + // of the destination type size. // Since the discrepancy should generally be small this should only result in some // bookkeeping updates and no memmove. if needs_realloc::(src_cap, dst_cap) { @@ -290,7 +293,7 @@ where let src_size = mem::size_of::().unchecked_mul(src_cap); let old_layout = Layout::from_size_align_unchecked(src_size, src_align); - // The must be equal or smaller for in-place iteration to be possible + // The allocation must be equal or smaller for in-place iteration to be possible // therefore the new layout must be ≤ the old one and therefore valid. let dst_align = mem::align_of::(); let dst_size = mem::size_of::().unchecked_mul(dst_cap); From 5afe1399b582434cfdfa2130353a8b03d885685c Mon Sep 17 00:00:00 2001 From: trevyn <230691+trevyn@users.noreply.github.com> Date: Fri, 19 Jan 2024 23:46:17 +0400 Subject: [PATCH 07/10] Increase vscode `git.detectSubmodulesLimit` --- src/bootstrap/src/core/build_steps/setup.rs | 1 + src/etc/rust_analyzer_settings.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/setup.rs b/src/bootstrap/src/core/build_steps/setup.rs index 9c897ae1bb7..dd9c68aba7f 100644 --- a/src/bootstrap/src/core/build_steps/setup.rs +++ b/src/bootstrap/src/core/build_steps/setup.rs @@ -37,6 +37,7 @@ static SETTINGS_HASHES: &[&str] = &[ "3468fea433c25fff60be6b71e8a215a732a7b1268b6a83bf10d024344e140541", "47d227f424bf889b0d899b9cc992d5695e1b78c406e183cd78eafefbe5488923", "b526bd58d0262dd4dda2bff5bc5515b705fb668a46235ace3e057f807963a11a", + "828666b021d837a33e78d870b56d34c88a5e2c85de58b693607ec574f0c27000", ]; static RUST_ANALYZER_SETTINGS: &str = include_str!("../../../../etc/rust_analyzer_settings.json"); diff --git a/src/etc/rust_analyzer_settings.json b/src/etc/rust_analyzer_settings.json index 32a04cfd5d1..d329fe997cd 100644 --- a/src/etc/rust_analyzer_settings.json +++ b/src/etc/rust_analyzer_settings.json @@ -1,4 +1,5 @@ { + "git.detectSubmodulesLimit": 20, "rust-analyzer.check.invocationLocation": "root", "rust-analyzer.check.invocationStrategy": "once", "rust-analyzer.check.overrideCommand": [ From 6237bebd349c7ba9286e2daa76eef07bd6b7c5be Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 15 Jan 2024 16:46:54 +0100 Subject: [PATCH 08/10] Fix impl stripped in rustdoc HTML whereas it should not be in case the impl is implemented on a type alias --- src/librustdoc/passes/stripper.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index df955421ba4..1bea93c7842 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -56,13 +56,10 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> { | clean::TraitItem(..) | clean::FunctionItem(..) | clean::VariantItem(..) - | clean::MethodItem(..) | clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) | clean::ConstantItem(..) | clean::UnionItem(..) - | clean::AssocConstItem(..) - | clean::AssocTypeItem(..) | clean::TraitAliasItem(..) | clean::MacroItem(..) | clean::ForeignTypeItem => { @@ -80,6 +77,16 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> { } } + clean::MethodItem(..) | clean::AssocConstItem(..) | clean::AssocTypeItem(..) => { + let item_id = i.item_id; + if item_id.is_local() + && !self.effective_visibilities.is_reachable(self.tcx, item_id.expect_def_id()) + { + debug!("Stripper: stripping {:?} {:?}", i.type_(), i.name); + return None; + } + } + clean::StructFieldItem(..) => { if i.visibility(self.tcx) != Some(Visibility::Public) { return Some(strip_item(i)); @@ -192,16 +199,16 @@ impl<'a> DocFolder for ImplStripper<'a, '_> { && imp.items.iter().all(|i| { let item_id = i.item_id; item_id.is_local() - && !is_item_reachable( - self.tcx, - self.is_json_output, - &self.cache.effective_visibilities, - item_id, - ) + && !self + .cache + .effective_visibilities + .is_reachable(self.tcx, item_id.expect_def_id()) }) { + debug!("ImplStripper: no public item; removing {imp:?}"); return None; } else if imp.items.is_empty() && i.doc_value().is_empty() { + debug!("ImplStripper: no item and no doc; removing {imp:?}"); return None; } } @@ -212,13 +219,13 @@ impl<'a> DocFolder for ImplStripper<'a, '_> { && !imp.for_.is_assoc_ty() && !self.should_keep_impl(&i, did) { - debug!("ImplStripper: impl item for stripped type; removing"); + debug!("ImplStripper: impl item for stripped type; removing {imp:?}"); return None; } if let Some(did) = imp.trait_.as_ref().map(|t| t.def_id()) && !self.should_keep_impl(&i, did) { - debug!("ImplStripper: impl item for stripped trait; removing"); + debug!("ImplStripper: impl item for stripped trait; removing {imp:?}"); return None; } if let Some(generics) = imp.trait_.as_ref().and_then(|t| t.generics()) { @@ -226,7 +233,7 @@ impl<'a> DocFolder for ImplStripper<'a, '_> { if let Some(did) = typaram.def_id(self.cache) && !self.should_keep_impl(&i, did) { - debug!("ImplStripper: stripped item in trait's generics; removing impl"); + debug!("ImplStripper: stripped item in trait's generics; removing {imp:?}"); return None; } } From 0933f48ac0a8631b3f7c9c508f38843ef10e839d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 15 Jan 2024 16:47:14 +0100 Subject: [PATCH 09/10] Add regression test for #119015 and update tests --- tests/rustdoc/async-fn.rs | 18 ++++++++----- .../rustdoc/impl-on-ty-alias-issue-119015.rs | 27 +++++++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 tests/rustdoc/impl-on-ty-alias-issue-119015.rs diff --git a/tests/rustdoc/async-fn.rs b/tests/rustdoc/async-fn.rs index 70bcbcb6ff4..b3c35c8c3f3 100644 --- a/tests/rustdoc/async-fn.rs +++ b/tests/rustdoc/async-fn.rs @@ -48,6 +48,8 @@ impl Foo { pub trait Pattern<'a> {} +impl Pattern<'_> for () {} + pub trait Trait {} // @has async_fn/fn.const_generics.html // @has - '//pre[@class="rust item-decl"]' 'pub async fn const_generics(_: impl Trait)' @@ -57,18 +59,18 @@ pub async fn const_generics(_: impl Trait) {} // regression test for #63037 // @has async_fn/fn.elided.html // @has - '//pre[@class="rust item-decl"]' 'pub async fn elided(foo: &str) -> &str' -pub async fn elided(foo: &str) -> &str {} +pub async fn elided(foo: &str) -> &str { "" } // This should really be shown as written, but for implementation reasons it's difficult. // See `impl Clean for TyKind::Ref`. // @has async_fn/fn.user_elided.html // @has - '//pre[@class="rust item-decl"]' 'pub async fn user_elided(foo: &str) -> &str' -pub async fn user_elided(foo: &'_ str) -> &str {} +pub async fn user_elided(foo: &'_ str) -> &str { "" } // @has async_fn/fn.static_trait.html // @has - '//pre[@class="rust item-decl"]' 'pub async fn static_trait(foo: &str) -> Box' -pub async fn static_trait(foo: &str) -> Box {} +pub async fn static_trait(foo: &str) -> Box { Box::new(()) } // @has async_fn/fn.lifetime_for_trait.html // @has - '//pre[@class="rust item-decl"]' "pub async fn lifetime_for_trait(foo: &str) -> Box" -pub async fn lifetime_for_trait(foo: &str) -> Box {} +pub async fn lifetime_for_trait(foo: &str) -> Box { Box::new(()) } // @has async_fn/fn.elided_in_input_trait.html // @has - '//pre[@class="rust item-decl"]' "pub async fn elided_in_input_trait(t: impl Pattern<'_>)" pub async fn elided_in_input_trait(t: impl Pattern<'_>) {} @@ -78,10 +80,12 @@ struct AsyncFdReadyGuard<'a, T> { x: &'a T } impl Foo { // @has async_fn/struct.Foo.html // @has - '//*[@class="method"]' 'pub async fn complicated_lifetimes( &self, context: &impl Bar ) -> impl Iterator' - pub async fn complicated_lifetimes(&self, context: &impl Bar) -> impl Iterator {} + pub async fn complicated_lifetimes(&self, context: &impl Bar) -> impl Iterator { + [0].iter() + } // taken from `tokio` as an example of a method that was particularly bad before // @has - '//*[@class="method"]' "pub async fn readable(&self) -> Result, ()>" - pub async fn readable(&self) -> Result, ()> {} + pub async fn readable(&self) -> Result, ()> { Err(()) } // @has - '//*[@class="method"]' "pub async fn mut_self(&mut self)" pub async fn mut_self(&mut self) {} } @@ -89,7 +93,7 @@ impl Foo { // test named lifetimes, just in case // @has async_fn/fn.named.html // @has - '//pre[@class="rust item-decl"]' "pub async fn named<'a, 'b>(foo: &'a str) -> &'b str" -pub async fn named<'a, 'b>(foo: &'a str) -> &'b str {} +pub async fn named<'a, 'b>(foo: &'a str) -> &'b str { "" } // @has async_fn/fn.named_trait.html // @has - '//pre[@class="rust item-decl"]' "pub async fn named_trait<'a, 'b>(foo: impl Pattern<'a>) -> impl Pattern<'b>" pub async fn named_trait<'a, 'b>(foo: impl Pattern<'a>) -> impl Pattern<'b> {} diff --git a/tests/rustdoc/impl-on-ty-alias-issue-119015.rs b/tests/rustdoc/impl-on-ty-alias-issue-119015.rs new file mode 100644 index 00000000000..68996deae6f --- /dev/null +++ b/tests/rustdoc/impl-on-ty-alias-issue-119015.rs @@ -0,0 +1,27 @@ +#![crate_name = "foo"] + +// @has 'foo/index.html' +// There should be only `type A`. +// @count - '//*[@class="item-table"]//*[@class="item-name"]' 1 +// @has - '//*[@class="item-name"]/a[@href="type.A.html"]' 'A' + +mod foo { + pub struct S; +} + +use foo::S; + +pub type A = S; + +// @has 'foo/type.A.html' +// @has - '//*[@id="method.default"]/h4' 'fn default() -> Self' +impl Default for A { + fn default() -> Self { + S + } +} + +// @has - '//*[@id="method.a"]/h4' 'pub fn a(&self)' +impl A { + pub fn a(&self) {} +} From 0e96840e7eeaabd3cced2319855893ec7e2a503d Mon Sep 17 00:00:00 2001 From: sunrosa <79175772+sunrosa@users.noreply.github.com> Date: Sat, 20 Jan 2024 18:27:55 +0000 Subject: [PATCH 10/10] Spelling fix "It's" expands to "it is". "Its" is the possessive form. --- library/core/src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/error.rs b/library/core/src/error.rs index f1a7ad93548..ded17e69bd9 100644 --- a/library/core/src/error.rs +++ b/library/core/src/error.rs @@ -415,7 +415,7 @@ where // Request and its methods /////////////////////////////////////////////////////////////////////////////// -/// `Request` supports generic, type-driven access to data. It's use is currently restricted to the +/// `Request` supports generic, type-driven access to data. Its use is currently restricted to the /// standard library in cases where trait authors wish to allow trait implementors to share generic /// information across trait boundaries. The motivating and prototypical use case is /// `core::error::Error` which would otherwise require a method per concrete type (eg.