Rollup merge of #81713 - estebank:unstable-assoc-item-lint, r=oli-obk
Account for associated consts in the "unstable assoc item name colission" lint Fix #81663.
This commit is contained in:
commit
c5629131fa
6 changed files with 67 additions and 23 deletions
|
@ -353,12 +353,12 @@ pub fn struct_lint_level<'s, 'd>(
|
||||||
it will become a hard error";
|
it will become a hard error";
|
||||||
|
|
||||||
let explanation = if lint_id == LintId::of(builtin::UNSTABLE_NAME_COLLISIONS) {
|
let explanation = if lint_id == LintId::of(builtin::UNSTABLE_NAME_COLLISIONS) {
|
||||||
"once this method is added to the standard library, \
|
"once this associated item is added to the standard library, the ambiguity may \
|
||||||
the ambiguity may cause an error or change in behavior!"
|
cause an error or change in behavior!"
|
||||||
.to_owned()
|
.to_owned()
|
||||||
} else if lint_id == LintId::of(builtin::MUTABLE_BORROW_RESERVATION_CONFLICT) {
|
} else if lint_id == LintId::of(builtin::MUTABLE_BORROW_RESERVATION_CONFLICT) {
|
||||||
"this borrowing pattern was not meant to be accepted, \
|
"this borrowing pattern was not meant to be accepted, and may become a hard error \
|
||||||
and may become a hard error in the future"
|
in the future"
|
||||||
.to_owned()
|
.to_owned()
|
||||||
} else if let Some(edition) = future_incompatible.edition {
|
} else if let Some(edition) = future_incompatible.edition {
|
||||||
format!("{} in the {} edition!", STANDARD_MESSAGE, edition)
|
format!("{} in the {} edition!", STANDARD_MESSAGE, edition)
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::hir::def_id::DefId;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::Namespace;
|
use rustc_hir::def::Namespace;
|
||||||
use rustc_infer::infer::canonical::OriginalQueryValues;
|
use rustc_infer::infer::canonical::OriginalQueryValues;
|
||||||
|
@ -1167,7 +1168,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
//
|
//
|
||||||
// We suppress warning if we're picking the method only because it is a
|
// We suppress warning if we're picking the method only because it is a
|
||||||
// suggestion.
|
// suggestion.
|
||||||
self.emit_unstable_name_collision_hint(p, &unstable_candidates);
|
self.emit_unstable_name_collision_hint(p, &unstable_candidates, self_ty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Some(pick);
|
return Some(pick);
|
||||||
|
@ -1246,24 +1247,46 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
stable_pick: &Pick<'_>,
|
stable_pick: &Pick<'_>,
|
||||||
unstable_candidates: &[(&Candidate<'tcx>, Symbol)],
|
unstable_candidates: &[(&Candidate<'tcx>, Symbol)],
|
||||||
|
self_ty: Ty<'tcx>,
|
||||||
) {
|
) {
|
||||||
self.tcx.struct_span_lint_hir(
|
self.tcx.struct_span_lint_hir(
|
||||||
lint::builtin::UNSTABLE_NAME_COLLISIONS,
|
lint::builtin::UNSTABLE_NAME_COLLISIONS,
|
||||||
self.fcx.body_id,
|
self.fcx.body_id,
|
||||||
self.span,
|
self.span,
|
||||||
|lint| {
|
|lint| {
|
||||||
let mut diag = lint.build(
|
let def_kind = stable_pick.item.kind.as_def_kind();
|
||||||
"a method with this name may be added to the standard library in the future",
|
let mut diag = lint.build(&format!(
|
||||||
);
|
"{} {} with this name may be added to the standard library in the future",
|
||||||
|
def_kind.article(),
|
||||||
|
def_kind.descr(stable_pick.item.def_id),
|
||||||
|
));
|
||||||
|
match (stable_pick.item.kind, stable_pick.item.container) {
|
||||||
|
(ty::AssocKind::Fn, _) => {
|
||||||
// FIXME: This should be a `span_suggestion` instead of `help`
|
// FIXME: This should be a `span_suggestion` instead of `help`
|
||||||
// However `self.span` only
|
// However `self.span` only
|
||||||
// highlights the method name, so we can't use it. Also consider reusing the code from
|
// highlights the method name, so we can't use it. Also consider reusing
|
||||||
// `report_method_error()`.
|
// the code from `report_method_error()`.
|
||||||
diag.help(&format!(
|
diag.help(&format!(
|
||||||
"call with fully qualified syntax `{}(...)` to keep using the current method",
|
"call with fully qualified syntax `{}(...)` to keep using the current \
|
||||||
|
method",
|
||||||
self.tcx.def_path_str(stable_pick.item.def_id),
|
self.tcx.def_path_str(stable_pick.item.def_id),
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
(ty::AssocKind::Const, ty::AssocItemContainer::TraitContainer(def_id)) => {
|
||||||
|
diag.span_suggestion(
|
||||||
|
self.span,
|
||||||
|
"use the fully qualified path to the associated const",
|
||||||
|
format!(
|
||||||
|
"<{} as {}>::{}",
|
||||||
|
self_ty,
|
||||||
|
self.tcx.def_path_str(def_id),
|
||||||
|
stable_pick.item.ident
|
||||||
|
),
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
if self.tcx.sess.is_nightly_build() {
|
if self.tcx.sess.is_nightly_build() {
|
||||||
for (candidate, feature) in unstable_candidates {
|
for (candidate, feature) in unstable_candidates {
|
||||||
diag.help(&format!(
|
diag.help(&format!(
|
||||||
|
|
|
@ -8,7 +8,11 @@ pub trait IpuIterator {
|
||||||
fn ipu_flatten(&self) -> u32 {
|
fn ipu_flatten(&self) -> u32 {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
#[unstable(feature = "assoc_const_ipu_iter", issue = "99999")]
|
||||||
|
const C: i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "ipu_iterator", since = "1.0.0")]
|
#[stable(feature = "ipu_iterator", since = "1.0.0")]
|
||||||
impl IpuIterator for char {}
|
impl IpuIterator for char {
|
||||||
|
const C: i32 = 42;
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,10 @@ pub trait IpuItertools {
|
||||||
fn ipu_flatten(&self) -> u32 {
|
fn ipu_flatten(&self) -> u32 {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const C: i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IpuItertools for char {}
|
impl IpuItertools for char {
|
||||||
|
const C: i32 = 1;
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,9 @@ use inference_unstable_itertools::IpuItertools;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
assert_eq!('x'.ipu_flatten(), 1);
|
assert_eq!('x'.ipu_flatten(), 1);
|
||||||
//~^ WARN a method with this name may be added to the standard library in the future
|
//~^ WARN an associated function with this name may be added to the standard library in the future
|
||||||
//~^^ WARN once this method is added to the standard library, the ambiguity may cause an error
|
//~| WARN once this associated item is added to the standard library, the ambiguity may cause an
|
||||||
|
assert_eq!(char::C, 1);
|
||||||
|
//~^ WARN an associated constant with this name may be added to the standard library in the future
|
||||||
|
//~| WARN once this associated item is added to the standard library, the ambiguity may cause an
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
warning: a method with this name may be added to the standard library in the future
|
warning: an associated function with this name may be added to the standard library in the future
|
||||||
--> $DIR/inference_unstable.rs:16:20
|
--> $DIR/inference_unstable.rs:16:20
|
||||||
|
|
|
|
||||||
LL | assert_eq!('x'.ipu_flatten(), 1);
|
LL | assert_eq!('x'.ipu_flatten(), 1);
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `#[warn(unstable_name_collisions)]` on by default
|
= note: `#[warn(unstable_name_collisions)]` on by default
|
||||||
= warning: once this method is added to the standard library, the ambiguity may cause an error or change in behavior!
|
= warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
|
||||||
= note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
|
= note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
|
||||||
= help: call with fully qualified syntax `inference_unstable_itertools::IpuItertools::ipu_flatten(...)` to keep using the current method
|
= help: call with fully qualified syntax `inference_unstable_itertools::IpuItertools::ipu_flatten(...)` to keep using the current method
|
||||||
= help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_flatten`
|
= help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_flatten`
|
||||||
|
|
||||||
warning: 1 warning emitted
|
warning: an associated constant with this name may be added to the standard library in the future
|
||||||
|
--> $DIR/inference_unstable.rs:19:16
|
||||||
|
|
|
||||||
|
LL | assert_eq!(char::C, 1);
|
||||||
|
| ^^^^^^^ help: use the fully qualified path to the associated const: `<char as IpuItertools>::C`
|
||||||
|
|
|
||||||
|
= warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
|
||||||
|
= note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
|
||||||
|
= help: add `#![feature(assoc_const_ipu_iter)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::C`
|
||||||
|
|
||||||
|
warning: 2 warnings emitted
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue