From 75fc8a664f82825aface01221a575568c7eaefaf Mon Sep 17 00:00:00 2001 From: yvt Date: Mon, 10 Oct 2022 14:04:08 +0900 Subject: [PATCH 01/16] chore: upgrade the Rust toolchain to `nightly-2022-04-25` --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index abcacd9bd1d..f6f9b5b6c64 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-04-11 +nightly-2022-04-25 From b4c1c972d4b482c0ae261f5db48af5c405da2781 Mon Sep 17 00:00:00 2001 From: yvt Date: Mon, 10 Oct 2022 14:14:59 +0900 Subject: [PATCH 02/16] fix(script_plugins): the visibility fields of `rustc_hir::intravisit::FnKind` are gone --- components/script_plugins/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/script_plugins/lib.rs b/components/script_plugins/lib.rs index 498e6027cac..14036184e78 100644 --- a/components/script_plugins/lib.rs +++ b/components/script_plugins/lib.rs @@ -268,7 +268,7 @@ impl<'tcx> LateLintPass<'tcx> for UnrootedPass { id: HirId, ) { let in_new_function = match kind { - visit::FnKind::ItemFn(n, _, _, _) | visit::FnKind::Method(n, _, _) => { + visit::FnKind::ItemFn(n, _, _) | visit::FnKind::Method(n, _) => { &*n.as_str() == "new" || n.as_str().starts_with("new_") }, visit::FnKind::Closure => return, From 37d09ebdfdd975b529593b69683a81545274cda8 Mon Sep 17 00:00:00 2001 From: yvt Date: Mon, 10 Oct 2022 18:31:47 +0900 Subject: [PATCH 03/16] chore: upgrade the Rust toolchain to `nightly-2022-05-13` --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index f6f9b5b6c64..181fd0a0594 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-04-25 +nightly-2022-05-13 From 065c59665c029b1471db729422254561076833f8 Mon Sep 17 00:00:00 2001 From: yvt Date: Mon, 10 Oct 2022 20:49:12 +0900 Subject: [PATCH 04/16] fix(script_plugins): replace `TyCtxt::{get_attrs -> get_attrs_unchecked}` [rust-lang/rust#95562][1] renames the existing method `get_attrs` to `get_attrs_unchecked` and introduces a new method in its former place. The new method takes an attribute name and returns attributes of that name. It also checks that, if the attribute name is marked as local- only, the given `DefId` is local as well to prevent misuses. The old method, now named `get_attrs_unchecked`, returns all attributes of a given `DefId`; thus it's "unchecked" in the sense that it's up to the callers to be certain whether the attributes they are looking for are local-only. The new `get_attrs` method lacks the support for attribute names with more than one path component, which is why we can't just migrate to the new `get_attrs` method here. Although `get_attrs_unchecked` is marked for future removal in the compile source code, there's a discussion about [supporting][2] this use case. [1]: https://github.com/rust-lang/rust/pull/95562 [2]: https://github.com/rust-lang/rust/pull/95562/files#r915537557 --- components/script_plugins/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/script_plugins/lib.rs b/components/script_plugins/lib.rs index 14036184e78..5ff11efd1bd 100644 --- a/components/script_plugins/lib.rs +++ b/components/script_plugins/lib.rs @@ -110,7 +110,8 @@ fn is_unrooted_ty<'tcx>( }; let recur_into_subtree = match t.kind() { ty::Adt(did, substs) => { - let has_attr = |did, name| has_lint_attr(sym, &cx.tcx.get_attrs(did), name); + let has_attr = + |did, name| has_lint_attr(sym, &cx.tcx.get_attrs_unchecked(did), name); if has_attr(did.did(), sym.must_root) { ret = true; false From 52ebde8e162523e993bfccc11a0a60d91cc1ee67 Mon Sep 17 00:00:00 2001 From: yvt Date: Wed, 12 Oct 2022 12:20:37 +0900 Subject: [PATCH 05/16] chore: upgrade the Rust toolchain to `nightly-2022-08-17` --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 181fd0a0594..0581bda0e6f 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-05-13 +nightly-2022-08-17 From 3fd4fd0388612942fedd3bef745085ac45d3b73c Mon Sep 17 00:00:00 2001 From: yvt Date: Wed, 12 Oct 2022 12:45:41 +0900 Subject: [PATCH 06/16] fix(script_plguins): `rustc_ast::ast::AttrKind::Normal` fields are now boxed --- components/script_plugins/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/script_plugins/lib.rs b/components/script_plugins/lib.rs index 5ff11efd1bd..bad98739450 100644 --- a/components/script_plugins/lib.rs +++ b/components/script_plugins/lib.rs @@ -83,10 +83,10 @@ fn has_lint_attr(sym: &Symbols, attrs: &[Attribute], name: Symbol) -> bool { attrs.iter().any(|attr| { matches!( &attr.kind, - AttrKind::Normal(attr_item, _) - if attr_item.path.segments.len() == 2 && - attr_item.path.segments[0].ident.name == sym.unrooted_must_root_lint && - attr_item.path.segments[1].ident.name == name + AttrKind::Normal(normal) + if normal.item.path.segments.len() == 2 && + normal.item.path.segments[0].ident.name == sym.unrooted_must_root_lint && + normal.item.path.segments[1].ident.name == name ) }) } From ffe06c133becc721091cec6209a2ddf07501b961 Mon Sep 17 00:00:00 2001 From: yvt Date: Thu, 13 Oct 2022 01:47:51 +0900 Subject: [PATCH 07/16] chore: upgrade the Rust toolchain to `nightly-2022-09-07` --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 0581bda0e6f..3cf39ef0201 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-08-17 +nightly-2022-09-07 From fbc1ae8533ac5616f0d4c5400e6ee53c60574bb7 Mon Sep 17 00:00:00 2001 From: yvt Date: Thu, 13 Oct 2022 02:02:49 +0900 Subject: [PATCH 08/16] fix(script_plugins): `hir::BindingAnnotation::{Unannotated, Mutable}` have been replaced by associated constants --- components/script_plugins/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/script_plugins/lib.rs b/components/script_plugins/lib.rs index bad98739450..2f757e7184f 100644 --- a/components/script_plugins/lib.rs +++ b/components/script_plugins/lib.rs @@ -360,8 +360,8 @@ impl<'a, 'tcx> visit::Visitor<'tcx> for FnDefVisitor<'a, 'tcx> { // are implemented, the `Unannotated` case could cause false-positives. // These should be fixable by adding an explicit `ref`. match pat.kind { - hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, ..) | - hir::PatKind::Binding(hir::BindingAnnotation::Mutable, ..) => { + hir::PatKind::Binding(hir::BindingAnnotation::NONE, ..) | + hir::PatKind::Binding(hir::BindingAnnotation::MUT, ..) => { let ty = cx.typeck_results().pat_ty(pat); if is_unrooted_ty(self.symbols, cx, ty, self.in_new_function) { cx.lint(UNROOTED_MUST_ROOT, |lint| { From 2f4f3f066e6dbfe4dd4598c07782814bd7b1004b Mon Sep 17 00:00:00 2001 From: yvt Date: Thu, 13 Oct 2022 02:10:24 +0900 Subject: [PATCH 09/16] chore: upgrade the Rust toolchain to `nightly-2022-09-09` --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 3cf39ef0201..528dd9b25a9 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-09-07 +nightly-2022-09-09 From 66c03e3c968803d9a6e3331755bbb34ab47f230a Mon Sep 17 00:00:00 2001 From: yvt Date: Thu, 13 Oct 2022 12:18:36 +0900 Subject: [PATCH 10/16] fix(script_plugins): `LintStore::register_late_pass` now passes an extra arg to a given closure --- components/script_plugins/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/script_plugins/lib.rs b/components/script_plugins/lib.rs index 2f757e7184f..e6bad197e23 100644 --- a/components/script_plugins/lib.rs +++ b/components/script_plugins/lib.rs @@ -43,7 +43,7 @@ fn registrar(reg: &mut Registry) { let symbols = Symbols::new(); reg.lint_store.register_lints(&[&UNROOTED_MUST_ROOT]); reg.lint_store - .register_late_pass(move || Box::new(UnrootedPass::new(symbols.clone()))); + .register_late_pass(move |_| Box::new(UnrootedPass::new(symbols.clone()))); } declare_lint!( From b1341f77f5d356906377ef401dfa1100e82d6f14 Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 15 Oct 2022 19:56:10 +0900 Subject: [PATCH 11/16] test(style): update the expected sizes of `{,Selector,Value}ParseError` --- tests/unit/style/size_of.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/style/size_of.rs b/tests/unit/style/size_of.rs index 7306cf059ef..cb64495141b 100644 --- a/tests/unit/style/size_of.rs +++ b/tests/unit/style/size_of.rs @@ -38,14 +38,14 @@ size_of_test!( 40 ); -size_of_test!(test_size_of_selector_parse_error, SelectorParseError, 56); +size_of_test!(test_size_of_selector_parse_error, SelectorParseError, 48); size_of_test!( test_size_of_style_traits_parse_error, ::style_traits::ParseError, - 72 + 64 ); size_of_test!( test_size_of_value_parse_error, ::style_traits::ValueParseError, - 56 + 48 ); From e7c92e962734518972b6bd2c31383333ea4abd16 Mon Sep 17 00:00:00 2001 From: yvt Date: Thu, 13 Oct 2022 12:58:03 +0900 Subject: [PATCH 12/16] chore: upgrade the Rust toolchain to `nightly-2022-09-26` --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 528dd9b25a9..596d35c3ae9 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-09-09 +nightly-2022-09-26 From 00f6b6f36e0290bada4f5f8fce788ae33131609a Mon Sep 17 00:00:00 2001 From: yvt Date: Thu, 13 Oct 2022 20:10:42 +0900 Subject: [PATCH 13/16] fix(script_plugins): `Map::get_parent_item` now returns `OwnerId` instead of `LocalDefId` --- components/script_plugins/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/script_plugins/lib.rs b/components/script_plugins/lib.rs index e6bad197e23..895bf94de8e 100644 --- a/components/script_plugins/lib.rs +++ b/components/script_plugins/lib.rs @@ -234,7 +234,7 @@ impl<'tcx> LateLintPass<'tcx> for UnrootedPass { /// must be #[unrooted_must_root_lint::must_root] themselves fn check_variant(&mut self, cx: &LateContext, var: &hir::Variant) { let ref map = cx.tcx.hir(); - let parent_item = map.expect_item(map.get_parent_item(var.id)); + let parent_item = map.expect_item(map.get_parent_item(var.id).def_id); let attrs = cx.tcx.hir().attrs(parent_item.hir_id()); if !has_lint_attr(&self.symbols, &attrs, self.symbols.must_root) { match var.data { From 3cd4837e635ad8a053e8be331c55a1efd0477b57 Mon Sep 17 00:00:00 2001 From: yvt Date: Fri, 14 Oct 2022 00:45:19 +0900 Subject: [PATCH 14/16] chore: upgrade the Rust toolchain to `nightly-2022-10-02` --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 596d35c3ae9..81fc95b62a3 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-09-26 +nightly-2022-10-02 From 687ac6c77ff6390d479711dd2c7ff89e427ca469 Mon Sep 17 00:00:00 2001 From: yvt Date: Fri, 14 Oct 2022 00:56:38 +0900 Subject: [PATCH 15/16] fix(script_plugins): adapt to the new rustc lint API --- components/script_plugins/lib.rs | 60 ++++++++++++++------------------ 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/components/script_plugins/lib.rs b/components/script_plugins/lib.rs index 895bf94de8e..396a63dca8a 100644 --- a/components/script_plugins/lib.rs +++ b/components/script_plugins/lib.rs @@ -217,14 +217,12 @@ impl<'tcx> LateLintPass<'tcx> for UnrootedPass { for ref field in def.fields() { let def_id = cx.tcx.hir().local_def_id(field.hir_id); if is_unrooted_ty(&self.symbols, cx, cx.tcx.type_of(def_id), false) { - cx.lint(UNROOTED_MUST_ROOT, |lint| { - lint.build( - "Type must be rooted, use #[unrooted_must_root_lint::must_root] \ - on the struct definition to propagate", - ) - .set_span(field.span) - .emit() - }) + cx.lint( + UNROOTED_MUST_ROOT, + "Type must be rooted, use #[unrooted_must_root_lint::must_root] \ + on the struct definition to propagate", + |lint| lint.set_span(field.span), + ) } } } @@ -242,15 +240,13 @@ impl<'tcx> LateLintPass<'tcx> for UnrootedPass { for field in fields { let def_id = cx.tcx.hir().local_def_id(field.hir_id); if is_unrooted_ty(&self.symbols, cx, cx.tcx.type_of(def_id), false) { - cx.lint(UNROOTED_MUST_ROOT, |lint| { - lint.build( - "Type must be rooted, \ - use #[unrooted_must_root_lint::must_root] \ - on the enum definition to propagate", - ) - .set_span(field.ty.span) - .emit() - }) + cx.lint( + UNROOTED_MUST_ROOT, + "Type must be rooted, \ + use #[unrooted_must_root_lint::must_root] \ + on the enum definition to propagate", + |lint| lint.set_span(field.ty.span), + ) } } }, @@ -281,8 +277,8 @@ impl<'tcx> LateLintPass<'tcx> for UnrootedPass { for (arg, ty) in decl.inputs.iter().zip(sig.inputs().skip_binder().iter()) { if is_unrooted_ty(&self.symbols, cx, *ty, false) { - cx.lint(UNROOTED_MUST_ROOT, |lint| { - lint.build("Type must be rooted").set_span(arg.span).emit() + cx.lint(UNROOTED_MUST_ROOT, "Type must be rooted", |lint| { + lint.set_span(arg.span) }) } } @@ -290,10 +286,8 @@ impl<'tcx> LateLintPass<'tcx> for UnrootedPass { if !in_new_function && is_unrooted_ty(&self.symbols, cx, sig.output().skip_binder(), false) { - cx.lint(UNROOTED_MUST_ROOT, |lint| { - lint.build("Type must be rooted") - .set_span(decl.output.span()) - .emit() + cx.lint(UNROOTED_MUST_ROOT, "Type must be rooted", |lint| { + lint.set_span(decl.output.span()) }) } } @@ -322,11 +316,11 @@ impl<'a, 'tcx> visit::Visitor<'tcx> for FnDefVisitor<'a, 'tcx> { let require_rooted = |cx: &LateContext, in_new_function: bool, subexpr: &hir::Expr| { let ty = cx.typeck_results().expr_ty(&subexpr); if is_unrooted_ty(&self.symbols, cx, ty, in_new_function) { - cx.lint(UNROOTED_MUST_ROOT, |lint| { - lint.build(&format!("Expression of type {:?} must be rooted", ty)) - .set_span(subexpr.span) - .emit() - }) + cx.lint( + UNROOTED_MUST_ROOT, + format!("Expression of type {:?} must be rooted", ty), + |lint| lint.set_span(subexpr.span), + ) } }; @@ -364,11 +358,11 @@ impl<'a, 'tcx> visit::Visitor<'tcx> for FnDefVisitor<'a, 'tcx> { hir::PatKind::Binding(hir::BindingAnnotation::MUT, ..) => { let ty = cx.typeck_results().pat_ty(pat); if is_unrooted_ty(self.symbols, cx, ty, self.in_new_function) { - cx.lint(UNROOTED_MUST_ROOT, |lint| { - lint.build(&format!("Expression of type {:?} must be rooted", ty)) - .set_span(pat.span) - .emit() - }) + cx.lint( + UNROOTED_MUST_ROOT, + format!("Expression of type {:?} must be rooted", ty), + |lint| lint.set_span(pat.span), + ) } }, _ => {}, From 24c19b60d597da9ca84e0522e7b11bdcef55907e Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 15 Oct 2022 00:34:51 +0900 Subject: [PATCH 16/16] chore: upgrade the Rust toolchain to `nightly-2022-10-13` --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 81fc95b62a3..19e67729bc3 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-10-02 +nightly-2022-10-13