Skip to content
Open
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
16 changes: 11 additions & 5 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2383,18 +2383,24 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}

// They are all the same, so if any of them is ambiguous, we report the pick as ambiguous.
let is_ambiguously_imported = probes.iter().any(|(p, _)| match p.kind {
TraitCandidate { is_ambiguously_imported, .. } => is_ambiguously_imported,
_ => false,
let ambiguously_imported_import_ids = probes.iter().find_map(|(p, _)| match p.kind {
TraitCandidate { is_ambiguously_imported, .. } => {
is_ambiguously_imported.then_some(p.import_ids)
}
_ => None,
});

let (is_ambiguously_imported, import_ids) = match ambiguously_imported_import_ids {
Some(import_ids) => (true, import_ids),
None => (false, probes[0].0.import_ids),
};

// FIXME: check the return type here somehow.
// If so, just use this trait and call it a day.
Some(Pick {
item: probes[0].0.item,

@lsunsi lsunsi Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe this item should get the same treatment as import_ids. I'm not sure if they are guaranteed to be the same, but avoid using "always the first" is probably best.

Any thoughts?

View changes since the review

kind: TraitPick { is_ambiguously_imported },
import_ids: probes[0].0.import_ids,
import_ids,
autoderefs: 0,
autoref_or_ptr_adjustment: None,
self_ty,
Expand Down
29 changes: 29 additions & 0 deletions tests/ui/imports/ambiguous-trait-with-mixed-import-paths.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/162857>.
//@ check-pass

mod vis1 {
pub trait Visitor {
fn visit_b(&self);
fn visit_c(&self);
}
}

mod vis2 {
pub trait Visitor {}
}

use crate::{vis1::*, vis2::*};

pub struct Impl;

impl vis1::Visitor for Impl {
fn visit_b(&self) {}

fn visit_c(&self) {
self.visit_b();
//~^ WARN: use of ambiguously glob imported trait `Visitor` [ambiguous_glob_imported_traits]
//~| WARN: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
}
}

fn main() {}
16 changes: 16 additions & 0 deletions tests/ui/imports/ambiguous-trait-with-mixed-import-paths.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
warning: use of ambiguously glob imported trait `Visitor`
--> $DIR/ambiguous-trait-with-mixed-import-paths.rs:23:14
|
LL | use crate::{vis1::*, vis2::*};
| ---- `Visitor` imported ambiguously here
...
LL | self.visit_b();
| ^^^^^^^
|
= help: import `Visitor` explicitly
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #152822 <https://github.com/rust-lang/rust/issues/152822>
= note: `#[warn(ambiguous_glob_imported_traits)]` (part of `#[warn(future_incompatible)]`) on by default

warning: 1 warning emitted

Loading