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

Rollup of 15 pull requests #62990

Merged
merged 58 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
72ac8ce
Stablize Euclidean Modulo (feature euclidean_division)
crlf0710 Jul 7, 2019
5397dfc
Remove obsolete “should not have to exist” reasons
SimonSapin Jul 8, 2019
01d93bf
Split the SliceConcat trait into Concat and Join
SimonSapin Jul 8, 2019
283f676
Take separator by value in `[T]::join`
SimonSapin Jul 8, 2019
b62a77b
Add joining slices of slices with a slice separator, not just a singl…
SimonSapin Jul 8, 2019
d0635ee
Update src/liballoc/slice.rs
SimonSapin Jul 9, 2019
bbc9366
Update src/liballoc/slice.rs
SimonSapin Jul 9, 2019
5f7768a
Update src/liballoc/str.rs
SimonSapin Jul 9, 2019
156173f
Add tests for overlapping explicitly dropped locals in generators
JohnTitor Jul 16, 2019
21b502b
warn that raw pointers must be aligned when used, and that writes cau…
RalfJung Jul 20, 2019
2e6b13a
references must be aligned; also move up the warning that fn ptrs mus…
RalfJung Jul 20, 2019
f502bf7
sync with nomicon: raw ptr must be non-dangling and aligned every tim…
RalfJung Jul 21, 2019
4081222
apply feedback
RalfJung Jul 21, 2019
a7b9246
weasle, weasle
RalfJung Jul 22, 2019
9196781
account for non-drop-glue types
RalfJung Jul 22, 2019
f78cd4d
Fix building_llvm in sanity check, add swig sanity check.
golddranks Jun 16, 2019
5b3b6b8
Make the parser TokenStream more resilient after mismatched delimiter…
estebank Jul 23, 2019
ba78db3
libsyntax: factor out file path resolving
jonas-schievink May 14, 2019
138e08c
Make #[doc(include)] paths behave like other paths
jonas-schievink May 18, 2019
1cc7c21
Adjust docs to new #[doc(include)] behaviour
jonas-schievink May 19, 2019
8ccf52c
stage0 -> bootstrap
jonas-schievink Jun 22, 2019
edb2187
Make path::resolve a method on ExtCtxt
jonas-schievink Jun 22, 2019
7c42259
Update stdarch submodule
jonas-schievink Jul 17, 2019
dd5045e
Apply suggestions from code review
RalfJung Jul 23, 2019
65cf10d
word things more like we usually do
RalfJung Jul 23, 2019
218ab4c
Update test
jonas-schievink Jul 23, 2019
f56c8f6
Fix another case
estebank Jul 23, 2019
fe2b5bb
review comments
estebank Jul 23, 2019
bd8813e
Add method disambiguation help for trait implementation
iluuu1994 Jul 23, 2019
be510db
Adjust tests for method disambiguation help
iluuu1994 Jul 24, 2019
a93fdfe
Merge `rustc_allocator` into `libsyntax_ext`
petrochenkov Jul 16, 2019
4330241
syntax_ext: Turn `#[global_allocator]` into a regular attribute macro
petrochenkov Jul 18, 2019
76b1ffa
syntax_ext: Reuse built-in attribute template checking for macro attr…
petrochenkov Jul 18, 2019
bf8fc8a
syntax_ext: Improve and simplify code generated by `#[global_allocator]`
petrochenkov Jul 18, 2019
6e4f161
Demote template check error to a lint for `#[test]` and `#[bench]`
petrochenkov Jul 20, 2019
a0c2c64
Fix rebase
petrochenkov Jul 20, 2019
f49a965
Add test for #51559
iluuu1994 Jul 24, 2019
c091818
Use match ergonomics in Condvar documentation
KevinWMatthews Jul 24, 2019
4042811
Use Foo instead of raw arrays
JohnTitor Jul 24, 2019
91fa898
Stabilize the type_name intrinsic in core::any
sfackler Apr 18, 2019
50d9b06
Fix inconsistent highlight blocks.
tomasz-rozanski Jul 25, 2019
9d39758
Remove `cfg(bootstrap)` code for array implementations
LukasKalbertodt Jul 25, 2019
3ab6026
Add note suggesting to borrow a String argument to find
estebank Jul 25, 2019
3b19dc9
Rollup merge of #60066 - sfackler:type-name, r=Centril
Centril Jul 25, 2019
845e146
Rollup merge of #60938 - jonas-schievink:doc-include-paths, r=petroch…
Centril Jul 25, 2019
a57c4f6
Rollup merge of #61884 - crlf0710:stablize_euc, r=dtolnay,Centril
Centril Jul 25, 2019
dbd0028
Rollup merge of #61890 - golddranks:fix_sanity_check_llvm, r=Dylan-DPC
Centril Jul 25, 2019
008d9d0
Rollup merge of #62528 - SimonSapin:concat, r=alexcrichton
Centril Jul 25, 2019
6f0e57f
Rollup merge of #62707 - JohnTitor:add-test-for-61922, r=tmandry
Centril Jul 25, 2019
e1de70b
Rollup merge of #62735 - petrochenkov:galloc, r=alexcrichton
Centril Jul 25, 2019
a534c37
Rollup merge of #62822 - RalfJung:pointers, r=Centril
Centril Jul 25, 2019
c9a766a
Rollup merge of #62887 - estebank:issue-62881, r=petrochenkov
Centril Jul 25, 2019
fe07132
Rollup merge of #62921 - iluuu1994:improve-help-for-method-disambigua…
Centril Jul 25, 2019
6e8d7b6
Rollup merge of #62930 - iluuu1994:test-for-51559, r=oli-obk
Centril Jul 25, 2019
42d924d
Rollup merge of #62942 - KevinWMatthews:condvar_docs_match_ergo, r=sf…
Centril Jul 25, 2019
ca26d2e
Rollup merge of #62977 - Rosto75:master, r=shepmaster
Centril Jul 25, 2019
f87f3db
Rollup merge of #62978 - LukasKalbertodt:remove-array-impl-bootstrap-…
Centril Jul 25, 2019
1a775b3
Rollup merge of #62981 - estebank:issue-62843, r=Centril
Centril Jul 25, 2019
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
Prev Previous commit
Next Next commit
Add method disambiguation help for trait implementation
Closes #51046
Closes #40471
  • Loading branch information
iluuu1994 committed Jul 24, 2019
commit bd8813e52c5120c40ec3cca096ff4a98fdf56be8
50 changes: 31 additions & 19 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use rustc::hir::{self, ExprKind, Node, QPath};
use rustc::hir::def::{Res, DefKind};
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
use rustc::hir::map as hir_map;
use rustc::hir::print;
use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc::traits::Obligation;
use rustc::ty::{self, Ty, TyCtxt, ToPolyTraitRef, ToPredicate, TypeFoldable};
Expand Down Expand Up @@ -78,6 +77,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return;
}

let print_disambiguation_help = |
err: &mut DiagnosticBuilder<'_>,
trait_name: String,
| {
err.help(&format!(
"to disambiguate the method call, write `{}::{}({}{})` instead",
trait_name,
item_name,
if rcvr_ty.is_region_ptr() && args.is_some() {
if rcvr_ty.is_mutable_pointer() {
"&mut "
} else {
"&"
}
} else {
""
},
args.map(|arg| arg
.iter()
.map(|arg| self.tcx.sess.source_map().span_to_snippet(arg.span)
.unwrap_or_else(|_| "...".to_owned()))
.collect::<Vec<_>>()
.join(", ")
).unwrap_or_else(|| "...".to_owned())
));
};

let report_candidates = |
span: Span,
err: &mut DiagnosticBuilder<'_>,
Expand Down Expand Up @@ -139,6 +165,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
err.note(&note_str);
}
if let Some(trait_ref) = self.tcx.impl_trait_ref(impl_did) {
print_disambiguation_help(err, self.tcx.def_path_str(trait_ref.def_id));
}
}
CandidateSource::TraitSource(trait_did) => {
let item = match self.associated_item(
Expand All @@ -163,24 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
"the candidate is defined in the trait `{}`",
self.tcx.def_path_str(trait_did));
}
err.help(&format!("to disambiguate the method call, write `{}::{}({}{})` \
instead",
self.tcx.def_path_str(trait_did),
item_name,
if rcvr_ty.is_region_ptr() && args.is_some() {
if rcvr_ty.is_mutable_pointer() {
"&mut "
} else {
"&"
}
} else {
""
},
args.map(|arg| arg.iter()
.map(|arg| print::to_string(print::NO_ANN,
|s| s.print_expr(arg)))
.collect::<Vec<_>>()
.join(", ")).unwrap_or_else(|| "...".to_owned())));
print_disambiguation_help(err, self.tcx.def_path_str(trait_did));
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/methods/method-ambig-two-traits-from-impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
trait A { fn foo(self); }
trait B { fn foo(self); }

struct AB {}

impl A for AB {
fn foo(self) {}
}

impl B for AB {
fn foo(self) {}
}

fn main() {
AB {}.foo(); //~ ERROR E0034
}
22 changes: 22 additions & 0 deletions src/test/ui/methods/method-ambig-two-traits-from-impls.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0034]: multiple applicable items in scope
--> $DIR/method-ambig-two-traits-from-impls.rs:15:11
|
LL | AB {}.foo();
| ^^^ multiple `foo` found
|
note: candidate #1 is defined in an impl of the trait `A` for the type `AB`
--> $DIR/method-ambig-two-traits-from-impls.rs:7:5
|
LL | fn foo(self) {}
| ^^^^^^^^^^^^
= help: to disambiguate the method call, write `A::foo(AB {})` instead
note: candidate #2 is defined in an impl of the trait `B` for the type `AB`
--> $DIR/method-ambig-two-traits-from-impls.rs:11:5
|
LL | fn foo(self) {}
| ^^^^^^^^^^^^
= help: to disambiguate the method call, write `B::foo(AB {})` instead

error: aborting due to previous error

For more information about this error, try `rustc --explain E0034`.
16 changes: 16 additions & 0 deletions src/test/ui/methods/method-ambig-two-traits-from-impls2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
trait A { fn foo(); }
trait B { fn foo(); }

struct AB {}

impl A for AB {
fn foo() {}
}

impl B for AB {
fn foo() {}
}

fn main() {
AB::foo(); //~ ERROR E0034
}
22 changes: 22 additions & 0 deletions src/test/ui/methods/method-ambig-two-traits-from-impls2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0034]: multiple applicable items in scope
--> $DIR/method-ambig-two-traits-from-impls2.rs:15:5
|
LL | AB::foo();
| ^^^^^^^ multiple `foo` found
|
note: candidate #1 is defined in an impl of the trait `A` for the type `AB`
--> $DIR/method-ambig-two-traits-from-impls2.rs:7:5
|
LL | fn foo() {}
| ^^^^^^^^
= help: to disambiguate the method call, write `A::foo(...)` instead
note: candidate #2 is defined in an impl of the trait `B` for the type `AB`
--> $DIR/method-ambig-two-traits-from-impls2.rs:11:5
|
LL | fn foo() {}
| ^^^^^^^^
= help: to disambiguate the method call, write `B::foo(...)` instead

error: aborting due to previous error

For more information about this error, try `rustc --explain E0034`.