diff options
| author | bors <bors@rust-lang.org> | 2019-11-04 09:00:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-11-04 09:00:39 +0000 |
| commit | ab6e47851b51a413db5d721f25d714653e7549fd (patch) | |
| tree | 31b2ec020f7c4c139561fdb05b6357574f91d5f7 /src/librustc_interface/util.rs | |
| parent | cba93685377bc74a2fde1eb8e7a086039b038e94 (diff) | |
| parent | c68df7c503676a1f63c0fcc2a7f10597fb93c375 (diff) | |
| download | rust-ab6e47851b51a413db5d721f25d714653e7549fd.tar.gz rust-ab6e47851b51a413db5d721f25d714653e7549fd.zip | |
Auto merge of #65835 - Mark-Simulacrum:lockless-lintbuffer, r=nikomatsakis
Remove LintBuffer from Session This moves the `LintBuffer` from `Session` into the `Resolver`, where it is used until lowering is done and then consumed by early lint passes. This also happily removes the failure mode of buffering lints too late where it would have previously lead to ICEs; it is statically no longer possible to do so. I suspect that with a bit more work a similar move could be done for the lint buffer inside `ParseSess`, but this PR doesn't touch it (in part to keep itself small). The last commit is the "interesting" commit -- the ones before it don't work (though they compile) as they sort of prepare the various crates for the lint buffer to be passed in rather than accessed through Session.
Diffstat (limited to 'src/librustc_interface/util.rs')
| -rw-r--r-- | src/librustc_interface/util.rs | 109 |
1 files changed, 59 insertions, 50 deletions
diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index 8f11dc93727..d0c15073f16 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -526,6 +526,63 @@ pub(crate) fn compute_crate_disambiguator(session: &Session) -> CrateDisambiguat CrateDisambiguator::from(hasher.finish::<Fingerprint>()) } +pub(crate) fn check_attr_crate_type(attrs: &[ast::Attribute], lint_buffer: &mut lint::LintBuffer) { + // Unconditionally collect crate types from attributes to make them used + for a in attrs.iter() { + if a.check_name(sym::crate_type) { + if let Some(n) = a.value_str() { + if let Some(_) = categorize_crate_type(n) { + return; + } + + if let ast::MetaItemKind::NameValue(spanned) = a.meta().unwrap().kind { + let span = spanned.span; + let lev_candidate = find_best_match_for_name( + CRATE_TYPES.iter().map(|(k, _)| k), + &n.as_str(), + None + ); + if let Some(candidate) = lev_candidate { + lint_buffer.buffer_lint_with_diagnostic( + lint::builtin::UNKNOWN_CRATE_TYPES, + ast::CRATE_NODE_ID, + span, + "invalid `crate_type` value", + lint::builtin::BuiltinLintDiagnostics:: + UnknownCrateTypes( + span, + "did you mean".to_string(), + format!("\"{}\"", candidate) + ) + ); + } else { + lint_buffer.buffer_lint( + lint::builtin::UNKNOWN_CRATE_TYPES, + ast::CRATE_NODE_ID, + span, + "invalid `crate_type` value" + ); + } + } + } + } + } +} + +const CRATE_TYPES: &[(Symbol, config::CrateType)] = &[ + (sym::rlib, config::CrateType::Rlib), + (sym::dylib, config::CrateType::Dylib), + (sym::cdylib, config::CrateType::Cdylib), + (sym::lib, config::default_lib_output()), + (sym::staticlib, config::CrateType::Staticlib), + (sym::proc_dash_macro, config::CrateType::ProcMacro), + (sym::bin, config::CrateType::Executable), +]; + +fn categorize_crate_type(s: Symbol) -> Option<config::CrateType> { + Some(CRATE_TYPES.iter().find(|(key, _)| *key == s)?.1) +} + pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<config::CrateType> { // Unconditionally collect crate types from attributes to make them used let attr_types: Vec<config::CrateType> = attrs @@ -533,56 +590,8 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c .filter_map(|a| { if a.check_name(sym::crate_type) { match a.value_str() { - Some(sym::rlib) => Some(config::CrateType::Rlib), - Some(sym::dylib) => Some(config::CrateType::Dylib), - Some(sym::cdylib) => Some(config::CrateType::Cdylib), - Some(sym::lib) => Some(config::default_lib_output()), - Some(sym::staticlib) => Some(config::CrateType::Staticlib), - Some(sym::proc_dash_macro) => Some(config::CrateType::ProcMacro), - Some(sym::bin) => Some(config::CrateType::Executable), - Some(n) => { - let crate_types = vec![ - sym::rlib, - sym::dylib, - sym::cdylib, - sym::lib, - sym::staticlib, - sym::proc_dash_macro, - sym::bin - ]; - - if let ast::MetaItemKind::NameValue(spanned) = a.meta().unwrap().kind { - let span = spanned.span; - let lev_candidate = find_best_match_for_name( - crate_types.iter(), - &n.as_str(), - None - ); - if let Some(candidate) = lev_candidate { - session.buffer_lint_with_diagnostic( - lint::builtin::UNKNOWN_CRATE_TYPES, - ast::CRATE_NODE_ID, - span, - "invalid `crate_type` value", - lint::builtin::BuiltinLintDiagnostics:: - UnknownCrateTypes( - span, - "did you mean".to_string(), - format!("\"{}\"", candidate) - ) - ); - } else { - session.buffer_lint( - lint::builtin::UNKNOWN_CRATE_TYPES, - ast::CRATE_NODE_ID, - span, - "invalid `crate_type` value" - ); - } - } - None - } - None => None + Some(s) => categorize_crate_type(s), + _ => None, } } else { None |
