Skip to content
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

Refer to types using the local identifier #44642

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub struct LifetimeDef {
}

/// A "Path" is essentially Rust's notion of a name; for instance:
/// std::cmp::PartialEq . It's represented as a sequence of identifiers,
/// `std::cmp::PartialEq`. It's represented as a sequence of identifiers,
/// along with a bunch of supporting information.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
pub struct Path {
Expand Down
776 changes: 517 additions & 259 deletions src/librustc/infer/error_reporting/mod.rs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/librustc/middle/const_val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ impl<'tcx> ConstVal<'tcx> {
_ => None
}
}

pub fn to_usize(&self) -> Option<usize> {
self.to_const_int().and_then(|i| i.to_usize())
}
}

#[derive(Clone, Debug)]
Expand Down
4 changes: 4 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.all_crate_nums(LOCAL_CRATE)
}

pub fn cstore(&self) -> &CrateStore {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @alexcrichton removed this for a reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure. This was a quick fix after rebasing against master to get the code as I had written it working. I fully intend to clean this up before attempting to merge this PR.

self.cstore
}

pub fn def_key(self, id: DefId) -> hir_map::DefKey {
if id.is_local() {
self.hir.def_key(id)
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1469,4 +1469,10 @@ pub struct Const<'tcx> {
pub val: ConstVal<'tcx>,
}

impl<'tcx> Const<'tcx> {
pub fn usize_val(&self) -> usize {
self.val.to_usize().unwrap_or(0)
}
}

impl<'tcx> serialize::UseSpecializedDecodable for &'tcx Const<'tcx> {}
9 changes: 9 additions & 0 deletions src/librustc_const_math/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ impl ConstInt {
})
}

/// Converts the value to a `usize` if it's in the range 0...std::usize::MAX
pub fn to_usize(&self) -> Option<usize> {
self.to_u128().and_then(|v| if v <= usize::max_value() as u128 {
Some(v as usize)
} else {
None
})
}

/// Converts the value to a `u128` if it's in the range 0...std::u128::MAX
pub fn to_u128(&self) -> Option<u128> {
match *self {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_errors/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct SubDiagnostic {
pub render_span: Option<RenderSpan>,
}

#[derive(PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq)]
pub struct DiagnosticStyledString(pub Vec<StringPart>);

impl DiagnosticStyledString {
Expand All @@ -62,7 +62,7 @@ impl DiagnosticStyledString {
}
}

#[derive(PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq)]
pub enum StringPart {
Normal(String),
Highlighted(String),
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/bad-const-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

static i: String = 10;
//~^ ERROR mismatched types
//~| expected type `std::string::String`
//~| expected type `String`
//~| found type `{integer}`
//~| expected struct `std::string::String`, found integral variable
fn main() { println!("{}", i); }
2 changes: 1 addition & 1 deletion src/test/compile-fail/cross-borrow-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ pub fn main() {
let x: Box<Trait> = Box::new(Foo);
let _y: &Trait = x; //~ ERROR E0308
//~| expected type `&Trait`
//~| found type `std::boxed::Box<Trait>`
//~| found type `Box<Trait>`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/destructure-trait-ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ fn main() {
let box box x = box 1isize as Box<T>;
//~^ ERROR mismatched types
//~| expected type `T`
//~| found type `std::boxed::Box<_>`
//~| found type `Box<_>`
}
6 changes: 3 additions & 3 deletions src/test/compile-fail/fn-trait-formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ fn main() {
let _: () = (box |_: isize| {}) as Box<FnOnce(isize)>;
//~^ ERROR mismatched types
//~| expected type `()`
//~| found type `std::boxed::Box<std::ops::FnOnce(isize)>`
//~| found type `Box<std::ops::FnOnce(isize)>`
let _: () = (box |_: isize, isize| {}) as Box<Fn(isize, isize)>;
//~^ ERROR mismatched types
//~| expected type `()`
//~| found type `std::boxed::Box<std::ops::Fn(isize, isize)>`
//~| found type `Box<std::ops::Fn(isize, isize)>`
let _: () = (box || -> isize { unimplemented!() }) as Box<FnMut() -> isize>;
//~^ ERROR mismatched types
//~| expected type `()`
//~| found type `std::boxed::Box<std::ops::FnMut() -> isize>`
//~| found type `Box<std::ops::FnMut() -> isize>`

needs_fn(1);
//~^ ERROR : std::ops::Fn<(isize,)>`
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/fully-qualified-type-name1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() {
let x: Option<usize>;
x = 5;
//~^ ERROR mismatched types
//~| expected type `std::option::Option<usize>`
//~| expected type `Option<usize>`
//~| found type `{integer}`
//~| expected enum `std::option::Option`, found integral variable
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/fully-qualified-type-name4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::option::Option;
fn bar(x: usize) -> Option<usize> {
return x;
//~^ ERROR mismatched types
//~| expected type `std::option::Option<usize>`
//~| expected type `Option<usize>`
//~| found type `usize`
//~| expected enum `std::option::Option`, found usize
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/generic-type-params-name-repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ fn main() {
// Including cases where the default is using previous type params.
let _: HashMap<String, isize> = ();
//~^ ERROR mismatched types
//~| expected type `HashMap<std::string::String, isize>`
//~| expected type `HashMap<String, isize>`
//~| found type `()`
//~| expected struct `HashMap`, found ()
let _: HashMap<String, isize, Hash<String>> = ();
//~^ ERROR mismatched types
//~| expected type `HashMap<std::string::String, isize>`
//~| expected type `HashMap<String, isize>`
//~| found type `()`
//~| expected struct `HashMap`, found ()

Expand Down
8 changes: 4 additions & 4 deletions src/test/compile-fail/issue-13466.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ pub fn main() {
let _x: usize = match Some(1) {
Ok(u) => u,
//~^ ERROR mismatched types
//~| expected type `std::option::Option<{integer}>`
//~| found type `std::result::Result<_, _>`
//~| expected type `Option<{integer}>`
//~| found type `Result<_, _>`
//~| expected enum `std::option::Option`, found enum `std::result::Result`

Err(e) => panic!(e)
//~^ ERROR mismatched types
//~| expected type `std::option::Option<{integer}>`
//~| found type `std::result::Result<_, _>`
//~| expected type `Option<{integer}>`
//~| found type `Result<_, _>`
//~| expected enum `std::option::Option`, found enum `std::result::Result`
};
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/issue-15783.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ fn main() {
let x = Some(&[name]);
let msg = foo(x);
//~^ ERROR mismatched types
//~| expected type `std::option::Option<&[&str]>`
//~| found type `std::option::Option<&[&str; 1]>`
//~| expected type `Option<&[&str]>`
//~| found type `Option<&[&str; 1]>`
//~| expected slice, found array of 1 elements
assert_eq!(msg, 3);
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/issue-3680.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ fn main() {
match None {
Err(_) => ()
//~^ ERROR mismatched types
//~| expected type `std::option::Option<_>`
//~| found type `std::result::Result<_, _>`
//~| expected type `Option<_>`
//~| found type `Result<_, _>`
//~| expected enum `std::option::Option`, found enum `std::result::Result`
}
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-40749.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ fn main() {
[0; ..10];
//~^ ERROR mismatched types
//~| expected type `usize`
//~| found type `std::ops::RangeTo<{integer}>`
//~| found type `RangeTo<{integer}>`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-5100.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn main() {
box (true, false) => ()
//~^ ERROR mismatched types
//~| expected type `(bool, bool)`
//~| found type `std::boxed::Box<_>`
//~| found type `Box<_>`
}

match (true, false) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-7061.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct BarStruct;
impl<'a> BarStruct {
fn foo(&'a mut self) -> Box<BarStruct> { self }
//~^ ERROR mismatched types
//~| expected type `std::boxed::Box<BarStruct>`
//~| expected type `Box<BarStruct>`
//~| found type `&'a mut BarStruct`
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-7092.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn foo(x: Whatever) {
Some(field) =>
//~^ ERROR mismatched types
//~| expected type `Whatever`
//~| found type `std::option::Option<_>`
//~| found type `Option<_>`
//~| expected enum `Whatever`, found enum `std::option::Option`
field.access(),
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/compile-fail/issue-7867.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ fn main() {
match &Some(42) {
Some(x) => (),
//~^ ERROR mismatched types
//~| expected type `&std::option::Option<{integer}>`
//~| found type `std::option::Option<_>`
//~| expected type `&Option<{integer}>`
//~| found type `Option<_>`
//~| expected reference, found enum `std::option::Option`
None => ()
//~^ ERROR mismatched types
//~| expected type `&std::option::Option<{integer}>`
//~| found type `std::option::Option<_>`
//~| expected type `&Option<{integer}>`
//~| found type `Option<_>`
//~| expected reference, found enum `std::option::Option`
}
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/noexporttypeexe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ fn main() {
let x: isize = noexporttypelib::foo();
//~^ ERROR mismatched types
//~| expected type `isize`
//~| found type `std::option::Option<isize>`
//~| found type `Option<isize>`
//~| expected isize, found enum `std::option::Option`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/occurs-check-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ fn main() {
f = box g;
//~^ ERROR mismatched types
//~| expected type `_`
//~| found type `std::boxed::Box<_>`
//~| found type `Box<_>`
//~| cyclic type of infinite size
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/occurs-check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ fn main() {
f = box f;
//~^ ERROR mismatched types
//~| expected type `_`
//~| found type `std::boxed::Box<_>`
//~| found type `Box<_>`
//~| cyclic type of infinite size
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/regions-infer-paramd-indirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl<'a> set_f<'a> for c<'a> {
fn set_f_bad(&mut self, b: Box<b>) {
self.f = b;
//~^ ERROR mismatched types
//~| expected type `std::boxed::Box<std::boxed::Box<&'a isize>>`
//~| found type `std::boxed::Box<std::boxed::Box<&isize>>`
//~| expected type `Box<Box<&'a isize>>`
//~| found type `Box<Box<&isize>>`
//~| lifetime mismatch
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/tag-that-dare-not-speak-its-name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ fn main() {
let x : char = last(y);
//~^ ERROR mismatched types
//~| expected type `char`
//~| found type `std::option::Option<_>`
//~| found type `Option<_>`
//~| expected char, found enum `std::option::Option`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/terr-sorts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn want_foo(f: foo) {}
fn have_bar(b: bar) {
want_foo(b); //~ ERROR mismatched types
//~| expected type `foo`
//~| found type `std::boxed::Box<foo>`
//~| found type `Box<foo>`
}

fn main() {}
4 changes: 2 additions & 2 deletions src/test/compile-fail/type-mismatch-same-crate-name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() {
//~^ ERROR mismatched types
//~| Perhaps two different versions of crate `crate_a1`
//~| expected trait `main::a::Bar`
//~| expected type `std::boxed::Box<main::a::Bar + 'static>`
//~| found type `std::boxed::Box<main::a::Bar>`
//~| expected type `Box<main::a::Bar + 'static>`
//~| found type `Box<main::a::Bar>`
}
}
4 changes: 2 additions & 2 deletions src/test/ui/block-result/consider-removing-last-semi.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ error[E0308]: mismatched types
14 | | }
| |_^ expected struct `std::string::String`, found ()
|
= note: expected type `std::string::String`
= note: expected type `String`
found type `()`

error[E0308]: mismatched types
Expand All @@ -23,7 +23,7 @@ error[E0308]: mismatched types
19 | | }
| |_^ expected struct `std::string::String`, found ()
|
= note: expected type `std::string::String`
= note: expected type `String`
found type `()`

error: aborting due to 2 previous errors
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/block-result/issue-13428.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ error[E0308]: mismatched types
19 | | }
| |_^ expected struct `std::string::String`, found ()
|
= note: expected type `std::string::String`
= note: expected type `String`
found type `()`

error[E0308]: mismatched types
Expand All @@ -26,7 +26,7 @@ error[E0308]: mismatched types
24 | | }
| |_^ expected struct `std::string::String`, found ()
|
= note: expected type `std::string::String`
= note: expected type `String`
found type `()`

error: aborting due to 2 previous errors
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/coercion-missing-tail-expected-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ error[E0308]: mismatched types
19 | | }
| |_^ expected enum `std::result::Result`, found ()
|
= note: expected type `std::result::Result<u8, u64>`
= note: expected type `Result<u8, u64>`
found type `()`

error: aborting due to 2 previous errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ note: but, the lifetime must be valid for the lifetime 'b as defined on the func
18 | | a.push(b);
19 | | }
| |_^
note: ...so that expression is assignable (expected &mut std::vec::Vec<Ref<'_, i32>>, found &mut std::vec::Vec<Ref<'b, i32>>)
note: ...so that expression is assignable (expected &mut Vec<Ref<'_, i32>>, found &mut Vec<Ref<'b, i32>>)
--> $DIR/ex2d-push-inference-variable-2.rs:16:33
|
16 | let a: &mut Vec<Ref<i32>> = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ note: but, the lifetime must be valid for the lifetime 'b as defined on the func
18 | | Vec::push(a, b);
19 | | }
| |_^
note: ...so that expression is assignable (expected &mut std::vec::Vec<Ref<'_, i32>>, found &mut std::vec::Vec<Ref<'b, i32>>)
note: ...so that expression is assignable (expected &mut Vec<Ref<'_, i32>>, found &mut Vec<Ref<'b, i32>>)
--> $DIR/ex2e-push-inference-variable-3.rs:16:33
|
16 | let a: &mut Vec<Ref<i32>> = x;
Expand Down
25 changes: 25 additions & 0 deletions src/test/ui/local-ident.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use Mod1::S;
use Mod2::*;

fn main() {
let x: X = S;
let y: Option<usize> = Ok(2);
}

mod Mod1 {
pub struct S;
}

mod Mod2 {
pub struct X;
}
Loading