Skip to content

Commit 96da356

Browse files
committed
auto merge of #9090 : jbclements/rust/let-var-hygiene, r=luqmana
This appears to fix issue #9049. It also re-enables the ICE check on comparing idents for equality; it appears that ICEs are better than seg faults.
2 parents 485446b + 634bddd commit 96da356

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

src/librustc/middle/trans/_match.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,8 @@ fn enter_opt<'r>(bcx: @mut Block,
671671
let mut reordered_patterns = ~[];
672672
let r = ty::lookup_struct_fields(tcx, struct_id);
673673
for field in r.iter() {
674-
match field_pats.iter().find(|p| p.ident == field.ident) {
674+
match field_pats.iter().find(|p| p.ident.name
675+
== field.ident.name) {
675676
None => reordered_patterns.push(dummy),
676677
Some(fp) => reordered_patterns.push(fp.pat)
677678
}
@@ -752,7 +753,7 @@ fn enter_rec_or_struct<'r>(bcx: @mut Block,
752753
ast::PatStruct(_, ref fpats, _) => {
753754
let mut pats = ~[];
754755
for fname in fields.iter() {
755-
match fpats.iter().find(|p| p.ident == *fname) {
756+
match fpats.iter().find(|p| p.ident.name == fname.name) {
756757
None => pats.push(dummy),
757758
Some(pat) => pats.push(pat.pat)
758759
}
@@ -1102,7 +1103,7 @@ fn collect_record_or_struct_fields(bcx: @mut Block,
11021103
fn extend(idents: &mut ~[ast::Ident], field_pats: &[ast::FieldPat]) {
11031104
for field_pat in field_pats.iter() {
11041105
let field_ident = field_pat.ident;
1105-
if !idents.iter().any(|x| *x == field_ident) {
1106+
if !idents.iter().any(|x| x.name == field_ident.name) {
11061107
idents.push(field_ident);
11071108
}
11081109
}

src/librustc/middle/trans/reflect.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ impl Reflector {
256256
let fields = ty::struct_fields(tcx, did, substs);
257257
let mut named_fields = false;
258258
if !fields.is_empty() {
259-
named_fields = fields[0].ident != special_idents::unnamed_field;
259+
named_fields =
260+
fields[0].ident.name != special_idents::unnamed_field.name;
260261
}
261262

262263
let extra = ~[self.c_slice(ty_to_str(tcx, t).to_managed()),

src/libsyntax/ast.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,15 @@ use extra::serialize::{Encodable, Decodable, Encoder, Decoder};
2828
// table) and a SyntaxContext to track renaming and
2929
// macro expansion per Flatt et al., "Macros
3030
// That Work Together"
31-
#[deriving(Clone, Eq, IterBytes, ToStr)]
31+
#[deriving(Clone, IterBytes, ToStr)]
3232
pub struct Ident { name: Name, ctxt: SyntaxContext }
3333

3434
impl Ident {
3535
/// Construct an identifier with the given name and an empty context:
3636
pub fn new(name: Name) -> Ident { Ident {name: name, ctxt: EMPTY_CTXT}}
3737
}
3838

39-
// defining eq in this way is a way of guaranteeing that later stages of the
40-
// compiler don't compare identifiers unhygienically. Unfortunately, some tests
41-
// (specifically debuginfo in no-opt) want to do these comparisons, and that
42-
// seems fine. If only I could find a nice way to statically ensure that
43-
// the compiler "proper" never compares identifiers.... I'm leaving this
44-
// code here (commented out) for potential use in debugging. Specifically, if
45-
// there's a bug where "identifiers aren't matching", it may be because
46-
// they should be compared using mtwt_resolve. In such a case, re-enabling this
47-
// code (and disabling deriving(Eq) for Idents) could help to isolate the
48-
// problem
49-
/* impl Eq for Ident {
39+
impl Eq for Ident {
5040
fn eq(&self, other: &Ident) -> bool {
5141
if (self.ctxt == other.ctxt) {
5242
self.name == other.name
@@ -64,7 +54,6 @@ impl Ident {
6454
! self.eq(other)
6555
}
6656
}
67-
*/
6857

6958
/// A SyntaxContext represents a chain of macro-expandings
7059
/// and renamings. Each macro expansion corresponds to

src/test/run-pass/match-in-macro.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Foo {
12+
B { b1: int, bb1: int},
13+
}
14+
15+
macro_rules! match_inside_expansion(
16+
() => (
17+
match B { b1:29 , bb1: 100} {
18+
B { b1:b2 , bb1:bb2 } => b2+bb2
19+
}
20+
)
21+
)
22+
23+
fn main() {
24+
assert_eq!(match_inside_expansion!(),129);
25+
}

0 commit comments

Comments
 (0)