Skip to content

Commit d6fa011

Browse files
committed
Remove some unnecessary uses of Option.
These arguments are never `None`.
1 parent f3a9de9 commit d6fa011

File tree

6 files changed

+39
-40
lines changed

6 files changed

+39
-40
lines changed

src/librustc_attr/builtin.rs

+17-14
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub enum UnwindAttr {
8686
}
8787

8888
/// Determine what `#[unwind]` attribute is present in `attrs`, if any.
89-
pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Option<UnwindAttr> {
89+
pub fn find_unwind_attr(diagnostic: &Handler, attrs: &[Attribute]) -> Option<UnwindAttr> {
9090
attrs.iter().fold(None, |ia, attr| {
9191
if attr.check_name(sym::unwind) {
9292
if let Some(meta) = attr.meta() {
@@ -99,19 +99,22 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op
9999
}
100100
}
101101

102-
if let Some(d) = diagnostic {
103-
struct_span_err!(d, attr.span, E0633, "malformed `unwind` attribute input")
104-
.span_label(attr.span, "invalid argument")
105-
.span_suggestions(
106-
attr.span,
107-
"the allowed arguments are `allowed` and `aborts`",
108-
(vec!["allowed", "aborts"])
109-
.into_iter()
110-
.map(|s| format!("#[unwind({})]", s)),
111-
Applicability::MachineApplicable,
112-
)
113-
.emit();
114-
};
102+
struct_span_err!(
103+
diagnostic,
104+
attr.span,
105+
E0633,
106+
"malformed `unwind` attribute input"
107+
)
108+
.span_label(attr.span, "invalid argument")
109+
.span_suggestions(
110+
attr.span,
111+
"the allowed arguments are `allowed` and `aborts`",
112+
(vec!["allowed", "aborts"])
113+
.into_iter()
114+
.map(|s| format!("#[unwind({})]", s)),
115+
Applicability::MachineApplicable,
116+
)
117+
.emit();
115118
}
116119
}
117120
}

src/librustc_driver/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ impl RustcDefaultCalls {
677677
let t_outputs = rustc_interface::util::build_output_filenames(
678678
input, odir, ofile, attrs, sess,
679679
);
680-
let id = rustc_session::output::find_crate_name(Some(sess), attrs, input);
680+
let id = rustc_session::output::find_crate_name(sess, attrs, input);
681681
if *req == PrintRequest::CrateName {
682682
println!("{}", id);
683683
continue;

src/librustc_interface/queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl<'tcx> Queries<'tcx> {
159159
None => {
160160
let parse_result = self.parse()?;
161161
let krate = parse_result.peek();
162-
find_crate_name(Some(self.session()), &krate.attrs, &self.compiler.input)
162+
find_crate_name(self.session(), &krate.attrs, &self.compiler.input)
163163
}
164164
})
165165
})

src/librustc_metadata/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ impl<'a> CrateLoader<'a> {
895895
);
896896
let name = match orig_name {
897897
Some(orig_name) => {
898-
validate_crate_name(Some(self.sess), &orig_name.as_str(), Some(item.span));
898+
validate_crate_name(self.sess, &orig_name.as_str(), Some(item.span));
899899
orig_name
900900
}
901901
None => item.ident.name,

src/librustc_mir_build/build/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ macro_rules! unpack {
537537
fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: LocalDefId, _abi: Abi) -> bool {
538538
// Validate `#[unwind]` syntax regardless of platform-specific panic strategy.
539539
let attrs = &tcx.get_attrs(fn_def_id.to_def_id());
540-
let unwind_attr = attr::find_unwind_attr(Some(tcx.sess.diagnostic()), attrs);
540+
let unwind_attr = attr::find_unwind_attr(tcx.sess.diagnostic(), attrs);
541541

542542
// We never unwind, so it's not relevant to stop an unwind.
543543
if tcx.sess.panic_strategy() != PanicStrategy::Unwind {

src/librustc_session/output.rs

+18-22
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn is_writeable(p: &Path) -> bool {
4545
}
4646
}
4747

48-
pub fn find_crate_name(sess: Option<&Session>, attrs: &[ast::Attribute], input: &Input) -> String {
48+
pub fn find_crate_name(sess: &Session, attrs: &[ast::Attribute], input: &Input) -> String {
4949
let validate = |s: String, span: Option<Span>| {
5050
validate_crate_name(sess, &s, span);
5151
s
@@ -58,25 +58,24 @@ pub fn find_crate_name(sess: Option<&Session>, attrs: &[ast::Attribute], input:
5858
let attr_crate_name =
5959
attr::find_by_name(attrs, sym::crate_name).and_then(|at| at.value_str().map(|s| (at, s)));
6060

61-
if let Some(sess) = sess {
62-
if let Some(ref s) = sess.opts.crate_name {
63-
if let Some((attr, name)) = attr_crate_name {
64-
if name.as_str() != *s {
65-
let msg = format!(
66-
"`--crate-name` and `#[crate_name]` are \
67-
required to match, but `{}` != `{}`",
68-
s, name
69-
);
70-
sess.span_err(attr.span, &msg);
71-
}
61+
if let Some(ref s) = sess.opts.crate_name {
62+
if let Some((attr, name)) = attr_crate_name {
63+
if name.as_str() != *s {
64+
let msg = format!(
65+
"`--crate-name` and `#[crate_name]` are \
66+
required to match, but `{}` != `{}`",
67+
s, name
68+
);
69+
sess.span_err(attr.span, &msg);
7270
}
73-
return validate(s.clone(), None);
7471
}
72+
return validate(s.clone(), None);
7573
}
7674

7775
if let Some((attr, s)) = attr_crate_name {
7876
return validate(s.to_string(), Some(attr.span));
7977
}
78+
8079
if let Input::File(ref path) = *input {
8180
if let Some(s) = path.file_stem().and_then(|s| s.to_str()) {
8281
if s.starts_with('-') {
@@ -85,9 +84,7 @@ pub fn find_crate_name(sess: Option<&Session>, attrs: &[ast::Attribute], input:
8584
`{}` has a leading hyphen",
8685
s
8786
);
88-
if let Some(sess) = sess {
89-
sess.err(&msg);
90-
}
87+
sess.err(&msg);
9188
} else {
9289
return validate(s.replace("-", "_"), None);
9390
}
@@ -97,14 +94,13 @@ pub fn find_crate_name(sess: Option<&Session>, attrs: &[ast::Attribute], input:
9794
"rust_out".to_string()
9895
}
9996

100-
pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
97+
pub fn validate_crate_name(sess: &Session, s: &str, sp: Option<Span>) {
10198
let mut err_count = 0;
10299
{
103100
let mut say = |s: &str| {
104-
match (sp, sess) {
105-
(_, None) => panic!("{}", s),
106-
(Some(sp), Some(sess)) => sess.span_err(sp, s),
107-
(None, Some(sess)) => sess.err(s),
101+
match sp {
102+
Some(sp) => sess.span_err(sp, s),
103+
None => sess.err(s),
108104
}
109105
err_count += 1;
110106
};
@@ -123,7 +119,7 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
123119
}
124120

125121
if err_count > 0 {
126-
sess.unwrap().abort_if_errors();
122+
sess.abort_if_errors();
127123
}
128124
}
129125

0 commit comments

Comments
 (0)