bug!("try_report_cannot_return_reference_to_local: not a local")
};
match self.body.local_kind(*local) {
- LocalKind::ReturnPointer | LocalKind::Temp => {
- (
- "temporary value".to_string(),
- "temporary value created here".to_string(),
- )
- }
- LocalKind::Arg => {
- (
- "function parameter".to_string(),
- "function parameter borrowed here".to_string(),
- )
- },
- LocalKind::Var => bug!("local variable without a name"),
+ LocalKind::ReturnPointer | LocalKind::Temp => (
+ "temporary value".to_string(),
+ "temporary value created here".to_string(),
+ ),
+ LocalKind::Arg => (
+ "function parameter".to_string(),
+ "function parameter borrowed here".to_string(),
+ ),
+ LocalKind::Var => (
+ "local binding".to_string(),
+ "local binding introduced here".to_string(),
+ ),
}
};
--- /dev/null
+use std::collections::HashMap;
+use std::hash::Hash;
+
+fn group_by<I, F, T>(xs: &mut I, f: F) -> HashMap<T, Vec<&I::Item>>
+where
+ I: Iterator,
+ F: Fn(&I::Item) -> T,
+ T: Eq + Hash,
+{
+ let mut result = HashMap::new();
+ for ref x in xs {
+ let key = f(x);
+ result.entry(key).or_insert(Vec::new()).push(x);
+ }
+ result //~ ERROR cannot return value referencing local binding
+}
+
+fn main() {}
--- /dev/null
+error[E0515]: cannot return value referencing local binding
+ --> $DIR/issue-63026.rs:15:5
+ |
+LL | for ref x in xs {
+ | -- local binding introduced here
+...
+LL | result
+ | ^^^^^^ returns a value referencing data owned by the current function
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0515`.