-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1779 from fzyzcjy/feat/11874
Improve hints when types are exported but not used
- Loading branch information
Showing
80 changed files
with
378 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 54 additions & 64 deletions
118
frb_codegen/src/library/codegen/parser/type_parser/path_data.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,65 @@ | ||
use crate::codegen::ir::ty::rust_opaque::NameComponent; | ||
use crate::codegen::parser::type_parser::TypeParserWithContext; | ||
use crate::if_then_some; | ||
use anyhow::Result; | ||
use syn::{ | ||
AngleBracketedGenericArguments, GenericArgument, Path, PathArguments, PathSegment, Type, | ||
}; | ||
|
||
impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { | ||
pub(crate) fn extract_path_data(&mut self, path: &Path) -> Result<Vec<NameComponent>> { | ||
path.segments | ||
.iter() | ||
.map(|segment| self.parse_path_segment(segment)) | ||
.collect() | ||
} | ||
|
||
fn parse_path_segment(&mut self, segment: &PathSegment) -> Result<NameComponent> { | ||
let ident = segment.ident.to_string(); | ||
let args = match &segment.arguments { | ||
PathArguments::None => vec![], | ||
PathArguments::AngleBracketed(args) => { | ||
self.parse_angle_bracketed_generic_arguments(args) | ||
// .with_context(|| { | ||
// // This will stop the whole generator and tell the users, so we do not care about testing it | ||
// // frb-coverage:ignore-start | ||
// anyhow!("\"{ident}\" of \"{}\" is not valid", path.to_token_stream()) | ||
// // frb-coverage:ignore-end | ||
// })? | ||
} | ||
// frb-coverage:ignore-start | ||
_ => unreachable!(), | ||
// frb-coverage:ignore-end | ||
pub(crate) fn extract_path_data(path: &Path) -> Result<Vec<NameComponent>> { | ||
path.segments.iter().map(parse_path_segment).collect() | ||
} | ||
|
||
// not used yet (detected by codecov) | ||
// syn doc says "The `(A, B) -> C` in `Fn(A, B) -> C`", | ||
// thus it seems we will not use it here. | ||
// | ||
// PathArguments::Parenthesized(args) => Some(Args::Signature( | ||
// self.parse_parenthesized_generic_arguments(args)?, | ||
// )), | ||
}; | ||
Ok(NameComponent { ident, args }) | ||
} | ||
fn parse_path_segment(segment: &PathSegment) -> Result<NameComponent> { | ||
let ident = segment.ident.to_string(); | ||
let args = match &segment.arguments { | ||
PathArguments::None => vec![], | ||
PathArguments::AngleBracketed(args) => { | ||
parse_angle_bracketed_generic_arguments(args) | ||
// .with_context(|| { | ||
// // This will stop the whole generator and tell the users, so we do not care about testing it | ||
// // frb-coverage:ignore-start | ||
// anyhow!("\"{ident}\" of \"{}\" is not valid", path.to_token_stream()) | ||
// // frb-coverage:ignore-end | ||
// })? | ||
} | ||
// frb-coverage:ignore-start | ||
_ => unreachable!(), | ||
// frb-coverage:ignore-end | ||
|
||
fn parse_angle_bracketed_generic_arguments( | ||
&mut self, | ||
args: &AngleBracketedGenericArguments, | ||
) -> Vec<Type> { | ||
args.args | ||
.iter() | ||
.filter_map(|arg| if_then_some!(let GenericArgument::Type(ty) = arg, ty.to_owned())) | ||
// .map(|ty| self.parse_type(ty)) | ||
.collect() | ||
} | ||
// not used yet (detected by codecov) | ||
// syn doc says "The `(A, B) -> C` in `Fn(A, B) -> C`", | ||
// thus it seems we will not use it here. | ||
// | ||
// PathArguments::Parenthesized(args) => Some(Args::Signature( | ||
// self.parse_parenthesized_generic_arguments(args)?, | ||
// )), | ||
}; | ||
Ok(NameComponent { ident, args }) | ||
} | ||
|
||
// not used yet | ||
// fn parse_parenthesized_generic_arguments( | ||
// &mut self, | ||
// args: &ParenthesizedGenericArguments, | ||
// ) -> Result<Vec<IrType>> { | ||
// let input_types = args | ||
// .inputs | ||
// .iter() | ||
// .map(|ty| self.parse_type(ty)) | ||
// .collect::<Result<Vec<_>>>()?; | ||
// | ||
// let output_type = self.parse_return_type(&args.output)?; | ||
// | ||
// Ok({ | ||
// let mut ans = vec![output_type]; | ||
// ans.extend(input_types); | ||
// ans | ||
// }) | ||
// } | ||
fn parse_angle_bracketed_generic_arguments(args: &AngleBracketedGenericArguments) -> Vec<Type> { | ||
args.args | ||
.iter() | ||
.filter_map(|arg| if_then_some!(let GenericArgument::Type(ty) = arg, ty.to_owned())) | ||
.collect() | ||
} | ||
|
||
// not used yet | ||
// fn parse_parenthesized_generic_arguments( | ||
// &mut self, | ||
// args: &ParenthesizedGenericArguments, | ||
// ) -> Result<Vec<IrType>> { | ||
// let input_types = args | ||
// .inputs | ||
// .iter() | ||
// .map(|ty| self.parse_type(ty)) | ||
// .collect::<Result<Vec<_>>>()?; | ||
// | ||
// let output_type = self.parse_return_type(&args.output)?; | ||
// | ||
// Ok({ | ||
// let mut ans = vec![output_type]; | ||
// ans.extend(input_types); | ||
// ans | ||
// }) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.