Skip to content

Commit cc0d63c

Browse files
committed
Remove attribute on match
1 parent dd13cc3 commit cc0d63c

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

src/librustc/hir/lowering.rs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,8 +1815,7 @@ impl<'a> LoweringContext<'a> {
18151815
let match_expr = P(self.expr_match(e.span,
18161816
into_iter_expr,
18171817
hir_vec![iter_arm],
1818-
hir::MatchSource::ForLoopDesugar,
1819-
ThinVec::new()));
1818+
hir::MatchSource::ForLoopDesugar));
18201819

18211820
// `{ let _result = ...; _result }`
18221821
// underscore prevents an unused_variables lint if the head diverges
@@ -1911,23 +1910,8 @@ impl<'a> LoweringContext<'a> {
19111910
self.arm(hir_vec![err_pat], ret_expr)
19121911
};
19131912

1914-
// #[allow(unreachable_patterns)]
1915-
let match_attr = {
1916-
// allow(unreachable_patterns)
1917-
let allow = {
1918-
let allow_ident = self.str_to_ident("allow");
1919-
let up_ident = self.str_to_ident("unreachable_patterns");
1920-
let up_meta_item = attr::mk_spanned_word_item(e.span, up_ident);
1921-
let up_nested = NestedMetaItemKind::MetaItem(up_meta_item);
1922-
let up_spanned = respan(e.span, up_nested);
1923-
attr::mk_spanned_list_item(e.span, allow_ident, vec![up_spanned])
1924-
};
1925-
attr::mk_spanned_attr_outer(e.span, attr::mk_attr_id(), allow)
1926-
};
1927-
1928-
let attrs = From::from(vec![match_attr]);
19291913
return self.expr_match(e.span, discr, hir_vec![err_arm, ok_arm],
1930-
hir::MatchSource::TryDesugar, attrs);
1914+
hir::MatchSource::TryDesugar);
19311915
}
19321916

19331917
ExprKind::Mac(_) => panic!("Shouldn't exist here"),
@@ -2110,10 +2094,9 @@ impl<'a> LoweringContext<'a> {
21102094
span: Span,
21112095
arg: P<hir::Expr>,
21122096
arms: hir::HirVec<hir::Arm>,
2113-
source: hir::MatchSource,
2114-
attrs: ThinVec<Attribute>)
2097+
source: hir::MatchSource)
21152098
-> hir::Expr {
2116-
self.expr(span, hir::ExprMatch(arg, arms, source), attrs)
2099+
self.expr(span, hir::ExprMatch(arg, arms, source), ThinVec::new())
21172100
}
21182101

21192102
fn expr_block(&mut self, b: P<hir::Block>, attrs: ThinVec<Attribute>) -> hir::Expr {

src/test/run-pass/unreachable-try-pattern.rs renamed to src/test/compile-fail/unreachable-try-pattern.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ fn bar(x: Result<!, i32>) -> Result<u32, i32> {
1616
x?
1717
}
1818

19+
fn foo(x: Result<!, i32>) -> Result<u32, i32> {
20+
let y = (match x { Ok(n) => Ok(n as u32), Err(e) => Err(e) })?;
21+
//~^ ERROR unreachable pattern
22+
//~| ERROR unreachable expression
23+
Ok(y)
24+
}
25+
1926
fn main() {
2027
let _ = bar(Err(123));
28+
let _ = foo(Err(123));
2129
}
2230

0 commit comments

Comments
 (0)