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

Use replacen instead of strip_prefix to skip prefix chars #111728

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 3 additions & 7 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span = item_name.span;

// Don't show generic arguments when the method can't be found in any implementation (#81576).
let mut ty_str_reported = if trait_missing_method {
ty_str.strip_prefix("dyn ").expect("Failed to remove the prefix dyn").to_owned()
} else {
ty_str.clone()
};
let mut ty_str_reported =
if trait_missing_method { ty_str.replacen("dyn ", "", 1) } else { ty_str.clone() };

if let ty::Adt(_, generics) = rcvr_ty.kind() {
if generics.len() > 0 {
Expand Down Expand Up @@ -389,8 +386,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty_str
};
if trait_missing_method {
ty_str =
ty_str.strip_prefix("dyn ").expect("Failed to remove the prefix dyn").to_owned();
ty_str = ty_str.replacen("dyn ", "", 1);
}

if let Some(file) = ty_file {
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/resolve/issue-111727.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// edition: 2021

fn main() {
std::any::Any::create(); //~ ERROR
}
9 changes: 9 additions & 0 deletions tests/ui/resolve/issue-111727.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0599]: no function or associated item named `create` found for trait `(Any + 'static)`
--> $DIR/issue-111727.rs:4:20
|
LL | std::any::Any::create();
| ^^^^^^ function or associated item not found in `Any`

error: aborting due to previous error

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