Skip to content

Commit d91b32b

Browse files
committed
Auto merge of #59256 - petrochenkov:derval2, r=Zoxc
Make meta-item API compatible with `LocalInternedString::get` soundness fix r? @Zoxc
2 parents 3f36ac4 + db74efc commit d91b32b

File tree

17 files changed

+84
-97
lines changed

17 files changed

+84
-97
lines changed

src/librustc/hir/check_attr.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,8 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
177177
let mut is_transparent = false;
178178

179179
for hint in &hints {
180-
let name = if let Some(name) = hint.ident_str() {
181-
name
182-
} else {
183-
// Invalid repr hint like repr(42). We don't check for unrecognized hints here
184-
// (libsyntax does that), so just ignore it.
185-
continue;
186-
};
187-
188-
let (article, allowed_targets) = match name {
189-
"C" | "align" => {
180+
let (article, allowed_targets) = match hint.name_or_empty().get() {
181+
name @ "C" | name @ "align" => {
190182
is_c |= name == "C";
191183
if target != Target::Struct &&
192184
target != Target::Union &&

src/librustc/lint/levels.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'a> LintLevelsBuilder<'a> {
194194
struct_span_err!(sess, span, E0452, "malformed lint attribute")
195195
};
196196
for attr in attrs {
197-
let level = match attr.ident_str().and_then(|name| Level::from_str(name)) {
197+
let level = match Level::from_str(&attr.name_or_empty()) {
198198
None => continue,
199199
Some(lvl) => lvl,
200200
};

src/librustc/lint/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -723,12 +723,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
723723

724724
pub fn maybe_lint_level_root(tcx: TyCtxt<'_, '_, '_>, id: hir::HirId) -> bool {
725725
let attrs = tcx.hir().attrs_by_hir_id(id);
726-
for attr in attrs {
727-
if attr.ident_str().and_then(Level::from_str).is_some() {
728-
return true;
729-
}
730-
}
731-
false
726+
attrs.iter().any(|attr| Level::from_str(&attr.name_or_empty()).is_some())
732727
}
733728

734729
fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum)

src/librustc/middle/lib_features.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ impl<'a, 'tcx> LibFeatureCollector<'a, 'tcx> {
6565
for meta in metas {
6666
if let Some(mi) = meta.meta_item() {
6767
// Find the `feature = ".."` meta-item.
68-
match (mi.ident_str(), mi.value_str()) {
69-
(Some("feature"), val) => feature = val,
70-
(Some("since"), val) => since = val,
68+
match (mi.name_or_empty().get(), mi.value_str()) {
69+
("feature", val) => feature = val,
70+
("since", val) => since = val,
7171
_ => {}
7272
}
7373
}

src/librustc/middle/stability.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,11 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
194194
} else {
195195
// Emit errors for non-staged-api crates.
196196
for attr in attrs {
197-
if let Some(tag) = attr.ident_str() {
198-
if tag == "unstable" || tag == "stable" || tag == "rustc_deprecated" {
199-
attr::mark_used(attr);
200-
self.tcx.sess.span_err(attr.span, "stability attributes may not be used \
201-
outside of the standard library");
202-
}
197+
let name = attr.name_or_empty();
198+
if ["unstable", "stable", "rustc_deprecated"].contains(&name.get()) {
199+
attr::mark_used(attr);
200+
self.tcx.sess.span_err(attr.span, "stability attributes may not be used \
201+
outside of the standard library");
203202
}
204203
}
205204

src/librustc/traits/on_unimplemented.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective {
177177
for command in self.subcommands.iter().chain(Some(self)).rev() {
178178
if let Some(ref condition) = command.condition {
179179
if !attr::eval_condition(condition, &tcx.sess.parse_sess, &mut |c| {
180-
c.ident_str().map_or(false, |name| {
180+
c.ident().map_or(false, |ident| {
181181
options.contains(&(
182-
name.to_string(),
182+
ident.to_string(),
183183
c.value_str().map(|s| s.as_str().to_string())
184184
))
185185
})

src/librustc_incremental/persist/dirty_clean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,8 @@ fn expect_associated_value(tcx: TyCtxt<'_, '_, '_>, item: &NestedMetaItem) -> as
576576
if let Some(value) = item.value_str() {
577577
value
578578
} else {
579-
let msg = if let Some(name) = item.ident_str() {
580-
format!("associated value expected for `{}`", name)
579+
let msg = if let Some(ident) = item.ident() {
580+
format!("associated value expected for `{}`", ident)
581581
} else {
582582
"expected an associated value".to_string()
583583
};

src/librustc_lint/builtin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,9 @@ impl LintPass for DeprecatedAttr {
756756

757757
impl EarlyLintPass for DeprecatedAttr {
758758
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
759+
let name = attr.name_or_empty();
759760
for &&(n, _, _, ref g) in &self.depr_attrs {
760-
if attr.ident_str() == Some(n) {
761+
if name == n {
761762
if let &AttributeGate::Gated(Stability::Deprecated(link, suggestion),
762763
ref name,
763764
ref reason,

src/librustc_lint/unused.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,21 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
267267
}
268268
}
269269

270-
let name = attr.ident_str();
270+
let name = attr.name_or_empty();
271271
if !attr::is_used(attr) {
272272
debug!("Emitting warning for: {:?}", attr);
273273
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute");
274274
// Is it a builtin attribute that must be used at the crate level?
275275
let known_crate = BUILTIN_ATTRIBUTES.iter()
276276
.find(|&&(builtin, ty, ..)| {
277-
name == Some(builtin) && ty == AttributeType::CrateLevel
277+
name == builtin && ty == AttributeType::CrateLevel
278278
})
279279
.is_some();
280280

281281
// Has a plugin registered this attribute as one that must be used at
282282
// the crate level?
283283
let plugin_crate = plugin_attributes.iter()
284-
.find(|&&(ref x, t)| name == Some(x) && AttributeType::CrateLevel == t)
284+
.find(|&&(ref x, t)| name == x.as_str() && AttributeType::CrateLevel == t)
285285
.is_some();
286286
if known_crate || plugin_crate {
287287
let msg = match attr.style {

src/librustc_passes/layout_test.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ impl<'a, 'tcx> VarianceTest<'a, 'tcx> {
5353
// The `..` are the names of fields to dump.
5454
let meta_items = attr.meta_item_list().unwrap_or_default();
5555
for meta_item in meta_items {
56-
let name = meta_item.ident_str().unwrap_or("");
57-
match name {
56+
match meta_item.name_or_empty().get() {
5857
"abi" => {
5958
self.tcx
6059
.sess
@@ -84,7 +83,7 @@ impl<'a, 'tcx> VarianceTest<'a, 'tcx> {
8483
);
8584
}
8685

87-
_ => {
86+
name => {
8887
self.tcx.sess.span_err(
8988
meta_item.span(),
9089
&format!("unrecognized field name `{}`", name),

0 commit comments

Comments
 (0)