Skip to content

Indexing Autoref + Borrow = :( #22826

Closed
Closed
@Gankra

Description

@Gankra
use std::collections::HashMap;
fn main(){
    let mut map = HashMap::new();
    map.insert("foo".to_string(), "bar".to_string());

    // Oh hey I can use borrow to do lookup with a string literal!
    println!("{}", map["foo"]);
}

// <anon>:5:20: 5:30 error: the trait `collections::borrow::Borrow<&str>` 
// is not implemented for the type `collections::string::String` [E0277]
// <anon>:5     println!("{}", map["foo"]);
//                             ^~~~~~~~~~

:(

use std::collections::HashMap;
fn main(){
    let mut map = HashMap::new();
    map.insert("foo".to_string(), "bar".to_string());

    // Ok, maybe I can deref to cancel out the autoref?
    println!("{}", map[*"foo"]);
}

// error: internal compiler error: trying to take the 
// sizing type of str, an unsized type

:((((((

These two conveniences are basically cancelling each-other out for the super-natural case of doing lookup with a string literal. Is there something that can be done about this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priority

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions