mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Remove some unnecessary uses of Option
.
These arguments are never `None`.
This commit is contained in:
parent
f3a9de9b08
commit
d6fa011f62
@ -86,7 +86,7 @@ pub enum UnwindAttr {
|
||||
}
|
||||
|
||||
/// Determine what `#[unwind]` attribute is present in `attrs`, if any.
|
||||
pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Option<UnwindAttr> {
|
||||
pub fn find_unwind_attr(diagnostic: &Handler, attrs: &[Attribute]) -> Option<UnwindAttr> {
|
||||
attrs.iter().fold(None, |ia, attr| {
|
||||
if attr.check_name(sym::unwind) {
|
||||
if let Some(meta) = attr.meta() {
|
||||
@ -99,19 +99,22 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(d) = diagnostic {
|
||||
struct_span_err!(d, attr.span, E0633, "malformed `unwind` attribute input")
|
||||
.span_label(attr.span, "invalid argument")
|
||||
.span_suggestions(
|
||||
attr.span,
|
||||
"the allowed arguments are `allowed` and `aborts`",
|
||||
(vec!["allowed", "aborts"])
|
||||
.into_iter()
|
||||
.map(|s| format!("#[unwind({})]", s)),
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
.emit();
|
||||
};
|
||||
struct_span_err!(
|
||||
diagnostic,
|
||||
attr.span,
|
||||
E0633,
|
||||
"malformed `unwind` attribute input"
|
||||
)
|
||||
.span_label(attr.span, "invalid argument")
|
||||
.span_suggestions(
|
||||
attr.span,
|
||||
"the allowed arguments are `allowed` and `aborts`",
|
||||
(vec!["allowed", "aborts"])
|
||||
.into_iter()
|
||||
.map(|s| format!("#[unwind({})]", s)),
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -677,7 +677,7 @@ impl RustcDefaultCalls {
|
||||
let t_outputs = rustc_interface::util::build_output_filenames(
|
||||
input, odir, ofile, attrs, sess,
|
||||
);
|
||||
let id = rustc_session::output::find_crate_name(Some(sess), attrs, input);
|
||||
let id = rustc_session::output::find_crate_name(sess, attrs, input);
|
||||
if *req == PrintRequest::CrateName {
|
||||
println!("{}", id);
|
||||
continue;
|
||||
|
@ -159,7 +159,7 @@ impl<'tcx> Queries<'tcx> {
|
||||
None => {
|
||||
let parse_result = self.parse()?;
|
||||
let krate = parse_result.peek();
|
||||
find_crate_name(Some(self.session()), &krate.attrs, &self.compiler.input)
|
||||
find_crate_name(self.session(), &krate.attrs, &self.compiler.input)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -895,7 +895,7 @@ impl<'a> CrateLoader<'a> {
|
||||
);
|
||||
let name = match orig_name {
|
||||
Some(orig_name) => {
|
||||
validate_crate_name(Some(self.sess), &orig_name.as_str(), Some(item.span));
|
||||
validate_crate_name(self.sess, &orig_name.as_str(), Some(item.span));
|
||||
orig_name
|
||||
}
|
||||
None => item.ident.name,
|
||||
|
@ -537,7 +537,7 @@ macro_rules! unpack {
|
||||
fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: LocalDefId, _abi: Abi) -> bool {
|
||||
// Validate `#[unwind]` syntax regardless of platform-specific panic strategy.
|
||||
let attrs = &tcx.get_attrs(fn_def_id.to_def_id());
|
||||
let unwind_attr = attr::find_unwind_attr(Some(tcx.sess.diagnostic()), attrs);
|
||||
let unwind_attr = attr::find_unwind_attr(tcx.sess.diagnostic(), attrs);
|
||||
|
||||
// We never unwind, so it's not relevant to stop an unwind.
|
||||
if tcx.sess.panic_strategy() != PanicStrategy::Unwind {
|
||||
|
@ -45,7 +45,7 @@ fn is_writeable(p: &Path) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_crate_name(sess: Option<&Session>, attrs: &[ast::Attribute], input: &Input) -> String {
|
||||
pub fn find_crate_name(sess: &Session, attrs: &[ast::Attribute], input: &Input) -> String {
|
||||
let validate = |s: String, span: Option<Span>| {
|
||||
validate_crate_name(sess, &s, span);
|
||||
s
|
||||
@ -58,25 +58,24 @@ pub fn find_crate_name(sess: Option<&Session>, attrs: &[ast::Attribute], input:
|
||||
let attr_crate_name =
|
||||
attr::find_by_name(attrs, sym::crate_name).and_then(|at| at.value_str().map(|s| (at, s)));
|
||||
|
||||
if let Some(sess) = sess {
|
||||
if let Some(ref s) = sess.opts.crate_name {
|
||||
if let Some((attr, name)) = attr_crate_name {
|
||||
if name.as_str() != *s {
|
||||
let msg = format!(
|
||||
"`--crate-name` and `#[crate_name]` are \
|
||||
required to match, but `{}` != `{}`",
|
||||
s, name
|
||||
);
|
||||
sess.span_err(attr.span, &msg);
|
||||
}
|
||||
if let Some(ref s) = sess.opts.crate_name {
|
||||
if let Some((attr, name)) = attr_crate_name {
|
||||
if name.as_str() != *s {
|
||||
let msg = format!(
|
||||
"`--crate-name` and `#[crate_name]` are \
|
||||
required to match, but `{}` != `{}`",
|
||||
s, name
|
||||
);
|
||||
sess.span_err(attr.span, &msg);
|
||||
}
|
||||
return validate(s.clone(), None);
|
||||
}
|
||||
return validate(s.clone(), None);
|
||||
}
|
||||
|
||||
if let Some((attr, s)) = attr_crate_name {
|
||||
return validate(s.to_string(), Some(attr.span));
|
||||
}
|
||||
|
||||
if let Input::File(ref path) = *input {
|
||||
if let Some(s) = path.file_stem().and_then(|s| s.to_str()) {
|
||||
if s.starts_with('-') {
|
||||
@ -85,9 +84,7 @@ pub fn find_crate_name(sess: Option<&Session>, attrs: &[ast::Attribute], input:
|
||||
`{}` has a leading hyphen",
|
||||
s
|
||||
);
|
||||
if let Some(sess) = sess {
|
||||
sess.err(&msg);
|
||||
}
|
||||
sess.err(&msg);
|
||||
} else {
|
||||
return validate(s.replace("-", "_"), None);
|
||||
}
|
||||
@ -97,14 +94,13 @@ pub fn find_crate_name(sess: Option<&Session>, attrs: &[ast::Attribute], input:
|
||||
"rust_out".to_string()
|
||||
}
|
||||
|
||||
pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
|
||||
pub fn validate_crate_name(sess: &Session, s: &str, sp: Option<Span>) {
|
||||
let mut err_count = 0;
|
||||
{
|
||||
let mut say = |s: &str| {
|
||||
match (sp, sess) {
|
||||
(_, None) => panic!("{}", s),
|
||||
(Some(sp), Some(sess)) => sess.span_err(sp, s),
|
||||
(None, Some(sess)) => sess.err(s),
|
||||
match sp {
|
||||
Some(sp) => sess.span_err(sp, s),
|
||||
None => sess.err(s),
|
||||
}
|
||||
err_count += 1;
|
||||
};
|
||||
@ -123,7 +119,7 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
|
||||
}
|
||||
|
||||
if err_count > 0 {
|
||||
sess.unwrap().abort_if_errors();
|
||||
sess.abort_if_errors();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user