diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-03-17 14:17:47 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-03-17 17:04:58 +0300 |
| commit | db74efce69711fcee03d3338afcbca67c27ceee8 (patch) | |
| tree | ab54b453943a292c250b890140d431e99091be5e /src/librustc | |
| parent | 7cf074a1e655ac07d04d045667278fa1a9970b93 (diff) | |
| download | rust-db74efce69711fcee03d3338afcbca67c27ceee8.tar.gz rust-db74efce69711fcee03d3338afcbca67c27ceee8.zip | |
Make meta-item API compatible with `LocalInternedString::get` soundness fix
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/hir/check_attr.rs | 12 | ||||
| -rw-r--r-- | src/librustc/lint/levels.rs | 2 | ||||
| -rw-r--r-- | src/librustc/lint/mod.rs | 7 | ||||
| -rw-r--r-- | src/librustc/middle/lib_features.rs | 6 | ||||
| -rw-r--r-- | src/librustc/middle/stability.rs | 11 | ||||
| -rw-r--r-- | src/librustc/traits/on_unimplemented.rs | 4 |
6 files changed, 14 insertions, 28 deletions
diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 8602d159ba9..4c527f80d0f 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -177,16 +177,8 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> { let mut is_transparent = false; for hint in &hints { - let name = if let Some(name) = hint.ident_str() { - name - } else { - // Invalid repr hint like repr(42). We don't check for unrecognized hints here - // (libsyntax does that), so just ignore it. - continue; - }; - - let (article, allowed_targets) = match name { - "C" | "align" => { + let (article, allowed_targets) = match hint.name_or_empty().get() { + name @ "C" | name @ "align" => { is_c |= name == "C"; if target != Target::Struct && target != Target::Union && diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index 19e899ceb42..2e5bd8add0c 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -194,7 +194,7 @@ impl<'a> LintLevelsBuilder<'a> { struct_span_err!(sess, span, E0452, "malformed lint attribute") }; for attr in attrs { - let level = match attr.ident_str().and_then(|name| Level::from_str(name)) { + let level = match Level::from_str(&attr.name_or_empty()) { None => continue, Some(lvl) => lvl, }; diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index b1ff66eb64f..f92e33582c4 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -723,12 +723,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session, pub fn maybe_lint_level_root(tcx: TyCtxt<'_, '_, '_>, id: hir::HirId) -> bool { let attrs = tcx.hir().attrs_by_hir_id(id); - for attr in attrs { - if attr.ident_str().and_then(Level::from_str).is_some() { - return true; - } - } - false + attrs.iter().any(|attr| Level::from_str(&attr.name_or_empty()).is_some()) } fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum) diff --git a/src/librustc/middle/lib_features.rs b/src/librustc/middle/lib_features.rs index 237b00db575..ee8dd9e58b5 100644 --- a/src/librustc/middle/lib_features.rs +++ b/src/librustc/middle/lib_features.rs @@ -65,9 +65,9 @@ impl<'a, 'tcx> LibFeatureCollector<'a, 'tcx> { for meta in metas { if let Some(mi) = meta.meta_item() { // Find the `feature = ".."` meta-item. - match (mi.ident_str(), mi.value_str()) { - (Some("feature"), val) => feature = val, - (Some("since"), val) => since = val, + match (mi.name_or_empty().get(), mi.value_str()) { + ("feature", val) => feature = val, + ("since", val) => since = val, _ => {} } } diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 2664d6eaa28..e63665574b9 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -194,12 +194,11 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { } else { // Emit errors for non-staged-api crates. for attr in attrs { - if let Some(tag) = attr.ident_str() { - if tag == "unstable" || tag == "stable" || tag == "rustc_deprecated" { - attr::mark_used(attr); - self.tcx.sess.span_err(attr.span, "stability attributes may not be used \ - outside of the standard library"); - } + let name = attr.name_or_empty(); + if ["unstable", "stable", "rustc_deprecated"].contains(&name.get()) { + attr::mark_used(attr); + self.tcx.sess.span_err(attr.span, "stability attributes may not be used \ + outside of the standard library"); } } diff --git a/src/librustc/traits/on_unimplemented.rs b/src/librustc/traits/on_unimplemented.rs index d0acaf674ae..2b286ee1b97 100644 --- a/src/librustc/traits/on_unimplemented.rs +++ b/src/librustc/traits/on_unimplemented.rs @@ -177,9 +177,9 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective { for command in self.subcommands.iter().chain(Some(self)).rev() { if let Some(ref condition) = command.condition { if !attr::eval_condition(condition, &tcx.sess.parse_sess, &mut |c| { - c.ident_str().map_or(false, |name| { + c.ident().map_or(false, |ident| { options.contains(&( - name.to_string(), + ident.to_string(), c.value_str().map(|s| s.as_str().to_string()) )) }) |
