resolve how to handle constants and default binding modes

5f1fd03
Opened by Niko Matsakis at 2022-01-29 01:05:36

Another interesting question that @tschottdorf encountered when implementing default binding modes: What do we do with constants? The RFC specifies that we ought to treat a FOO binding that resolves to a constant as something which can skip through &T types -- however, that runs into trouble if the type of the constant itself is &str or &[T]. The current logic at least skips through all &T or &mut T types when it skips through any, but handling &str correctly would require skipping through "only the right number".

@tschottdorf implemented various rules but we should at minimum update the RFC to match.

  1. An example. Per the language in the RFC, constants of reference type will not "autoderef", but that means that this example does not work, which seems unfortunate:

    let s: &'static str = "abc";
    match &s {
      "abc" => true,
      _ => panic!(),
    };
    

    Niko Matsakis at 2017-10-03 10:32:54