Skip to content

Commit 988c1b6

Browse files
committed
---
yaml --- r: 273212 b: refs/heads/beta c: abb1515 h: refs/heads/master
1 parent 6af4f9b commit 988c1b6

32 files changed

+244
-181
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 6cc06b36c4da7f21f43d663d6c8a8ee547651cde
26+
refs/heads/beta: abb1515c53d209be3e8c1e9e73c1a98bc86b8692
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc/middle/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
671671
}
672672
hir::ExprBinary(op, ref a, ref b) => {
673673
let b_ty = match op.node {
674-
hir::BiShl | hir::BiShr => ty_hint.checked_or(tcx.types.usize),
674+
hir::BiShl | hir::BiShr => ty_hint.erase_hint(),
675675
_ => ty_hint
676676
};
677677
// technically, if we don't have type hints, but integral eval

branches/beta/src/librustc/middle/liveness.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ use self::VarKind::*;
112112
use dep_graph::DepNode;
113113
use middle::def::*;
114114
use middle::pat_util;
115-
use middle::ty::{self, TyCtxt};
115+
use middle::ty::{self, TyCtxt, ParameterEnvironment};
116+
use middle::traits::{self, ProjectionMode};
117+
use middle::infer;
116118
use lint;
117119
use util::nodemap::NodeMap;
118120

@@ -1490,9 +1492,19 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
14901492

14911493
match fn_ret {
14921494
ty::FnConverging(t_ret)
1493-
if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() => {
1494-
1495-
if t_ret.is_nil() {
1495+
if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() => {
1496+
1497+
let param_env = ParameterEnvironment::for_item(&self.ir.tcx, id);
1498+
let infcx = infer::new_infer_ctxt(&self.ir.tcx,
1499+
&self.ir.tcx.tables,
1500+
Some(param_env),
1501+
ProjectionMode::Any);
1502+
let cause = traits::ObligationCause::dummy();
1503+
let norm = traits::fully_normalize(&infcx,
1504+
cause,
1505+
&t_ret);
1506+
1507+
if norm.unwrap().is_nil() {
14961508
// for nil return types, it is ok to not return a value expl.
14971509
} else {
14981510
let ends_with_stmt = match body.expr {

branches/beta/src/librustc_resolve/build_reduced_graph.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -105,36 +105,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
105105
/// otherwise, reports an error.
106106
fn define<T: ToNameBinding<'b>>(&self, parent: Module<'b>, name: Name, ns: Namespace, def: T) {
107107
let binding = def.to_name_binding();
108-
let old_binding = match parent.try_define_child(name, ns, binding.clone()) {
109-
Ok(()) => return,
110-
Err(old_binding) => old_binding,
111-
};
112-
113-
let span = binding.span.unwrap_or(DUMMY_SP);
114-
if !old_binding.is_extern_crate() && !binding.is_extern_crate() {
115-
// Record an error here by looking up the namespace that had the duplicate
116-
let ns_str = match ns { TypeNS => "type or module", ValueNS => "value" };
117-
let resolution_error = ResolutionError::DuplicateDefinition(ns_str, name);
118-
let mut err = resolve_struct_error(self, span, resolution_error);
119-
120-
if let Some(sp) = old_binding.span {
121-
let note = format!("first definition of {} `{}` here", ns_str, name);
122-
err.span_note(sp, &note);
123-
}
124-
err.emit();
125-
} else if old_binding.is_extern_crate() && binding.is_extern_crate() {
126-
span_err!(self.session,
127-
span,
128-
E0259,
129-
"an external crate named `{}` has already been imported into this module",
130-
name);
131-
} else {
132-
span_err!(self.session,
133-
span,
134-
E0260,
135-
"the name `{}` conflicts with an external crate \
136-
that has been imported into this module",
137-
name);
108+
if let Err(old_binding) = parent.try_define_child(name, ns, binding.clone()) {
109+
self.report_conflict(parent, name, ns, old_binding, &binding);
138110
}
139111
}
140112

branches/beta/src/librustc_resolve/lib.rs

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ pub enum ResolutionError<'a> {
183183
UndeclaredLabel(&'a str),
184184
/// error E0427: cannot use `ref` binding mode with ...
185185
CannotUseRefBindingModeWith(&'a str),
186-
/// error E0428: duplicate definition
187-
DuplicateDefinition(&'a str, Name),
188186
/// error E0429: `self` imports are only allowed within a { } list
189187
SelfImportsOnlyAllowedWithin,
190188
/// error E0430: `self` import can only appear once in the list
@@ -490,14 +488,6 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
490488
"cannot use `ref` binding mode with {}",
491489
descr)
492490
}
493-
ResolutionError::DuplicateDefinition(namespace, name) => {
494-
struct_span_err!(resolver.session,
495-
span,
496-
E0428,
497-
"duplicate definition of {} `{}`",
498-
namespace,
499-
name)
500-
}
501491
ResolutionError::SelfImportsOnlyAllowedWithin => {
502492
struct_span_err!(resolver.session,
503493
span,
@@ -3530,8 +3520,62 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
35303520
}
35313521
}
35323522
}
3533-
}
35343523

3524+
fn report_conflict(&self,
3525+
parent: Module,
3526+
name: Name,
3527+
ns: Namespace,
3528+
binding: &NameBinding,
3529+
old_binding: &NameBinding) {
3530+
// Error on the second of two conflicting names
3531+
if old_binding.span.unwrap().lo > binding.span.unwrap().lo {
3532+
return self.report_conflict(parent, name, ns, old_binding, binding);
3533+
}
3534+
3535+
let container = match parent.def {
3536+
Some(Def::Mod(_)) => "module",
3537+
Some(Def::Trait(_)) => "trait",
3538+
None => "block",
3539+
_ => "enum",
3540+
};
3541+
3542+
let (participle, noun) = match old_binding.is_import() || old_binding.is_extern_crate() {
3543+
true => ("imported", "import"),
3544+
false => ("defined", "definition"),
3545+
};
3546+
3547+
let span = binding.span.unwrap();
3548+
let msg = {
3549+
let kind = match (ns, old_binding.module()) {
3550+
(ValueNS, _) => "a value",
3551+
(TypeNS, Some(module)) if module.extern_crate_id.is_some() => "an extern crate",
3552+
(TypeNS, Some(module)) if module.is_normal() => "a module",
3553+
(TypeNS, Some(module)) if module.is_trait() => "a trait",
3554+
(TypeNS, _) => "a type",
3555+
};
3556+
format!("{} named `{}` has already been {} in this {}",
3557+
kind, name, participle, container)
3558+
};
3559+
3560+
let mut err = match (old_binding.is_extern_crate(), binding.is_extern_crate()) {
3561+
(true, true) => struct_span_err!(self.session, span, E0259, "{}", msg),
3562+
(true, _) | (_, true) if binding.is_import() || old_binding.is_import() =>
3563+
struct_span_err!(self.session, span, E0254, "{}", msg),
3564+
(true, _) | (_, true) => struct_span_err!(self.session, span, E0260, "{}", msg),
3565+
_ => match (old_binding.is_import(), binding.is_import()) {
3566+
(false, false) => struct_span_err!(self.session, span, E0428, "{}", msg),
3567+
(true, true) => struct_span_err!(self.session, span, E0252, "{}", msg),
3568+
_ => struct_span_err!(self.session, span, E0255, "{}", msg),
3569+
},
3570+
};
3571+
3572+
let span = old_binding.span.unwrap();
3573+
if span != codemap::DUMMY_SP {
3574+
err.span_note(span, &format!("previous {} of `{}` here", noun, name));
3575+
}
3576+
err.emit();
3577+
}
3578+
}
35353579

35363580
fn names_to_string(names: &[Name]) -> String {
35373581
let mut first = true;

branches/beta/src/librustc_resolve/resolve_imports.rs

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
513513
let imported_binding = directive.import(binding, privacy_error);
514514
let conflict = module_.try_define_child(target, ns, imported_binding);
515515
if let Err(old_binding) = conflict {
516-
self.report_conflict(target, ns, &directive.import(binding, None), old_binding);
516+
let binding = &directive.import(binding, None);
517+
self.resolver.report_conflict(module_, target, ns, binding, old_binding);
517518
}
518519
}
519520

@@ -650,67 +651,6 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
650651
return Success(());
651652
}
652653

653-
fn report_conflict(&mut self,
654-
name: Name,
655-
ns: Namespace,
656-
binding: &NameBinding,
657-
old_binding: &NameBinding) {
658-
// Error on the second of two conflicting imports
659-
if old_binding.is_import() && binding.is_import() &&
660-
old_binding.span.unwrap().lo > binding.span.unwrap().lo {
661-
self.report_conflict(name, ns, old_binding, binding);
662-
return;
663-
}
664-
665-
if old_binding.is_extern_crate() {
666-
let msg = format!("import `{0}` conflicts with imported crate \
667-
in this module (maybe you meant `use {0}::*`?)",
668-
name);
669-
span_err!(self.resolver.session, binding.span.unwrap(), E0254, "{}", &msg);
670-
} else if old_binding.is_import() {
671-
let ns_word = match (ns, old_binding.module()) {
672-
(ValueNS, _) => "value",
673-
(TypeNS, Some(module)) if module.is_normal() => "module",
674-
(TypeNS, Some(module)) if module.is_trait() => "trait",
675-
(TypeNS, _) => "type",
676-
};
677-
let mut err = struct_span_err!(self.resolver.session,
678-
binding.span.unwrap(),
679-
E0252,
680-
"a {} named `{}` has already been imported \
681-
in this module",
682-
ns_word,
683-
name);
684-
err.span_note(old_binding.span.unwrap(),
685-
&format!("previous import of `{}` here", name));
686-
err.emit();
687-
} else if ns == ValueNS { // Check for item conflicts in the value namespace
688-
let mut err = struct_span_err!(self.resolver.session,
689-
binding.span.unwrap(),
690-
E0255,
691-
"import `{}` conflicts with value in this module",
692-
name);
693-
err.span_note(old_binding.span.unwrap(), "conflicting value here");
694-
err.emit();
695-
} else { // Check for item conflicts in the type namespace
696-
let (what, note) = match old_binding.module() {
697-
Some(ref module) if module.is_normal() =>
698-
("existing submodule", "note conflicting module here"),
699-
Some(ref module) if module.is_trait() =>
700-
("trait in this module", "note conflicting trait here"),
701-
_ => ("type in this module", "note conflicting type here"),
702-
};
703-
let mut err = struct_span_err!(self.resolver.session,
704-
binding.span.unwrap(),
705-
E0256,
706-
"import `{}` conflicts with {}",
707-
name,
708-
what);
709-
err.span_note(old_binding.span.unwrap(), note);
710-
err.emit();
711-
}
712-
}
713-
714654
// Miscellaneous post-processing, including recording reexports, recording shadowed traits,
715655
// reporting conflicts, reporting the PRIVATE_IN_PUBLIC lint, and reporting unresolved imports.
716656
fn finalize_resolutions(&mut self, module: Module<'b>, report_unresolved_imports: bool) {
@@ -720,7 +660,10 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
720660

721661
let mut reexports = Vec::new();
722662
for (&(name, ns), resolution) in module.resolutions.borrow().iter() {
723-
resolution.report_conflicts(|b1, b2| self.report_conflict(name, ns, b1, b2));
663+
resolution.report_conflicts(|b1, b2| {
664+
self.resolver.report_conflict(module, name, ns, b1, b2)
665+
});
666+
724667
let binding = match resolution.binding {
725668
Some(binding) => binding,
726669
None => continue,

branches/beta/src/libsyntax/print/pprust.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,8 @@ pub trait PrintState<'a> {
752752
}
753753
try!(self.maybe_print_comment(attr.span.lo));
754754
if attr.node.is_sugared_doc {
755-
word(self.writer(), &attr.value_str().unwrap())
755+
try!(word(self.writer(), &attr.value_str().unwrap()));
756+
hardbreak(self.writer())
756757
} else {
757758
match attr.node.style {
758759
ast::AttrStyle::Inner => try!(word(self.writer(), "#![")),

branches/beta/src/test/compile-fail/blind-item-block-item-shadow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
{
1515
struct Bar;
1616
use foo::Bar;
17-
//~^ ERROR import `Bar` conflicts with type in this module
18-
//~^^ ERROR import `Bar` conflicts with value in this module
17+
//~^ ERROR a type named `Bar` has already been defined in this block
18+
//~^^ ERROR a value named `Bar` has already been defined in this block
1919
}
2020
}

branches/beta/src/test/compile-fail/blind-item-item-shadow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
mod foo { pub mod foo { } }
11+
mod foo { pub mod foo { } } //~ NOTE previous definition of `foo` here
1212

13-
use foo::foo; //~ ERROR import `foo` conflicts with existing submodule
13+
use foo::foo; //~ ERROR a module named `foo` has already been defined in this module
1414

1515
fn main() {}

branches/beta/src/test/compile-fail/enum-and-module-in-same-scope.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
enum Foo {
11+
enum Foo { //~ NOTE previous definition
1212
X
1313
}
1414

15-
mod Foo { //~ ERROR duplicate definition of type or module `Foo`
15+
mod Foo { //~ ERROR a type named `Foo` has already been defined
1616
pub static X: isize = 42;
1717
fn f() { f() } // Check that this does not result in a resolution error
1818
}

branches/beta/src/test/compile-fail/issue-19498.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use self::A; //~ ERROR import `A` conflicts with existing submodule
12-
use self::B; //~ ERROR import `B` conflicts with existing submodule
13-
mod A {}
14-
pub mod B {}
11+
use self::A; //~ NOTE previous import of `A` here
12+
use self::B; //~ NOTE previous import of `B` here
13+
mod A {} //~ ERROR a module named `A` has already been imported in this module
14+
pub mod B {} //~ ERROR a module named `B` has already been imported in this module
1515

1616
mod C {
17-
use C::D; //~ ERROR import `D` conflicts with existing submodule
18-
mod D {}
17+
use C::D; //~ NOTE previous import of `D` here
18+
mod D {} //~ ERROR a module named `D` has already been imported in this module
1919
}
2020

2121
fn main() {}

0 commit comments

Comments
 (0)