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

Fixed regression in associated item resolution #28395

Merged
merged 4 commits into from
Sep 15, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,20 @@ fn create_substs_for_ast_path<'tcx>(
let mut type_substs = if param_mode == PathParamMode::Optional &&
types_provided.is_empty() {
let mut substs = region_substs.clone();

ty_param_defs
.iter()
.map(|p| this.ty_infer(Some(p.clone()), Some(&mut substs), Some(TypeSpace), span))
.map(|p| {
Copy link
Contributor

Choose a reason for hiding this comment

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

This code rather needs some refactoring (at least, split it into another method).

if let Some(ref default) = p.default {
if self_ty.is_none() && default.has_self_ty() {
// There is no suitable inference default for a type parameter
// that references Self with no self-type provided.
return this.ty_infer(None, Some(&mut substs), Some(TypeSpace), span);
}
}

this.ty_infer(Some(p.clone()), Some(&mut substs), Some(TypeSpace), span)
})
.collect()
} else {
types_provided
Expand Down
21 changes: 21 additions & 0 deletions src/test/compile-fail/issue-28344.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2015 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 std::ops::BitXor;

fn main() {
let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
//~^ ERROR must be specified
//~| no associated item named

let g = BitXor::bitor;
//~^ ERROR must be specified
//~| no associated item named
}
28 changes: 28 additions & 0 deletions src/test/compile-fail/unspecified-self-in-trait-ref.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2015 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.

pub trait Foo<A=Self> {
fn foo();
}

pub trait Bar<X=usize, A=Self> {
fn foo();
}

fn main() {
let a = Foo::lol();
//~^ ERROR no associated item named
let b = Foo::<_>::lol();
//~^ ERROR no associated item named
let c = Bar::lol();
//~^ ERROR no associated item named
let d = Bar::<usize, _>::lol();
//~^ ERROR no associated item named
}