-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restrict constants in patterns #32199
Changes from all commits
5bc2868
99c2a6b
05baf64
f69eb8e
73b4f06
56ebf2b
7f661ec
93e4443
944dc4a
2536ae5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1023,9 +1023,10 @@ impl f64 { | |
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[inline] | ||
pub fn asinh(self) -> f64 { | ||
match self { | ||
NEG_INFINITY => NEG_INFINITY, | ||
x => (x + ((x * x) + 1.0).sqrt()).ln(), | ||
if self == NEG_INFINITY { | ||
NEG_INFINITY | ||
} else { | ||
(self + ((self * self) + 1.0).sqrt()).ln() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (as above, I personally would have left this as a match and just changed its first clause to |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1304,6 +1304,31 @@ impl CodeMap { | |
return a; | ||
} | ||
|
||
/// Check if the backtrace `subtrace` contains `suptrace` as a prefix. | ||
pub fn more_specific_trace(&self, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: the name seems to imply that this method ought to produce a more specific backtrace. Perhaps “is_supertrace” or something would be more suitable? |
||
mut subtrace: ExpnId, | ||
suptrace: ExpnId) | ||
-> bool { | ||
loop { | ||
if subtrace == suptrace { | ||
return true; | ||
} | ||
|
||
let stop = self.with_expn_info(subtrace, |opt_expn_info| { | ||
if let Some(expn_info) = opt_expn_info { | ||
subtrace = expn_info.call_site.expn_id; | ||
false | ||
} else { | ||
true | ||
} | ||
}); | ||
|
||
if stop { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
pub fn record_expansion(&self, expn_info: ExpnInfo) -> ExpnId { | ||
let mut expansions = self.expansions.borrow_mut(); | ||
expansions.push(expn_info); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ use visit::Visitor; | |
use std_inject; | ||
|
||
use std::collections::HashSet; | ||
|
||
use std::env; | ||
|
||
pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> { | ||
let expr_span = e.span; | ||
|
@@ -1275,11 +1275,41 @@ impl<'a, 'b> MacroExpander<'a, 'b> { | |
} | ||
|
||
fn new_span(cx: &ExtCtxt, sp: Span) -> Span { | ||
/* this discards information in the case of macro-defining macros */ | ||
Span { | ||
lo: sp.lo, | ||
hi: sp.hi, | ||
expn_id: cx.backtrace(), | ||
debug!("new_span(sp={:?})", sp); | ||
|
||
if cx.codemap().more_specific_trace(sp.expn_id, cx.backtrace()) { | ||
// If the span we are looking at has a backtrace that has more | ||
// detail than our current backtrace, then we keep that | ||
// backtrace. Honestly, I have no idea if this makes sense, | ||
// because I have no idea why we are stripping the backtrace | ||
// below. But the reason I made this change is because, in | ||
// deriving, we were generating attributes with a specific | ||
// backtrace, which was essential for `#[structural_match]` to | ||
// be properly supported, but these backtraces were being | ||
// stripped and replaced with a null backtrace. Sort of | ||
// unclear why this is the case. --nmatsakis | ||
debug!("new_span: keeping trace from {:?} because it is more specific", | ||
sp.expn_id); | ||
sp | ||
} else { | ||
// This discards information in the case of macro-defining macros. | ||
// | ||
// The comment above was originally added in | ||
// b7ec2488ff2f29681fe28691d20fd2c260a9e454 in Feb 2012. I | ||
// *THINK* the reason we are doing this is because we want to | ||
// replace the backtrace of the macro contents with the | ||
// backtrace that contains the macro use. But it's pretty | ||
// unclear to me. --nmatsakis | ||
let sp1 = Span { | ||
lo: sp.lo, | ||
hi: sp.hi, | ||
expn_id: cx.backtrace(), | ||
}; | ||
debug!("new_span({:?}) = {:?}", sp, sp1); | ||
if sp.expn_id.into_u32() == 0 && env::var_os("NDM").is_some() { | ||
panic!("NDM"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, oops -- that was a debugging remnant, obviously :) should have left a |
||
} | ||
sp1 | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I personally would have left this as a match and just changed its first clause to
x if x == NEG_INFINITY => x
)