Skip to content

Commit

Permalink
fix(script_plugins): replace `TyCtxt::{get_attrs -> get_attrs_uncheck…
Browse files Browse the repository at this point in the history
…ed}`

[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 also a discussion
about [supporting][2] this use case.

[1]: rust-lang/rust#95562
[2]: https://github.com/rust-lang/rust/pull/95562/files#r915537557
  • Loading branch information
yvt committed Oct 16, 2022
1 parent 37d09eb commit b8e0ae4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/script_plugins/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8e0ae4

Please sign in to comment.