Help! I get this weird error message!

I need some help with:

use std::fs;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::string;
use std::prelude::rust_2021::String as String;

pub fn main() {
    let data = fs::read_to_string("config.set");
    let fsread = data;
    let mut stringset:String;
    let mut auga:String;
    let mut augb:String;
    let mut setting;
	let mut stringsetaug:String;
    setting = "B";
	let mut f = BufReader::new(File::open("main.fs").expect("open failed"));
    for line in f.lines() {
        for c in line.expect("lines failed").chars() {
            // main system
            if c != ' ' {
            } else {
                setting = "A";
                if c != ';' {
					if setting != "A" {

It gives me this error:

error[E0381]: borrow of possibly-uninitialized variable: `stringset`
  --> C:\Users\staff\.cargo\bin\myapp\
21 |             stringset.push(c);
   |             ^^^^^^^^^ use of possibly-uninitialized `stringset`

error[E0381]: borrow of possibly-uninitialized variable: `stringsetaug`
  --> C:\Users\staff\.cargo\bin\myapp\
28 |                         stringsetaug.push(c);
   |                         ^^^^^^^^^^^^ use of possibly-uninitialized `stringsetaug`

error: aborting due to 2 previous errors; 6 warnings emitted

For more information about this error, try `rustc --explain E0381`.

Can anyone help me?
NOTICE: This is to make a simple coding language that takes code and converts it to rust.

I clearly defined the vars, so they are initialized, right?

I think you need

let mut stringsetaug:String = String::new();

1 Like

No, you need to assign them a value.

1 Like

No, variable definition doesn't implies initialization. Normally you don't need to explicitly annotate the type of the variables as they usually can be inferred clearly from the initialization code.

let mut stringset = String::new();


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.