Skip to content

Commit d15ec79

Browse files
Haofeiclaude
andcommitted
review #3: fix remaining Result generic-param duplicates and consolidate
The previous fix changed only the lowerer's builtin_generic_type_params; two more identical copies (hir.rs, checks/calls.rs — the latter drives the actual generic substitution) still mapped Result -> [K,V] instead of [T,E], weakening Result.map/map_error/and_then substitution. Fixed both, then consolidated all three into a single text_util::builtin_generic_type_params so the names can't drift per layer again. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 100f98f commit d15ec79

4 files changed

Lines changed: 21 additions & 31 deletions

File tree

crates/rsscript/src/checks/calls.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4847,16 +4847,7 @@ pub(crate) fn unresolved_generic_type(type_name: &str) -> bool {
48474847
.any(|param_type| unresolved_generic_type(param_type))
48484848
}
48494849

4850-
fn builtin_generic_type_params(root: &str) -> Option<Vec<&'static str>> {
4851-
match root {
4852-
"List" | "Set" | "Option" | "ResourcePool" | "Channel" | "Sender" | "Receiver"
4853-
| "Stream" | "Pipeline" => Some(vec!["T"]),
4854-
"FalliblePipeline" => Some(vec!["T", "E"]),
4855-
"Capability" => Some(vec!["P"]),
4856-
"Map" | "Result" => Some(vec!["K", "V"]),
4857-
_ => None,
4858-
}
4859-
}
4850+
use crate::text_util::builtin_generic_type_params;
48604851

48614852
fn hir_expr_span(expr: &HirExpr) -> &Span {
48624853
match expr {

crates/rsscript/src/hir.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,16 +2869,7 @@ fn substitute_type_params(type_name: &str, substitutions: &HashMap<String, Strin
28692869
format!("{root}<{args}>")
28702870
}
28712871

2872-
fn builtin_generic_type_params(root: &str) -> Option<Vec<&'static str>> {
2873-
match root {
2874-
"List" | "Set" | "Option" | "ResourcePool" | "Channel" | "Sender" | "Receiver"
2875-
| "Stream" | "Pipeline" => Some(vec!["T"]),
2876-
"FalliblePipeline" => Some(vec!["T", "E"]),
2877-
"Capability" => Some(vec!["P"]),
2878-
"Map" | "Result" => Some(vec!["K", "V"]),
2879-
_ => None,
2880-
}
2881-
}
2872+
use crate::text_util::builtin_generic_type_params;
28822873

28832874
fn capability_protocol(type_name: &str) -> Option<&str> {
28842875
let root = type_root_name(type_name);

crates/rsscript/src/rust_lower/lowerer.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5450,17 +5450,7 @@ fn collect_type_ref_substitutions(
54505450
}
54515451
}
54525452

5453-
fn builtin_generic_type_params(root: &str) -> Option<Vec<&'static str>> {
5454-
match root {
5455-
"List" | "Set" | "Option" | "ResourcePool" | "Channel" | "Sender" | "Receiver"
5456-
| "Stream" | "Pipeline" => Some(vec!["T"]),
5457-
"FalliblePipeline" => Some(vec!["T", "E"]),
5458-
"Capability" => Some(vec!["P"]),
5459-
"Map" => Some(vec!["K", "V"]),
5460-
"Result" => Some(vec!["T", "E"]),
5461-
_ => None,
5462-
}
5463-
}
5453+
use crate::text_util::builtin_generic_type_params;
54645454

54655455
/// Type names declared by the bundled stdlib (`builtin`) interfaces. These are
54665456
/// runtime-backed (lowered as `rsscript_runtime::X`), so they must be kept out of

crates/rsscript/src/text_util.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,21 @@ pub(crate) fn split_top_level_type_args(args: &str) -> Vec<&str> {
146146
}
147147
parts
148148
}
149+
150+
/// Declared generic parameter names for a builtin generic type root, e.g.
151+
/// `Map<K, V>` -> `["K", "V"]`, `Result<T, E>` -> `["T", "E"]`, `List<T>` ->
152+
/// `["T"]`. `None` for non-generic / unknown roots. Single source of truth: the
153+
/// HIR substitution path, the call-site substitution path, and the Rust lowerer
154+
/// all use this, so the names can't drift apart per layer (they did once: a
155+
/// `Result -> ["K","V"]` copy weakened error-combinator substitution).
156+
pub(crate) fn builtin_generic_type_params(root: &str) -> Option<Vec<&'static str>> {
157+
match root {
158+
"List" | "Set" | "Option" | "ResourcePool" | "Channel" | "Sender" | "Receiver"
159+
| "Stream" | "Pipeline" => Some(vec!["T"]),
160+
"FalliblePipeline" => Some(vec!["T", "E"]),
161+
"Capability" => Some(vec!["P"]),
162+
"Map" => Some(vec!["K", "V"]),
163+
"Result" => Some(vec!["T", "E"]),
164+
_ => None,
165+
}
166+
}

0 commit comments

Comments
 (0)