MCPcopy Index your code
hub / github.com/RustPython/RustPython / warn_invalid_escape_sequence

Function warn_invalid_escape_sequence

crates/vm/src/vm/compile.rs:175–200  ·  view source on GitHub ↗

Emit `SyntaxWarning` for an invalid escape sequence. `warn_invalid_escape_sequence()` in `Parser/string_parser.c`

(
        source: &str,
        ch: char,
        offset: usize,
        filename: &str,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

173 ///
174 /// `warn_invalid_escape_sequence()` in `Parser/string_parser.c`
175 fn warn_invalid_escape_sequence(
176 source: &str,
177 ch: char,
178 offset: usize,
179 filename: &str,
180 vm: &VirtualMachine,
181 ) {
182 let lineno = line_number_at(source, offset);
183 let message = vm.ctx.new_str(format!(
184 "\"\\{ch}\" is an invalid escape sequence. \
185 Such sequences will not work in the future. \
186 Did you mean \"\\\\{ch}\"? A raw string is also an option."
187 ));
188 let fname = vm.ctx.new_str(filename);
189 let _ = warn::warn_explicit(
190 Some(vm.ctx.exceptions.syntax_warning.to_owned()),
191 message.into(),
192 fname,
193 lineno,
194 None,
195 vm.ctx.none(),
196 None,
197 None,
198 vm,
199 );
200 }
201
202 struct EscapeWarningVisitor<'a> {
203 source: &'a str,

Callers 2

check_quoted_literalMethod · 0.85
check_fstring_literalMethod · 0.85

Calls 6

line_number_atFunction · 0.85
noneMethod · 0.80
warn_explicitFunction · 0.50
SomeClass · 0.50
new_strMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected