Repository: rust-lang/rust
File: compiler/rustc_resolve/src/build_reduced_graph.rs (Rust)

Code before:
                    kw::Crate => {
                        if !module_path.is_empty() {
                            self.r.dcx().span_err(
                                source.ident.span,
                                "`crate` in paths can only be used in start position",
                            );
                            return;
                        }
                    }
                    kw::Super => {
                        // Allow `self::super` as a valid prefix - `self` at position 0
                        // followed by any number of `super` segments.
                        let valid_prefix = module_path.iter().enumerate().all(|(i, seg)| {
                            let name = seg.ident.name;
                            name == kw::Super || (name == kw::SelfLower && i == 0)
                        });

                        if !valid_prefix {
                            self.r.dcx().span_err(
                                source.ident.span,
                                "`super` in paths can only be used in start position, after `self`, or after another `super`",
                            );
                            return;
                        }
                    }
                    kw::SelfLower => {
                        if let Some(parent) = module_path.pop() {
                            // Suggest `use prefix::{self};` for `use prefix::self;`
                            if !type_ns_only
                                && (parent.ident.name != kw::PathRoot
                                    || self.r.path_root_is_crate_root(parent.ident))
                            {
                                let span_with_rename = match rename {
                                    Some(rename) => source.ident.span.to(rename.span),
                                    None => source.ident.span,
                                };

                                self.r.report_error(
                                    parent.ident.span.shrink_to_hi().to(source.ident.span),
                                    ResolutionError::SelfImportsOnlyAllowedWithin {
                                        root: parent.ident.name == kw::PathRoot,
                                        span_with_rename,
                                    },
                                );
                            }

                            let self_span = source.ident.span;
                            source = parent;
                            if rename.is_none() {
                                ident = Ident::new(source.ident.name, self_span);
                            }

Review comment (suggestion):
It looks like moving the code wasn't necessary, could you keep it in its old place?
Now I don't see what the actual difference is.

Code after:
                            None => source.ident.span,
                        };

                        self.r.report_error(
                            parent.ident.span.shrink_to_hi().to(source.ident.span),
                            ResolutionError::SelfImportsOnlyAllowedWithin {
                                root: parent.ident.name == kw::PathRoot,
                                span_with_rename,
                            },
                        );
                    }

                    let self_span = source.ident.span;
                    source = parent;
                    if rename.is_none() {
                        ident = Ident::new(source.ident.name, self_span);
                    }
                }

                match source.ident.name {
                    kw::DollarCrate => {
                        if !module_path.is_empty() {
                            self.r.dcx().span_err(
                                source.ident.span,
                                "`$crate` in paths can only be used in start position",
                            );
                            return;
                        }
                    }
                    kw::Crate => {
                        if !module_path.is_empty() {
                            self.r.dcx().span_err(
                                source.ident.span,
                                "`crate` in paths can only be used in start position",
                            );
                            return;
                        }
                    }
                    kw::Super => {
                        // Allow `self::super` as a valid prefix - `self` at position 0
                        // followed by any number of `super` segments.
                        let valid_prefix = module_path.iter().enumerate().all(|(i, seg)| {
                            let name = seg.ident.name;
                            name == kw::Super || (name == kw::SelfLower && i == 0)
                        });

                        if !valid_prefix {
                            self.r.dcx().span_err(
                                source.ident.span,
                                "`super` in paths can only be used in start position, after `self`, or after another `super`",
                            );