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 9 pull requests #131723

Merged
merged 20 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e904761
Use environment variables instead of command line arguments for merge…
GuillaumeGomez Oct 1, 2024
2bd0d07
Expand set_ptr_value / with_metadata_of docs
HeroicKatora Oct 6, 2024
c128b4c
Fix typo thing->thin referring to pointer
HeroicKatora Oct 13, 2024
feecfaa
Fix bug where `option_env!` would return `None` when env var is prese…
beetrees Mar 18, 2024
b6b6c12
Update lint message for ABI not supported
tdittr Oct 14, 2024
c6e1fbf
Fix up-to-date checking for run-make tests
Zalathar Oct 14, 2024
7500e09
Move trait bound modifiers into hir::PolyTraitRef
compiler-errors Oct 13, 2024
95dba28
Move trait bound modifiers into ast::PolyTraitRef
compiler-errors Oct 13, 2024
c3b696d
Suppress import errors for traits that couldve applied in method look…
compiler-errors Oct 14, 2024
eb6062c
Resolved python deprecation warning in publish_toolstate.py
alex Oct 14, 2024
dda3066
Remove `'apostrophes'` from `rustc_parse_format`
ShE3py Oct 14, 2024
6d99996
Rollup merge of #122670 - beetrees:non-unicode-option-env-error, r=co…
matthiaskrgr Oct 15, 2024
bb2f970
Rollup merge of #131095 - GuillaumeGomez:switch-to-env-variables, r=n…
matthiaskrgr Oct 15, 2024
09103f2
Rollup merge of #131339 - HeroicKatora:set_ptr_value-documentation, r…
matthiaskrgr Oct 15, 2024
4d53a28
Rollup merge of #131652 - compiler-errors:modifiers, r=Nadrieril,jiey…
matthiaskrgr Oct 15, 2024
bd649b4
Rollup merge of #131675 - tdittr:update-unsupported-abi-message, r=co…
matthiaskrgr Oct 15, 2024
258c177
Rollup merge of #131681 - Zalathar:fix-run-make-stamp, r=jieyouxu
matthiaskrgr Oct 15, 2024
2e2c433
Rollup merge of #131702 - compiler-errors:method-lookup-trait-warning…
matthiaskrgr Oct 15, 2024
d82a49d
Rollup merge of #131703 - alex:patch-1, r=Kobzol
matthiaskrgr Oct 15, 2024
c99c4d4
Rollup merge of #131710 - ShE3py:parse_format_apostrophes, r=compiler…
matthiaskrgr Oct 15, 2024
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
Suppress import errors for traits that couldve applied in method look…
…up on error
  • Loading branch information
compiler-errors committed Oct 14, 2024
commit c3b696dec99e7646b84d8b43c05a113acf7d249c
2 changes: 2 additions & 0 deletions compiler/rustc_hir_typeck/src/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self_ty, segment, span, call_expr, self_expr, &pick, args,
);

// NOTE: on the failure path, we also record the possibly-used trait methods
// since an unused import warning is kinda distracting from the method error.
for &import_id in &pick.import_ids {
debug!("used_trait_import: {:?}", import_id);
self.typeck_results.borrow_mut().used_trait_imports.insert(import_id);
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected: Expectation<'tcx>,
trait_missing_method: bool,
) -> ErrorGuaranteed {
// NOTE: Reporting a method error should also suppress any unused trait errors,
// since the method error is very possibly the reason why the trait wasn't used.
for &import_id in
self.tcx.in_scope_traits(call_id).into_iter().flatten().flat_map(|c| &c.import_ids)
{
self.typeck_results.borrow_mut().used_trait_imports.insert(import_id);
}

let (span, sugg_span, source, item_name, args) = match self.tcx.hir_node(call_id) {
hir::Node::Expr(&hir::Expr {
kind: hir::ExprKind::MethodCall(segment, rcvr, args, _),
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/use/unused-trait-with-method-err.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Test that we don't issue an unused import warning when there's
// a method lookup error and that trait was possibly applicable.

use foo::Bar;

mod foo {
pub trait Bar {
fn uwu(&self) {}
}
}

struct Foo;

fn main() {
Foo.uwu();
//~^ ERROR no method named `uwu` found for struct `Foo` in the current scope
}
19 changes: 19 additions & 0 deletions tests/ui/use/unused-trait-with-method-err.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0599]: no method named `uwu` found for struct `Foo` in the current scope
--> $DIR/unused-trait-with-method-err.rs:15:9
|
LL | struct Foo;
| ---------- method `uwu` not found for this struct
...
LL | Foo.uwu();
| ^^^ method not found in `Foo`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `Bar` defines an item `uwu`, perhaps you need to implement it
--> $DIR/unused-trait-with-method-err.rs:7:5
|
LL | pub trait Bar {
| ^^^^^^^^^^^^^

error: aborting due to 1 previous error

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