Skip to content

Commit 248765a

Browse files
committed
auto merge of #9135 : jbclements/rust/let-var-hygiene, r=erickt
Fixes issue #9110, changes field_ty element to Name, adds test case, improves fail error message
2 parents 5f97dbe + de5b9b9 commit 248765a

File tree

10 files changed

+47
-19
lines changed

10 files changed

+47
-19
lines changed

Diff for: src/librustc/metadata/decoder.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1202,10 +1202,11 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: Cmd, id: ast::NodeId)
12021202
do reader::tagged_docs(item, tag_item_field) |an_item| {
12031203
let f = item_family(an_item);
12041204
if f == PublicField || f == PrivateField || f == InheritedField {
1205+
// FIXME #6993: name should be of type Name, not Ident
12051206
let name = item_name(intr, an_item);
12061207
let did = item_def_id(an_item, cdata);
12071208
result.push(ty::field_ty {
1208-
ident: name,
1209+
name: name.name,
12091210
id: did, vis:
12101211
struct_field_family_to_visibility(f),
12111212
});
@@ -1215,7 +1216,7 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: Cmd, id: ast::NodeId)
12151216
do reader::tagged_docs(item, tag_item_unnamed_field) |an_item| {
12161217
let did = item_def_id(an_item, cdata);
12171218
result.push(ty::field_ty {
1218-
ident: special_idents::unnamed_field,
1219+
name: special_idents::unnamed_field.name,
12191220
id: did,
12201221
vis: ast::inherited,
12211222
});

Diff for: src/librustc/middle/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ pub fn specialize(cx: &MatchCheckCtxt,
700700
}
701701
let args = class_fields.iter().map(|class_field| {
702702
match flds.iter().find(|f|
703-
f.ident == class_field.ident) {
703+
f.ident.name == class_field.name) {
704704
Some(f) => f.pat,
705705
_ => wild()
706706
}

Diff for: src/librustc/middle/mem_categorization.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ impl mem_categorization_ctxt {
10591059
/// an enum to determine which variant is in use.
10601060
pub fn field_mutbl(tcx: ty::ctxt,
10611061
base_ty: ty::t,
1062+
// FIXME #6993: change type to Name
10621063
f_name: ast::Ident,
10631064
node_id: ast::NodeId)
10641065
-> Option<ast::Mutability> {
@@ -1067,7 +1068,7 @@ pub fn field_mutbl(tcx: ty::ctxt,
10671068
ty::ty_struct(did, _) => {
10681069
let r = ty::lookup_struct_fields(tcx, did);
10691070
for fld in r.iter() {
1070-
if fld.ident == f_name {
1071+
if fld.name == f_name.name {
10711072
return Some(ast::MutImmutable);
10721073
}
10731074
}
@@ -1077,7 +1078,7 @@ pub fn field_mutbl(tcx: ty::ctxt,
10771078
ast::DefVariant(_, variant_id, _) => {
10781079
let r = ty::lookup_struct_fields(tcx, variant_id);
10791080
for fld in r.iter() {
1080-
if fld.ident == f_name {
1081+
if fld.name == f_name.name {
10811082
return Some(ast::MutImmutable);
10821083
}
10831084
}

Diff for: src/librustc/middle/privacy.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,11 @@ impl PrivacyVisitor {
203203
}
204204

205205
// Checks that a private field is in scope.
206+
// FIXME #6993: change type (and name) from Ident to Name
206207
fn check_field(&mut self, span: Span, id: ast::DefId, ident: ast::Ident) {
207208
let fields = ty::lookup_struct_fields(self.tcx, id);
208209
for field in fields.iter() {
209-
if field.ident.name != ident.name { loop; }
210+
if field.name != ident.name { loop; }
210211
if field.vis == private {
211212
self.tcx.sess.span_err(span, fmt!("field `%s` is private",
212213
token::ident_to_str(&ident)));

Diff for: src/librustc/middle/trans/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ fn enter_opt<'r>(bcx: @mut Block,
672672
let r = ty::lookup_struct_fields(tcx, struct_id);
673673
for field in r.iter() {
674674
match field_pats.iter().find(|p| p.ident.name
675-
== field.ident.name) {
675+
== field.name) {
676676
None => reordered_patterns.push(dummy),
677677
Some(fp) => reordered_patterns.push(fp.pat)
678678
}

Diff for: src/librustc/middle/ty.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub enum SelfMode {
156156
}
157157

158158
pub struct field_ty {
159-
ident: Ident,
159+
name: Name,
160160
id: DefId,
161161
vis: ast::visibility,
162162
}
@@ -1757,7 +1757,7 @@ fn type_is_newtype_immediate(cx: ctxt, ty: t) -> bool {
17571757
ty_struct(def_id, ref substs) => {
17581758
let fields = struct_fields(cx, def_id, substs);
17591759
fields.len() == 1 &&
1760-
fields[0].ident == token::special_idents::unnamed_field &&
1760+
fields[0].ident.name == token::special_idents::unnamed_field.name &&
17611761
type_is_immediate(cx, fields[0].mt.ty)
17621762
}
17631763
_ => false
@@ -4227,15 +4227,15 @@ fn struct_field_tys(fields: &[@struct_field]) -> ~[field_ty] {
42274227
match field.node.kind {
42284228
named_field(ident, visibility) => {
42294229
field_ty {
4230-
ident: ident,
4230+
name: ident.name,
42314231
id: ast_util::local_def(field.node.id),
42324232
vis: visibility,
42334233
}
42344234
}
42354235
unnamed_field => {
42364236
field_ty {
4237-
ident:
4238-
syntax::parse::token::special_idents::unnamed_field,
4237+
name:
4238+
syntax::parse::token::special_idents::unnamed_field.name,
42394239
id: ast_util::local_def(field.node.id),
42404240
vis: ast::public,
42414241
}
@@ -4250,7 +4250,8 @@ pub fn struct_fields(cx: ctxt, did: ast::DefId, substs: &substs)
42504250
-> ~[field] {
42514251
do lookup_struct_fields(cx, did).map |f| {
42524252
field {
4253-
ident: f.ident,
4253+
// FIXME #6993: change type of field to Name and get rid of new()
4254+
ident: ast::Ident::new(f.name),
42544255
mt: mt {
42554256
ty: lookup_field_type(cx, did, f.id, substs),
42564257
mutbl: MutImmutable

Diff for: src/librustc/middle/typeck/check/_match.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use middle::typeck::require_same_types;
2121
use std::hashmap::{HashMap, HashSet};
2222
use syntax::ast;
2323
use syntax::ast_util;
24+
use syntax::parse::token;
2425
use syntax::codemap::Span;
2526
use syntax::print::pprust;
2627

@@ -296,7 +297,7 @@ pub fn check_struct_pat_fields(pcx: &pat_ctxt,
296297
// Index the class fields.
297298
let mut field_map = HashMap::new();
298299
for (i, class_field) in class_fields.iter().enumerate() {
299-
field_map.insert(class_field.ident.name, i);
300+
field_map.insert(class_field.name, i);
300301
}
301302
302303
// Typecheck each field.
@@ -333,7 +334,7 @@ pub fn check_struct_pat_fields(pcx: &pat_ctxt,
333334
}
334335
tcx.sess.span_err(span,
335336
fmt!("pattern does not mention field `%s`",
336-
tcx.sess.str_of(field.ident)));
337+
token::interner_get(field.name)));
337338
}
338339
}
339340
}

Diff for: src/librustc/middle/typeck/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ pub fn lookup_field_ty(tcx: ty::ctxt,
11201120
fieldname: ast::Name,
11211121
substs: &ty::substs) -> Option<ty::t> {
11221122

1123-
let o_field = items.iter().find(|f| f.ident.name == fieldname);
1123+
let o_field = items.iter().find(|f| f.name == fieldname);
11241124
do o_field.map() |f| {
11251125
ty::lookup_field_type(tcx, class_id, f.id, substs)
11261126
}
@@ -2018,7 +2018,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
20182018
let mut class_field_map = HashMap::new();
20192019
let mut fields_found = 0;
20202020
for field in field_types.iter() {
2021-
class_field_map.insert(field.ident.name, (field.id, false));
2021+
class_field_map.insert(field.name, (field.id, false));
20222022
}
20232023

20242024
let mut error_happened = false;
@@ -2070,7 +2070,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
20702070
if fields_found < field_types.len() {
20712071
let mut missing_fields = ~[];
20722072
for class_field in field_types.iter() {
2073-
let name = class_field.ident.name;
2073+
let name = class_field.name;
20742074
let (_, seen) = *class_field_map.get(&name);
20752075
if !seen {
20762076
missing_fields.push(

Diff for: src/libsyntax/ast.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ impl Eq for Ident {
4747
// if it should be non-hygienic (most things are), just compare the
4848
// 'name' fields of the idents. Or, even better, replace the idents
4949
// with Name's.
50-
fail!(fmt!("not allowed to compare these idents: %?, %?", self, other));
50+
fail!(fmt!("not allowed to compare these idents: %?, %?. Probably \
51+
related to issue #6993", self, other));
5152
}
5253
}
5354
fn ne(&self, other: &Ident) -> bool {

Diff for: src/test/run-pass/issue-9110.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2013 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+
macro_rules! silly_macro(
12+
() => (
13+
pub mod Qux {
14+
pub struct Foo { x : u8 }
15+
pub fn bar(_foo : Foo) {}
16+
}
17+
);
18+
)
19+
20+
silly_macro!()
21+
22+
fn main() {}

0 commit comments

Comments
 (0)