pub fn term_to_record_constraint(
        &self,
        span: Span,
        terms: Vec<Spanned<Term>>,
    ) -> Result<Spanned<hir::RecordConstraint>> {
        if terms.is_empty() {
            self.emit(DiagBuilder2::error(format!("record constraint cannot be empty")).span(span));
            return Err(());
        }
        let mut fields = Vec::new();
        let mut has_fails = false;
        let mut used_names = HashMap::new();
        for term in terms {
            // Make sure that the term is of the form `field (constraint)`.
            let (name, con) = match term.value {
                Term::SuffixParen(name, con) => (name, *con),
                _ => {
                    self.emit(
                        DiagBuilder2::error(format!(
                            "`{}` is not a valid constraint for a record element",
                            term.span.extract()
                        ))
                        .span(term.span)
                        .add_note(
                            "Element constraints must be of the form `name (constraint)`. See \
                             IEEE 1076-2008 section 5.3.3.",
                        ),
                    );
                    debugln!("It is a {:#?}", term.value);
                    has_fails = true;
                    continue;
                }
            };
            let name = match name.value {
                Term::Unresolved(ResolvableName::Ident(i)) => Spanned::new(i, name.span),
                _ => {
                    self.emit(
                        DiagBuilder2::error(format!(
                            "`{}` is not a valid record element name",
                            name.span.extract()
                        ))
                        .span(name.span),
                    );
                    debugln!("It is a {:#?}", name.value);
                    has_fails = true;
                    continue;
                }
            };

            // Make sure a field is not constrained twice.
            if let Some(&span) = used_names.get(&name.value) {
                self.emit(
                    DiagBuilder2::error(format!(
                        "element `{}` has already been constrained",
                        name.value
                    ))
                    .span(name.span)
                    .add_note("Previous constraint was here:")
                    .span(span),
                );
                has_fails = true;
                continue;
            } else {
                used_names.insert(name.value, name.span);
            }

            // Parse the constraint.
            fields.push((name, Box::new(self.term_to_element_constraint(con)?)));
        }
        if has_fails {
            return Err(());
        }
        Ok(Spanned::new(
            hir::RecordConstraint {
                span: span,
                elems: fields,
            },
            span,
        ))
    }
/// Map a term to a record constraint.
Map a term to a record constraint.
Map a term to a record constraint .
pub fn term_to_record_constraint(
        &self,
        span: Span,
        terms: Vec<Spanned<Term>>,
    ) -> Result<Spanned<hir::RecordConstraint>> {
        if terms.is_empty() {
            self.emit(DiagBuilder2::error(format!("record constraint cannot be empty")).span(span));
            return Err(());
        }
        let mut fields = Vec::new();
        let mut has_fails = false;
        let mut used_names = HashMap::new();
        for term in terms {
            // Make sure that the term is of the form `field (constraint)`.
            let (name, con) = match term.value {
                Term::SuffixParen(name, con) => (name, *con),
                _ => {
                    self.emit(
                        DiagBuilder2::error(format!(
                            "`{}` is not a valid constraint for a record element",
                            term.span.extract()
                        ))
                        .span(term.span)
                        .add_note(
                            "Element constraints must be of the form `name (constraint)`. See \
                             IEEE 1076-2008 section 5.3.3.",
                        ),
                    );
                    debugln!("It is a {:#?}", term.value);
                    has_fails = true;
                    continue;
                }
            };
            let name = match name.value {
                Term::Unresolved(ResolvableName::Ident(i)) => Spanned::new(i, name.span),
                _ => {
                    self.emit(
                        DiagBuilder2::error(format!(
                            "`{}` is not a valid record element name",
                            name.span.extract()
                        ))
                        .span(name.span),
                    );
                    debugln!("It is a {:#?}", name.value);
                    has_fails = true;
                    continue;
                }
            };
            // Make sure a field is not constrained twice.
            if let Some(&span) = used_names.get(&name.value) {
                self.emit(
                    DiagBuilder2::error(format!(
                        "element `{}` has already been constrained",
                        name.value
                    ))
                    .span(name.span)
                    .add_note("Previous constraint was here:")
                    .span(span),
                );
                has_fails = true;
                continue;
            } else {
                used_names.insert(name.value, name.span);
            }
            // Parse the constraint.
            fields.push((name, Box::new(self.term_to_element_constraint(con)?)));
        }
        if has_fails {
            return Err(());
        }
        Ok(Spanned::new(
            hir::RecordConstraint {
                span: span,
                elems: fields,
            },
            span,
        ))
    }
pub fn term_to_record_constraint ( & self , span : Span , terms : Vec < Spanned < Term > > , ) -> Result < Spanned < hir :: RecordConstraint > > { if terms . is_empty ( ) { self . emit ( DiagBuilder2 :: error ( format ! ( " " ) ) . span ( span ) ) ; return Err ( ( ) ) ; } let mut fields = Vec :: new ( ) ; let mut has_fails = false ; let mut used_names = HashMap :: new ( ) ; for term in terms { // Make sure that the term is of the form `field (constraint)`. let ( name , con ) = match term . value { Term :: SuffixParen ( name , con ) => ( name , * con ) , _ => { self . emit ( DiagBuilder2 :: error ( format ! ( " " term span extract ( ) ) ) . span ( term . span ) . add_note ( " \
 " , ) , ) ; debugln ! ( " " term value ) ; has_fails = true ; continue ; } } ; let name = match name . value { Term :: Unresolved ( ResolvableName :: Ident ( i ) ) => Spanned :: new ( i , name . span ) , _ => { self . emit ( DiagBuilder2 :: error ( format ! ( " " name span extract ( ) ) ) . span ( name . span ) , ) ; debugln ! ( " " name value ) ; has_fails = true ; continue ; } } ; // Make sure a field is not constrained twice. if let Some ( & span ) = used_names . get ( & name . value ) { self . emit ( DiagBuilder2 :: error ( format ! ( " " name value ) ) . span ( name . span ) . add_note ( " " ) . span ( span ) , ) ; has_fails = true ; continue ; } else { used_names . insert ( name . value , name . span ) ; } // Parse the constraint. fields . push ( ( name , Box :: new ( self . term_to_element_constraint ( con ) ? ) ) ) ; } if has_fails { return Err ( ( ) ) ; } Ok ( Spanned :: new ( hir :: RecordConstraint { span : span , elems : fields , } , span , ) ) }
Map a term to a record constraint.
Map a term to a record constraint .
&self
span
Span
terms
Vec<Spanned<Term>>
&self
span
Span
terms
Vec<Spanned<Term>>